Skip to content

Commit 0b0f44e

Browse files
committed
Allow running semaphore test only any platform.
1 parent f76d7d3 commit 0b0f44e

2 files changed

Lines changed: 55 additions & 41 deletions

File tree

test/semaphore.py

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,117 @@
11
#!/usr/bin/env python3
22

33
# Copyright 2026 Paolo Pastori
4+
# Copyright 2026 Rene Ferdinand Rivera Morell
45
# Distributed under the Boost Software License, Version 1.0.
56
# (See accompanying file LICENSE.txt or https://www.bfgroup.xyz/b2/LICENSE.txt)
67

78
# Test for the JAM_SEMAPHORE variable:
89
# verify that actions for targets sharing the same named semaphore
910
# cannot be run in parallel.
1011

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-
1712
import sys
1813

14+
1915
def touch(fname):
20-
with open(fname, 'w'):
16+
with open(fname, "w"):
2117
pass
2218

19+
2320
def update(sentry, secs, target):
2421
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)
2727
from time import sleep
28+
2829
sleep(int(secs))
2930
touch(target)
3031
from os import unlink
32+
3133
try:
3234
unlink(sentry)
3335
except FileNotFoundError:
34-
print('PARALLEL UPDATE')
36+
print("PARALLEL UPDATE")
3537
except:
3638
pass
3739

40+
3841
if len(sys.argv) == 4:
3942
# called by jam udate action
4043
# ./semaphore.py <sentry_fname> <sleep_secs> <target_fname>
4144
update(*sys.argv[1:])
4245
sys.exit()
4346

4447
import os.path
48+
4549
# remember this script absolute pathname
4650
script = os.path.abspath(__file__)
4751

4852
import BoostBuild
4953
import shutil
5054

51-
t = BoostBuild.Tester(['-ffile.jam', '-j2'], pass_toolset=False)
55+
t = BoostBuild.Tester(["-ffile.jam"], pass_toolset=False)
5256

5357
# install in workdir a copy of this script
54-
shutil.copy(script, 'semaphore.py')
58+
shutil.copy(script, "semaphore.py")
5559

5660
# 1. test parallel execution of update
57-
t.write('file.jam', '''\
61+
t.write(
62+
"file.jam",
63+
"""\
5864
DEPENDS all : x1 x2 ;
5965
actions update
60-
{
61-
"./semaphore.py" sentry 1 $(<)
62-
}
66+
{{
67+
"{0}" "./semaphore.py" sentry 1 $(<)
68+
}}
6369
6470
update x1 ;
6571
update x2 ;
66-
''')
72+
""".format(
73+
sys.executable
74+
),
75+
)
6776

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")
7281

73-
t.rm('x1')
74-
t.rm('x2')
82+
t.rm("x1")
83+
t.rm("x2")
7584

7685
# 2. test parallel execution suppression by JAM_SEMAPHORE
77-
t.write('file.jam', '''\
86+
t.write(
87+
"file.jam",
88+
"""\
7889
DEPENDS all : x1 x2 ;
7990
actions update
80-
{
81-
"./semaphore.py" sentry 1 $(<)
82-
}
91+
{{
92+
"{0}" "./semaphore.py" sentry 1 $(<)
93+
}}
8394
8495
JAM_SEMAPHORE on x1 x2 = <s>update_sem ;
8596
8697
update x1 ;
8798
update x2 ;
88-
''')
99+
""".format(
100+
sys.executable
101+
),
102+
)
89103

90-
expected_output = '''\
104+
expected_output = """\
91105
...found 3 targets...
92106
...updating 2 targets...
93107
update x1
94108
update x2
95109
96110
...updated 2 targets...
97-
'''
111+
"""
98112

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")
102116

103117
t.cleanup()

test/test_all.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,11 @@ def reorder_tests(tests, first_test):
316316
"cli_property_expansion",
317317
"command_line_properties",
318318
"composite",
319+
"conditionals_multiple",
319320
"conditionals",
320321
"conditionals2",
321322
"conditionals3",
322323
"conditionals4",
323-
"conditionals_multiple",
324324
"configuration",
325325
"configure",
326326
"copy_time",
@@ -330,7 +330,6 @@ def reorder_tests(tests, first_test):
330330
"core_at_file",
331331
"core_bindrule",
332332
"core_dependencies",
333-
"core_syntax_error_exit_status",
334333
"core_fail_expected",
335334
"core_jamshell",
336335
"core_modifiers",
@@ -344,6 +343,7 @@ def reorder_tests(tests, first_test):
344343
"core_parallel_multifile_actions_2",
345344
"core_scanner",
346345
"core_source_line_tracking",
346+
"core_syntax_error_exit_status",
347347
"core_update_now",
348348
"core_variables_in_actions",
349349
"custom_generator",
@@ -381,15 +381,15 @@ def reorder_tests(tests, first_test):
381381
"inline",
382382
"install_build_no",
383383
"lang_asm",
384+
"lib_source_property",
385+
"lib_zlib",
384386
"libjpeg",
385387
"liblzma",
386388
"libpng",
387-
"libtiff",
388-
"libzstd",
389-
"lib_source_property",
390-
"lib_zlib",
391389
"library_chain",
392390
"library_property",
391+
"libtiff",
392+
"libzstd",
393393
"link",
394394
"load_order",
395395
"loop",
@@ -413,9 +413,9 @@ def reorder_tests(tests, first_test):
413413
"project_dependencies",
414414
"project_glob",
415415
"project_id",
416-
"project_sub_resolution",
417416
"project_root_constants",
418417
"project_root_rule",
418+
"project_sub_resolution",
419419
"project_test3",
420420
"project_test4",
421421
"property_expansion",
@@ -429,6 +429,7 @@ def reorder_tests(tests, first_test):
429429
"rootless",
430430
"scanner_causing_rebuilds",
431431
"searched_lib",
432+
"semaphore",
432433
"skipping",
433434
"sort_rule",
434435
"source_locations",
@@ -462,7 +463,6 @@ def reorder_tests(tests, first_test):
462463
]
463464

464465
if os.name == "posix":
465-
tests.append("semaphore")
466466
tests.append("symlink")
467467
# On Windows, library order is not important, so skip this test. Besides,
468468
# it fails ;-). Further, the test relies on the fact that on Linux, one can

0 commit comments

Comments
 (0)