Skip to content

Commit 69f1217

Browse files
authored
Merge pull request #2870 from jeffng-or/at-enable-code-coverage2
Enabled code coverage for AutoTuner smoke tests
2 parents 51d9aa5 + c02b509 commit 69f1217

File tree

7 files changed

+43
-6
lines changed

7 files changed

+43
-6
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
5+
6+
class AutoTunerTestUtils:
7+
@staticmethod
8+
def get_exec_cmd():
9+
"""
10+
Returns the execution command based on whether this is a coverage run or
11+
not.
12+
13+
Note that you need to run coverage combine after the runs complete to
14+
get the coverage of the parent plus the child invocations
15+
"""
16+
17+
if "COVERAGE_RUN" in os.environ:
18+
exec = "coverage run --parallel-mode --omit=*/site-packages/*,*/dist-packages/*"
19+
else: # pragma: no cover
20+
exec = "python3"
21+
return exec + " -m autotuner.distributed"
22+
23+
24+
if __name__ == "__main__": # pragma: no cover
25+
print(AutoTunerTestUtils.get_exec_cmd())

tools/AutoTuner/test/ref_file_check.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import subprocess
33
import os
4+
from .autotuner_test_utils import AutoTunerTestUtils
45

56
cur_dir = os.path.dirname(os.path.abspath(__file__))
67
src_dir = os.path.join(cur_dir, "../src")
@@ -18,8 +19,9 @@ def setUp(self):
1819
"../../test/files/no_sdc_ref.json",
1920
"../../test/files/no_fr_ref.json",
2021
]
22+
self.exec = AutoTunerTestUtils.get_exec_cmd()
2123
self.commands = [
22-
f"python3 -m autotuner.distributed"
24+
f"{self.exec}"
2325
f" --design {self.design}"
2426
f" --platform {self.platform}"
2527
f" --config {c}"

tools/AutoTuner/test/resume_check.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import subprocess
33
import os
44
import time
5+
from .autotuner_test_utils import AutoTunerTestUtils
56

67
from contextlib import contextmanager
78

@@ -45,8 +46,9 @@ def setUp(self):
4546
# Cast to 1 decimal place
4647
res_per_trial = float("{:.1f}".format(self.num_cpus / self.samples))
4748
options = ["", "--resume"]
49+
self.exec = AutoTunerTestUtils.get_exec_cmd()
4850
self.commands = [
49-
f"python3 -m autotuner.distributed"
51+
f"{self.exec}"
5052
f" --design {self.design}"
5153
f" --platform {self.platform}"
5254
f" --config {self.config}"

tools/AutoTuner/test/smoke_test_algo_eval.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import subprocess
33
import os
4+
from .autotuner_test_utils import AutoTunerTestUtils
45

56
cur_dir = os.path.dirname(os.path.abspath(__file__))
67
orfs_dir = os.path.join(cur_dir, "../../../flow")
@@ -19,8 +20,9 @@ def setUp(self):
1920
_algo = ["hyperopt", "ax", "optuna", "pbt", "random"]
2021
_eval = ["default", "ppa-improv"]
2122
self.matrix = [(a, e) for a in _algo for e in _eval]
23+
self.exec = AutoTunerTestUtils.get_exec_cmd()
2224
self.commands = [
23-
f"python3 -m autotuner.distributed"
25+
f"{self.exec}"
2426
f" --design {self.design}"
2527
f" --platform {self.platform}"
2628
f" --experiment {self.experiment}"

tools/AutoTuner/test/smoke_test_sample_iteration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import subprocess
33
import os
4+
from .autotuner_test_utils import AutoTunerTestUtils
45

56
cur_dir = os.path.dirname(os.path.abspath(__file__))
67

@@ -16,8 +17,9 @@ def setUp(self):
1617
)
1718
self.experiment = f"smoke-test-sample-iteration-{self.platform}"
1819
self.matrix = [(5, 1), (1, 5), (2, 2), (1, 1)]
20+
self.exec = AutoTunerTestUtils.get_exec_cmd()
1921
self.commands = [
20-
f"python3 -m autotuner.distributed"
22+
f"{self.exec}"
2123
f" --design {self.design}"
2224
f" --platform {self.platform}"
2325
f" --experiment {self.experiment}"

tools/AutoTuner/test/smoke_test_sweep.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import subprocess
33
import os
44
import json
5+
from .autotuner_test_utils import AutoTunerTestUtils
56

67
cur_dir = os.path.dirname(os.path.abspath(__file__))
78

@@ -30,8 +31,9 @@ def setUp(self):
3031
core = os.cpu_count()
3132
self.jobs = 4 if core >= 4 else core
3233
self.experiment = f"smoke-test-sweep-{self.platform}"
34+
self.exec = AutoTunerTestUtils.get_exec_cmd()
3335
self.command = (
34-
"python3 -m autotuner.distributed"
36+
f"{self.exec}"
3537
f" --design {self.design}"
3638
f" --platform {self.platform}"
3739
f" --experiment {self.experiment}"

tools/AutoTuner/test/smoke_test_tune.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import unittest
22
import subprocess
33
import os
4+
from .autotuner_test_utils import AutoTunerTestUtils
45

56
cur_dir = os.path.dirname(os.path.abspath(__file__))
67

@@ -15,8 +16,9 @@ def setUp(self):
1516
f"../../../flow/designs/{self.platform}/{self.design}/autotuner.json",
1617
)
1718
self.experiment = f"smoke-test-tune-{self.platform}"
19+
self.exec = AutoTunerTestUtils.get_exec_cmd()
1820
self.command = (
19-
"python3 -m autotuner.distributed"
21+
f"{self.exec}"
2022
f" --design {self.design}"
2123
f" --platform {self.platform}"
2224
f" --experiment {self.experiment}"

0 commit comments

Comments
 (0)