Bug 1457127 - Add basic gtest coverage for histogram persistence I/O. r=chutten,janerik
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Wed, 16 May 2018 13:09:34 +0200
changeset 419070 8850728602d63cec6ffc39945ccaa82ae44cf1e0
parent 419069 b07106556b62c9f9034778c7e172f4e66a744ed6
child 419124 dc1868d255be744a7d2d462216be205086cc60af
child 419126 5352d48512f78e1dd767ce24ca6292396bb21fac
push id34025
push userapavel@mozilla.com
push dateMon, 21 May 2018 09:46:09 +0000
treeherdermozilla-central@8850728602d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten, janerik
bugs1457127
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1457127 - Add basic gtest coverage for histogram persistence I/O. r=chutten,janerik MozReview-Commit-ID: 75MQ1oDXLj0
toolkit/components/telemetry/geckoview/gtest/TestGeckoView.cpp
--- a/toolkit/components/telemetry/geckoview/gtest/TestGeckoView.cpp
+++ b/toolkit/components/telemetry/geckoview/gtest/TestGeckoView.cpp
@@ -27,16 +27,38 @@ const char kSampleData[] = R"({
     }
   },
   "keyedScalars": {
     "parent": {
       "telemetry.test.keyed_unsigned_int": {
         "testKey": 73
       }
     }
+  },
+  "histograms": {
+    "parent": {
+      "TELEMETRY_TEST_MULTIPRODUCT": {
+        "sum": 6,
+        "counts": [
+          3, 5, 7
+        ]
+      }
+    }
+  },
+  "keyedHistograms": {
+    "content": {
+      "TELEMETRY_TEST_MULTIPRODUCT_KEYED": {
+        "niceKey": {
+          "sum": 10,
+          "counts": [
+            1, 2, 3
+          ]
+        }
+      }
+    }
   }
 })";
 
 const char16_t kPersistedFilename[] = u"gv_measurements.json";
 
 namespace {
 
 /**
@@ -220,16 +242,90 @@ TestDeserializePersistedKeyedScalars(JSC
   JS::RootedObject sampleObj(aCx, &sampleData.toObject());
   JS::RootedValue keyedScalarData(aCx);
   ASSERT_TRUE(JS_GetProperty(aCx, sampleObj, "keyedScalars", &keyedScalarData)
               && keyedScalarData.isObject()) << "Failed to get sampleData['keyedScalars']";
 
   CheckJSONEqual(aCx, aData, keyedScalarData);
 }
 
+void
+TestSerializeHistograms(JSONWriter& aWriter)
+{
+  // Report the same data that's in kSampleData for histograms.
+  // We only want to make sure that I/O and parsing works, as telemetry
+  // measurement updates is taken care of by xpcshell tests.
+  aWriter.StartObjectProperty("parent");
+  aWriter.StartObjectProperty("TELEMETRY_TEST_MULTIPRODUCT");
+  aWriter.IntProperty("sum", 6);
+  aWriter.StartArrayProperty("counts");
+  aWriter.IntElement(3);
+  aWriter.IntElement(5);
+  aWriter.IntElement(7);
+  aWriter.EndArray();
+  aWriter.EndObject();
+  aWriter.EndObject();
+}
+
+void
+TestSerializeKeyedHistograms(JSONWriter& aWriter)
+{
+  // Report the same data that's in kSampleData for keyed histograms.
+  // We only want to make sure that I/O and parsing works, as telemetry
+  // measurement updates is taken care of by xpcshell tests.
+  aWriter.StartObjectProperty("content");
+  aWriter.StartObjectProperty("TELEMETRY_TEST_MULTIPRODUCT_KEYED");
+  aWriter.StartObjectProperty("niceKey");
+  aWriter.IntProperty("sum", 10);
+  aWriter.StartArrayProperty("counts");
+  aWriter.IntElement(1);
+  aWriter.IntElement(2);
+  aWriter.IntElement(3);
+  aWriter.EndArray();
+  aWriter.EndObject();
+  aWriter.EndObject();
+  aWriter.EndObject();
+}
+
+void
+TestDeserializeHistograms(JSContext* aCx, JS::HandleValue aData)
+{
+  // Get a JS object out of the JSON sample.
+  JS::RootedValue sampleData(aCx);
+  NS_ConvertUTF8toUTF16 utf16Content(kSampleData);
+  ASSERT_TRUE(JS_ParseJSON(aCx, utf16Content.BeginReading(), utf16Content.Length(), &sampleData))
+    << "Failed to create a JS object from the JSON sample";
+
+  // Get sampleData["histograms"].
+  JS::RootedObject sampleObj(aCx, &sampleData.toObject());
+  JS::RootedValue histogramData(aCx);
+  ASSERT_TRUE(JS_GetProperty(aCx, sampleObj, "histograms", &histogramData) && histogramData.isObject())
+    << "Failed to get sampleData['histograms']";
+
+  CheckJSONEqual(aCx, aData, histogramData);
+}
+
+void
+TestDeserializeKeyedHistograms(JSContext* aCx, JS::HandleValue aData)
+{
+  // Get a JS object out of the JSON sample.
+  JS::RootedValue sampleData(aCx);
+  NS_ConvertUTF8toUTF16 utf16Content(kSampleData);
+  ASSERT_TRUE(JS_ParseJSON(aCx, utf16Content.BeginReading(), utf16Content.Length(), &sampleData))
+    << "Failed to create a JS object from the JSON sample";
+
+  // Get sampleData["keyedHistograms"].
+  JS::RootedObject sampleObj(aCx, &sampleData.toObject());
+  JS::RootedValue keyedHistogramData(aCx);
+  ASSERT_TRUE(JS_GetProperty(aCx, sampleObj, "keyedHistograms", &keyedHistogramData)
+              && keyedHistogramData.isObject()) << "Failed to get sampleData['keyedHistograms']";
+
+  CheckJSONEqual(aCx, aData, keyedHistogramData);
+}
+
 } // Anonymous
 
 /**
  * A GeckoView specific test fixture. Please note that this
  * can't live in the above anonymous namespace.
  */
 class TelemetryGeckoViewFixture : public TelemetryTestFixture {
 protected:
@@ -247,16 +343,25 @@ namespace TelemetryScalar {
 
 nsresult SerializeScalars(JSONWriter& aWriter) { TestSerializeScalars(aWriter); return NS_OK; }
 nsresult SerializeKeyedScalars(JSONWriter& aWriter) { TestSerializeKeyedScalars(aWriter); return NS_OK; }
 nsresult DeserializePersistedScalars(JSContext* aCx, JS::HandleValue aData) { TestDeserializePersistedScalars(aCx, aData); return NS_OK; }
 nsresult DeserializePersistedKeyedScalars(JSContext* aCx, JS::HandleValue aData) { TestDeserializePersistedKeyedScalars(aCx, aData); return NS_OK; }
 
 } // TelemetryScalar
 
+namespace TelemetryHistogram {
+
+nsresult SerializeHistograms(mozilla::JSONWriter &aWriter) { TestSerializeHistograms(aWriter); return NS_OK; }
+nsresult SerializeKeyedHistograms(mozilla::JSONWriter &aWriter) { TestSerializeKeyedHistograms(aWriter); return NS_OK; }
+nsresult DeserializeHistograms(JSContext* aCx, JS::HandleValue aData) { TestDeserializeHistograms(aCx, aData); return NS_OK; }
+nsresult DeserializeKeyedHistograms(JSContext* aCx, JS::HandleValue aData) { TestDeserializeKeyedHistograms(aCx, aData); return NS_OK; }
+
+} // TelemetryHistogram
+
 namespace TelemetryGeckoViewTesting {
 
 void TestDispatchPersist();
 
 } // TelemetryGeckoViewTesting
 
 /**
  * Test that corrupted JSON files don't crash the Telemetry core.