82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
import pytest
|
|
|
|
from speccpu import SPEC, find_build
|
|
|
|
|
|
class TestFindBuild:
|
|
def test_find_build_success(self, tmpdir):
|
|
# Create a mock directory structure with a build directory
|
|
build_parent = Path(tmpdir)
|
|
build_dir = build_parent / "build_2023"
|
|
build_dir.mkdir()
|
|
|
|
# Test that find_build correctly identifies the build directory
|
|
found_dir = find_build(build_parent)
|
|
assert found_dir == build_dir
|
|
|
|
def test_find_build_multiple_dirs(self, tmpdir):
|
|
# Create multiple build directories
|
|
build_parent = Path(tmpdir)
|
|
build_dir1 = build_parent / "build_2022"
|
|
build_dir2 = build_parent / "build_2023"
|
|
build_dir1.mkdir()
|
|
build_dir2.mkdir()
|
|
|
|
# Should find the alphabetically first one
|
|
found_dir = find_build(build_parent)
|
|
assert found_dir == build_dir1
|
|
|
|
def test_find_build_no_dir(self, tmpdir):
|
|
# Test the error case when no build directory exists
|
|
build_parent = Path(tmpdir)
|
|
with pytest.raises(RuntimeError):
|
|
find_build(build_parent)
|
|
|
|
|
|
class TestSPEC:
|
|
def test_init(self):
|
|
spec_dir = Path("/path/to/spec")
|
|
spec = SPEC(spec_dir)
|
|
assert spec.dir == spec_dir
|
|
|
|
def test_config_dir(self):
|
|
spec_dir = Path("/path/to/spec")
|
|
spec = SPEC(spec_dir)
|
|
assert spec.config_dir == spec_dir / "config"
|
|
|
|
def test_env(self):
|
|
spec_dir = Path("/path/to/spec")
|
|
spec = SPEC(spec_dir)
|
|
with mock.patch("speccpu.create_spec_env") as mock_create_env:
|
|
spec.env()
|
|
mock_create_env.assert_called_once_with(spec_dir)
|
|
|
|
def test_mkcmd_runcpu_default(self):
|
|
spec = SPEC(Path("/path/to/spec"))
|
|
cmd = spec.mkcmd_runcpu("myconfig", ["benchmark1", "benchmark2"])
|
|
assert cmd == [
|
|
"runcpu",
|
|
"--setprocgroup",
|
|
"-i",
|
|
"ref",
|
|
"-c",
|
|
"myconfig",
|
|
"benchmark1",
|
|
"benchmark2",
|
|
]
|
|
|
|
def test_mkcmd_runcpu_no_procgroup(self):
|
|
spec = SPEC(Path("/path/to/spec"))
|
|
cmd = spec.mkcmd_runcpu("myconfig", ["benchmark1"], setprocgroup=False)
|
|
assert "--setprocgroup" not in cmd
|
|
|
|
def test_mkcmd_runcpu_with_output_dir(self):
|
|
spec = SPEC(Path("/path/to/spec"))
|
|
output_dir = Path("/output/dir")
|
|
cmd = spec.mkcmd_runcpu("myconfig", ["benchmark1"], output_root=output_dir)
|
|
assert "--outputdir" in cmd
|
|
assert str(output_dir) in cmd
|