Skip to content

Commit b234414

Browse files
authored
Allow execution under analysis tools (#207)
Performance analysis and memory debugging tools such as Perf and Valgrind do not currently work with Charm4Py's charmrun.start. This patch enables the use of charmrun.start with these tools.
1 parent 217f706 commit b234414

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

auto_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def searchForPython(python_implementations):
6969
if num_tests >= CHARM_QUIET_AFTER_NUM_TESTS and '++quiet' not in commonArgs:
7070
additionalArgs.append('++quiet')
7171
cmd = ['charmrun/charmrun']
72+
if test.get('prefix'):
73+
cmd += [test['prefix']]
7274
if not test.get('interactive', False):
7375
cmd += [python] + [test['path']]
7476
else:

charmrun/start.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
33
import os.path
44

55

6+
def executable_is_python(args):
7+
"""
8+
Determines whether the first executable passed to args is a
9+
Python file. Other valid examples include analysis tools
10+
such as Perf that will run the actual Python program.
11+
12+
Note: Returns true if no executable was found or if an executable
13+
was found and that executable is a Python file.
14+
"""
15+
def is_exe(fpath):
16+
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
17+
18+
def is_pyfile(fpath):
19+
return os.path.isfile(fpath) and fpath.endswith(".py")
20+
for each in args:
21+
if is_pyfile(each):
22+
return True
23+
if is_exe(each):
24+
return False
25+
# No executable was found, but we'll let Python tell us
26+
return True
27+
28+
629
def nodelist_islocal(filename, regexp):
730
if not os.path.exists(filename):
831
# it is an error if filename doesn't exist, but I'll let charmrun print
@@ -53,7 +76,11 @@ def start(args=[]):
5376
args += ['-m', 'charm4py.interactive']
5477

5578
cmd = [os.path.join(os.path.dirname(__file__), 'charmrun')]
56-
cmd.append(sys.executable) # for example: /usr/bin/python3
79+
if executable_is_python(args):
80+
# Note: sys.executable is the absolute path to the Python interpreter
81+
# We only want to invoke the interpreter if the execution target is a
82+
# Python file
83+
cmd.append(sys.executable) # for example: /usr/bin/python3
5784
cmd.extend(args)
5885
try:
5986
return subprocess.call(cmd)

test_config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@
288288
{
289289
"path": "examples/simple/hello_world.py"
290290
},
291+
{
292+
"prefix": "tests/exec.sh",
293+
"path": "examples/simple/hello_world.py"
294+
},
291295
{
292296
"condition": "numbaInstalled",
293297
"path": "examples/wave2d/wave2d.py",

tests/exec.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
# Just execute the given command
3+
"$@"

0 commit comments

Comments
 (0)