Skip to content

Commit

Permalink
Bug 1286809 - Provide mechanism to run a subset of tasks in nss-try r…
Browse files Browse the repository at this point in the history
…=franziskus
  • Loading branch information
Tim Taubert committed Jul 26, 2016
1 parent e71e757 commit dce78df
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .taskcluster.yml
Expand Up @@ -57,12 +57,13 @@ tasks:
- "tc-treeherder.v2.{{project}}.{{revision}}.{{pushlog_id}}"

payload:
image: "ttaubert/nss-ci:0.0.17"
image: "ttaubert/nss-ci:0.0.18"

env:
TC_OWNER: {{owner}}
TC_SOURCE: {{{source}}}
TC_PROJECT: {{project}}
TC_COMMENT: '{{comment}}'
NSS_PUSHLOG_ID: '{{pushlog_id}}'
NSS_HEAD_REPOSITORY: '{{{url}}}'
NSS_HEAD_REVISION: '{{revision}}'
Expand Down
3 changes: 0 additions & 3 deletions automation/taskcluster/docker/setup.sh
Expand Up @@ -58,9 +58,6 @@ update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 30
locale-gen en_US.UTF-8
dpkg-reconfigure locales

# Install required Node modules.
su -c "npm install flatmap js-yaml merge slugid" worker

# Cleanup.
rm -rf ~/.ccache ~/.cache
apt-get clean
Expand Down
10 changes: 8 additions & 2 deletions automation/taskcluster/graph/build.js
Expand Up @@ -8,13 +8,14 @@ var merge = require("merge");
var yaml = require("js-yaml");
var slugid = require("slugid");
var flatmap = require("flatmap");
var try_syntax = require("./try_syntax");

// Default values for debugging.
var TC_OWNER = process.env.TC_OWNER || "{{tc_owner}}";
var TC_SOURCE = process.env.TC_SOURCE || "{{tc_source}}";
var TC_PROJECT = process.env.TC_PROJECT || "{{tc_project}}";
var TC_COMMENT = process.env.TC_COMMENT || "{{tc_comment}}";
var NSS_PUSHLOG_ID = process.env.NSS_PUSHLOG_ID || "{{nss_pushlog_id}}";
var NSS_HEAD_REPOSITORY = process.env.NSS_HEAD_REPOSITORY || "{{nss_head_repo}}";
var NSS_HEAD_REVISION = process.env.NSS_HEAD_REVISION || "{{nss_head_rev}}";

// Register custom YAML types.
Expand Down Expand Up @@ -43,7 +44,7 @@ var YAML_SCHEMA = yaml.Schema.create([
},

construct: function (data) {
return process.env[data];
return process.env[data] || "{{" + data.toLowerCase() + "}}";
}
})
]);
Expand Down Expand Up @@ -173,5 +174,10 @@ var graph = {
tasks: flatmap(["linux", "windows", "tools"], generatePlatformTasks)
};

// Filter tasks when try syntax is given.
if (TC_PROJECT == "nss-try") {
graph.tasks = try_syntax.filterTasks(graph.tasks, TC_COMMENT);
}

// Output the final graph.
process.stdout.write(JSON.stringify(graph, null, 2));
2 changes: 1 addition & 1 deletion automation/taskcluster/graph/linux/_build_base.yml
Expand Up @@ -14,7 +14,7 @@ task:

payload:
maxRunTime: 3600
image: ttaubert/nss-ci:0.0.17
image: ttaubert/nss-ci:0.0.18

artifacts:
public:
Expand Down
2 changes: 1 addition & 1 deletion automation/taskcluster/graph/linux/_test_base.yml
Expand Up @@ -14,7 +14,7 @@ task:

payload:
maxRunTime: 3600
image: ttaubert/nss-ci:0.0.17
image: ttaubert/nss-ci:0.0.18

command:
- "/bin/bash"
Expand Down
2 changes: 1 addition & 1 deletion automation/taskcluster/graph/tools/_build_base.yml
Expand Up @@ -14,7 +14,7 @@ task:

payload:
maxRunTime: 3600
image: ttaubert/nss-ci:0.0.17
image: ttaubert/nss-ci:0.0.18

