|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | 3 | # Copyright 2026 Paolo Pastori |
| 4 | +# Copyright 2026 Rene Ferdinand Rivera Morell |
4 | 5 | # Distributed under the Boost Software License, Version 1.0. |
5 | 6 | # (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt) |
6 | 7 |
|
7 | 8 | # Test for the JAM_SEMAPHORE variable: |
8 | 9 | # verify that actions for targets sharing the same named semaphore |
9 | 10 | # cannot be run in parallel. |
10 | 11 |
|
11 | | -# NOTE: because of the jam update action calling this python script |
12 | | -# (actually a copy), this test does not work on non-posix platforms, |
13 | | -# this limitation is primarily due to different launchers, python |
14 | | -# interpreter/shell conventions to be used on non posix platform |
15 | | -# (e.g. windows) of which b2 is not aware of. |
16 | | - |
17 | 12 | import sys |
18 | 13 |
|
| 14 | + |
19 | 15 | def touch(fname): |
20 | | - with open(fname, 'w'): |
| 16 | + with open(fname, "w"): |
21 | 17 | pass |
22 | 18 |
|
| 19 | + |
23 | 20 | def update(sentry, secs, target): |
24 | 21 | from os.path import isfile |
25 | | - if isfile(sentry): print('PARALLEL UPDATE') |
26 | | - else: touch(sentry) |
| 22 | + |
| 23 | + if isfile(sentry): |
| 24 | + print("PARALLEL UPDATE") |
| 25 | + else: |
| 26 | + touch(sentry) |
27 | 27 | from time import sleep |
| 28 | + |
28 | 29 | sleep(int(secs)) |
29 | 30 | touch(target) |
30 | 31 | from os import unlink |
| 32 | + |
31 | 33 | try: |
32 | 34 | unlink(sentry) |
33 | 35 | except FileNotFoundError: |
34 | | - print('PARALLEL UPDATE') |
| 36 | + print("PARALLEL UPDATE") |
35 | 37 | except: |
36 | 38 | pass |
37 | 39 |
|
| 40 | + |
38 | 41 | if len(sys.argv) == 4: |
39 | 42 | # called by jam udate action |
40 | 43 | # ./semaphore.py <sentry_fname> <sleep_secs> <target_fname> |
41 | 44 | update(*sys.argv[1:]) |
42 | 45 | sys.exit() |
43 | 46 |
|
44 | 47 | import os.path |
| 48 | + |
45 | 49 | # remember this script absolute pathname |
46 | 50 | script = os.path.abspath(__file__) |
47 | 51 |
|
48 | 52 | import BoostBuild |
49 | 53 | import shutil |
50 | 54 |
|
51 | | -t = BoostBuild.Tester(['-ffile.jam', '-j2'], pass_toolset=False) |
| 55 | +t = BoostBuild.Tester(["-ffile.jam"], pass_toolset=False) |
52 | 56 |
|
53 | 57 | # install in workdir a copy of this script |
54 | | -shutil.copy(script, 'semaphore.py') |
| 58 | +shutil.copy(script, "semaphore.py") |
55 | 59 |
|
56 | 60 | # 1. test parallel execution of update |
57 | | -t.write('file.jam', '''\ |
| 61 | +t.write( |
| 62 | + "file.jam", |
| 63 | + """\ |
58 | 64 | DEPENDS all : x1 x2 ; |
59 | 65 | actions update |
60 | | -{ |
61 | | - "./semaphore.py" sentry 1 $(<) |
62 | | -} |
| 66 | +{{ |
| 67 | + "{0}" "./semaphore.py" sentry 1 $(<) |
| 68 | +}} |
63 | 69 |
|
64 | 70 | update x1 ; |
65 | 71 | update x2 ; |
66 | | -''') |
| 72 | +""".format( |
| 73 | + sys.executable |
| 74 | + ), |
| 75 | +) |
67 | 76 |
|
68 | | -t.run_build_system() |
69 | | -t.expect_addition('x1') |
70 | | -t.expect_addition('x2') |
71 | | -t.expect_output_lines('PARALLEL UPDATE') |
| 77 | +t.run_build_system(extra_args=["-j2"]) |
| 78 | +t.expect_addition("x1") |
| 79 | +t.expect_addition("x2") |
| 80 | +t.expect_output_lines("PARALLEL UPDATE") |
72 | 81 |
|
73 | | -t.rm('x1') |
74 | | -t.rm('x2') |
| 82 | +t.rm("x1") |
| 83 | +t.rm("x2") |
75 | 84 |
|
76 | 85 | # 2. test parallel execution suppression by JAM_SEMAPHORE |
77 | | -t.write('file.jam', '''\ |
| 86 | +t.write( |
| 87 | + "file.jam", |
| 88 | + """\ |
78 | 89 | DEPENDS all : x1 x2 ; |
79 | 90 | actions update |
80 | | -{ |
81 | | - "./semaphore.py" sentry 1 $(<) |
82 | | -} |
| 91 | +{{ |
| 92 | + "{0}" "./semaphore.py" sentry 1 $(<) |
| 93 | +}} |
83 | 94 |
|
84 | 95 | JAM_SEMAPHORE on x1 x2 = <s>update_sem ; |
85 | 96 |
|
86 | 97 | update x1 ; |
87 | 98 | update x2 ; |
88 | | -''') |
| 99 | +""".format( |
| 100 | + sys.executable |
| 101 | + ), |
| 102 | +) |
89 | 103 |
|
90 | | -expected_output = '''\ |
| 104 | +expected_output = """\ |
91 | 105 | ...found 3 targets... |
92 | 106 | ...updating 2 targets... |
93 | 107 | update x1 |
94 | 108 | update x2 |
95 | 109 |
|
96 | 110 | ...updated 2 targets... |
97 | | -''' |
| 111 | +""" |
98 | 112 |
|
99 | | -t.run_build_system(stdout=expected_output) |
100 | | -t.expect_addition('x1') |
101 | | -t.expect_addition('x2') |
| 113 | +t.run_build_system(stdout=expected_output, extra_args=["-j2"]) |
| 114 | +t.expect_addition("x1") |
| 115 | +t.expect_addition("x2") |
102 | 116 |
|
103 | 117 | t.cleanup() |
0 commit comments