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:
parent
109717457e
commit
339f02a594
@ -47,7 +47,7 @@ class FS:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def stat(self, path):
|
def stat(self, path):
|
||||||
if path == "__injected.mpy":
|
if path == "/__injected.mpy":
|
||||||
return tuple(0 for _ in range(10))
|
return tuple(0 for _ in range(10))
|
||||||
else:
|
else:
|
||||||
raise OSError(-2) # ENOENT
|
raise OSError(-2) # ENOENT
|
||||||
@ -58,7 +58,7 @@ class FS:
|
|||||||
|
|
||||||
def mount():
|
def mount():
|
||||||
os.mount(FS(), "/__remote")
|
os.mount(FS(), "/__remote")
|
||||||
os.chdir("/__remote")
|
sys.path.insert(0, "/__remote")
|
||||||
|
|
||||||
|
|
||||||
def test(r):
|
def test(r):
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# The first import of a module will intern strings that don't already exist, and
|
# 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.
|
# 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")):
|
if not (hasattr(io, "IOBase") and hasattr(os, "mount")):
|
||||||
print("SKIP")
|
print("SKIP")
|
||||||
@ -102,7 +102,7 @@ class FS:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def stat(self, path):
|
def stat(self, path):
|
||||||
if path == "__injected.mpy":
|
if path == "/__injected.mpy":
|
||||||
return tuple(0 for _ in range(10))
|
return tuple(0 for _ in range(10))
|
||||||
else:
|
else:
|
||||||
raise OSError(-2) # ENOENT
|
raise OSError(-2) # ENOENT
|
||||||
@ -113,7 +113,7 @@ class FS:
|
|||||||
|
|
||||||
def mount():
|
def mount():
|
||||||
os.mount(FS(), "/__remote")
|
os.mount(FS(), "/__remote")
|
||||||
os.chdir("/__remote")
|
sys.path.insert(0, "/__remote")
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
|
@ -109,8 +109,9 @@ def run_benchmarks(args, target, param_n, param_m, n_average, test_list):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# Create test script
|
# Create test script
|
||||||
|
test_script = b"import sys\nsys.path.remove('')\n\n"
|
||||||
with open(test_file, "rb") as f:
|
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:
|
with open(BENCH_SCRIPT_DIR + "benchrun.py", "rb") as f:
|
||||||
test_script += f.read()
|
test_script += f.read()
|
||||||
test_script += b"bm_run(%u, %u)\n" % (param_n, param_m)
|
test_script += b"bm_run(%u, %u)\n" % (param_n, param_m)
|
||||||
|
Loading…
Reference in New Issue
Block a user