env:
NSS_HEAD_REPOSITORY: !env NSS_HEAD_REPOSITORY
Expand Down
136 changes: 136 additions & 0 deletions automation/taskcluster/graph/try_syntax.js
@@ -0,0 +1,136 @@
/* 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/. */

var intersect = require("intersect");
var parse_args = require("minimist");

function parseOptions(opts) {
opts = parse_args(opts.split(/\s+/), {
default: {build: "do", platform: "all", unittests: "none", tools: "none"},
alias: {b: "build", p: "platform", u: "unittests", t: "tools"},
string: ["build", "platform", "unittests", "tools"]
});

// Parse build types (d=debug, o=opt).
var builds = intersect(opts.build.split(""), ["d", "o"]);

// If the given value is nonsense default to debug and opt builds.
if (builds.length == 0) {
builds = ["d", "o"];
}

// Parse platforms.
var allPlatforms = ["linux", "linux64", "linux64-asan", "win64"];
var platforms = intersect(opts.platform.split(/\s*,\s*/), allPlatforms);

// If the given value is nonsense or "none" default to all platforms.
if (platforms.length == 0 && opts.platform != "none") {
platforms = allPlatforms;
}

// Parse unit tests.
var allUnitTests = ["crmf", "chains", "cipher", "db", "ec", "fips", "gtest",
"lowhash", "merge", "sdr", "smime", "tools", "ssl"];
var unittests = intersect(opts.unittests.split(/\s*,\s*/), allUnitTests);

// If the given value is "all" run all tests.
// If it's nonsense then don't run any tests.
if (opts.unittests == "all") {
unittests = allUnitTests;
} else if (unittests.length == 0) {
unittests = [];
}

// Parse tools.
var allTools = ["clang-format", "scan-build"];
var tools = intersect(opts.tools.split(/\s*,\s*/), allTools);

// If the given value is "all" run all tools.
// If it's nonsense then don't run any tools.
if (opts.tools == "all") {
tools = allTools;
} else if (tools.length == 0) {
tools = [];
}

return {
builds: builds,
platforms: platforms,
unittests: unittests,
tools: tools
};
}

function filterTasks(tasks, comment) {
// Check for try syntax in changeset comment.
var match = comment.match(/^\s*try:\s*(.*)\s*$/);
if (!match) {
return tasks;
}

var opts = parseOptions(match[1]);

return tasks.filter(function (task) {
var env = task.task.payload.env || {};
var th = task.task.extra.treeherder;
var symbol = th.symbol.toLowerCase();
var machine = th.machine.platform;
var coll = th.collection || {};
var found;

// Never include memleak builds, they'll go away soon.
if (coll.memleak) {
return false;
}

// Filter tools. We can immediately return here as those
// are not affected by platform or build type selectors.
if (machine == "nss-tools") {
return opts.tools.some(function (tool) {
return symbol.startsWith(tool);
});
}

// Filter unit tests.
if (env.NSS_TESTS && env.TC_PARENT_TASK_ID) {
found = opts.unittests.some(function (test) {
return symbol.startsWith(test);
});

if (!found) {
return false;
}
}

// Filter by platform.
found = opts.platforms.some(function (platform) {
var aliases = {
"linux": "linux32",
"linux64-asan": "linux64",
"win64": "windows2012-64"
};

// Check the platform name.
var keep = machine == (aliases[platform] || platform);

// Additional check for LSan.
if (platform == "linux64-asan") {
keep &= coll.asan || coll.lsan;
}

return keep;
});

if (!found) {
return false;
}

// Finally, filter by build type.
var isDebug = coll.debug || coll.asan || coll.lsan;
return (isDebug && opts.builds.indexOf("d") > -1) ||
(!isDebug && opts.builds.indexOf("o") > -1);
});
}

module.exports.filterTasks = filterTasks;
3 changes: 3 additions & 0 deletions automation/taskcluster/scripts/extend_task_graph.sh
Expand Up @@ -9,5 +9,8 @@ fi

mkdir -p /home/worker/artifacts

# Install Node.JS dependencies.
npm install flatmap js-yaml merge slugid minimist intersect

# Build the task graph definition.
nodejs nss/automation/taskcluster/graph/build.js > /home/worker/artifacts/graph.json

0 comments on commit dce78df

Please sign in to comment.