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

Engine doesn't cover branch with "not instanceof" #820

Open
sergeypospelov opened this issue Aug 30, 2022 · 0 comments
Open

Engine doesn't cover branch with "not instanceof" #820

sergeypospelov opened this issue Aug 30, 2022 · 0 comments
Assignees
Labels
comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one

Comments

@sergeypospelov
Copy link
Member

Description

Engine generates 7 executions for this method, but doesn't cover "else" branch for condition (cs1 instanceof String && cs2 instanceof String).

public static boolean equals(CharSequence cs1, CharSequence cs2) {
    if (cs1 == cs2) {
        return true;
    } else if (cs1 != null && cs2 != null) {
        if (cs1.length() != cs2.length()) {
            return false;
        } else if (cs1 instanceof String && cs2 instanceof String) {
            return cs1.equals(cs2);
        } else {
            // Engine never comes into this branch
            int length = cs1.length();
             
            for(int i = 0; i < length; ++i) {
                if (cs1.charAt(i) != cs2.charAt(i)) {
                    return false;
                }
            }
             
            return true;
         }
     } else {
        return false;
    }
}

It happens because of wrappers: we create an object with the only type and concrete implementation. Therefore we don't have any type to !instanceof branch. So we have to work with them both with concrete implementation and without. When we face instanceof instruction, we should use concrete in true branch, otherwise use pure symbolic version

To Reproduce

Steps to reproduce the behavior:

  1. Create the mentioned method
  2. Use plugin to generate tests
  3. Open the generated test
  4. Run tests with coverage

Expected behavior

All branches are covered.

Actual behavior

There is uncovered branch.

Visual proofs (screenshots, logs, images)

image

@sergeypospelov sergeypospelov added ctg-bug Issue is a bug comp-symbolic-engine Issue is related to the symbolic execution engine labels Aug 30, 2022
@dtim dtim self-assigned this Aug 31, 2022
@alisevych alisevych added this to the Release preparation milestone Sep 7, 2022
@alisevych alisevych assigned SBOne-Kenobi and dtim and unassigned dtim Sep 7, 2022
@denis-fokin denis-fokin added the spec-release-tailings Failed to include in the current release, let's include it in the next one label Sep 28, 2022
@denis-fokin denis-fokin removed this from the Release preparation milestone Sep 28, 2022
@alisevych alisevych added this to the 2022.12 Release milestone Oct 7, 2022
@CaelmBleidd CaelmBleidd assigned CaelmBleidd and unassigned dtim Oct 13, 2022
@SBOne-Kenobi SBOne-Kenobi removed their assignment Oct 20, 2022
@alisevych alisevych removed this from the 2022.12 Release milestone Dec 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-symbolic-engine Issue is related to the symbolic execution engine ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one
Projects
Status: In Progress
Development

No branches or pull requests

6 participants