Currently Netperf module transforms each rate into bps internally.
When reporting the rates/thresholds like this is not user friendly.
I changed the reporting so that rate is reported like this:
Measured rate 858.66 +-0.00 Mbits/sec is higher than threshold 700.00 +-0.00 Mbits/sec
instead of this:
Measured rate 914154070.00 +-0.00 bps is higher than threshold 600.00 +-100.00
The data in res_data is left intact, the change is only for
logging.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
test_modules/Netperf.py | 69 ++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 59 insertions(+), 10 deletions(-)
diff --git a/test_modules/Netperf.py b/test_modules/Netperf.py
index 18bf825..31bea31 100644
--- a/test_modules/Netperf.py
+++ b/test_modules/Netperf.py
@@ -294,6 +294,43 @@ class Netperf(TestGeneric):
if e.errno == errno.EINTR:
server.kill()
+ def _pretty_rate(self, rate, unit=None):
+ pretty_rate = {}
+ if unit is None:
+ if rate < 1024:
+ pretty_rate["unit"] = "bits/sec"
+ pretty_rate["rate"] = rate
+ elif rate < 1024 * 1024:
+ pretty_rate["unit"] = "Kbits/sec"
+ pretty_rate["rate"] = rate / 1024
+ elif rate < 1024 * 1024 * 1024:
+ pretty_rate["unit"] = "Mbits/sec"
+ pretty_rate["rate"] = rate / (1024 * 1024)
+ elif rate < 1024 * 1024 * 1024 * 1024:
+ pretty_rate["unit"] = "Gbits/sec"
+ pretty_rate["rate"] = rate / (1024 * 1024 * 1024)
+ elif rate < 1024 * 1024 * 1024 * 1024 * 1024:
+ pretty_rate["unit"] = "tbits/sec"
+ pretty_rate["rate"] = rate / (1024 * 1024 * 1024 * 1024)
+ else:
+ if unit == "bits/sec":
+ pretty_rate["unit"] = "bits/sec"
+ pretty_rate["rate"] = rate
+ elif unit == "Kbits/sec":
+ pretty_rate["unit"] = "Kbits/sec"
+ pretty_rate["rate"] = rate / 1024
+ elif unit == "Mbits/sec":
+ pretty_rate["unit"] = "Mbits/sec"
+ pretty_rate["rate"] = rate / (1024 * 1024)
+ elif unit == "Gbits/sec":
+ pretty_rate["unit"] = "Gbits/sec"
+ pretty_rate["rate"] = rate / (1024 * 1024 * 1024)
+ elif unit == "Tbits/sec":
+ pretty_rate["unit"] = "Tbits/sec"
+ pretty_rate["rate"] = rate / (1024 * 1024 * 1024)
+
+ return pretty_rate
+
def _run_client(self, cmd):
logging.debug("running as client...")
@@ -354,6 +391,12 @@ class Netperf(TestGeneric):
res_data["rate"] = rate
res_data["rate_deviation"] = rate_deviation
+ rate_pretty = self._pretty_rate(rate)
+ rate_dev_pretty = self._pretty_rate(rate_deviation,
unit=rate_pretty["unit"])
+ threshold_pretty = self._pretty_rate(self._threshold["rate"])
+ threshold_dev_pretty =
self._pretty_rate(self._threshold_deviation["rate"],
+ unit =
threshold_pretty["unit"])
+
res_val = False
if self._threshold_interval is not None:
result_interval = (rate - rate_deviation,
@@ -361,18 +404,24 @@ class Netperf(TestGeneric):
if self._threshold_interval[0] > result_interval[1]:
res_val = False
- res_data["msg"] = "Measured rate %.2f +-%.2f bps is lower
"\
- "than threshold %.2f +-%.2f" %\
- (rate, rate_deviation,
- self._threshold["rate"],
- self._threshold_deviation["rate"])
+ res_data["msg"] = "Measured rate %.2f +-%.2f %s is lower
"\
+ "than threshold %.2f +-%.2f %s" %\
+ (rate_pretty["rate"],
+ rate_deviation,
+ rate_pretty["unit"],
+ threshold_pretty["rate"],
+ threshold_dev_pretty["rate"],
+ threshold_pretty["unit"])
else:
res_val = True
- res_data["msg"] = "Measured rate %.2f +-%.2f bps is higher
"\
- "than threshold %.2f +-%.2f" %\
- (rate, rate_deviation,
- self._threshold["rate"],
- self._threshold_deviation["rate"])
+ res_data["msg"] = "Measured rate %.2f +-%.2f %s is higher
"\
+ "than threshold %.2f +-%.2f %s" %\
+ (rate_pretty["rate"],
+ rate_deviation,
+ rate_pretty["unit"],
+ threshold_pretty["rate"],
+ threshold_dev_pretty["rate"],
+ threshold_pretty["unit"])
else:
if rate > 0.0:
res_val = True
--
2.4.11