Skip to content

Commit

Permalink
Enabled code coverage for AutoTuner smoke tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ng <jeffng@precisioninno.com>
  • Loading branch information
jeffng-or committed Feb 21, 2025
1 parent 11fe858 commit ba32a5f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 5 deletions.
3 changes: 3 additions & 0 deletions flow/test/test_autotuner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ python3 -m unittest tools.AutoTuner.test.smoke_test_sweep.${PLATFORM_WITHOUT_DAS
echo "Running Autotuner smoke tests for --sample and --iteration."
python3 -m unittest tools.AutoTuner.test.smoke_test_sample_iteration.${PLATFORM_WITHOUT_DASHES}SampleIterationSmokeTest.test_sample_iteration

echo "Running Autotuner smoke algorithm eval test"
python3 -m unittest tools.AutoTuner.test.smoke_test_algo_eval.${PLATFORM_WITHOUT_DASHES}AlgoEvalSmokeTest.test_algo_eval

if [ "$PLATFORM_WITHOUT_DASHES" == "asap7" ] && [ "$DESIGN_NAME" == "gcd" ]; then
echo "Running Autotuner ref file test (only once)"
python3 -m unittest tools.AutoTuner.test.ref_file_check.RefFileCheck.test_files
Expand Down
25 changes: 25 additions & 0 deletions tools/AutoTuner/test/autotuner_test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3

import os


class AutoTunerTestUtils:
@staticmethod
def get_exec_cmd():
"""
Returns the execution command based on whether this is a coverage run or
not.
Note that you need to run coverage combine after the runs complete to
get the coverage of the parent plus the child invocations
"""

if "COVERAGE_RUN" in os.environ:
exec = "coverage run --parallel-mode --omit=*/site-packages/*,*/dist-packages/*"
else: # pragma: no cover
exec = "python3"
return exec + " -m autotuner.distributed"


if __name__ == "__main__": # pragma: no cover
print(AutoTunerTestUtils.get_exec_cmd())
6 changes: 4 additions & 2 deletions tools/AutoTuner/test/ref_file_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import subprocess
import os
from .autotuner_test_utils import AutoTunerTestUtils

cur_dir = os.path.dirname(os.path.abspath(__file__))
src_dir = os.path.join(cur_dir, "../src")
Expand All @@ -18,8 +19,9 @@ def setUp(self):
"../../test/files/no_sdc_ref.json",
"../../test/files/no_fr_ref.json",
]
self.commands = [
f"python3 -m autotuner.distributed"
self.exec = AutoTunerTestUtils.get_exec_cmd()
self.command = (
f"{self.exec}"
f" --design {self.design}"
f" --platform {self.platform}"
f" --config {c}"
Expand Down
4 changes: 3 additions & 1 deletion tools/AutoTuner/test/resume_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import os
import time
from .autotuner_test_utils import AutoTunerTestUtils

from contextlib import contextmanager

Expand Down Expand Up @@ -45,8 +46,9 @@ def setUp(self):
# Cast to 1 decimal place
res_per_trial = float("{:.1f}".format(self.num_cpus / self.samples))
options = ["", "--resume"]
self.exec = AutoTunerTestUtils.get_exec_cmd()
self.commands = [
f"python3 -m autotuner.distributed"
f"{self.exec}"
f" --design {self.design}"
f" --platform {self.platform}"
f" --config {self.config}"
Expand Down
2 changes: 2 additions & 0 deletions tools/AutoTuner/test/smoke_test_algo_eval.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import subprocess
import os
from .autotuner_test_utils import AutoTunerTestUtils

cur_dir = os.path.dirname(os.path.abspath(__file__))
orfs_dir = os.path.join(cur_dir, "../../../flow")
Expand All @@ -19,6 +20,7 @@ def setUp(self):
_algo = ["hyperopt", "ax", "optuna", "pbt", "random"]
_eval = ["default", "ppa-improv"]
self.matrix = [(a, e) for a in _algo for e in _eval]
self.exec = AutoTunerTestUtils.get_exec_cmd()
self.commands = [
f"python3 -m autotuner.distributed"
f" --design {self.design}"
Expand Down
3 changes: 3 additions & 0 deletions tools/AutoTuner/test/smoke_test_sample_iteration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import subprocess
import os
from .autotuner_test_utils import AutoTunerTestUtils

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

Expand All @@ -16,7 +17,9 @@ def setUp(self):
)
self.experiment = f"smoke-test-sample-iteration-{self.platform}"
self.matrix = [(5, 1), (1, 5), (2, 2), (1, 1)]
self.exec = AutoTunerTestUtils.get_exec_cmd()
self.commands = [
f"{self.exec}"
f"python3 -m autotuner.distributed"
f" --design {self.design}"
f" --platform {self.platform}"
Expand Down
4 changes: 3 additions & 1 deletion tools/AutoTuner/test/smoke_test_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import os
import json
from .autotuner_test_utils import AutoTunerTestUtils

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

Expand Down Expand Up @@ -30,8 +31,9 @@ def setUp(self):
core = os.cpu_count()
self.jobs = 4 if core >= 4 else core
self.experiment = f"smoke-test-sweep-{self.platform}"
self.exec = AutoTunerTestUtils.get_exec_cmd()
self.command = (
"python3 -m autotuner.distributed"
f"{self.exec}"
f" --design {self.design}"
f" --platform {self.platform}"
f" --experiment {self.experiment}"
Expand Down
4 changes: 3 additions & 1 deletion tools/AutoTuner/test/smoke_test_tune.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
import subprocess
import os
from .autotuner_test_utils import AutoTunerTestUtils

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

Expand All @@ -15,8 +16,9 @@ def setUp(self):
f"../../../flow/designs/{self.platform}/{self.design}/autotuner.json",
)
self.experiment = f"smoke-test-tune-{self.platform}"
self.exec = AutoTunerTestUtils.get_exec_cmd()
self.command = (
"python3 -m autotuner.distributed"
f"{self.exec}"
f" --design {self.design}"
f" --platform {self.platform}"
f" --experiment {self.experiment}"
Expand Down

0 comments on commit ba32a5f

Please sign in to comment.