From 7e22f19e0d92c2c82f7856b393ab1c11cf37a39e Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Wed, 9 Aug 2017 06:44:17 +0900 Subject: [PATCH] Add a log for elapsed time per each test (#1104) IoT.js-DCO-1.0-Signed-off-by: Daeyeon Jeong daeyeon.jeong@samsung.com --- tools/check_test.js | 10 +++++++--- tools/common_js/util.js | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tools/check_test.js b/tools/check_test.js index 52c7d1ee64..6b6a022420 100644 --- a/tools/check_test.js +++ b/tools/check_test.js @@ -22,6 +22,7 @@ var EventEmitter = require('events').EventEmitter; var root = 'test'; var parent = '..'; +var watch = new util.Watch(); function Driver() { this.results = { @@ -33,6 +34,8 @@ function Driver() { this.emitter = new EventEmitter(); this.emitter.addListener('nextTest', function(driver, status, test) { + var elapsedTime = ' (' + watch.delta().toFixed(2) + 's) '; + if (driver.runner) { driver.runner.cleanup(); } @@ -40,17 +43,17 @@ function Driver() { if (status == 'pass') { driver.results.pass++; - driver.logger.message('PASS : ' + filename, status); + driver.logger.message('PASS : ' + filename + elapsedTime, status); } else if (status == 'fail') { driver.results.fail++; - driver.logger.message('FAIL : ' + filename, status); + driver.logger.message('FAIL : ' + filename + elapsedTime, status); } else if (status == 'skip') { driver.results.skip++; driver.logger.message('SKIP : ' + filename + ' (reason : ' + test.reason + ")", status); } else if (status == 'timeout') { driver.results.timeout++; - driver.logger.message('TIMEOUT : ' + filename, status); + driver.logger.message('TIMEOUT : ' + filename + elapsedTime, status); } driver.fIdx++; driver.runNextTest(); @@ -258,5 +261,6 @@ process.exit = function(code) { var conf = driver.config(); if (conf) { + watch.delta(); driver.runNextTest(); } diff --git a/tools/common_js/util.js b/tools/common_js/util.js index ca797045f7..dee234b18a 100644 --- a/tools/common_js/util.js +++ b/tools/common_js/util.js @@ -25,5 +25,25 @@ function join() { return path; } +function Watch() { + this.reset(); +} + +Watch.prototype.reset = function() { + this.startTime = 0; + this.elapsedTime = 0; +} + +Watch.prototype.delta = function() { + if (this.startTime) { + this.elapsedTime = (Date.now() - this.startTime) / 1000; + } + + this.startTime = Date.now(); + + return this.elapsedTime; +} + module.exports.absolutePath = absolutePath; module.exports.join = join; +module.exports.Watch = Watch;