mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-17 22:32:51 +00:00
Bug 1774329 - Profiler gtests compute the proportion of JSON whitespace - r=florian
JSON whitespace comprises all spaces and newlines that are not inside strings, and which could be removed without changing the decoded contents. This tests the current state of affairs, where JSON whitespace in profiles may account for up to 25% of the full length. Differential Revision: https://phabricator.services.mozilla.com/D152601
This commit is contained in:
parent
f6e48e8f08
commit
9cb83c13c2
@ -1252,6 +1252,45 @@ TEST(BaseProfiler, BlocksRingBuffer)
|
||||
|
||||
// Common JSON checks.
|
||||
|
||||
// Check that the given JSON string only includes up to a certain proportion of
|
||||
// JSON whitespace characters (excluding those in property names and strings).
|
||||
void JSONWhitespaceCheck(const char* aOutput) {
|
||||
ASSERT_NE(aOutput, nullptr);
|
||||
|
||||
enum class State { Data, String, StringEscaped };
|
||||
State state = State::Data;
|
||||
size_t length = 0;
|
||||
size_t whitespaces = 0;
|
||||
for (const char* p = aOutput; *p != '\0'; ++p) {
|
||||
++length;
|
||||
const char c = *p;
|
||||
|
||||
switch (state) {
|
||||
case State::Data:
|
||||
if (c == '\n' || c == '\r' || c == ' ' || c == '\t') {
|
||||
++whitespaces;
|
||||
} else if (c == '"') {
|
||||
state = State::String;
|
||||
}
|
||||
break;
|
||||
|
||||
case State::String:
|
||||
if (c == '"') {
|
||||
state = State::Data;
|
||||
} else if (c == '\\') {
|
||||
state = State::StringEscaped;
|
||||
}
|
||||
break;
|
||||
|
||||
case State::StringEscaped:
|
||||
state = State::String;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_LE(double(whitespaces) / double(length), 0.25);
|
||||
}
|
||||
|
||||
// Does the GETTER return a non-null TYPE? (Non-critical)
|
||||
# define EXPECT_HAS_JSON(GETTER, TYPE) \
|
||||
do { \
|
||||
@ -1530,6 +1569,8 @@ void JSONOutputCheck(const char* aOutput,
|
||||
JSONCheckFunction&& aJSONCheckFunction) {
|
||||
ASSERT_NE(aOutput, nullptr);
|
||||
|
||||
JSONWhitespaceCheck(aOutput);
|
||||
|
||||
// Extract JSON.
|
||||
Json::Value parsedRoot;
|
||||
Json::CharReaderBuilder builder;
|
||||
|
Loading…
x
Reference in New Issue
Block a user