Skip to content

Commit

Permalink
Add regression tests
Browse files Browse the repository at this point in the history
Now regression tests for resolved issues can be added to the project.
Regression tests are enabled by default.
They can be manually run by appending `regression-tests` to the `run-tests.py` command.
There is an `expected-failures` directory for tests that should fail.
The .gitignore file was modified as well to making sure it doesn't ignore these testfiles.

Signed-off-by: Daniel Balla [email protected]
  • Loading branch information
Daniel Balla committed Jan 4, 2019
1 parent 12525b5 commit 0998653
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ output.js
*.js
*.swp
#!test/*.js
!test/regression-tests/*.js
!test/regression-tests/xfail/*.js
*.pyc
tags
cscope.out
Expand Down
20 changes: 20 additions & 0 deletions test/regression-tests/assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright 2019-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 assert(expression) {
if (!expression) {
throw new Error("Assertion failed");
}
}
16 changes: 16 additions & 0 deletions test/regression-tests/issue-31.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright 2019-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.
*/

assert(JSON.stringify(new Uint32Array()) === '{}');
19 changes: 19 additions & 0 deletions test/regression-tests/issue-33.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright 2019-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.
*/

var arrObj = [ ] ;
Object.preventExtensions( arrObj , "length" , { writable : false } ) ;
Object.defineProperty( arrObj , "length" , { value : 12 } ) ;
assert(arrObj.toString() == ",,,,,,,,,,,");
20 changes: 20 additions & 0 deletions test/regression-tests/issue-5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright 2018-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.
*/

assert(Function.length == 1);
assert(Function.prototype.length == 0);

Function.prototype.length = function() { };
Function.prototype.bind(0);
16 changes: 16 additions & 0 deletions test/regression-tests/xfail/issue-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Copyright 2018-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.
*/

new Float32Array({ length: 0x40000001 });
43 changes: 43 additions & 0 deletions tools/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,49 @@ def run_jsc_stress(engine, arch):
env={'PYTHONPATH': '.'})


def _run_regression_tests(engine, files, is_fail, assert_js):
fails = 0
for file in files:
passed = True

proc = Popen([engine, assert_js, file], stdout=PIPE)
out, _ = proc.communicate()

if is_fail and proc.returncode or not is_fail and not proc.returncode:
print('%sOK: %s%s' % (COLOR_GREEN, file, COLOR_RESET))
else:
print('%sFAIL(%d): %s%s' % (COLOR_RED, proc.returncode, file, COLOR_RESET))
print(out)

fails += 1

return fails


@runner('regression-tests', default=True)
def run_regression_tests(engine, arch):
REGRESSION_DIR = join(PROJECT_SOURCE_DIR, 'test', 'regression-tests')
REGRESSION_XFAIL_DIR = join(REGRESSION_DIR, 'xfail')
REGRESSION_ASSERT_JS = join(REGRESSION_DIR, 'assert.js')

print('Running regression tests:')
xpass = glob(join(REGRESSION_DIR, 'issue-*.js'))
xpass_result = _run_regression_tests(engine, xpass, False, REGRESSION_ASSERT_JS)

print('Running regression tests expected to fail:')
xfail = glob(join(REGRESSION_XFAIL_DIR, '*.js'))
xfail_result = _run_regression_tests(engine, xfail, True, REGRESSION_ASSERT_JS)

tests_total = len(xpass) + len(xfail)
fail_total = xfail_result + xpass_result
print('TOTAL: %d' % (tests_total))
print('%sPASS : %d%s' % (COLOR_GREEN, tests_total - fail_total, COLOR_RESET))
print('%sFAIL : %d%s' % (COLOR_RED, fail_total, COLOR_RESET))

if xfail_result > 0 or xpass_result > 0:
raise Exception("Regression tests failed")


def _run_jetstream(engine, target_test):
JETSTREAM_OVERRIDE_DIR = join(PROJECT_SOURCE_DIR, 'test', 'vendortest', 'driver', 'jetstream')
JETSTREAM_DIR = join(PROJECT_SOURCE_DIR, 'test', 'vendortest', 'JetStream-1.1')
Expand Down

0 comments on commit 0998653

Please sign in to comment.