You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by db...@apache.org on 2015/05/02 09:09:32 UTC

cordova-medic git commit: CB-8870 Fixing windows debug script path. Making builds store the master's hostname. Adding test number display to build steps. Adding --path parameter to medic-check.

Repository: cordova-medic
Updated Branches:
  refs/heads/master 904ab01de -> d8cc71039


CB-8870 Fixing windows debug script path. Making builds store the master's hostname. Adding test number display to build steps. Adding --path parameter to medic-check.


Project: http://git-wip-us.apache.org/repos/asf/cordova-medic/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-medic/commit/d8cc7103
Tree: http://git-wip-us.apache.org/repos/asf/cordova-medic/tree/d8cc7103
Diff: http://git-wip-us.apache.org/repos/asf/cordova-medic/diff/d8cc7103

Branch: refs/heads/master
Commit: d8cc710395a8d4ecf963c32f228b383f962a7870
Parents: 904ab01
Author: Dmitry Blotsky <dm...@gmail.com>
Authored: Thu Apr 30 16:37:37 2015 -0700
Committer: Dmitry Blotsky <dm...@gmail.com>
Committed: Sat May 2 00:08:19 2015 -0700

----------------------------------------------------------------------
 buildbot-conf/cordova.conf | 91 ++++++++++++++++++++++++++++-------------
 lib/testcheck.js           | 22 +---------
 lib/util.js                |  4 ++
 medic/medic-check.js       | 45 ++++++++++++++++----
 medic/medic-checkout.js    |  2 +-
 medic/medic-run.js         | 29 +++++++------
 6 files changed, 121 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/d8cc7103/buildbot-conf/cordova.conf
----------------------------------------------------------------------
diff --git a/buildbot-conf/cordova.conf b/buildbot-conf/cordova.conf
index 3ac15b6..4933760 100644
--- a/buildbot-conf/cordova.conf
+++ b/buildbot-conf/cordova.conf
@@ -1,6 +1,7 @@
 import os
 import re
 import json
+import socket
 
 from buildbot.schedulers.timed import Nightly
 
@@ -13,10 +14,10 @@ from buildbot.process.properties import Property as P
 
 from buildbot.steps.source.git import Git
 from buildbot.steps.transfer import FileDownload
-from buildbot.steps.shell import ShellCommand
+from buildbot.steps.shell import ShellCommand, Test, SetPropertyFromCommand
 from buildbot.steps.master import SetProperty
 
-from buildbot.status.results import SUCCESS
+from buildbot.status import words, results
 
 # config
 MEDIC_CONFIG_FILE    = os.path.join(FP, 'cordova-config.json')
@@ -30,15 +31,17 @@ medic_config    = parse_config_file(MEDIC_CONFIG_FILE)
 projects_config = parse_config_file(PROJECTS_CONFIG_FILE)
 
 # constants
-DEFAULT_REPO_NAME   = 'src'
-BASE_WORKDIR        = '.'
-TEST_APP_NAME       = 'mobilespec'
-REPOS_PROPERTY_NAME = 'repositories_config'
-NPM_CACHE_DIR       = 'npm_cache'
-NPM_TEMP_DIR        = 'npm_tmp'
-COUCHDB_URI         = medic_config['couchdb']['uri']
-ENTRY_POINT         = medic_config['app']['entry']
-TEST_RUN_TIMEOUT    = medic_config['app']['timeout'] # in seconds
+DEFAULT_REPO_NAME      = 'src'
+BASE_WORKDIR           = '.'
+TEST_APP_NAME          = 'mobilespec'
+REPOS_PROPERTY_NAME    = 'repositories_config'
+NPM_CACHE_DIR          = 'npm_cache'
+NPM_TEMP_DIR           = 'npm_tmp'
+COUCHDB_URI            = medic_config['couchdb']['uri']
+ENTRY_POINT            = medic_config['app']['entry']
+TEST_RUN_TIMEOUT       = medic_config['app']['timeout'] # in seconds
+TEST_SUMMARY_FILE_NAME = 'test_summary.json'
+MASTER_HOSTNAME        = socket.gethostname()
 
 CORDOVA_SUPPORTED_CATEGORY   = 'cordova'
 CORDOVA_UNSUPPORTED_CATEGORY = 'cordova-medic-unsupported'
