From c411cdfbc31370aad1df2e4599338824feaf2cda Mon Sep 17 00:00:00 2001 From: Yves Gerey Date: Fri, 21 Sep 2018 12:28:56 +0200 Subject: [PATCH] Output 0 instead of NaN in perftest-output.json Subsequent recipe step requires the json to be valid. TBR: terelius@webrtc.org No-Try: True Bug: webrtc:9767 Change-Id: I1b7457a147039772e2cb4dbdbc0eab3e699492be Reviewed-on: https://webrtc-review.googlesource.com/101260 Reviewed-by: Oleh Prypin Commit-Queue: Oleh Prypin Cr-Commit-Position: refs/heads/master@{#24782} --- modules/remote_bitrate_estimator/test/bwe_test.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/remote_bitrate_estimator/test/bwe_test.cc b/modules/remote_bitrate_estimator/test/bwe_test.cc index 817a515100..ca685fe514 100644 --- a/modules/remote_bitrate_estimator/test/bwe_test.cc +++ b/modules/remote_bitrate_estimator/test/bwe_test.cc @@ -27,6 +27,10 @@ using std::vector; namespace { const int kQuickTestTimeoutMs = 500; + +double SafeDiv(double a, double b) { + return b ? a / b : 0; +} } namespace webrtc { @@ -217,12 +221,13 @@ void BweTest::PrintResults(double max_throughput_kbps, Stats throughput_kbps, std::map> flow_delay_ms, std::map> flow_throughput_kbps) { - double utilization = throughput_kbps.GetMean() / max_throughput_kbps; + double utilization = SafeDiv(throughput_kbps.GetMean(), max_throughput_kbps); webrtc::test::PrintResult("BwePerformance", GetTestName(), "Utilization", utilization * 100.0, "%", false); webrtc::test::PrintResult( "BwePerformance", GetTestName(), "Utilization var coeff", - throughput_kbps.GetStdDev() / throughput_kbps.GetMean(), "", false); + SafeDiv(throughput_kbps.GetStdDev(), throughput_kbps.GetMean()), "", + false); std::stringstream ss; for (auto& kv : flow_throughput_kbps) { ss.str(""); @@ -246,8 +251,8 @@ void BweTest::PrintResults(double max_throughput_kbps, squared_bitrate_sum += kv.second.GetMean() * kv.second.GetMean(); fairness_index += kv.second.GetMean(); } - fairness_index *= fairness_index; - fairness_index /= flow_throughput_kbps.size() * squared_bitrate_sum; + fairness_index *= SafeDiv( + fairness_index, flow_throughput_kbps.size() * squared_bitrate_sum); } webrtc::test::PrintResult("BwePerformance", GetTestName(), "Fairness", fairness_index * 100, "%", false);