Skip to content

Commit 126fa7a

Browse files
author
Theofilos Manitaras
committed
Address PR comments (version 2)
1 parent 8d655e7 commit 126fa7a

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

docs/tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ The first occurrence will be used as the reference value of the ``perf`` perform
824824
In our example, the ``perf`` key will be resolved in the ``daint:gpu`` scope giving us the reference value.
825825

826826
Reference values in ReFrame are specified as a three-tuple comprising the reference value and lower and upper thresholds.
827-
Thresholds are specified as decimal fractions of the reference value. The lower threshold must lie in the [-1,0] interval, whereas the upper threshold must be lie in the [0,inf] interval.
827+
Thresholds are specified as decimal fractions of the reference value. For nonnegative reference values, the lower threshold must lie in the [-1,0], whereas the upper threshold must lie in the [0,inf] interval.
828828
In our example, the reference value for this test on ``daint:gpu`` is 50 Gflop/s ±10%. Setting a threshold value to :class:`None` disables the threshold.
829829

830830
Combining It All Together

reframe/utility/sanity.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -471,26 +471,40 @@ def assert_reference(val, ref, lower_thres=None, upper_thres=None, msg=None):
471471
:arg val: The value to check.
472472
:arg ref: The reference value.
473473
:arg lower_thres: The lower threshold value expressed as a negative decimal
474-
fraction of the reference value. Must be in [-1, 0]. If ``None``, no
475-
lower thresholds is applied.
474+
fraction of the reference value. Must be in [-1, 0] for ref >= 0.0 and
475+
in [-inf, 0] for ref < 0.0.
476+
If ``None``, no lower thresholds is applied.
476477
:arg upper_thres: The upper threshold value expressed as a decimal fraction
477-
of the reference value. Must be in [0, inf]. If ``None``, no upper
478-
thresholds is applied.
478+
of the reference value. Must be in [0, inf] for ref >= 0.0 and
479+
in [0, 1] for ref < 0.0.
480+
If ``None``, no upper thresholds is applied.
479481
:returns: ``True`` on success.
480482
:raises reframe.core.exceptions.SanityError: if assertion fails or if the
481483
lower and upper thresholds do not have appropriate values.
482484
"""
483485
if lower_thres is not None:
484-
try:
485-
evaluate(assert_bounded(lower_thres, -1, 0))
486-
except SanityError:
487-
raise SanityError('invalid low threshold value: %s' % lower_thres)
486+
if ref >= 0.0:
487+
try:
488+
evaluate(assert_bounded(lower_thres, -1, 0))
489+
except SanityError:
490+
raise SanityError('invalid low threshold value: %s' % lower_thres)
491+
else:
492+
try:
493+
evaluate(assert_bounded(lower_thres, None, 0))
494+
except SanityError:
495+
raise SanityError('invalid low threshold value: %s' % lower_thres)
488496

489497
if upper_thres is not None:
490-
try:
491-
evaluate(assert_bounded(upper_thres, None, None))
492-
except SanityError:
493-
raise SanityError('invalid high threshold value: %s' % upper_thres)
498+
if ref >= 0.0:
499+
try:
500+
evaluate(assert_bounded(upper_thres, 0, None))
501+
except SanityError:
502+
raise SanityError('invalid high threshold value: %s' % upper_thres)
503+
else:
504+
try:
505+
evaluate(assert_bounded(upper_thres, 0, 1))
506+
except SanityError:
507+
raise SanityError('invalid high threshold value: %s' % upper_thres)
494508

495509
def calc_bound(thres):
496510
if thres is None:

unittests/test_sanity_functions.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ def test_assert_reference(self):
342342

343343
# Check upper threshold values greater than 1
344344
self.assertTrue(sn.assert_reference(30.0, 10.0, None, 3.0))
345-
self.assertTrue(sn.assert_reference(-50.0, -20.0, None, 2.0))
345+
self.assertTrue(sn.assert_reference(-50.0, -20.0, -2.0, 0.5))
346+
self.assertTrue(sn.assert_reference(30.0, 10.0, None, 3.0))
347+
self.assertTrue(sn.assert_reference(-50.0, -20.0, -2.0, 0.5))
346348

347349
self.assertRaisesRegex(
348350
SanityError,
@@ -382,6 +384,16 @@ def test_assert_reference(self):
382384
'invalid low threshold value: 1\.2',
383385
evaluate, sn.assert_reference(0.9, 1, 1.2, 0.1))
384386

387+
# check invalid thresholds greater than 1
388+
self.assertRaisesRegex(SanityError,
389+
'invalid low threshold value: -2\.0',
390+
evaluate, sn.assert_reference(0.9, 1, -2.0, 0.1))
391+
self.assertRaisesRegex(SanityError,
392+
'invalid high threshold value: 1\.5',
393+
evaluate, sn.assert_reference(-1.5, -1, -0.5, 1.5))
394+
395+
396+
385397
def _write_tempfile(self):
386398
ret = None
387399
with NamedTemporaryFile('wt', delete=False) as fp:

0 commit comments

Comments
 (0)