Skip to content
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

Mutation testing for Servo #18529

Closed
asajeffrey opened this issue Sep 15, 2017 · 12 comments
Closed

Mutation testing for Servo #18529

asajeffrey opened this issue Sep 15, 2017 · 12 comments

Comments

@asajeffrey
Copy link
Member

@asajeffrey asajeffrey commented Sep 15, 2017

Implement mutation testing (https://en.wikipedia.org/wiki/Mutation_testing) for Servo, based on the WPT test suite.

@asajeffrey
Copy link
Member Author

@asajeffrey asajeffrey commented Sep 15, 2017

@edunham
Copy link
Contributor

@edunham edunham commented Sep 15, 2017

This came up in a conversation with Lonnen about a similar project on Firefox, so he can also be a resource if someone or a team embarks on this.

@panup21091993 panup21091993 mentioned this issue Oct 27, 2017
4 of 4 tasks complete
bors-servo added a commit that referenced this issue Nov 13, 2017
 Initial steps of Mutation testing

<!-- Please describe your changes on the following line: -->
- Added one strategy of mutation which is replacing occurrences && to ||.
- Added test mapping framework for running mutation tests corresponding to a mutant.
- Added one test_mapping.json to map source file in a folder to WPT test.
- Added README mentioning about Mutation testing.
- Added CI script to invoke mutation test.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes #18529 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because it is a python script to run mutation test and does not change any behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18984)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Nov 13, 2017
 Initial steps of Mutation testing

<!-- Please describe your changes on the following line: -->
- Added one strategy of mutation which is replacing occurrences && to ||.
- Added test mapping framework for running mutation tests corresponding to a mutant.
- Added one test_mapping.json to map source file in a folder to WPT test.
- Added README mentioning about Mutation testing.
- Added CI script to invoke mutation test.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes #18529 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because it is a python script to run mutation test and does not change any behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18984)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Nov 13, 2017
 Initial steps of Mutation testing

<!-- Please describe your changes on the following line: -->
- Added one strategy of mutation which is replacing occurrences && to ||.
- Added test mapping framework for running mutation tests corresponding to a mutant.
- Added one test_mapping.json to map source file in a folder to WPT test.
- Added README mentioning about Mutation testing.
- Added CI script to invoke mutation test.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes #18529 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because it is a python script to run mutation test and does not change any behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18984)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Nov 13, 2017
 Initial steps of Mutation testing

<!-- Please describe your changes on the following line: -->
- Added one strategy of mutation which is replacing occurrences && to ||.
- Added test mapping framework for running mutation tests corresponding to a mutant.
- Added one test_mapping.json to map source file in a folder to WPT test.
- Added README mentioning about Mutation testing.
- Added CI script to invoke mutation test.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes #18529 (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because it is a python script to run mutation test and does not change any behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18984)
<!-- Reviewable:end -->
@dsandeephegde
Copy link
Contributor

@dsandeephegde dsandeephegde commented Nov 15, 2017

We have done initial steps Mutation testing project. This is our pull request
Highlights of the changes are:

  1. One mutation strategy is introduced - replacing occurrences && to ||.
  2. Test mapping framework for mapping source code to WPT tests.
  3. Run Mutation test in linux-rel-nogate step on CI.

More Info

@dsandeephegde
Copy link
Contributor

@dsandeephegde dsandeephegde commented Nov 15, 2017

Test mapping is introduced to reduce the time taken to run the tests. As for each mutant, we need to run only small part of the WPT tests, It would be time-consuming to run all tests so a multiple number of times.

sample test_mapping.josn

{
  "xmlhttprequest.rs": [
     "XMLHttpRequest"
  ],
   "range.rs": [
    "dom/ranges"
  ]
}

Now test mapping is present for a couple of known source code files. The rest of the mapping needs to be filled. We need to come up with a way finding out test mapping for WPT tests. It could be done by something similar to the test coverage tool, which keeps track of the code executed when the tests run.

Is there code coverage tool for WPT test in servo?
Is there any other simpler way to populate test mapping?

@jdm
Copy link
Member

@jdm jdm commented Nov 15, 2017

There is no code coverage tool for tests in Servo, unfortunately.

@dsandeephegde
Copy link
Contributor

@dsandeephegde dsandeephegde commented Nov 15, 2017

Then the only way is to add the mapping manually by a person who knows about the particular part of the code? It would be a cumbersome task.
This could actually be a one time task for the full project. Then always update the test mapping when source code or test changes.

bors-servo added a commit that referenced this issue Nov 16, 2017
 Initial steps of Mutation testing

<!-- Please describe your changes on the following line: -->
- Added one strategy of mutation which is replacing occurrences && to ||.
- Added test mapping framework for running mutation tests corresponding to a mutant.
- Added one test_mapping.json to map source file in a folder to WPT test.
- Added README mentioning about Mutation testing.
- Added CI script to invoke mutation test.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes #18529 (github issue number if applicable).
- [x] These changes do not require tests because it is a python script to run mutation test and does not change any behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18984)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Nov 16, 2017
 Initial steps of Mutation testing

