Skip to content

Setting maxTestsPerMethod is ignored #1297

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
alisevych opened this issue Nov 2, 2022 · 3 comments · Fixed by #1309
Closed

Setting maxTestsPerMethod is ignored #1297

alisevych opened this issue Nov 2, 2022 · 3 comments · Fixed by #1309
Assignees
Labels
ctg-bug Issue is a bug

Comments

@alisevych
Copy link
Member

alisevych commented Nov 2, 2022

Description

With new functionality:

When maxTestsPerMethod=1 is set test generation for ExceptionExamples is made with default settings.
There are 2 tests generated in a region, 3 tests generated per method.

To Reproduce

  1. In ~/.utbot/settings.properties: set maxTestsPerMethod=1
  2. Install latest build from main into IDEA 2022.2.3
  3. Open UTBotJava project
  4. Generate tests with 95% Symbolic execution for ExceptionExamples#initAnArray(int)

Expected behavior

There should be only 1 test per method generated.

Actual behavior

There are up to 3 tests per method generated, including 2 in the same region.

Visual proofs (screenshots, logs, images)

    ///region Test suites for executable org.utbot.examples.exceptions.ExceptionExamples.initAnArray

    ///region FUZZER: SUCCESSFUL EXECUTIONS for method initAnArray(int)
    /// Actual number of generated tests (3) exceeds per-method limit (1)
    /// The limit can be configured in '{HOME_DIR}/.utbot/settings.properties' with 'maxTestsPerMethod' property

    /**
     * @utbot.classUnderTest {@link ExceptionExamples}
     * @utbot.methodUnderTest {@link ExceptionExamples#initAnArray(int)}
     */
    @Test
    @DisplayName("initAnArray: n = 0 -> return -3")
    public void testInitAnArrayWithCornerCase() {
        ExceptionExamples exceptionExamples = new ExceptionExamples();

        int actual = exceptionExamples.initAnArray(0);

        assertEquals(-3, actual);
    }
    ///endregion

    ///region FUZZER: EXPLICITLY_THROWN_UNCHECKED_EXCEPTIONS for method initAnArray(int)

    /**
     * @utbot.classUnderTest {@link ExceptionExamples}
     * @utbot.methodUnderTest {@link ExceptionExamples#initAnArray(int)}
     */
    @Test
    @DisplayName("initAnArray: n = Int.MAX_VALUE -> throw OutOfMemoryError")
    public void testInitAnArrayThrowsOOMEWithCornerCase() {
        ExceptionExamples exceptionExamples = new ExceptionExamples();

        assertThrows(OutOfMemoryError.class, () -> exceptionExamples.initAnArray(Integer.MAX_VALUE));
    }
    ///endregion

    ///endregion

    ///region Test suites for executable org.utbot.examples.exceptions.ExceptionExamples.nestedExceptions

    ///region FUZZER: SUCCESSFUL EXECUTIONS for method nestedExceptions(int)
    /// Actual number of generated tests (2) exceeds per-method limit (1)
    /// The limit can be configured in '{HOME_DIR}/.utbot/settings.properties' with 'maxTestsPerMethod' property

    /**
     * @utbot.classUnderTest {@link ExceptionExamples}
     * @utbot.methodUnderTest {@link ExceptionExamples#nestedExceptions(int)}
     */
    @Test
    @DisplayName("nestedExceptions: i > 0 -> return 100")
    public void testNestedExceptionsReturns100() {
        ExceptionExamples exceptionExamples = new ExceptionExamples();

        int actual = exceptionExamples.nestedExceptions(1);

        assertEquals(100, actual);
    }
    ///endregion

    ///endregion

Environment

Windows 10 Pro
IntelliJ IDEA 2022.2.3

Related to #1235

@alisevych alisevych added the ctg-bug Issue is a bug label Nov 2, 2022
@alisevych alisevych added this to the 2022.11 Release milestone Nov 2, 2022
@korifey korifey moved this to Todo in UTBot Java Nov 2, 2022
@Vassiliy-Kudryashov Vassiliy-Kudryashov moved this from Todo to In Progress in UTBot Java Nov 3, 2022
@Vassiliy-Kudryashov Vassiliy-Kudryashov linked a pull request Nov 3, 2022 that will close this issue
3 tasks
Repository owner moved this from In Progress to Done in UTBot Java Nov 7, 2022
@alisevych
Copy link
Member Author

@Vassiliy-Kudryashov
Reproducing

