Bug 1680995 - Profiler gtests: Use JSONOutputCheck in GeckoProfiler.Markers gtest - r=canaltinova

Consolidate all JSON checks to go through JSONOutputCheck.

Differential Revision: https://phabricator.services.mozilla.com/D98893
This commit is contained in:
Gerald Squelart 2020-12-09 04:14:56 +00:00
Родитель 7961b8c71d
Коммит 1bd03378a6
1 изменённых файлов: 472 добавлений и 506 удалений

Просмотреть файл

@ -1074,36 +1074,17 @@ TEST(GeckoProfiler, Markers)
double ts1Double = 0.0;
double ts2Double = 0.0;
// Extract JSON.
Json::Value parsedRoot;
Json::CharReaderBuilder builder;
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
ASSERT_TRUE(reader->parse(profile.get(), strchr(profile.get(), '\0'),
&parsedRoot, nullptr));
// Use const root, we only want to test what's in the profile, not change it.
const Json::Value& root = parsedRoot;
ASSERT_TRUE(root.isObject());
// We have a root object.
JSONOutputCheck(profile.get(), [&](const Json::Value& root) {
{
const Json::Value& threads = root["threads"];
ASSERT_TRUE(!threads.isNull());
ASSERT_TRUE(threads.isArray());
GET_JSON(threads, root["threads"], Array);
ASSERT_EQ(threads.size(), 1u);
// root.threads is a 1-element array.
{
const Json::Value& thread0 = threads[0];
ASSERT_TRUE(thread0.isObject());
// root.threads[0] is an object.
GET_JSON(thread0, threads[0], Object);
// Keep a reference to the string table in this block, it will be used
// below.
const Json::Value& stringTable = thread0["stringTable"];
GET_JSON(stringTable, thread0["stringTable"], Array);
ASSERT_TRUE(stringTable.isArray());
// Test the expected labels in the string table.
@ -1137,16 +1118,10 @@ TEST(GeckoProfiler, Markers)
EXPECT_TRUE(foundTooLong);
{
const Json::Value& markers = thread0["markers"];
ASSERT_TRUE(markers.isObject());
// root.threads[0].markers is an object.
GET_JSON(markers, thread0["markers"], Object);
{
const Json::Value& data = markers["data"];
ASSERT_TRUE(data.isArray());
// root.threads[0].markers.data is an array.
GET_JSON(data, markers["data"], Array);
for (const Json::Value& marker : data) {
// Name the indexes into the marker tuple:
@ -1171,11 +1146,11 @@ TEST(GeckoProfiler, Markers)
ASSERT_GE(marker.size(), SIZE_WITHOUT_PAYLOAD);
ASSERT_LE(marker.size(), SIZE_WITH_PAYLOAD);
// root.threads[0].markers.data[i] is an array with 5 or 6 elements.
// root.threads[0].markers.data[i] is an array with 5 or 6
// elements.
ASSERT_TRUE(marker[NAME].isUInt()); // name id
const Json::Value& name = stringTable[marker[NAME].asUInt()];
ASSERT_TRUE(name.isString());
GET_JSON(name, stringTable[marker[NAME].asUInt()], String);
std::string nameString = name.asString();
EXPECT_TRUE(marker[START_TIME].isNumeric());
@ -1239,7 +1214,8 @@ TEST(GeckoProfiler, Markers)
state = State(S_Markers2DefaultWithOptions + 1);
#endif
} else if (nameString ==
"explicitly-default-templated markers 2.0 with empty "
"explicitly-default-templated markers 2.0 with "
"empty "
"options") {
EXPECT_EQ(state, S_Markers2ExplicitDefaultEmptyOptions);
state = State(S_Markers2ExplicitDefaultEmptyOptions + 1);
@ -1252,15 +1228,13 @@ TEST(GeckoProfiler, Markers)
} else {
// root.threads[0].markers.data[i] is an array with 6 elements,
// so there is a payload.
const Json::Value& payload = marker[PAYLOAD];
ASSERT_TRUE(payload.isObject());
GET_JSON(payload, marker[PAYLOAD], Object);
// root.threads[0].markers.data[i][PAYLOAD] is an object
// (payload).
// It should at least have a "type" string.
const Json::Value& type = payload["type"];
ASSERT_TRUE(type.isString());
GET_JSON(type, payload["type"], String);
std::string typeString = type.asString();
if (nameString == "tracing event") {
@ -1349,7 +1323,7 @@ TEST(GeckoProfiler, Markers)
// Unique strings can be fetched from the string table.
ASSERT_TRUE(payload["unique text"].isUInt());
auto textIndex = payload["unique text"].asUInt();
const Json::Value& uniqueText = stringTable[textIndex];
GET_JSON(uniqueText, stringTable[textIndex], String);
ASSERT_TRUE(uniqueText.isString());
ASSERT_EQ(uniqueText.asString(), "gtest unique text");
// The duplicate unique text should have the exact same index.
@ -1423,7 +1397,8 @@ TEST(GeckoProfiler, Markers)
EXPECT_FALSE(payload["stack"].isNull());
EXPECT_EQ_JSON(payload["name"], String, "");
} else if (nameString == "Text in registered thread with stack") {
} else if (nameString ==
"Text in registered thread with stack") {
ADD_FAILURE()
<< "Unexpected 'Text in registered thread with stack'";
@ -1454,35 +1429,24 @@ TEST(GeckoProfiler, Markers)
} // markers
} // thread0
} // threads
// We should have read all expected markers.
EXPECT_EQ(state, S_LAST);
{
const Json::Value& meta = root["meta"];
ASSERT_TRUE(!meta.isNull());
ASSERT_TRUE(meta.isObject());
GET_JSON(meta, root["meta"], Object);
// root.meta is an object.
{
const Json::Value& markerSchema = meta["markerSchema"];
ASSERT_TRUE(!markerSchema.isNull());
ASSERT_TRUE(markerSchema.isArray());
// root.meta.markerSchema is an array.
GET_JSON(markerSchema, meta["markerSchema"], Array);
std::set<std::string> testedSchemaNames;
for (const Json::Value& schema : markerSchema) {
const Json::Value& name = schema["name"];
ASSERT_TRUE(name.isString());
GET_JSON(name, schema["name"], String);
const std::string nameString = name.asString();
const Json::Value& display = schema["display"];
ASSERT_TRUE(display.isArray());
GET_JSON(display, schema["display"], Array);
const Json::Value& data = schema["data"];
ASSERT_TRUE(data.isArray());
GET_JSON(data, schema["data"], Array);
EXPECT_TRUE(
testedSchemaNames
@ -1701,11 +1665,13 @@ TEST(GeckoProfiler, Markers)
// Check that we've got all expected schema.
EXPECT_TRUE(testedSchemaNames.find("Text") != testedSchemaNames.end());
EXPECT_TRUE(testedSchemaNames.find("tracing") != testedSchemaNames.end());
EXPECT_TRUE(testedSchemaNames.find("tracing") !=
testedSchemaNames.end());
EXPECT_TRUE(testedSchemaNames.find("MediaSample") !=
testedSchemaNames.end());
} // markerSchema
} // meta
});
Maybe<ProfilerBufferInfo> info = profiler_get_buffer_info();
MOZ_RELEASE_ASSERT(info.isSome());