Prevent NaN and Inf values in webrtc_perf_test

That is, cause a fatal error when a test produces such a result.

Bug: webrtc:9767
Change-Id: I588a34aa1e7e34b3036d5661e894676b21072862
Reviewed-on: https://webrtc-review.googlesource.com/c/101320
Commit-Queue: Oleh Prypin <oprypin@webrtc.org>
Reviewed-by: Yves Gerey <yvesg@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24950}
This commit is contained in:
Oleh Prypin
2018-10-03 13:53:44 +02:00
committed by Commit Bot
parent 86f78cb196
commit d136b2884e
3 changed files with 33 additions and 0 deletions

View File

@ -127,6 +127,7 @@ rtc_source_set("perf_test") {
deps = [
"..:webrtc_common",
"../api:array_view",
"../rtc_base:checks",
"../rtc_base:rtc_base_approved",
]
}

View File

@ -9,9 +9,11 @@
*/
#include "test/testsupport/perf_test.h"
#include "rtc_base/checks.h"
#include "rtc_base/criticalsection.h"
#include <stdio.h>
#include <cmath>
#include <fstream>
#include <map>
#include <sstream>
@ -44,6 +46,8 @@ class PerfResultsLogger {
const double value,
const std::string& units,
const bool important) {
RTC_CHECK(std::isfinite(value));
std::ostringstream value_stream;
value_stream.precision(8);
value_stream << value;
@ -64,6 +68,9 @@ class PerfResultsLogger {
const double error,
const std::string& units,
const bool important) {
RTC_CHECK(std::isfinite(mean));
RTC_CHECK(std::isfinite(error));
std::ostringstream value_stream;
value_stream.precision(8);
value_stream << '{' << mean << ',' << error << '}';
@ -84,6 +91,10 @@ class PerfResultsLogger {
const rtc::ArrayView<const double> values,
const std::string& units,
const bool important) {
for (double v : values) {
RTC_CHECK(std::isfinite(v));
}
std::ostringstream value_stream;
value_stream.precision(8);
value_stream << '[';

View File

@ -10,6 +10,7 @@
#include "test/testsupport/perf_test.h"
#include <limits>
#include <string>
#include "test/gtest.h"
@ -104,5 +105,25 @@ TEST_F(PerfTest, TestClearPerfResults) {
EXPECT_EQ(R"({"format_version":"1.0","charts":{}})", GetPerfResultsJSON());
}
#if GTEST_HAS_DEATH_TEST
using PerfDeathTest = PerfTest;
TEST_F(PerfDeathTest, TestFiniteResultError) {
const double kNan = std::numeric_limits<double>::quiet_NaN();
const double kInf = std::numeric_limits<double>::infinity();
EXPECT_DEATH(PrintResult("a", "b", "c", kNan, "d", false), "finit");
EXPECT_DEATH(PrintResult("a", "b", "c", kInf, "d", false), "finit");
EXPECT_DEATH(PrintResultMeanAndError("a", "b", "c", kNan, 1, "d", false), "");
EXPECT_DEATH(PrintResultMeanAndError("a", "b", "c", 1, kInf, "d", false), "");
const double kNanList[] = {kNan, kNan};
EXPECT_DEATH(PrintResultList("a", "b", "c", kNanList, "d", false), "");
const double kInfList[] = {0, kInf};
EXPECT_DEATH(PrintResultList("a", "b", "c", kInfList, "d", false), "");
}
#endif
} // namespace test
} // namespace webrtc