Steps to reproduce

  1. Set maxTestsPerMethod=1 and maxTestsPerMethod=2
  2. Installed the latest main in IDEA 2022.2.3
  3. Generated tests with default setting on the following code:
public class CheckStatic {
    public int connect(Socket socket) throws IOException {
        socket.connect(new InetSocketAddress("0.0.0.0", 22));
        return 0;
    }

Actual result

The following tests were generated:

    ///region Test suites for executable CheckStatic.connect

    ///region FUZZER: SECURITY for method connect(java.net.Socket)

    /**
     * @utbot.classUnderTest {@link .CheckStatic}
     * @utbot.methodUnderTest {@link .CheckStatic#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int, boolean)")
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect() throws IOException {
        CheckStatic checkStatic = new CheckStatic();
        Socket socket = new Socket("jkmqh", 568849899, true);

        /* This test fails because method [CheckStatic.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "jkmqh" "resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link .CheckStatic}
     * @utbot.methodUnderTest {@link .CheckStatic#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int)")
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect1() throws IOException {
        CheckStatic checkStatic = new CheckStatic();
        Socket socket = new Socket("hlcoj", 1525745488);

        /* This test fails because method [CheckStatic.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "hlcoj" "resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link .CheckStatic}
     * @utbot.methodUnderTest {@link .CheckStatic#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int, boolean)")
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect2() throws IOException {
        CheckStatic checkStatic = new CheckStatic();
        Socket socket = new Socket("", 22, true);

        /* This test fails because method [CheckStatic.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:22" "connect,resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link .CheckStatic}
     * @utbot.methodUnderTest {@link .CheckStatic#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int, boolean)")
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect3() throws IOException {
        CheckStatic checkStatic = new CheckStatic();
        Socket socket = new Socket("jkmqh", 22, false);

        /* This test fails because method [CheckStatic.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "jkmqh" "resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link .CheckStatic}
     * @utbot.methodUnderTest {@link .CheckStatic#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int, boolean)")
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect4() throws IOException {
        CheckStatic checkStatic = new CheckStatic();
        Socket socket = new Socket("", 0, true);

        /* This test fails because method [CheckStatic.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:0" "connect,resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link .CheckStatic}
     * @utbot.methodUnderTest {@link .CheckStatic#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int)")
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect5() throws IOException {
        CheckStatic checkStatic = new CheckStatic();
        Socket socket = new Socket("0.0.0.0", 22);

        /* This test fails because method [CheckStatic.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "0.0.0.0:22" "connect,resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link .CheckStatic}
     * @utbot.methodUnderTest {@link .CheckStatic#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int)")
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect6() throws IOException {
        CheckStatic checkStatic = new CheckStatic();
        Socket socket = new Socket("noimn", 427785292);

        /* This test fails because method [CheckStatic.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "noimn" "resolve")] */
    }

    /**
     * @utbot.classUnderTest {@link .CheckStatic}
     * @utbot.methodUnderTest {@link .CheckStatic#connect(Socket)}
     */
    @Test
    @DisplayName("connect: socket = Socket(String, int)")
    @Disabled(value = "Disabled due to sandbox")
    public void testConnect7() throws IOException {
        CheckStatic checkStatic = new CheckStatic();
        Socket socket = new Socket("", 0);

        /* This test fails because method [CheckStatic.connect] produces [java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:0" "connect,resolve")] */
    }
    ///endregion

    ///region Errors report for connect

    public void testConnect_errors() {
        // Couldn't generate some tests. List of errors:
        // 
        // 70 occurrences of:
        // Default concrete execution failed

    }
    ///endregion

    ///endregion

@alisevych alisevych reopened this Nov 9, 2022
Repository owner moved this from Done to In Progress in UTBot Java Nov 9, 2022
@alisevych
Copy link
Member Author

alisevych commented Nov 9, 2022

One more scenario:

  1. Set maxTestsPerMethod=2 in settings.properties
  2. Installed the latest main in IDEA 2022.2.3
  3. Generated tests with default setting on the following code:
    org.utbot.examples.controlflow.Cycles.loopInsideLoop

Actual result

There are 4 tests generated in region
///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method loopInsideLoop(int)

@alisevych alisevych changed the title maxTestsPerMethod=1 is exceeded Setting maxTestsPerMethod is ignored Nov 10, 2022
@Vassiliy-Kudryashov
Copy link
Member

The key was renamed to maxTestsPerMethodInRegion within 32deee9

Repository owner moved this from In Progress to Done in UTBot Java Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ctg-bug Issue is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants