Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / teshsuite / python / corrupt-stack / corrupt-stack.py
1 # Copyright (c) 2019-2023. The SimGrid Team. All rights reserved.
2 #
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the license (GNU LGPL) which comes with this package.
5
6 """
7 Second failing example for bug #9 on Framagit (Python bindings crashing)
8
9 An intricate recursion is used to make the crash happen.
10 """
11
12 import sys
13 from simgrid import Engine, this_actor
14
15 def do_sleep1(i, dur):
16     if i > 0:
17         this_actor.info("1-Iter {:d}".format(i))
18         do_sleep3(i - 1, dur)
19         this_actor.sleep_for(dur)
20         this_actor.info("1-Mid ({:d})".format(i))
21         do_sleep3(int(i / 2), dur)
22         this_actor.info("1-Done ({:d})".format(i))
23
24 def do_sleep3(i, dur):
25     if i > 0:
26         this_actor.info("3-Iter {:d}".format(i))
27         do_sleep5(i - 1, dur)
28         this_actor.sleep_for(dur)
29         this_actor.info("3-Mid ({:d})".format(i))
30         do_sleep5(int(i / 2), dur)
31         this_actor.info("3-Done ({:d})".format(i))
32
33 def do_sleep5(i, dur):
34     if i > 0:
35         this_actor.info("5-Iter {:d}".format(i))
36         do_sleep1(i - 1, dur)
37         this_actor.sleep_for(dur)
38         this_actor.info("5-Mid ({:d})".format(i))
39         do_sleep1(int(i / 2), dur)
40         this_actor.info("5-Done ({:d})".format(i))
41
42 def sleeper1():
43     do_sleep1(16, 1)
44
45 def sleeper3():
46     do_sleep3(6, 3)
47
48 def sleeper5():
49     do_sleep5(4, 5)
50
51 if __name__ == '__main__':
52     e = Engine(sys.argv)
53
54     e.load_platform(sys.argv[1])             # Load the platform description
55
56     # Register the classes representing the actors
57     e.register_actor("sleeper1", sleeper1)
58     e.register_actor("sleeper3", sleeper3)
59     e.register_actor("sleeper5", sleeper5)
60
61     e.load_deployment(sys.argv[2])
62
63     e.run()
64     this_actor.info("Finalize!")