Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / simix / stack-overflow / stack-overflow.cpp
1 /* stack_overflow -- simple program generating a stack overflow             */
2
3 /* Copyright (c) 2014-2018. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "simgrid/simix.h"
9 #include "xbt/log.h"
10
11 #include <string>
12
13 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "my log messages");
14
15 static unsigned collatz(unsigned c0, unsigned n)
16 {
17   unsigned x;
18   if (n == 0) {
19     x = c0;
20   } else {
21     x = collatz(c0, n - 1);
22     if (x % 2 == 0)
23       x = x / 2;
24     else
25       x = 3 * x + 1;
26   }
27   return x;
28 }
29
30 static int master(int argc, char* argv[])
31 {
32   XBT_INFO("Launching our nice bugged recursive function...");
33   unsigned i = 1;
34   while (i <= 0x80000000U) {
35     i *= 2;
36     unsigned res = collatz(i, i);
37     XBT_VERB("collatz(%u, %u) returned %u", i, i, res);
38   }
39   return 0;
40 }
41
42 int main(int argc, char* argv[])
43 {
44   SIMIX_global_init(&argc, argv);
45
46   xbt_assert(argc == 2, "Usage: %s platform.xml\n", argv[0]);
47
48   SIMIX_function_register("master", master);
49   SIMIX_create_environment(argv[1]);
50   simcall_process_create("master", master, NULL, sg_host_by_name("Tremblay"), 0, NULL, NULL);
51   SIMIX_run();
52
53   return 0;
54 }