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
add PolDet (Pollution Detection) implementation #285
Conversation
Thank you for this contribution. Unfortunately, the build fails. Can you please investigate?
|
The build failure is not due to my code. The JPF builds in Travis CI have been failing due to the same reason since this commit : 1f9c880 |
I can confirm that the mentioned test case is an issue with the build system. #286 should bring in a more recent java version to ci and in the best case this is sufficient to fix the build. |
@y553546436 could you rebase this PR against the current master? I merged the new build system. After a rebase, this PR should pick up the new CI system and we could easily check whether everything is working nicely now. |
df7db5d
to
0532a51
Compare
Thanks! I have rebased my commit and it indeed passes all checks now. |
Looks good, thanks a lot! Do you have a test (even a simple one) that confirms that the feature is working as intended? Maybe you can write a JPF unit test that calls your |
Can you give me some guideline on how to write a JPF unit test? For example, is there an easy way of writing a test that runs something in the JPF level (instead of the native JVM level) and checks whether the JPF crashes? Besides, after running something in the JPF level, is there some way to check the JPF's output? I didn't find guidelines for this in the wiki and the comment in file TestJPF.java is a bit hard to understand. Thanks a lot! |
Hi Luke,
You are right, the wiki page is just an overview; we are always grateful
for additional documentation:
https://github.com/javapathfinder/jpf-core/wiki/Writing-JPF-tests
Perhaps this test can give you some hints:
src/tests/gov/nasa/jpf/test/java/io/FileIOTest.java
It is in general not so easy to capture JPF's output. You could, for
example, work with a listener or write a customer reporter (to report the
final result).
However, it may be easier to check some key data that your extension
detects/reports, and check with one or two assertions if that corresponds
to your expectations.
Perhaps this can be done? Have two tests that execute one unit test each
with your extension, one of them with test pollution and the other one without?
Luke Yi wrote:
… Looks good, thanks a lot! Do you have a test (even a simple one) that
confirms that the feature is working as intended? Maybe you can write a
JPF unit test that calls your |main| method with a very simple example,
and either test that something expected happens, or at the very least,
that the test runs without crashing.
Can you give me some guideline on how to write a JPF unit test? For
example, is there an easy way of writing a test that runs something in the
JPF level (instead of the native JVM level) and checks whether the JPF
crashes? Besides, after running something in the JPF level, is there some
way to check the JPF's output? I didn't find guidelines for this in the
wiki and the comment in file TestJPF.java is a bit hard to understand.
Thanks a lot!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#285 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABXV4R3FECME277CFABQKMDTILY5PANCNFSM42IDKU7A>.
--
Regards,
Cyrille Artho - http://artho.com/
There is no comfort without pain; thus we define salvation through suffering.
-- Cato
|
f448fea
to
6d91ed8
Compare
Hi Cyrille, thanks to your detailed guideline, I managed to write a JPF test (src/tests/PolDet/PolDetTest.java) that runs PolDet@JPF on the 7 example JUnit tests created by me (src/tests/PolDet/PolDetExamples.java). The 7 example tests contain 3 polluter tests (t2, t5, t6), and PolDet@JPF expectedly reports 2 polluter tests (t2, t5), with t6 being a false negative due to common-root isomorphism (described in my paper). t7 modifies the cache in JPF using reflection, and is correctly classified as not a polluter test. Explanation on the two jars addedBecause the PolDet@JPF is dependent on JUnit, I have to provide the JPF test with classpath that contains JUnit dependency (see line 38 in src/tests/PolDet/PolDetTest.java), for which I added two jars (hamcrest-core-1.3.jar and junit-4.12.jar) in src/tests/PolDet . |
Thank you for adding a unit test, this will ensure that the extension's basic functionality still runs when other changes are made to jpf-core. |
Thanks for your quick reply. I understand that the copy of these two JAR files are not desirable, but the problem is that Gradle supports these two JAR files automatically in JVM level, but not in JPF level. Because the PolDet@JPF runs JUnit in the JPF level, I have to provide it with JUnit dependency in the JPF test. If I remove the JAR files, the following error occurs:
My workaround is adding these two JAR files and adding them in the JPF classpath (line 38 in src/tests/PolDet/PolDetTest.java). I didn't find other ways to circumvent the issue without adding the JAR files. |
I see. Gradle produces the right JAR files in
Is it perhaps possible to produce a gradle app task to run the test, instead of a unit test (where I think we are too limited and cannot pass command line arguments)? |
Thanks for your advice. I have successfully removed the two JARs from the commit. After consideration, I agree with you that it makes more sense to produce a gradle app to run the test. To run PolDet@JPF on the example tests now, we can simply run
It also occurred to me that to help people use the tool, we can produce another gradle app that executes PolDet@JPF on a given test class (with given classpath to it). With this gradle app, we can run PolDet@JPF more easily by:
where |
Very nice, thanks! I have just started the CI builds and will get back to it later and merge your PR if the builds pass. |
Hello @y553546436, the Would you please be open to distribute your code under the Apache License as it would help greatly in ensuring license compatibility across the project? The 4 files currently covered under GPL v3.0 are Thanks in advance! |
PolDet@JPF
PolDet (Pollution Detection) implementation using Java PathFinder. This tool detects JUnit tests that pollute the shared program state. For more information, read our paper accepted by JPF workshop 2021: https://y553546436.github.io/files/jpf_sen.pdf .
PolDet implementation
PolDet implementation is in the following three files:
File PolDetMain.java contains class PolDetMain, the entry class to run PolDet. It also contains PolDetListener class, a specialized JUnit listener to call our code before and after the test. File JPF_PolDetListener.java contains the peer class for PolDetListener class. File PolDetSerializer.java contains a specialized JPF state serializer which ignores certain irrelevant parts of the state when serializing.
7 example JUnit test methods are in src/tests/PolDet/PolDetExamples.java, which can be used to check the functionality of PolDet.
Note that no existing code is changed in jpf-core, so it is unlikely that some existing functionality breaks with the changes.
Usage
To run PolDet@JPF:
where
$CLASSPATH
is the classpath to the test class, and$CLASSNAME
is the fully qualified test class name.To test PolDet@JPF on the 7 example tests in src/tests/PolDet/PolDetExamples.java, run
Get the classpath for a Maven project
If you want to run a test class in a Maven project, you can get the classpath containing the class and its dependencies with the following command:
For a single-module maven project,
MODULE
is the project directory. For a multi-project maven directory, MODULE
is the specific module directory containing the test class. For example, project httpcomponents-client (https://github.com/apache/httpcomponents-client) contains sub-modules like httpclient5 and httpclient5-cache. If your test class is inside httpclient5 module, you should run theCP=...
command in directoryhttpcomponents-client/httpclient5
to get the correct classpath. To test your classpath, you can run PolDet@JPF on test classorg.apache.hc.client5.http.async.methods.SimpleBasicHttpRequests
with the script above. There should be one test method namedtestCreateMethodUriString
detected as a polluter test.