Skip to content

Create mocks in output values. **CANNOT BE MERGED INTO MAIN** - #127

Merged
EgorkaKulikov merged 5 commits into
competitions_2024from
caelmbleidd/mocks
Nov 28, 2023
Merged

Create mocks in output values. **CANNOT BE MERGED INTO MAIN**#127
EgorkaKulikov merged 5 commits into
competitions_2024from
caelmbleidd/mocks

Conversation

@CaelmBleidd

Copy link
Copy Markdown
Member

No description provided.

@CaelmBleiddCaelmBleidd changed the title Create mocks in output valuesCreate mocks in output values. **CANNOT BE MERGED INTO MAIN**Nov 21, 2023
@EgorkaKulikov
EgorkaKulikovforce-pushed the competitions_2024 branch 3 times, most recently from 9b1acd9 to a4b05b7CompareNovember 24, 2023 14:52
@IlyaMuravjov

Copy link
Copy Markdown
Collaborator

Running on org.usvm.samples.mock.MockRandomExamples.randomAsParameter after updating JcTestExecutor in UtBot I get the following tests (we can't use USVM's JcTestExecutor, because it's in test source root and also it doesn't return UTest and UTestExecutionResult).

/** * @utbot.classUnderTest {@link org.usvm.samples.mock.MockRandomExamples} * @utbot.methodUnderTest {@link org.usvm.samples.mock.MockRandomExamples#randomAsParameter(java.util.Random,int)} */@Test(expected = NullPointerException.class)
publicvoidtestRandomAsParameterThrowsNPEWithCornerCase() throwsException {
MockRandomExamplesmockRandomExamples = ((MockRandomExamples) createInstance("org.usvm.samples.mock.MockRandomExamples"));
mockRandomExamples.randomAsParameter(null, 0);
}
/** * @utbot.classUnderTest {@link org.usvm.samples.mock.MockRandomExamples} * @utbot.methodUnderTest {@link org.usvm.samples.mock.MockRandomExamples#randomAsParameter(java.util.Random,int)} */@Test(expected = NullPointerException.class)
publicvoidtestRandomAsParameterThrowsNPEWithCornerCase1() throwsException {
MockRandomExamplesmockRandomExamples = ((MockRandomExamples) createInstance("org.usvm.samples.mock.MockRandomExamples"));
RandomrandomMock = mock(Random.class);
setField(randomMock, "java.util.Random", "nextNextGaussian", 0.0);
mockRandomExamples.randomAsParameter(randomMock, 0);
}

The following JcState:
image

And the following UTest with no mocked methods:
image

@Saloed

Copy link
Copy Markdown
Collaborator

@IlyaMuravjov should be fixed now

@IlyaMuravjov

Copy link
Copy Markdown
Collaborator

@Saloed I am still getting same results on ilya_m/contest/mocks branch (update usvmVersion locally)

@Saloed

Copy link
Copy Markdown
Collaborator

Fixed

@IlyaMuravjovIlyaMuravjov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Now, two correct tests are generated for org.usvm.samples.mock.MockRandomExamples.randomAsParameter, although there's still unnecessary set field for nextNextGaussian.

/** * @utbot.classUnderTest {@link org.usvm.samples.mock.MockRandomExamples} * @utbot.methodUnderTest {@link org.usvm.samples.mock.MockRandomExamples#randomAsParameter(java.util.Random,int)} */@TestpublicvoidtestRandomAsParameterReturnsZeroWithCornerCase() throwsException {
MockRandomExamplesmockRandomExamples = ((MockRandomExamples) createInstance("org.usvm.samples.mock.MockRandomExamples"));
RandomrandomMock = mock(Random.class);
(when(randomMock.nextInt())).thenReturn(0);
setField(randomMock, "java.util.Random", "nextNextGaussian", 0.0);
intactual = mockRandomExamples.randomAsParameter(randomMock, 0);
assertEquals(0, actual);
}
/** * @utbot.classUnderTest {@link org.usvm.samples.mock.MockRandomExamples} * @utbot.methodUnderTest {@link org.usvm.samples.mock.MockRandomExamples#randomAsParameter(java.util.Random,int)} */@TestpublicvoidtestRandomAsParameterReturnsOneWithCornerCase() throwsException {
MockRandomExamplesmockRandomExamples = ((MockRandomExamples) createInstance("org.usvm.samples.mock.MockRandomExamples"));
RandomrandomMock = mock(Random.class);
(when(randomMock.nextInt())).thenReturn(1);
setField(randomMock, "java.util.Random", "nextNextGaussian", 0.0);
intactual = mockRandomExamples.randomAsParameter(randomMock, 0);
assertEquals(1, actual);
}

@EgorkaKulikov
EgorkaKulikov merged commit 2f255c6 into competitions_2024Nov 28, 2023
Saloed added a commit that referenced this pull request Nov 29, 2023
* Create mocks in output values
* Rebase
* Fix tests
* Fix mocks for approximated methods
* Remove approximations specific methods filter
---------
Co-authored-by: Valentyn Sobol <napster_1997@mail.ru>
@Saloed
Saloed deleted the caelmbleidd/mocks branch December 11, 2023 13:21
Saloed added a commit that referenced this pull request Feb 14, 2024
* Create mocks in output values
* Rebase
* Fix tests
* Fix mocks for approximated methods
* Remove approximations specific methods filter
---------
Co-authored-by: Valentyn Sobol <napster_1997@mail.ru>
Saloed pushed a commit that referenced this pull request Apr 4, 2024
Allow configuring paths to instrumentation jars, approximation jars and java home (#166)
Revert "Removed copying <clinit> for interfaces in instrumentation"
Fixed Trace Collector
Removed copying <clinit> for interfaces in instrumentation
Added caching of trace methods
Fixed mocking methods of unknown classes
Hacked max array size for concrete size
Fixed classloader for logger
Treat runner timeout as failure
Fix jdk internal types
Added hack for non-null `value` field in strings (#165)
Fix bug with tracing of approximated methods
concrete-executor: java home option
Types draft
concrete-executor: add persistence option
Fixed resolving enum values without any constraints
approximations: fix map anyKey guarantees
jc-test-resolver: class constants
core: more safe machine step
core: more safe machine step
jc-test-resolver: better handling of strings and classes
core: better soft constraints
jc-interpreter: better exception types
jc-interpreter: get rid of unknown classes when possible
jc-interpreter: fix getTyped for method
jvm-concrete-executor: Don't ignore exceptions in instance allocation
Create mocks in output values. **CANNOT BE MERGED INTO MAIN** (#127)
* Create mocks in output values
* Rebase
* Fix tests
* Fix mocks for approximated methods
* Remove approximations specific methods filter
---------
Co-authored-by: Valentyn Sobol <napster_1997@mail.ru>
More informative error message
Fix compilation after rebase
more safe uTestInst execution
minor
Fix of bug with classloader
Flow state collectors (#125)
* Avoid `jdk.internal` in `org.usvm.instrumentation.util.URLClassPathLoader` (#94)
* Flow collectors
---------
Co-authored-by: IlyaMuravjov <71839386+IlyaMuravjov@users.noreply.github.com>
Avoid `jdk.internal` in `org.usvm.instrumentation.util.URLClassPathLoader` (#94)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@CaelmBleidd@IlyaMuravjov@Saloed@DaniilStepanov@EgorkaKulikov