Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
342c9cd70e99292bb681f75e5f0d739dec592627
[simgrid.git] / teshsuite / simix / stack_overflow / stack_overflow.c
1 /* stack_overflow -- simple program generating a stack overflow          */
2
3 /* Copyright (c) 2014. The SimGrid Team.
4  * All rights reserved.                                                     */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "simgrid/platf.h"
10 #include "simgrid/simix.h"
11 #include "xbt/log.h"
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   do {
35     i *= 2;
36     unsigned res = collatz(i, i);
37     XBT_VERB("collatz(%u, %u) returned %u", i, i, res);
38   } while (i <= 0x80000000u);
39   return 0;
40 }
41
42 int main(int argc, char *argv[])
43 {
44   SIMIX_global_init(&argc, argv);
45
46   if (argc != 3) {
47     printf("Usage: %s platform.xml deployment.xml\n", argv[0]);
48     exit(EXIT_FAILURE);
49   }
50
51   SIMIX_function_register("master", master);
52   SIMIX_create_environment(argv[1]);
53   SIMIX_launch_application(argv[2]);
54   SIMIX_run();
55
56   return 0;
57 }