Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / teshsuite / kernel / stack-overflow / stack-overflow.cpp
1 /* stack_overflow -- simple program generating a stack overflow             */
2
3 /* Copyright (c) 2014-2022. 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/s4u/Actor.hpp"
9 #include "simgrid/s4u/Engine.hpp"
10 #include "xbt/asserts.h"
11 #include "xbt/log.h"
12
13 #include <string>
14
15 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "my log messages");
16
17 static unsigned collatz(unsigned c0, unsigned n)
18 {
19   unsigned x;
20   if (n == 0) {
21     x = c0;
22   } else {
23     x = collatz(c0, n - 1);
24     if (x % 2 == 0)
25       x = x / 2;
26     else
27       x = 3 * x + 1;
28   }
29   return x;
30 }
31
32 static void master()
33 {
34   XBT_INFO("Launching our nice bugged recursive function...");
35   unsigned i = 1;
36   while (i <= 0x80000000U) {
37     i *= 2;
38     unsigned res = collatz(i, i);
39     XBT_VERB("collatz(%u, %u) returned %u", i, i, res);
40   }
41 }
42
43 int main(int argc, char* argv[])
44 {
45   simgrid::s4u::Engine e(&argc, argv);
46
47   xbt_assert(argc == 2, "Usage: %s platform.xml\n", argv[0]);
48
49   e.load_platform(argv[1]);
50   simgrid::s4u::Actor::create("master", e.host_by_name("Tremblay"), master);
51   e.run();
52
53   return 0;
54 }