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:
@ -127,6 +127,7 @@ rtc_source_set("perf_test") {
|
|||||||
deps = [
|
deps = [
|
||||||
"..:webrtc_common",
|
"..:webrtc_common",
|
||||||
"../api:array_view",
|
"../api:array_view",
|
||||||
|
"../rtc_base:checks",
|
||||||
"../rtc_base:rtc_base_approved",
|
"../rtc_base:rtc_base_approved",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "test/testsupport/perf_test.h"
|
#include "test/testsupport/perf_test.h"
|
||||||
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/criticalsection.h"
|
#include "rtc_base/criticalsection.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -44,6 +46,8 @@ class PerfResultsLogger {
|
|||||||
const double value,
|
const double value,
|
||||||
const std::string& units,
|
const std::string& units,
|
||||||
const bool important) {
|
const bool important) {
|
||||||
|
RTC_CHECK(std::isfinite(value));
|
||||||
|
|
||||||
std::ostringstream value_stream;
|
std::ostringstream value_stream;
|
||||||
value_stream.precision(8);
|
value_stream.precision(8);
|
||||||
value_stream << value;
|
value_stream << value;
|
||||||
@ -64,6 +68,9 @@ class PerfResultsLogger {
|
|||||||
const double error,
|
const double error,
|
||||||
const std::string& units,
|
const std::string& units,
|
||||||
const bool important) {
|
const bool important) {
|
||||||
|
RTC_CHECK(std::isfinite(mean));
|
||||||
|
RTC_CHECK(std::isfinite(error));
|
||||||
|
|
||||||
std::ostringstream value_stream;
|
std::ostringstream value_stream;
|
||||||
value_stream.precision(8);
|
value_stream.precision(8);
|
||||||
value_stream << '{' << mean << ',' << error << '}';
|
value_stream << '{' << mean << ',' << error << '}';
|
||||||
@ -84,6 +91,10 @@ class PerfResultsLogger {
|
|||||||
const rtc::ArrayView<const double> values,
|
const rtc::ArrayView<const double> values,
|
||||||
const std::string& units,
|
const std::string& units,
|
||||||
const bool important) {
|
const bool important) {
|
||||||
|
for (double v : values) {
|
||||||
|
RTC_CHECK(std::isfinite(v));
|
||||||
|
}
|
||||||
|
|
||||||
std::ostringstream value_stream;
|
std::ostringstream value_stream;
|
||||||
value_stream.precision(8);
|
value_stream.precision(8);
|
||||||
value_stream << '[';
|
value_stream << '[';
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "test/testsupport/perf_test.h"
|
#include "test/testsupport/perf_test.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
@ -104,5 +105,25 @@ TEST_F(PerfTest, TestClearPerfResults) {
|
|||||||
EXPECT_EQ(R"({"format_version":"1.0","charts":{}})", GetPerfResultsJSON());
|
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 test
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
Reference in New Issue
Block a user