speccpu: add benchdir related utils
This commit is contained in:
@@ -3,7 +3,7 @@ from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from speccpu import SPEC, find_build
|
||||
from speccpu import SPEC, check_bench_dir, find_build
|
||||
|
||||
|
||||
class TestFindBuild:
|
||||
@@ -79,3 +79,66 @@ class TestSPEC:
|
||||
cmd = spec.mkcmd_runcpu("myconfig", ["benchmark1"], output_root=output_dir)
|
||||
assert "--outputdir" in cmd
|
||||
assert str(output_dir) in cmd
|
||||
|
||||
|
||||
class TestCheckBenchDir:
|
||||
def test_valid_bench_dir(self, tmpdir):
|
||||
"""Test that check_bench_dir returns True for a valid benchmark directory."""
|
||||
bench_dir = Path(tmpdir)
|
||||
|
||||
# Create the required subdirectories
|
||||
(bench_dir / "build").mkdir()
|
||||
(bench_dir / "exe").mkdir()
|
||||
(bench_dir / "run").mkdir()
|
||||
|
||||
# Add some extra files/directories to make sure they don't affect the result
|
||||
(bench_dir / "other_dir").mkdir()
|
||||
(bench_dir / "file.txt").write_text("test")
|
||||
|
||||
assert check_bench_dir(bench_dir) is True
|
||||
|
||||
def test_invalid_bench_dir_missing_build(self, tmpdir):
|
||||
"""Test that check_bench_dir returns False when 'build' directory is missing."""
|
||||
bench_dir = Path(tmpdir)
|
||||
|
||||
# Create only exe and run directories
|
||||
(bench_dir / "exe").mkdir()
|
||||
(bench_dir / "run").mkdir()
|
||||
|
||||
assert check_bench_dir(bench_dir) is False
|
||||
|
||||
def test_invalid_bench_dir_missing_exe(self, tmpdir):
|
||||
"""Test that check_bench_dir returns False when 'exe' directory is missing."""
|
||||
bench_dir = Path(tmpdir)
|
||||
|
||||
# Create only build and run directories
|
||||
(bench_dir / "build").mkdir()
|
||||
(bench_dir / "run").mkdir()
|
||||
|
||||
assert check_bench_dir(bench_dir) is False
|
||||
|
||||
def test_invalid_bench_dir_missing_run(self, tmpdir):
|
||||
"""Test that check_bench_dir returns False when 'run' directory is missing."""
|
||||
bench_dir = Path(tmpdir)
|
||||
|
||||
# Create only build and exe directories
|
||||
(bench_dir / "build").mkdir()
|
||||
(bench_dir / "exe").mkdir()
|
||||
|
||||
assert check_bench_dir(bench_dir) is False
|
||||
|
||||
def test_empty_dir(self, tmpdir):
|
||||
"""Test that check_bench_dir returns False for an empty directory."""
|
||||
bench_dir = Path(tmpdir)
|
||||
assert check_bench_dir(bench_dir) is False
|
||||
|
||||
def test_invalid_dir_case_sensitive(self, tmpdir):
|
||||
"""Test that check_bench_dir is case-sensitive."""
|
||||
bench_dir = Path(tmpdir)
|
||||
|
||||
# Create directories with different case
|
||||
(bench_dir / "Build").mkdir()
|
||||
(bench_dir / "EXE").mkdir()
|
||||
(bench_dir / "RUN").mkdir()
|
||||
|
||||
assert check_bench_dir(bench_dir) is False
|
||||
|
||||
Reference in New Issue
Block a user