@@ -50,11 +53,24 @@ WINDOWS = 'windows'
 # patterns
 CORDOVA_REPO_PATTERN = r'^.*(cordova-[^\.]+)\.git$'
 
-# interpretation of every byte-sized return code as success
-ALWAYS_SUCCESS = {i: SUCCESS for i in range(0, 256)}
-
 ####### UTILITIES
 
+# custom steps
+class DisplayResults(Test):
+
+    def start(self):
+
+        test_summary = json.loads(self.getProperty('test_summary'))
+
+        total    = test_summary['total']
+        failed   = test_summary['failed']
+        passed   = test_summary['passed']
+        warnings = test_summary['warnings']
+
+        self.setTestResults(total=total, failed=failed, passed=passed, warnings=warnings)
+        self.finished(results.SUCCESS if failed == 0 else results.WARNINGS)
+        self.step_status.setText(self.describe(True))
+
 # helper functions
 def repo_name_from_url(url):
     match = re.match(CORDOVA_REPO_PATTERN, url)
@@ -114,7 +130,7 @@ def NPMInstall(command=list(), **kwargs):
     #      adding the --tmp parameter so that even if the command doesn't
     #      exit cleanly, the folder will get removed during cleanup;
     #      refer to: https://docs.npmjs.com/files/folders#temp-files
-    return NPM('install', command=command + [I('--cache=%(prop:builddir)s/' + NPM_CACHE_DIR), I('--tmp=%(prop:builddir)s/' + NPM_TEMP_DIR)], **kwargs)
+    return NPM('install', command=command + ['--cache', P('npm_cache_dir'), '--tmp', P('npm_temp_dir')], **kwargs)
 
 def NPMTest(**kwargs):
     return NPM('test', **kwargs)
@@ -154,6 +170,14 @@ WINDOWS_SLAVES = ['cordova-windows-slave']
 
 ####### STEPS
 
