tests/run-perfbench.py: Don't allow imports from the cwd.

Make tests run in an isolated environment (i.e. `import io` would
otherwise get the `tests/io` directory).

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2023-06-02 15:40:03 +10:00
parent 109717457e
commit 339f02a594
3 changed files with 7 additions and 6 deletions

View File

@ -47,7 +47,7 @@ class FS:
pass
def stat(self, path):
if path == "__injected.mpy":
if path == "/__injected.mpy":
return tuple(0 for _ in range(10))
else:
raise OSError(-2) # ENOENT
@ -58,7 +58,7 @@ class FS:
def mount():
os.mount(FS(), "/__remote")
os.chdir("/__remote")
sys.path.insert(0, "/__remote")
def test(r):

View File

@ -2,7 +2,7 @@
# The first import of a module will intern strings that don't already exist, and
# this test should be representative of what happens in a real application.
import io, os
import io, os, sys
if not (hasattr(io, "IOBase") and hasattr(os, "mount")):
print("SKIP")
@ -102,7 +102,7 @@ class FS:
pass
def stat(self, path):
if path == "__injected.mpy":
if path == "/__injected.mpy":
return tuple(0 for _ in range(10))
else:
raise OSError(-2) # ENOENT
@ -113,7 +113,7 @@ class FS:
def mount():
os.mount(FS(), "/__remote")
os.chdir("/__remote")
sys.path.insert(0, "/__remote")
def test():

View File

@ -109,8 +109,9 @@ def run_benchmarks(args, target, param_n, param_m, n_average, test_list):
continue
# Create test script
test_script = b"import sys\nsys.path.remove('')\n\n"
with open(test_file, "rb") as f:
test_script = f.read()
test_script += f.read()
with open(BENCH_SCRIPT_DIR + "benchrun.py", "rb") as f:
test_script += f.read()
test_script += b"bm_run(%u, %u)\n" % (param_n, param_m)