Skip to content

Commit 423320e

Browse files
author
Vasileios Karakasis
authored
Merge pull request #1183 from victorusu/framework/perf-value-str-fail-nicely
[bugfix] Fix TypeError crash in the performance checking phase when the extracted performance variable value is not a number
2 parents 2df7a4a + baa91fa commit 423320e

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

reframe/core/pipeline.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import functools
1616
import inspect
1717
import itertools
18+
import numbers
1819
import os
1920
import shutil
2021

@@ -37,7 +38,6 @@
3738
from reframe.core.schedulers import Job
3839
from reframe.core.schedulers.registry import getscheduler
3940
from reframe.core.systems import SystemPartition
40-
from reframe.utility.sanity import assert_reference
4141

4242

4343
# Dependency kinds
@@ -1321,10 +1321,18 @@ def check_performance(self):
13211321

13221322
for key, values in self._perfvalues.items():
13231323
val, ref, low_thres, high_thres, *_ = values
1324+
1325+
# Verify that val is a number
1326+
if not isinstance(val, numbers.Number):
1327+
raise SanityError(
1328+
"the value extracted for performance variable '%s' "
1329+
"is not a number: %s" % (key, val)
1330+
)
1331+
13241332
tag = key.split(':')[-1]
13251333
try:
13261334
sn.evaluate(
1327-
assert_reference(
1335+
sn.assert_reference(
13281336
val, ref, low_thres, high_thres,
13291337
msg=('failed to meet reference: %s={0}, '
13301338
'expected {1} (l={2}, u={3})' % tag))

reframe/utility/sanity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
computing statistical information on series of data etc.
6464
6565
'''
66+
6667
import builtins
6768
import glob as pyglob
6869
import itertools
@@ -551,7 +552,7 @@ def calc_bound(thres):
551552
evaluate(assert_bounded(val, lower, upper))
552553
except SanityError:
553554
error_msg = msg or '{0} is beyond reference value {1} (l={2}, u={3})'
554-
raise SanityError(_format(error_msg, val, ref, lower, upper))
555+
raise SanityError(_format(error_msg, val, ref, lower, upper)) from None
555556
else:
556557
return True
557558

unittests/test_pipeline.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,6 @@ def setUp(self):
740740
'value3': sn.extractsingle(r'performance3 = (\S+)',
741741
self.perf_file.name, 1, float)
742742
}
743-
744743
self.test.sanity_patterns = sn.assert_found(r'result = success',
745744
self.output_file.name)
746745

@@ -896,6 +895,21 @@ def test_tag_resolution(self):
896895
}
897896
self.test.check_performance()
898897

898+
def test_invalid_perf_value(self):
899+
self.test.perf_patterns = {
900+
'value1': sn.extractsingle(r'performance1 = (\S+)',
901+
self.perf_file.name, 1, float),
902+
'value2': sn.extractsingle(r'performance2 = (\S+)',
903+
self.perf_file.name, 1, str),
904+
'value3': sn.extractsingle(r'performance3 = (\S+)',
905+
self.perf_file.name, 1, float)
906+
}
907+
self.write_performance_output(performance1=1.3,
908+
performance2='foo',
909+
performance3=3.3)
910+
with pytest.raises(SanityError, match='not a number'):
911+
self.test.check_performance()
912+
899913
def test_perf_var_evaluation(self):
900914
# All performance values must be evaluated, despite the first one
901915
# failing To test this, we need an extract function that will have a

0 commit comments

Comments
 (0)