diff --git a/test/run_fail/attrs.js b/test/run_fail/attrs.js deleted file mode 100644 index 82491db3ff..0000000000 --- a/test/run_fail/attrs.js +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -(function() { - var attrs = { - }; - - return attrs; -})(); diff --git a/test/run_pass/attrs.js b/test/run_pass/attrs.js deleted file mode 100644 index 794d8ba686..0000000000 --- a/test/run_pass/attrs.js +++ /dev/null @@ -1,199 +0,0 @@ -/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -(function() { - var attrs = { - 'test_adc.js': { - skip: ['all'], - reason: "need to setup test environment" - }, - 'test_ble.js': { - skip: ['all'], - reason: "need to setup test environment" - }, - 'test_cwd.js': { - skip: ['all'], - reason: "this test had @STDOUT=COMMAND[pwd], but there's no way to " + - "check out current directory path with js driver. So it skips " + - "temporarily." - }, - 'test_dgram_address.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_dgram_broadcast.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_dgram_multicast_membership.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_dgram_multicast_set_multicast_loop.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_dns.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_events.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_exit.js': { - skip: ['all'], - reason: - "driver can not run with test which checks out process.exit events" - }, - 'test_fs_exists.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs_existssync.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs_mkdir_rmdir.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs_open_close.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs_readfile.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs_readdir.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs_readfilesync.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs_stat.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs1.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_fs2.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_gpio1.js': { - skip: ['all'], - reason: "need hardware" - }, - 'test_gpio2.js': { - skip: ['all'], - reason: "need user input" - }, - 'test_i2c.js': { - skip: ['all'], - reason: "need to setup test environment" - }, - 'test_http_get.js': { - timeout: { - all: 20 - }, - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_http_header.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_httpclient_timeout.js': { - timeout: { - all: 10 - }, - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_httpclient_timeout2.js': { - timeout: { - all: 15 - }, - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_httpserver_timeout.js': { - timeout: { - all: 10 - }, - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_httpserver.js': { - timeout: { - all: 20 - }, - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_module_cache.js': { - skip: ['nuttx'], - reason: "not implemented for nuttx" - }, - 'test_net3.js': { - timeout: { - all: 20 - }, - skip: ['nuttx'], - reason: "too many socket descriptors, too long buffers are in need" - }, - 'test_net7.js': { - skip: ['nuttx'], - reason: "too many socket descriptors are in need" - }, - 'test_pwm.js': { - skip: ['all'], - reason: "need to setup test environment" - }, - 'test_timers.js': { - timeout: { - all: 10 - }, - }, - 'test_uart.js': { - skip: ['all'], - reason: "need to setup test environment" - }, - 'test_uncaught1.js': { - uncaught: true, - }, - 'test_uncaught2.js': { - uncaught: true, - }, - 'test_uncaught_errpr1.js': { - uncaught: true, - }, - 'test_uncaught_error2.js': { - uncaught: true, - }, - }; - - return attrs; -})(); diff --git a/test/run_pass/issue/attrs.js b/test/run_pass/issue/attrs.js deleted file mode 100644 index 82491db3ff..0000000000 --- a/test/run_pass/issue/attrs.js +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -(function() { - var attrs = { - }; - - return attrs; -})(); diff --git a/test/testsets.js b/test/testsets.js deleted file mode 100644 index 5fdb25f4dc..0000000000 --- a/test/testsets.js +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -function testsets() { - var tests = { - 'run_pass': [ - 'test_adc.js', - 'test_assert.js', - 'test_ble.js', - 'test_buffer_builtin.js', - 'test_buffer.js', - 'test_console.js', - 'test_cwd.js', - 'test_dgram_1_server_1_client.js', - 'test_dgram_1_server_n_clients.js', - 'test_dgram_address.js', - 'test_dgram_broadcast.js', - 'test_dgram_multicast_membership.js', - 'test_dgram_multicast_set_multicast_loop.js', - 'test_dns.js', - 'test_events.js', - 'test_exit.js', - 'test_fs_exists.js', - 'test_fs_existssync.js', - 'test_fs_mkdir_rmdir.js', - 'test_fs_open_close.js', - 'test_fs_readfile.js', - 'test_fs_readfilesync.js', - 'test_fs_readdir.js', - 'test_fs_rename.js', - 'test_fs_rename_sync.js', - 'test_fs_stat.js', - 'test_fs_writefile_unlink.js', - 'test_fs_writefile_unlink_sync.js', - 'test_fs.js', - 'test_fs1.js', - 'test_fs2.js', - 'test_gpio1.js', - 'test_gpio2.js', - 'test_http_get.js', - 'test_http_header.js', - 'test_httpclient_timeout.js', - 'test_httpclient_timeout2.js', - 'test_httpserver_timeout.js', - 'test_httpserver.js', - 'test_i2c.js', - 'test_module_cache.js', - 'test_net1.js', - 'test_net2.js', - 'test_net3.js', - 'test_net4.js', - 'test_net5.js', - 'test_net6.js', - 'test_net7.js', - 'test_net8.js', - 'test_net9.js', - 'test_net10.js', - 'test_next_tick.js', - 'test_process.js', - 'test_pwm.js', - 'test_stream.js', - 'test_timers.js', - 'test_timers2.js', - 'test_uart.js', - 'test_uncaught1.js', - 'test_uncaught2.js', - 'test_uncaught_error1.js', - 'test_uncaught_error2.js', - ], - 'run_pass/issue': [ - 'issue-133.js', - 'issue-137.js', - 'issue-198.js', - 'issue-223.js', - 'issue-266.js', - 'issue-323.js', - ], - 'run_fail': [ - 'assert_fail1.js', - 'assert_fail2.js', - 'assert_fail3.js', - 'fs_callbacks_called.js', - 'process_exit1.js', - 'process_exit2.js', - 'process_exitcode1.js', - 'process_exitcode2.js', - 'require_fail1.js', - 'runtime_error1.js', - 'syntax_fail1.js', - 'uncaught_error_event.js', - ] - }; - - return tests; -} - -module.exports = testsets; diff --git a/test/testsets.json b/test/testsets.json new file mode 100644 index 0000000000..f3c50e94c9 --- /dev/null +++ b/test/testsets.json @@ -0,0 +1,88 @@ +{ + "run_pass": [ + { "name": "test_adc.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_assert.js" }, + { "name": "test_ble.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_buffer_builtin.js" }, + { "name": "test_buffer.js" }, + { "name": "test_console.js" }, + { "name": "test_cwd.js", "skip": ["all"], "reason": "this test had @STDOUT=COMMAND[pwd], but there's no way to check out current directory path with js driver. So it skips temporarily." }, + { "name": "test_dgram_1_server_1_client.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_dgram_1_server_n_clients.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_dgram_address.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_dgram_broadcast.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_dgram_multicast_membership.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_dgram_multicast_set_multicast_loop.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_dns.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_events.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_exit.js", "skip": ["all"], "reason": "driver can not run with test which checks out process.exit events" }, + { "name": "test_fs_exists.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs_existssync.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs_mkdir_rmdir.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs_open_close.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs_readdir.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs_readfile.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs_readfilesync.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs_rename.js" }, + { "name": "test_fs_rename_sync.js" }, + { "name": "test_fs_stat.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs_writefile_unlink.js" }, + { "name": "test_fs_writefile_unlink_sync.js" }, + { "name": "test_fs.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs1.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_fs2.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_gpio1.js", "skip": ["all"], "reason": "needs hardware" }, + { "name": "test_gpio2.js", "skip": ["all"], "reason": "need user input"}, + { "name": "test_http_get.js", "timeout": 20, "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_http_header.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_httpclient_timeout.js", "timeout": 10, "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_httpclient_timeout2.js", "timeout": 15, "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_httpserver_timeout.js", "timeout": 10, "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_httpserver.js", "timeout": 20, "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_i2c.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_module_cache.js", "skip": ["nuttx"], "reason": "not implemented for nuttx" }, + { "name": "test_net1.js" }, + { "name": "test_net2.js" }, + { "name": "test_net3.js", "timeout": 20, "skip": ["nuttx"], "reason": "requires too many socket descriptors and too large buffers" }, + { "name": "test_net4.js" }, + { "name": "test_net5.js" }, + { "name": "test_net6.js" }, + { "name": "test_net7.js", "skip": ["nuttx"], "reason": "requires too many socket descriptors" }, + { "name": "test_net8.js" }, + { "name": "test_net9.js" }, + { "name": "test_net10.js" }, + { "name": "test_next_tick.js" }, + { "name": "test_process.js" }, + { "name": "test_pwm.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_stream.js" }, + { "name": "test_timers.js", "timeout": 10 }, + { "name": "test_timers2.js" }, + { "name": "test_uart.js", "skip": ["all"], "reason": "need to setup test environment" }, + { "name": "test_uncaught1.js", "uncaught": true }, + { "name": "test_uncaught2.js", "uncaught": true }, + { "name": "test_uncaught_error1.js", "uncaught": true }, + { "name": "test_uncaught_error2.js", "uncaught": true } + ], + "run_pass/issue": [ + { "name": "issue-133.js" }, + { "name": "issue-137.js" }, + { "name": "issue-198.js" }, + { "name": "issue-223.js" }, + { "name": "issue-266.js" }, + { "name": "issue-323.js" } + ], + "run_fail": [ + { "name": "assert_fail1.js", "expected-failure": true }, + { "name": "assert_fail2.js", "expected-failure": true }, + { "name": "assert_fail3.js", "expected-failure": true }, + { "name": "fs_callbacks_called.js", "expected-failure": true }, + { "name": "process_exit1.js", "expected-failure": true }, + { "name": "process_exit2.js", "expected-failure": true }, + { "name": "process_exitcode1.js", "expected-failure": true }, + { "name": "process_exitcode2.js", "expected-failure": true }, + { "name": "require_fail1.js", "expected-failure": true }, + { "name": "runtime_error1.js", "expected-failure": true }, + { "name": "syntax_fail1.js", "expected-failure": true }, + { "name": "uncaught_error_event.js", "expected-failure": true } + ] +} diff --git a/tools/check_test.js b/tools/check_test.js index 36acb05643..c0daf54e85 100644 --- a/tools/check_test.js +++ b/tools/check_test.js @@ -18,9 +18,6 @@ var Runner = require('test_runner').Runner; var Logger = require('common_js/logger').Logger; var OptionParser = require('common_js/option_parser').OptionParser; var util = require('common_js/util'); -// FIXME: After fs.readDirSync is implemented, this should be replaced. -var testsets = require('test/testsets'); - var EventEmitter = require('events').EventEmitter; var root = 'test'; @@ -35,11 +32,11 @@ function Driver() { }; this.emitter = new EventEmitter(); - this.emitter.addListener('nextTest', function(driver, status, attr) { + this.emitter.addListener('nextTest', function(driver, status, test) { if (driver.runner) { driver.runner.cleanup(); } - var filename = driver.filename(); + var filename = test['name']; if (status == 'pass') { driver.results.pass++; @@ -50,7 +47,7 @@ function Driver() { } else if (status == 'skip') { driver.results.skip++; driver.logger.message('SKIP : ' + filename + - ' (reason : ' + attr.reason + ")", status); + ' (reason : ' + test.reason + ")", status); } else if (status == 'timeout') { driver.results.timeout++; driver.logger.message('TIMEOUT : ' + filename, status); @@ -108,7 +105,10 @@ Driver.prototype.config = function() { this.options = options; - this.tests = testsets(); + var testfile = util.join(this.root, 'testsets.json'); + var testsets = fs.readFileSync(testfile).toString(); + + this.tests = JSON.parse(testsets); this.dIdx = 0; this.dLength = Object.keys(this.tests).length; @@ -119,25 +119,6 @@ Driver.prototype.config = function() { return true; }; -Driver.prototype.getAttrs = function() { - var content = fs.readFileSync(util.absolutePath('attrs.js')).toString(); - var attrs = eval(content); - - var dirname = this.dirname(); - if (dirname == 'run_fail') { - var files = this.tests[dirname]; - for (var fIdx in files) { - var file = files[fIdx]; - if (!attrs[file]) { - attrs[file] = {}; - } - attrs[file].fail = true; - } - } - - return attrs; -}; - Driver.prototype.runNextTest = function() { if (this.dIdx == this.dLength) { this.finish(); @@ -168,7 +149,7 @@ Driver.prototype.skipTestSet = function(filename) { var dir = this.tests[dirname]; var fLength = dir.length; for (var fIdx = 0; fIdx < fLength; fIdx++) { - if (dir[fIdx] == filename) { + if (dir[fIdx]['name'] == filename) { this.fIdx = fIdx; this.dIdx = dIdx; return true; @@ -187,7 +168,6 @@ Driver.prototype.nextTestSet = function(skipped) { var dirname = this.dirname(); this.fLength = this.tests[dirname].length; process.chdir(util.absolutePath(dirname)); - this.attrs = this.getAttrs(); this.logger.message("\n"); this.logger.message(">>>> " + dirname, "summary"); }; @@ -196,15 +176,14 @@ Driver.prototype.dirname = function() { return Object.keys(this.tests)[this.dIdx] }; -Driver.prototype.filename = function() { +Driver.prototype.currentTest = function() { var dirname = this.dirname(); - var filename = this.tests[dirname][this.fIdx]; - return filename; + return this.tests[dirname][this.fIdx]; }; Driver.prototype.test = function() { - var filename = this.filename(); - var content = fs.readFileSync(util.absolutePath(filename)).toString(); + var test = this.currentTest(); + var content = fs.readFileSync(util.absolutePath(test['name'])).toString(); return content; }; @@ -241,7 +220,7 @@ process.exit = function(code) { // this function is called when the following happens. // 1. the test case is finished normally. // 2. assertion inside the callback function is failed. - var should_fail = driver.runner.attr.fail; + var should_fail = driver.runner.test['expected-failure']; try { process.emitExit(code); } catch(e) { diff --git a/tools/test_runner.js b/tools/test_runner.js index 4a6a36d9df..64a09ef7fd 100644 --- a/tools/test_runner.js +++ b/tools/test_runner.js @@ -20,8 +20,7 @@ function Runner(driver) { process._exiting = false; this.driver = driver; - this.filename = driver.filename(); - this.attr = driver.attrs[this.filename] || {}; + this.test = driver.currentTest(); this.finished = false; if (driver.skipModule) { this.skipModule = driver.skipModule; @@ -70,7 +69,7 @@ Runner.prototype.spin = function() { Runner.prototype.checkSkipModule = function() { for (var i = 0; i < this.skipModuleLength; i++) { - if (this.filename.indexOf(this.skipModule[i]) >= 0) { + if (this.test['name'].indexOf(this.skipModule[i]) >= 0) { return true; } } @@ -80,21 +79,23 @@ Runner.prototype.checkSkipModule = function() { Runner.prototype.run = function() { - if (this.attr.skip && (this.attr.skip.indexOf('all') >= 0 || - this.attr.skip.indexOf(this.driver.os) >= 0)) { + var skip = this.test['skip']; + if (skip) { + if ((skip.indexOf('all') >= 0) || (skip.indexOf(this.driver.os) >= 0)) { this.finish('skip'); return; + } } if (this.skipModuleLength && this.checkSkipModule()) { - this.attr.reason = 'exclude module'; + this.test.reason = 'exclude module'; this.finish('skip'); return; } this.timer = null; - if (this.attr.timeout) { - var timeout = this.attr.timeout['all'] || this.attr.timeout[this.driver.os]; + if (this.test['timeout']) { + var timeout = this.test['timeout']; if (timeout) { var that = this; this.timer = setTimeout(function () { @@ -107,9 +108,9 @@ Runner.prototype.run = function() { var source = this.driver.test(); eval(source); } catch(e) { - if (this.attr.fail) { + if (this.test['expected-failure']) { this.finish('pass'); - } else if (this.attr.uncaught) { + } else if (this.test['uncaught']) { throw e; } else { console.error(e); @@ -128,7 +129,7 @@ Runner.prototype.finish = function(status) { this.finished = true; - this.driver.emitter.emit('nextTest', this.driver, status, this.attr); + this.driver.emitter.emit('nextTest', this.driver, status, this.test); }; module.exports.Runner = Runner;