Skip to content

Increase test coverage: Array.prototype.sort #2674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

repasics
Copy link
Contributor

@repasics repasics commented Jan 4, 2019

Added new test cases to array-prototype-sort.js to improve branch coverage.
Branch coverage:
sort:
- before: 44/50
- after: 48/48

sort compare helper:
- before: 18/24
- after: 24/24

Also removed an unnecessary condition from the while loop what counts properties
with lower index than len.

JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]

@akosthekiss
Copy link
Member

@repasics: How did you measure branch coverage? Which tool did you use?

@matedabis
Copy link
Contributor

@akosthekiss
We used LCOV to measure the coverage.


try {
arr.sort();
assert(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are misaligned.

@akosthekiss
Copy link
Member

@repasics @matedabis Could you please elaborate on the whole measurement setup a bit more? How did you build jerryscript, how did you invoke lcov, which test suite(s) did you execute?

@matedabis
Copy link
Contributor

To set up LCOV I used the help of the following page:
http://ltp.sourceforge.net/coverage/lcov.php
There is also an example for how the result looks like.

We used this script I made to measure coverage:
https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

JerryScript build command:
https://github.com/matedabis/jerryscript/blob/6a2b9cc3ce2e6621b133fc5003309ad160cc0a0e/tests/gcov-tests/gcovtester.py#L47

Coverage information capture command:
https://github.com/matedabis/jerryscript/blob/6a2b9cc3ce2e6621b133fc5003309ad160cc0a0e/tests/gcov-tests/gcovtester.py#L75

Generate HTML command:
https://github.com/matedabis/jerryscript/blob/6a2b9cc3ce2e6621b133fc5003309ad160cc0a0e/tests/gcov-tests/gcovtester.py#L88

It is also important, that in ECMA_TRY_CATCH and ECMA_OP_TO_NUMBER_TRY_CATCH we had to disable the following line:
JERRY_ASSERT (return_value == ECMA_VALUE_EMPTY);
Because of more than one test cases, if it is enabled, we may can not reach some branches.

@akosthekiss
Copy link
Member

@matedabis Thanks for the link. The script and your note raise some further questions:

  • The script runs only a single test file in the engine (via the command line shell). Coverage (be that line or branch coverage) is usually measured by running all tests in a test suite or by running all available test suites. So, what are the (branch) coverage results when all test suites are executed?
  • What is 48? Total number of branches of a function? Of a file? Which function? Which file? The script you linked or the commit message above don't answer that.
  • The removal of an assert is a red flag to me. What branches can only be reached if an assert is removed? Asserts should not make any difference (theoretically, at least).

@matedabis
Copy link
Contributor

@akosthekiss

  1. I don't know that yet, we only measured the coverage of functions each with its test file in the /tests/jerry folder. For example in this case we test ecma_builtin_array_prototype_object_sort function only with /tests/jerry/array-prototype-sort.js. But if it is better, we will test the coverage by running all the test suites.

  2. The total number is the number of branches of the function we are actually testing, in this case, the mentioned above, excluding JERRY_ASSERTs.

  3. The reason we do not test JERRY_ASSERTs and we removed 1-1 of them in ECMA_TRY_CATCH and ECMA_OP_TO_NUMBER_TRY_CATCH is that, there are many test cases in a file, and if we trigger an assert, the engine stops running the js code at that point, so the test cases below are not executed. This way if we trigger one of the try-catches, the code does not stop running, we can reach those branches without disabling the asserts, but we would have this issue. This way I think we have two options. Either splitting the test file to many small parts to avoid this problem, or do not trigger asserts, and disable asserts in try-catches.

@akosthekiss
Copy link
Member

akosthekiss commented Jan 15, 2019

  1. I'm a bit puzzled as I recall we've had similar discussions before when the test suite was planned to get extended with additional code. Then, I've pointed at both the jerry-test-suite and at test262. Picking out single test files from a suite can be quite misleading about the coverage. At the least, /tests/jerry-test-suite and /tests/jerry should be executed before drawing any conclusions, as they are project internal suites. But I'd be interested about combining them with test262, too, since that's a submodule, too.

  2. I cannot get my head around two things. First, in a well-behaving engine, asserts must not happen in the executed test files. No matter how many test cases are written in a single .js file, they will all run. If they didn't execute properly, Travis CI were red. Second, what's the connection between asserts in .js test files and asserts in C macros? I cannot see how they affect each other.

@matedabis
Copy link
Contributor

Sorry I realized I misunderstood a thing, I did not want to mislead you. JERRY_ASSERTs are only disabled to see the real branch coverage, without the asserts. Of course we can reach all branches with asserts enabled, except 1 branch of each asserts. It is only for better visibility.

@matedabis
Copy link
Contributor

I will create a modified version of the coverage tester script and test the coverage with the test suites.

@akosthekiss
Copy link
Member

re. asserts: If I get it correctly, what you'd like to achieve is to disable asserts in debug builds. In that case you should disable JERRY_ASSERT in jerry-core/jrt/jrt.h, not its call sites all over the code base (e.g., in ECMA_TRY_CATCH or ECMA_OP_TO_NUMBER_TRY_CATCH)

@matedabis
Copy link
Contributor

matedabis commented Jan 15, 2019

Yes, that is what I would like to achieve. That will help for sure, thank you.

@repasics
Copy link
Contributor Author

repasics commented Jan 18, 2019

I checked the coverage including jerry-test-suite and test262 tests, then removed the unnecessary test cases.
The new stat is:
- before: 44/50
- after: 48/48
The two branch difference between the two stats is because the removed condition from the while loop what counts properties with lower index than len.

rerobika
rerobika previously approved these changes Jan 18, 2019
Copy link
Member

@rerobika rerobika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (informal)

@rerobika rerobika added the test Related to testing label Jan 19, 2019
@rerobika rerobika dismissed their stale review January 21, 2019 14:10

After the #2721 statistic this PR should contain the tests for the sort_compare_helper function as well to achive the full branch coverage.

@repasics
Copy link
Contributor Author

I added new test cases what covers the sort_compare_helper function too.

repasics added a commit to repasics/jerryscript that referenced this pull request Jan 30, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including jerryscript-project#2682 and jerryscript-project#2674:
	-before: 492 / 578
	-after:  570 / 574

There are 28 functions in ecma-builtin-arraybuffer-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

Co-authored-by: Mate Dabis [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
Added new test cases to array-prototype-sort.js to improve branch coverage.
Branch coverage:
sort:
     - before: 44/50
     - after:  48/48

sort compare helper:
     - before: 18/24
     - after:  24/24

Also removed an unnecessary condition from the while loop what counts properties
with lower index than len.

JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
repasics added a commit to repasics/jerryscript that referenced this pull request Feb 4, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including jerryscript-project#2682 and jerryscript-project#2674:
	-before: 492 / 578
	-after:  570 / 574

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

Co-authored-by: Mate Dabis [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
@repasics
Copy link
Contributor Author

repasics commented Feb 8, 2019

Summary:
The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we don't count JERRY_ASSERT s.

Branch coverage (covered branch/all branch):
sort function:
- before: 44/50
- after: 48/48

sort compare helper:
- before: 18/24
- after: 24/24

matedabis referenced this pull request in matedabis/jerryscript Feb 20, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 401 / 478
	-after:  474 / 478

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information on the link below:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

Co-authored-by: Mate Dabis [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]

JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
matedabis referenced this pull request in matedabis/jerryscript Feb 20, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 401 / 478
	-after:  474 / 478

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

Co-authored-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
matedabis referenced this pull request in matedabis/jerryscript Feb 20, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 401 / 478
	-after:  474 / 478

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

While improving the coverage we found an unnecessary condition check, which can not be false in any cases.

Co-authored-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
matedabis referenced this pull request in matedabis/jerryscript Feb 20, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 401 / 478
	-after:  474 / 478

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

While improving the coverage we found an unnecessary condition check, which can not be false in any cases.

Co-authored-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
matedabis referenced this pull request in matedabis/jerryscript Mar 12, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 399 / 476
	-after:  472 / 476

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

While improving the coverage we found an unnecessary condition check, which can not be false in any cases.

Co-authored-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
@repasics
Copy link
Contributor Author

Closed PR because of moving into a unified PR.

@repasics repasics closed this Mar 13, 2019
matedabis referenced this pull request in matedabis/jerryscript Mar 13, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 399 / 476
	-after:  472 / 476

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

While improving the coverage we found an unnecessary condition check, which can not be false in any cases.

Co-authored-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
matedabis referenced this pull request in matedabis/jerryscript Mar 14, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 399 / 476
	-after:  472 / 476

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

While improving the coverage we found an unnecessary condition check, which can not be false in any cases.

Co-authored-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
matedabis referenced this pull request in matedabis/jerryscript Mar 18, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 399 / 476
	-after:  472 / 476

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

While improving the coverage we found an unnecessary condition check, which can not be false in any cases.

Co-authored-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
matedabis referenced this pull request in matedabis/jerryscript Mar 18, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 399 / 476
	-after:  472 / 476

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

While improving the coverage we found an unnecessary condition check, which can not be false in any cases.

Co-authored-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
dbatyai referenced this pull request Apr 12, 2019
Added new test cases to improve branch coverage in Array.prototype routines.

The following script is made for testing branch coverage with all the test suites (--jerry-test-suite --test262 --unittests --jerry-tests), or with only one .js file.

https://github.com/matedabis/jerryscript/blob/gcov_coverage_tester/tests/gcov-tests/gcovtester.py

While measuring the branch coverage we dont count JERRY_ASSERT s. The results are measured by running all the test scripts, with the modifications in the PRs.

Branch coverage including pando-project#2682 and pando-project#2674:
	-before: 399 / 476
	-after:  472 / 476

There are 28 functions in ecma-builtin-array-prototype.c, we hit 14 from them.
The other 14 functions are either already covered, or we could not improve the coverage of it.

More information about the coverage improvement and the branches not reached:
https://gist.github.com/matedabis/d7b9fc0690aa2f4be6aa160fdf482e0e

While improving the coverage we found an unnecessary condition check, which can not be false in any cases.

Co-authored-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Csaba Repasi [email protected]
JerryScript-DCO-1.0-Signed-off-by: Mate Dabis [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants