18
18
import pytest
19
19
20
20
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 ()
21
30
22
- COVERAGE_TARGET_PCT = 84.90
23
31
COVERAGE_MAX_DELTA = 0.05
24
32
25
33
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):
45
53
The result is extracted from the $KCOV_COVERAGE_FILE file created by kcov
46
54
after a coverage run.
47
55
"""
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 ]]
48
59
exclude_pattern = (
49
60
'${CARGO_HOME:-$HOME/.cargo/},'
50
61
'build/,'
@@ -87,22 +98,22 @@ def test_coverage(test_session_root_path, test_session_tmp_path):
87
98
88
99
coverage_low_msg = (
89
100
'Current code coverage ({:.2f}%) is below the target ({}%).'
90
- .format (coverage , COVERAGE_TARGET_PCT )
101
+ .format (coverage , coverage_target_pct )
91
102
)
92
103
93
- min_coverage = COVERAGE_TARGET_PCT - COVERAGE_MAX_DELTA
104
+ min_coverage = coverage_target_pct - COVERAGE_MAX_DELTA
94
105
assert coverage >= min_coverage , coverage_low_msg
95
106
96
107
# Get the name of the variable that needs updating.
97
108
namespace = globals ()
98
109
cov_target_name = [name for name in namespace if namespace [name ]
99
- is COVERAGE_TARGET_PCT ][0 ]
110
+ is COVERAGE_DICT ][0 ]
100
111
101
112
coverage_high_msg = (
102
113
'Current code coverage ({:.2f}%) is above the target ({}%).\n '
103
114
'Please update the value of {}.'
104
- .format (coverage , COVERAGE_TARGET_PCT , cov_target_name )
115
+ .format (coverage , coverage_target_pct , cov_target_name )
105
116
)
106
117
107
- assert coverage - COVERAGE_TARGET_PCT <= COVERAGE_MAX_DELTA ,\
118
+ assert coverage - coverage_target_pct <= COVERAGE_MAX_DELTA ,\
108
119
coverage_high_msg
0 commit comments