<!-- Please describe your changes on the following line: -->
- Added one strategy of mutation which is replacing occurrences && to ||.
- Added test mapping framework for running mutation tests corresponding to a mutant.
- Added one test_mapping.json to map source file in a folder to WPT test.
- Added README mentioning about Mutation testing.
- Added CI script to invoke mutation test.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes #18529 (github issue number if applicable).
- [x] These changes do not require tests because it is a python script to run mutation test and does not change any behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18984)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Nov 16, 2017
 Initial steps of Mutation testing

<!-- Please describe your changes on the following line: -->
- Added one strategy of mutation which is replacing occurrences && to ||.
- Added test mapping framework for running mutation tests corresponding to a mutant.
- Added one test_mapping.json to map source file in a folder to WPT test.
- Added README mentioning about Mutation testing.
- Added CI script to invoke mutation test.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes #18529 (github issue number if applicable).
- [x] These changes do not require tests because it is a python script to run mutation test and does not change any behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18984)
<!-- Reviewable:end -->
@dsandeephegde
Copy link
Contributor

@dsandeephegde dsandeephegde commented Nov 18, 2017

We are now implementing more strategies we would need more test mappings so that we can run it on more files. So if manually adding the test mapping is the only solution then someone can start with it.
Or alternatively, we can just run the whole WPT test for each mutant, if populating the mapping file is too hard. But this would cause additional ~20mins to run tests for each mutant.

We need suggestion on these approaches. Appreciate your thoughts.

@jdm
Copy link
Member

@jdm jdm commented Nov 19, 2017

What's wrong with falling back to all tests for any files that do not have known mappings?

@dsandeephegde
Copy link
Contributor

@dsandeephegde dsandeephegde commented Nov 19, 2017

Time would be the main constraint here. Each mutant will take 25-30mins. If we scale it to the whole servo project there are ~1000 source files then it will take days.
Even if we run only required tests, the build step is taking a lot of time which we are not able to avoid. If we run all tests which will take more time than the build, then we will be in big trouble in terms of time.

@edunham
Copy link
Contributor

@edunham edunham commented Nov 20, 2017

Could we procedurally generate the mappings using a one-time, highly aggressive set of tests? Basically perform a mutation that's guaranteed to break any tests relevant to the file, then use whichever tests break as a result as the list of tests which map to that file.

I'm pretty sure the mutation of deleting each function's body and replacing it with a single line to return a constant of that function's type would be such a "guaranteed mutation".

@dsandeephegde
Copy link
Contributor

@dsandeephegde dsandeephegde commented Nov 22, 2017

Yes, this looks like a very good option to generate test mapping, with a few manual verification. We should definitely consider this approach. But, we currently don't have such a strong mutation strategy, which will not have a lot of false negatives (no test mapping is generated even if there should be one). So, the plan is to finish the existing goals in this project, then come back to this when we are better equipped to tackle this.

bors-servo added a commit that referenced this issue Dec 6, 2017
Mutation Test: with more mutation strategies

<!-- Please describe your changes on the following line: -->

1. Added following mutation strategies:
 - If True (make if always true)
 - If False(make if always false)
 - Modify Comparision (<= to <, >= to >)
 - Plus To Minus
 - Minus To Plus
 - Changing Atomic Strings (make string constant empty)
 - Duplicate Line
 - Delete If Block
2. Randomized the test order.
3. Introduced logging instead of print.
4. Added retry mechanism when mutation cannot be performed on a file by a strategy.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes #18529 (github issue number if applicable).

<!-- Either: -->
- [X] These changes do not require tests because it is a python script to run mutation test and does not change any behavior.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19417)
<!-- Reviewable:end -->
@jdm
Copy link
Member

@jdm jdm commented Mar 7, 2018

This was implemented.

@jdm jdm closed this Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.