+properties_steps = [
+    Set('repository_name',   render_repo_name),
+    Set('build_id',          I('%(prop:buildername)s-%(prop:buildnumber)s-' + MASTER_HOSTNAME)),
+    Set('npm_cache_dir',     I('%(prop:builddir)s/' + NPM_CACHE_DIR)),
+    Set('npm_temp_dir',      I('%(prop:builddir)s/' + NPM_TEMP_DIR)),
+    Set('test_summary_file', I('%(prop:builddir)s/' + TEST_SUMMARY_FILE_NAME)),
+]
+
 medic_steps = [
 
     # remove and re-clone medic
@@ -166,11 +190,7 @@ medic_steps = [
     NPMInstall(command=['--production'], what='cordova-medic', workdir='cordova-medic'),
 ]
 
-cordova_plugins_prepare_steps = medic_steps + [
-
-    # set build properties
-    Set('repository_name', render_repo_name),
-    Set('build_id', I('%(prop:buildername)s-%(prop:buildnumber)s')),
+cordova_plugins_prepare_steps = properties_steps + medic_steps + [
 
     # kill emulators and clean workspace
     SH(command=['node', 'cordova-medic/medic/medic.js', 'kill', '--platform', P('platform')], description='killing running tasks'),
@@ -240,21 +260,36 @@ cordova_plugins_check_command = [
     'cordova-medic/medic/medic.js',
     'check',
     '--id',      P('build_id'),
-    '--couchdb', COUCHDB_URI
+    '--couchdb', COUCHDB_URI,
+    '--file',    P('test_summary_file'),
 ]
 
 cordova_plugins_run_steps = [
     SH(command=cordova_plugins_run_command, description='running tests'),
-    SH(command=cordova_plugins_check_command, description='analyzing results')
+    SH(command=cordova_plugins_check_command, description='getting test results'),
+    SetPropertyFromCommand(command=['cat', P('test_summary_file')], property='test_summary', hideStepIf=True),
+    DisplayResults(),
 ]
 
+# NOTE:
+#      all of these have haltOnFailure=False because all the
+#      windows builds must run even if the previous ones failed
 cordova_plugins_windows_run_steps = [
-    SH(command=cordova_plugins_run_command + ['--winvers',  'store80'], description='running tests (Windows 8.0)',           haltOnFailure=False),
-    SH(command=cordova_plugins_check_command,                           description='analysing results (Windows 8.0)',       haltOnFailure=False),
-    SH(command=cordova_plugins_run_command + ['--winvers',  'store'],   description='running tests (Windows 8.1)',           haltOnFailure=False),
-    SH(command=cordova_plugins_check_command,                           description='analysing results (Windows 8.1)',       haltOnFailure=False),
-    SH(command=cordova_plugins_run_command + ['--winvers',  'phone'],   description='running tests (Windows Phone 8.1)',     haltOnFailure=False),
-    SH(command=cordova_plugins_check_command,                           description='analysing results (Windows Phone 8.1)', haltOnFailure=False),
+
+    SH(command=cordova_plugins_run_command + ['--winvers',  'store80'], description='running tests (Windows 8.0)', haltOnFailure=False),
+    SH(command=cordova_plugins_check_command, description='getting test results (Windows 8.0)', haltOnFailure=False),
+    SetPropertyFromCommand(command=['cat', P('test_summary_file')], property='test_summary', hideStepIf=True, haltOnFailure=False),
+    DisplayResults(haltOnFailure=False),
+
+    SH(command=cordova_plugins_run_command + ['--winvers',  'store'], description='running tests (Windows 8.1)', haltOnFailure=False),
+    SH(command=cordova_plugins_check_command, description='getting test results (Windows 8.1)', haltOnFailure=False),
+    SetPropertyFromCommand(command=['cat', P('test_summary_file')], property='test_summary', hideStepIf=True, haltOnFailure=False),
+    DisplayResults(haltOnFailure=False),
+
+    SH(command=cordova_plugins_run_command + ['--winvers',  'phone'], description='running tests (Windows Phone 8.1)', haltOnFailure=False),
+    SH(command=cordova_plugins_check_command, description='getting test results (Windows Phone 8.1)', haltOnFailure=False),
+    SetPropertyFromCommand(command=['cat', P('test_summary_file')], property='test_summary', hideStepIf=True, haltOnFailure=False),
+    DisplayResults(haltOnFailure=False),
 ]
 
 cordova_plugins_all = BuildFactory()

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/d8cc7103/lib/testcheck.js
----------------------------------------------------------------------
diff --git a/lib/testcheck.js b/lib/testcheck.js
index 37de8df..cc574fa 100644
--- a/lib/testcheck.js
+++ b/lib/testcheck.js
@@ -76,25 +76,5 @@ module.exports = function (sha, dbHost) {
         return d.promise;
     };
 
-    function checkFailure(testResult) {
-        if (typeof testResult.mobilespec.failures == "undefined" || testResult.mobilespec.failures === 0) {
-            console.log("No failures were detected");
-            return true;
-        } else {
-            console.log("Total failures: " + testResult.mobilespec.failures);
-            console.log('Test failures were detected. Open ' + dbHost + '/_utils/document.html?mobilespec_results/' + testResult._id + ' for details');
-            console.log("Failing tests:");
-            testResult.mobilespec.results.forEach(function (result) {
-                if (result.status === "failed") {
-                    console.log(result.fullName);
-                }
-            });
-
-            return false;
-        }
-    };
-
-    console.log('Starting results verification for ' + sha);
-
-    return getDocumentIdBySha().then(getTestResult).then(checkFailure);
+    return getDocumentIdBySha().then(getTestResult);
 };

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/d8cc7103/lib/util.js
----------------------------------------------------------------------
diff --git a/lib/util.js b/lib/util.js
index 2e5dfd0..222c791 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -25,12 +25,16 @@ module.exports = function () {
 
     return {
 
+        // constants
         ANDROID:    "android",
         BLACKBERRY: "blackberry10",
         IOS:        "ios",
         WINDOWS:    "windows",
         WP8:        "wp8",
 
+        DEFAULT_ENCODING: "utf-8",
+
+        // functions
         fatal: function (message) {
             console.error("FATAL: " + message);
             process.exit(1);

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/d8cc7103/medic/medic-check.js
----------------------------------------------------------------------
diff --git a/medic/medic-check.js b/medic/medic-check.js
index f9c0d83..5646900 100644
--- a/medic/medic-check.js
+++ b/medic/medic-check.js
@@ -23,8 +23,11 @@
 
 "use strict";
 
+var fs = require("fs");
+
 var optimist = require("optimist");
 
+var util      = require("../lib/util");
 var testcheck = require("../lib/testcheck");
 
 function main() {
@@ -34,19 +37,47 @@ function main() {
         .usage("Usage: $0 {options}")
         .demand("id")
         .demand("couchdb")
+        .describe("id", "the build for which results are to be retrieved")
+        .describe("couchdb", "the CouchDB server from which to retrieve results")
+        .describe("file", "filename to which to optionally write results")
         .argv;
 
     var buildId    = argv.id;
     var couchdbURI = argv.couchdb;
+    var outputPath = argv.file;
+
+    console.log('Getting test results for ' + buildId);
+
+    testcheck(buildId, couchdbURI).done(
+        function onFulfilled(testResults) {
+
+            var numFailures = testResults.mobilespec.failures;
+            var numSpecs    = testResults.mobilespec.specs;
+
+            var counts = {
+                total:    numSpecs,
+                failed:   numFailures,
+                passed:   numSpecs - numFailures,
+                warnings: 0,
+            }
+
+            if (outputPath) {
+                fs.writeFileSync(outputPath, JSON.stringify(counts) + "\n", util.DEFAULT_ENCODING);
+            }
 
-    var result = testcheck(buildId, couchdbURI);
-    result.then(
-        function onFulfilled(value) {
-            if (value === true) {
-                process.exit(0);
-            } else {
-                process.exit(1);
+            if (typeof numFailures == "undefined" || numFailures === 0) {
+                console.log("No failures were detected");
             }
+
+            console.log("Total failures: " + numFailures);
+            console.log("Test failures were detected. Open " + couchdbURI + "/_utils/document.html?mobilespec_results/" + testResults._id + " for details");
+            console.log("Failing tests:");
+
+            testResults.mobilespec.results.forEach(function (result) {
+                if (result.status === "failed") {
+                    console.log(result.fullName);
+                }
+            });
         },
         function onRejected(error) {
             console.error("test check failed: " + error);

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/d8cc7103/medic/medic-checkout.js
----------------------------------------------------------------------
diff --git a/medic/medic-checkout.js b/medic/medic-checkout.js
index 0cb978a..63e43a5 100644
--- a/medic/medic-checkout.js
+++ b/medic/medic-checkout.js
@@ -67,7 +67,7 @@ function main() {
     }
 
     // read in config
-    var projectsConfig = JSON.parse(fs.readFileSync(configFile, "utf-8"));
+    var projectsConfig = JSON.parse(fs.readFileSync(configFile, util.DEFAULT_ENCODING));
 
     // clone all projects in the config
     for (var projectName in projectsConfig) {

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/d8cc7103/medic/medic-run.js
----------------------------------------------------------------------
diff --git a/medic/medic-run.js b/medic/medic-run.js
index 77fe255..f211a3e 100644
--- a/medic/medic-run.js
+++ b/medic/medic-run.js
@@ -33,7 +33,6 @@ var util     = require("../lib/util");
 var testwait = require("../lib/testwait");
 
 // constants
-var DEFAULT_ENCODING        = "utf-8";
 var CORDOVA_MEDIC_DIR       = "cordova-medic";
 var DEFAULT_APP_PATH        = "mobilespec";
 var CORDOVA_ERROR_PATTERN   = /^ERROR/;
@@ -79,7 +78,7 @@ function createMedicJson(appPath, buildId, couchdbURI) {
     var medicConfigContents = JSON.stringify(medicConfig) + "\n";
     var medicConfigPath     = path.join(appPath, "www", "medic.json");
 
-    fs.writeFileSync(medicConfigPath, medicConfigContents, DEFAULT_ENCODING);
+    fs.writeFileSync(medicConfigPath, medicConfigContents, util.DEFAULT_ENCODING);
 }
 
 function addURIToWhitelist(appPath, uri) {
@@ -87,8 +86,8 @@ function addURIToWhitelist(appPath, uri) {
     var configFile = getConfigPath(appPath);
     var cspFile    = getCSPPath(appPath);
 
-    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
-    var cspContent    = fs.readFileSync(cspFile, DEFAULT_ENCODING);
+    var configContent = fs.readFileSync(configFile, util.DEFAULT_ENCODING);
+    var cspContent    = fs.readFileSync(cspFile, util.DEFAULT_ENCODING);
 
     // add whitelisting rule allow access to couch server
     util.medicLog("Adding whitelist rule for CouchDB host: " + uri);
@@ -96,7 +95,7 @@ function addURIToWhitelist(appPath, uri) {
     if (!util.contains(configContent, accessOriginTag)) {
         configContent = configContent.split("</widget>").join("");
         configContent += "    " + accessOriginTag + "\n</widget>\n";
-        fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
+        fs.writeFileSync(configFile, configContent, util.DEFAULT_ENCODING);
     }
 
     // add couchdb address to csp rules
@@ -104,14 +103,14 @@ function addURIToWhitelist(appPath, uri) {
     var cspRule = "connect-src " + uri;
     if (!util.contains(cspContent, cspRule)) {
         cspContent = cspContent.replace("connect-src", cspRule);
-        fs.writeFileSync(cspFile, cspContent, DEFAULT_ENCODING);
+        fs.writeFileSync(cspFile, cspContent, util.DEFAULT_ENCODING);
     }
 }
 
 function setEntryPoint(appPath, entryPoint) {
 
     var configFile = getConfigPath(appPath);
-    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
+    var configContent = fs.readFileSync(configFile, util.DEFAULT_ENCODING);
 
     // replace/add start page preference
     // check if config.xml already contains <content /> element
@@ -131,7 +130,7 @@ function setEntryPoint(appPath, entryPoint) {
     }
 
     // write the changes
-    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
+    fs.writeFileSync(configFile, configContent, util.DEFAULT_ENCODING);
 }
 
 function changeAndroidLoadTimeout(appPath, timeout) {
@@ -145,7 +144,7 @@ function changeAndroidLoadTimeout(appPath, timeout) {
     var widgetRegex            = /<\/s*widget\s*>/i;
 
     var configFile    = getConfigPath(appPath);
-    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
+    var configContent = fs.readFileSync(configFile, util.DEFAULT_ENCODING);
 
     if (timeoutRegex.test(configContent)) {
         configContent = configContent.replace(timeoutRegex, timeoutTag);
@@ -163,7 +162,7 @@ function changeAndroidLoadTimeout(appPath, timeout) {
     }
 
     // write the changes
-    fs.writeFileSync(configFile, configContent, DEFAULT_ENCODING);
+    fs.writeFileSync(configFile, configContent, util.DEFAULT_ENCODING);
 }
 
 function setWindowsTargetStoreVersion(appPath, version) {
@@ -171,7 +170,7 @@ function setWindowsTargetStoreVersion(appPath, version) {
     util.medicLog('setting target store version to ' + version);
 
     var configFile    = getConfigPath(appPath);
-    var configContent = fs.readFileSync(configFile, DEFAULT_ENCODING);
+    var configContent = fs.readFileSync(configFile, util.DEFAULT_ENCODING);
 
     var versionPreference = '    <preference name="windows-target-version" value="' + version + '" />';
     configContent = configContent.replace('</widget>', versionPreference + '\r\n</widget>');
@@ -218,8 +217,7 @@ function windowsSpecificPreparation(argv) {
 
         util.medicLog('Patching WindowsStoreAppUtils to allow app to be run in automated mode');
 
-        var platformPath = path.join(appPath, 'platforms', 'windows');
-
+        var platformPath   = path.join(appPath, 'platforms', 'windows');
         var libPath        = path.join(platformPath, 'cordova', 'lib');
         var appUtilsPath   = path.join(libPath, 'WindowsStoreAppUtils.ps1');
         var srcScriptPath  = path.join('cordova-medic', 'lib', 'patches', 'EnableDebuggingForPackage.ps1');
@@ -230,9 +228,10 @@ function windowsSpecificPreparation(argv) {
 
         // add extra code to patch
         shelljs.sed(
-            '-i', /^\s*\$appActivator .*$/gim,
+            '-i',
+            /^\s*\$appActivator .*$/gim,
             '$&\n' +
-            '    powershell ' + destScriptPath + ' $$ID\n' +
+            '    powershell ' + path.join(process.cwd(), destScriptPath) + ' $$ID\n' +
             '    $Ole32 = Add-Type -MemberDefinition \'[DllImport("Ole32.dll")]public static extern int CoAllowSetForegroundWindow(IntPtr pUnk, IntPtr lpvReserved);\' -Name \'Ole32\' -Namespace \'Win32\' -PassThru\n' +
             '    $Ole32::CoAllowSetForegroundWindow([System.Runtime.InteropServices.Marshal]::GetIUnknownForObject($appActivator), [System.IntPtr]::Zero)',
             appUtilsPath


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org