зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
7961b8c71d
Коммит
1bd03378a6
|
@ -1074,36 +1074,17 @@ TEST(GeckoProfiler, Markers)
|
||||||
double ts1Double = 0.0;
|
double ts1Double = 0.0;
|
||||||
double ts2Double = 0.0;
|
double ts2Double = 0.0;
|
||||||
|
|
||||||
// Extract JSON.
|
JSONOutputCheck(profile.get(), [&](const Json::Value& root) {
|
||||||
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.
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const Json::Value& threads = root["threads"];
|
GET_JSON(threads, root["threads"], Array);
|
||||||
ASSERT_TRUE(!threads.isNull());
|
|
||||||
ASSERT_TRUE(threads.isArray());
|
|
||||||
ASSERT_EQ(threads.size(), 1u);
|
ASSERT_EQ(threads.size(), 1u);
|
||||||
|
|
||||||
// root.threads is a 1-element array.
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const Json::Value& thread0 = threads[0];
|
GET_JSON(thread0, threads[0], Object);
|
||||||
ASSERT_TRUE(thread0.isObject());
|
|
||||||
|
|
||||||
// root.threads[0] is an object.
|
|
||||||
|
|
||||||
// Keep a reference to the string table in this block, it will be used
|
// Keep a reference to the string table in this block, it will be used
|
||||||
// below.
|
// below.
|
||||||
const Json::Value& stringTable = thread0["stringTable"];
|
GET_JSON(stringTable, thread0["stringTable"], Array);
|
||||||
ASSERT_TRUE(stringTable.isArray());
|
ASSERT_TRUE(stringTable.isArray());
|
||||||
|
|
||||||
// Test the expected labels in the string table.
|
// Test the expected labels in the string table.
|
||||||
|
@ -1137,16 +1118,10 @@ TEST(GeckoProfiler, Markers)
|
||||||
EXPECT_TRUE(foundTooLong);
|
EXPECT_TRUE(foundTooLong);
|
||||||
|
|
||||||
{
|
{
|
||||||
const Json::Value& markers = thread0["markers"];
|
GET_JSON(markers, thread0["markers"], Object);
|
||||||
ASSERT_TRUE(markers.isObject());
|
|
||||||
|
|
||||||
// root.threads[0].markers is an object.
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const Json::Value& data = markers["data"];
|
GET_JSON(data, markers["data"], Array);
|
||||||
ASSERT_TRUE(data.isArray());
|
|
||||||
|
|
||||||
// root.threads[0].markers.data is an array.
|
|
||||||
|
|
||||||
for (const Json::Value& marker : data) {
|
for (const Json::Value& marker : data) {
|
||||||
// Name the indexes into the marker tuple:
|
// Name the indexes into the marker tuple:
|
||||||
|
@ -1171,11 +1146,11 @@ TEST(GeckoProfiler, Markers)
|
||||||
ASSERT_GE(marker.size(), SIZE_WITHOUT_PAYLOAD);
|
ASSERT_GE(marker.size(), SIZE_WITHOUT_PAYLOAD);
|
||||||
ASSERT_LE(marker.size(), SIZE_WITH_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
|
ASSERT_TRUE(marker[NAME].isUInt()); // name id
|
||||||
const Json::Value& name = stringTable[marker[NAME].asUInt()];
|
GET_JSON(name, stringTable[marker[NAME].asUInt()], String);
|
||||||
ASSERT_TRUE(name.isString());
|
|
||||||
std::string nameString = name.asString();
|
std::string nameString = name.asString();
|
||||||
|
|
||||||
EXPECT_TRUE(marker[START_TIME].isNumeric());
|
EXPECT_TRUE(marker[START_TIME].isNumeric());
|
||||||
|
@ -1239,7 +1214,8 @@ TEST(GeckoProfiler, Markers)
|
||||||
state = State(S_Markers2DefaultWithOptions + 1);
|
state = State(S_Markers2DefaultWithOptions + 1);
|
||||||
#endif
|
#endif
|
||||||
} else if (nameString ==
|
} else if (nameString ==
|
||||||
"explicitly-default-templated markers 2.0 with empty "
|
"explicitly-default-templated markers 2.0 with "
|
||||||
|
"empty "
|
||||||
"options") {
|
"options") {
|
||||||
EXPECT_EQ(state, S_Markers2ExplicitDefaultEmptyOptions);
|
EXPECT_EQ(state, S_Markers2ExplicitDefaultEmptyOptions);
|
||||||
state = State(S_Markers2ExplicitDefaultEmptyOptions + 1);
|
state = State(S_Markers2ExplicitDefaultEmptyOptions + 1);
|
||||||
|
@ -1252,15 +1228,13 @@ TEST(GeckoProfiler, Markers)
|
||||||
} else {
|
} else {
|
||||||
// root.threads[0].markers.data[i] is an array with 6 elements,
|
// root.threads[0].markers.data[i] is an array with 6 elements,
|
||||||
// so there is a payload.
|
// so there is a payload.
|
||||||
const Json::Value& payload = marker[PAYLOAD];
|
GET_JSON(payload, marker[PAYLOAD], Object);
|
||||||
ASSERT_TRUE(payload.isObject());
|
|
||||||
|
|
||||||
// root.threads[0].markers.data[i][PAYLOAD] is an object
|
// root.threads[0].markers.data[i][PAYLOAD] is an object
|
||||||
// (payload).
|
// (payload).
|
||||||
|
|
||||||
// It should at least have a "type" string.
|
// It should at least have a "type" string.
|
||||||
const Json::Value& type = payload["type"];
|
GET_JSON(type, payload["type"], String);
|
||||||
ASSERT_TRUE(type.isString());
|
|
||||||
std::string typeString = type.asString();
|
std::string typeString = type.asString();
|
||||||
|
|
||||||
if (nameString == "tracing event") {
|
if (nameString == "tracing event") {
|
||||||
|
@ -1349,7 +1323,7 @@ TEST(GeckoProfiler, Markers)
|
||||||
// Unique strings can be fetched from the string table.
|
// Unique strings can be fetched from the string table.
|
||||||
ASSERT_TRUE(payload["unique text"].isUInt());
|
ASSERT_TRUE(payload["unique text"].isUInt());
|
||||||
auto textIndex = payload["unique text"].asUInt();
|
auto textIndex = payload["unique text"].asUInt();
|
||||||
const Json::Value& uniqueText = stringTable[textIndex];
|
GET_JSON(uniqueText, stringTable[textIndex], String);
|
||||||
ASSERT_TRUE(uniqueText.isString());
|
ASSERT_TRUE(uniqueText.isString());
|
||||||
ASSERT_EQ(uniqueText.asString(), "gtest unique text");
|
ASSERT_EQ(uniqueText.asString(), "gtest unique text");
|
||||||
// The duplicate unique text should have the exact same index.
|
// The duplicate unique text should have the exact same index.
|
||||||
|
@ -1423,7 +1397,8 @@ TEST(GeckoProfiler, Markers)
|
||||||
EXPECT_FALSE(payload["stack"].isNull());
|
EXPECT_FALSE(payload["stack"].isNull());
|
||||||
EXPECT_EQ_JSON(payload["name"], String, "");
|
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()
|
ADD_FAILURE()
|
||||||
<< "Unexpected 'Text in registered thread with stack'";
|
<< "Unexpected 'Text in registered thread with stack'";
|
||||||
|
|
||||||
|
@ -1454,35 +1429,24 @@ TEST(GeckoProfiler, Markers)
|
||||||
} // markers
|
} // markers
|
||||||
} // thread0
|
} // thread0
|
||||||
} // threads
|
} // threads
|
||||||
|
|
||||||
// We should have read all expected markers.
|
// We should have read all expected markers.
|
||||||
EXPECT_EQ(state, S_LAST);
|
EXPECT_EQ(state, S_LAST);
|
||||||
|
|
||||||
{
|
{
|
||||||
const Json::Value& meta = root["meta"];
|
GET_JSON(meta, root["meta"], Object);
|
||||||
ASSERT_TRUE(!meta.isNull());
|
|
||||||
ASSERT_TRUE(meta.isObject());
|
|
||||||
|
|
||||||
// root.meta is an object.
|
|
||||||
{
|
{
|
||||||
const Json::Value& markerSchema = meta["markerSchema"];
|
GET_JSON(markerSchema, meta["markerSchema"], Array);
|
||||||
ASSERT_TRUE(!markerSchema.isNull());
|
|
||||||
ASSERT_TRUE(markerSchema.isArray());
|
|
||||||
|
|
||||||
// root.meta.markerSchema is an array.
|
|
||||||
|
|
||||||
std::set<std::string> testedSchemaNames;
|
std::set<std::string> testedSchemaNames;
|
||||||
|
|
||||||
for (const Json::Value& schema : markerSchema) {
|
for (const Json::Value& schema : markerSchema) {
|
||||||
const Json::Value& name = schema["name"];
|
GET_JSON(name, schema["name"], String);
|
||||||
ASSERT_TRUE(name.isString());
|
|
||||||
const std::string nameString = name.asString();
|
const std::string nameString = name.asString();
|
||||||
|
|
||||||
const Json::Value& display = schema["display"];
|
GET_JSON(display, schema["display"], Array);
|
||||||
ASSERT_TRUE(display.isArray());
|
|
||||||
|
|
||||||
const Json::Value& data = schema["data"];
|
GET_JSON(data, schema["data"], Array);
|
||||||
ASSERT_TRUE(data.isArray());
|
|
||||||
|
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(
|
||||||
testedSchemaNames
|
testedSchemaNames
|
||||||
|
@ -1701,11 +1665,13 @@ TEST(GeckoProfiler, Markers)
|
||||||
|
|
||||||
// Check that we've got all expected schema.
|
// Check that we've got all expected schema.
|
||||||
EXPECT_TRUE(testedSchemaNames.find("Text") != testedSchemaNames.end());
|
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") !=
|
EXPECT_TRUE(testedSchemaNames.find("MediaSample") !=
|
||||||
testedSchemaNames.end());
|
testedSchemaNames.end());
|
||||||
} // markerSchema
|
} // markerSchema
|
||||||
} // meta
|
} // meta
|
||||||
|
});
|
||||||
|
|
||||||
Maybe<ProfilerBufferInfo> info = profiler_get_buffer_info();
|
Maybe<ProfilerBufferInfo> info = profiler_get_buffer_info();
|
||||||
MOZ_RELEASE_ASSERT(info.isSome());
|
MOZ_RELEASE_ASSERT(info.isSome());
|
||||||
|
|
Загрузка…
Ссылка в новой задаче