Skip to contentSkip to conversation

rt-tests: hwlatdetect: Add check that width is not zero

PATCH New John Kacur 1 participant 1 message Feb 26

lore
Share & tools
lore

John Kacur

author
#0 lore raw

PATCH 1/1 rt-tests: hwlatdetect: Add check that width is not zero

Check that width is not zero before division when calculating the MTBF

---
 src/hwlatdetect/hwlatdetect.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/hwlatdetect/hwlatdetect.py +3 -2
index abfbb954fe75..42b9f301718a 100755
@@ -564,8 +564,9 @@ if __name__ == '__main__':
     info(f"Samples exceeding threshold: {exceeding}")
 
     if exceeding > 1:
-        mtbf = ((float(detect.last) - float(detect.first)) * int(detect.get('window'))
-                / ((exceeding - 1) * int(detect.get('width'))))
+        width = int(detect.get('width'))
+        if width > 0:
+            mtbf = (((float(detect.last) - float(detect.first)) * int(detect.get('window'))) / ((exceeding - 1) * width))
         info(f"MTBF: {mtbf:.3f} seconds")
 
     if detect.have_msr:
Signature · 1 line
2.53.0