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

Tests with same coverage are not minimized #2540

Closed
alisevych opened this issue Aug 21, 2023 · 4 comments
Closed

Tests with same coverage are not minimized #2540

alisevych opened this issue Aug 21, 2023 · 4 comments
Assignees
Labels
comp-fuzzing Issue is related to the fuzzing comp-minimizer Issue is related to Minimization phase ctg-bug Issue is a bug lang-java Issue is related to Java support

Comments

@alisevych
Copy link
Member

alisevych commented Aug 21, 2023

Description

There are generated two similar tests throwing StackOverflowError generated by Fuzzing.
Their coverage of the user code is the same.
But they are not minimized and both present in resulting test class.

To Reproduce

  1. Install UnitTestBot plugin built from main in IntelliJ IDEA
  2. Open UTBotJava project
  3. Set Fuzzing 100% mode
  4. Generate tests for Recursion$factorial
  5. Find ///region FUZZER: ERROR SUITE for method factorial(int)

Expected behavior

There should be one execution left after minimization with same coverage and same exception class.

Actual behavior

There are two tests on StackOverflowError with the same coverage.
They both cover lines 9, 12, 15 of Recursion.java

Screenshots, logs

    ///region FUZZER: ERROR SUITE for method factorial(int)

    /**
     * @utbot.classUnderTest {@link Recursion}
     * @utbot.methodUnderTest {@link Recursion#factorial(int)}
     */
    @Test
    @DisplayName("factorial: n = 262144 (mutated from zero) -> throw StackOverflowError")
    public void testFactorialThrowsSOE() {
        Recursion recursion = new Recursion();

        assertThrows(StackOverflowError.class, () -> recursion.factorial(262144));
    }

    /**
     * @utbot.classUnderTest {@link Recursion}
     * @utbot.methodUnderTest {@link Recursion#factorial(int)}
     */
    @Test
    @DisplayName("factorial: n = 65537 (mutated from positive) -> throw StackOverflowError")
    public void testFactorialThrowsSOE1() {
        Recursion recursion = new Recursion();

        assertThrows(StackOverflowError.class, () -> recursion.factorial(65537));
    }
    ///endregion

Environment

IntelliJ IDEA version - Ultimate 2023.2
Project - Gradle
JDK - 17

Additional context

Reproducing with Symbolic + Fuzzing mode.
Reproducing with Recursion class copy-pasted into spring-petclinic project.

Also there are many (now - 7) almost identical tests on timeout, with n = 1056, 36, 16416, 36, 2049, 133, 69
Two values are quite the same - 36:

    ///region FUZZER: TIMEOUTS for method fib(int)

    /**
     * @utbot.classUnderTest {@link Recursion}
     * @utbot.methodUnderTest {@link Recursion#fib(int)}
     */
    @Test
    @DisplayName("fib: n = 1056 (mutated from 32)")
    @Timeout(value = 1000L, unit = TimeUnit.MILLISECONDS)
    public void testFib1() {
        Recursion recursion = new Recursion();
        
        /* This execution may take longer than the 1000 ms timeout
         and therefore fail due to exceeding the timeout. */
        assertTimeoutPreemptively(Duration.ofMillis(1000L), () -> recursion.fib(1056));
    }
@alisevych alisevych added ctg-bug Issue is a bug comp-fuzzing Issue is related to the fuzzing comp-minimizer Issue is related to Minimization phase lang-java Issue is related to Java support labels Aug 21, 2023
@alisevych alisevych added this to the September Release milestone Aug 21, 2023
@IlyaMuravjov
Copy link
Collaborator

@alisevych

Minimization decides to keep both executions, because one StackOverflowError is thrown from the line public int factorial(int n) {, while the other one is thrown from the line return n * factorial(n - 1);.

Should we not consider the line which StackOverflowError is thrown from?

@alisevych
Copy link
Member Author

@alisevych

Minimization decides to keep both executions, because one StackOverflowError is thrown from the line public int factorial(int n) {, while the other one is thrown from the line return n * factorial(n - 1);.

Should we not consider the line which StackOverflowError is thrown from?

@Markoutte Please advise

@alisevych alisevych changed the title Two StackOverflowError tests with same coverage are not minimized Tests with same coverage are not minimized Aug 23, 2023
@alisevych
Copy link
Member Author

@alisevych alisevych removed this from the September Release milestone Sep 19, 2023
@alisevych
Copy link
Member Author

Summarizing: currently minimization is designed to check the traces. And if they are a bit different, both executions are kept.

@alisevych alisevych closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in UTBot Java Sep 19, 2023
@alisevych alisevych added this to the September Release milestone Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-fuzzing Issue is related to the fuzzing comp-minimizer Issue is related to Minimization phase ctg-bug Issue is a bug lang-java Issue is related to Java support
Projects
Archived in project
Development

No branches or pull requests

3 participants