Skip to content

Commit

Permalink
tests/run-perfbench.py: Don't allow imports from the cwd.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jimmo committed Jun 8, 2023
1 parent 1097174 commit 339f02a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/perf_bench/core_import_mpy_multi.py
Expand Up @@ -47,7 +47,7 @@ def chdir(self, path):
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
Expand All @@ -58,7 +58,7 @@ def open(self, path, mode):

def mount():
os.mount(FS(), "/__remote")
os.chdir("/__remote")
sys.path.insert(0, "/__remote")


def test(r):
Expand Down
6 changes: 3 additions & 3 deletions tests/perf_bench/core_import_mpy_single.py
Expand Up @@ -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")
Expand Down Expand Up @@ -102,7 +102,7 @@ def chdir(self, path):
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
Expand All @@ -113,7 +113,7 @@ def open(self, path, mode):

def mount():
os.mount(FS(), "/__remote")
os.chdir("/__remote")
sys.path.insert(0, "/__remote")


def test():
Expand Down
3 changes: 2 additions & 1 deletion tests/run-perfbench.py
Expand Up @@ -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)
Expand Down

0 comments on commit 339f02a

Please sign in to comment.