Skip to content

Commit 29dc39c

Browse files
dianpopaioanachirca
authored andcommitted
CI: fix bug in getting AMD's coverage
Signed-off-by: Diana Popa <[email protected]>
1 parent e01613b commit 29dc39c

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

tests/host_tools/proc.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Utility functions for interacting with the processor."""
4+
import re
5+
from subprocess import run, PIPE
6+
7+
8+
def proc_type():
9+
"""Obtain the model processor on a Linux system."""
10+
cmd = "cat /proc/cpuinfo"
11+
try:
12+
lines = run(
13+
cmd,
14+
shell=True,
15+
check=True,
16+
stdout=PIPE
17+
).stdout.decode('utf-8').split('\n')
18+
except ChildProcessError:
19+
return ""
20+
21+
for line in lines:
22+
if "model name" in line:
23+
return re.sub(".*model name.*:", "", line, 1)
24+
return ""

tests/integration_tests/build/test_coverage.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,16 @@
1818
import pytest
1919

2020
import host_tools.cargo_build as host # pylint: disable=import-error
21+
import host_tools.proc as proc
22+
23+
# AMD has a slightly different coverage due to
24+
# the appearance of the brand string. On Intel,
25+
# this contains the frequency while on AMD it does not.
26+
# Checkout the cpuid crate. In the future other
27+
# differences may appear.
28+
COVERAGE_DICT = {"Intel": 84.90, "AMD": 84.84}
29+
PROC_MODEL = proc.proc_type()
2130

22-
COVERAGE_TARGET_PCT = 84.90
2331
COVERAGE_MAX_DELTA = 0.05
2432

2533
CARGO_KCOV_REL_PATH = os.path.join(host.CARGO_BUILD_REL_PATH, 'kcov')
@@ -45,6 +53,9 @@ def test_coverage(test_session_root_path, test_session_tmp_path):
4553
The result is extracted from the $KCOV_COVERAGE_FILE file created by kcov
4654
after a coverage run.
4755
"""
56+
proc_model = [item for item in COVERAGE_DICT if item in PROC_MODEL]
57+
assert len(proc_model) == 1, "Could not get processor model!"
58+
coverage_target_pct = COVERAGE_DICT[proc_model[0]]
4859
exclude_pattern = (
4960
'${CARGO_HOME:-$HOME/.cargo/},'
5061
'build/,'
@@ -87,22 +98,22 @@ def test_coverage(test_session_root_path, test_session_tmp_path):
8798

8899
coverage_low_msg = (
89100
'Current code coverage ({:.2f}%) is below the target ({}%).'
90-
.format(coverage, COVERAGE_TARGET_PCT)
101+
.format(coverage, coverage_target_pct)
91102
)
92103

93-
min_coverage = COVERAGE_TARGET_PCT - COVERAGE_MAX_DELTA
104+
min_coverage = coverage_target_pct - COVERAGE_MAX_DELTA
94105
assert coverage >= min_coverage, coverage_low_msg
95106

96107
# Get the name of the variable that needs updating.
97108
namespace = globals()
98109
cov_target_name = [name for name in namespace if namespace[name]
99-
is COVERAGE_TARGET_PCT][0]
110+
is COVERAGE_DICT][0]
100111

101112
coverage_high_msg = (
102113
'Current code coverage ({:.2f}%) is above the target ({}%).\n'
103114
'Please update the value of {}.'
104-
.format(coverage, COVERAGE_TARGET_PCT, cov_target_name)
115+
.format(coverage, coverage_target_pct, cov_target_name)
105116
)
106117

107-
assert coverage - COVERAGE_TARGET_PCT <= COVERAGE_MAX_DELTA,\
118+
assert coverage - coverage_target_pct <= COVERAGE_MAX_DELTA,\
108119
coverage_high_msg

0 commit comments

Comments
 (0)