Bug 1454580 - Add a DAMP test to watch RDP/protocol.js performance. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 16 Apr 2018 10:52:17 -0700
changeset 791510 eaf7dc0250517875ee0a1972e0714a2cc5100fe6
parent 790321 258fa1eb49c9a559f0f75bd0a597d14398b01430
child 791515 972c0a9eb9af7841eef30fe555e57c4d354663c8
child 791606 6419af4ede9514bb82c4bd574437537690da4a96
push id108827
push userbmo:poirot.alex@gmail.com
push dateFri, 04 May 2018 14:15:42 +0000
reviewersjryans
bugs1454580
milestone61.0a1
Bug 1454580 - Add a DAMP test to watch RDP/protocol.js performance. r=jryans MozReview-Commit-ID: LQ5PyosfogU
testing/talos/talos/tests/devtools/addon/content/damp-tests.js
testing/talos/talos/tests/devtools/addon/content/tests/head.js
testing/talos/talos/tests/devtools/addon/content/tests/server/actor.js
testing/talos/talos/tests/devtools/addon/content/tests/server/protocol.js
testing/talos/talos/tests/devtools/addon/content/tests/server/spec.js
--- a/testing/talos/talos/tests/devtools/addon/content/damp-tests.js
+++ b/testing/talos/talos/tests/devtools/addon/content/damp-tests.js
@@ -119,13 +119,17 @@ window.DAMP_TESTS = [
   }, {
     name: "inspector.layout",
     path: "inspector/layout.js",
     description: "Measure the time to open/close toolbox on inspector with layout tab against big document with grid containers"
   }, {
     name: "panelsInBackground.reload",
     path: "toolbox/panels-in-background.js",
     description: "Measure page reload time when all panels are in background"
+  }, {
+    name: "server.protocoljs",
+    path: "server/protocol.js",
+    description: "Measure RDP/protocol.js performance"
   },
   // ⚠  Adding new individual tests slows down DAMP execution ⚠
   // ⚠  Consider contributing to custom.${tool} rather than adding isolated tests ⚠
   // ⚠  See http://docs.firefox-dev.tools/tests/writing-perf-tests.html ⚠
 ];
--- a/testing/talos/talos/tests/devtools/addon/content/tests/head.js
+++ b/testing/talos/talos/tests/devtools/addon/content/tests/head.js
@@ -112,17 +112,17 @@ exports.openToolbox = openToolbox;
 exports.closeToolbox =  async function() {
   let tab = getActiveTab();
   let target = TargetFactory.forTab(tab);
   await target.client.waitForRequestsToSettle();
   await gDevTools.closeToolbox(target);
 };
 
 exports.openToolboxAndLog = async function(name, tool, onLoad) {
-let test = runTest(name + ".open.DAMP");
+  let test = runTest(name + ".open.DAMP");
   let toolbox = await openToolbox(tool, onLoad);
   test.done();
 
   test = runTest(name + ".open.settle.DAMP");
   await waitForPendingPaints(toolbox);
   test.done();
 
   // Force freeing memory after toolbox open as it creates a lot of objects
new file mode 100644
--- /dev/null
+++ b/testing/talos/talos/tests/devtools/addon/content/tests/server/actor.js
@@ -0,0 +1,24 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const protocol = require("devtools/shared/protocol");
+
+const { dampTestSpec } = require("./spec");
+
+exports.DampTestActor = protocol.ActorClassWithSpec(dampTestSpec, {
+  initialize(conn) {
+    protocol.Actor.prototype.initialize.call(this, conn);
+  },
+
+  testMethod(arg, { option }, arraySize) {
+    // Emit an event with second argument's option.
+    this.emit("testEvent", option);
+
+    // Returns back an array of repetition of first argument.
+    return arg;
+  },
+});
+
new file mode 100644
--- /dev/null
+++ b/testing/talos/talos/tests/devtools/addon/content/tests/server/protocol.js
@@ -0,0 +1,78 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { openToolbox, closeToolbox, testSetup, testTeardown, runTest,
+        SIMPLE_URL } = require("../head");
+
+const protocol = require("devtools/shared/protocol");
+const { dampTestSpec } = require("./spec");
+
+// Test parameters
+const ATTRIBUTES = 10;
+const STRING_SIZE = 1000;
+const ARRAY_SIZE = 50;
+const REPEAT = 300;
+
+const DampTestFront = protocol.FrontClassWithSpec(dampTestSpec, {
+  initialize(client, tabForm) {
+    this.actorID = tabForm.dampTestActor;
+    protocol.Front.prototype.initialize.call(this, client);
+    // Root owns itself.
+    this.manage(this);
+  }
+});
+
+module.exports = async function() {
+  let tab = await testSetup(SIMPLE_URL);
+  let messageManager = tab.linkedBrowser.messageManager;
+
+  // Register a test actor within the content process
+  messageManager.loadFrameScript("data:,(" + encodeURIComponent(
+    `function () {
+      const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
+
+      const { DebuggerServer } = require("devtools/server/main");
+      DebuggerServer.registerModule("chrome://damp/content/tests/server/actor.js", {
+        prefix: "dampTest",
+        constructor: "DampTestActor",
+        type: { tab: true }
+      });
+    }`
+  ) + ")()", true);
+
+  // Create test payloads
+  let bigString = "";
+  for (let i = 0; i < STRING_SIZE; i++) {
+    bigString += "x";
+  }
+
+  let bigObject = {};
+  for (let i = 0; i < ATTRIBUTES; i++) {
+    bigObject["attribute-" + i] = bigString;
+  }
+
+  let bigArray = Array.from({length: ARRAY_SIZE}, (_, i) => bigObject);
+
+  // Open against options to avoid noise from tools
+  let toolbox = await openToolbox("options");
+
+  // Instanciate a front for this test actor
+  let { target } = toolbox;
+  let front = DampTestFront(target.client, target.form);
+
+  // Execute the core of this test, call one method multiple times
+  // and listen for an event sent by this method
+  let test = runTest("server.protocoljs.DAMP");
+  for (let i = 0; i < REPEAT; i++) {
+    let onEvent = front.once("testEvent");
+    await front.testMethod(bigArray, { option: bigArray }, ARRAY_SIZE);
+    await onEvent;
+  }
+  test.done();
+
+  await closeToolbox();
+  await testTeardown();
+};
new file mode 100644
--- /dev/null
+++ b/testing/talos/talos/tests/devtools/addon/content/tests/server/spec.js
@@ -0,0 +1,39 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const protocol = require("devtools/shared/protocol");
+const {Arg, Option, RetVal, types} = protocol;
+
+types.addDictType("test.option", {
+  "attribute-1": "string",
+  "attribute-2": "string",
+  "attribute-3": "string",
+  "attribute-4": "string",
+  "attribute-5": "string",
+  "attribute-6": "string",
+  "attribute-7": "string",
+  "attribute-9": "string",
+  "attribute-10": "string",
+});
+const dampTestSpec = protocol.generateActorSpec({
+  typeName: "dampTest",
+
+  events: {
+    "testEvent": { arg: Arg(0, "array:json") },
+  },
+
+  methods: {
+    testMethod: {
+      request: {
+        arg: Arg(0, "array:json"),
+        option: Option(1, "array:test.option"),
+        arraySize: Arg(2, "number"),
+      },
+      response: { value: RetVal("array:json") },
+    },
+  }
+});
+exports.dampTestSpec = dampTestSpec;