Skip to content

[BUG] False negative result of generated test with union for one of init value #450

@tyuldashev

Description

@tyuldashev

Description
With looking identical initialization UTBot test gives different result of the test

To Reproduce

  1. Run test generation on following example
// extracted from integration-tests/c-example/lib/structures/simple_unions.c
union MainUnion {
    union InnerUnion {
        char c;
        short s;
    } inner;

    int x;
    long long y;
};

signed char operate_with_inner_unions(union MainUnion st) {
    if (st.x == 5 || st.y == 5 || st.inner.c == '5' ||
        st.inner.s == 5 ) {
        return '5';
    }

    if (st.x == 5 || st.y == 102 || st.inner.s == 15) {
        return st.inner.c;
    }

    return 'o';
}
  1. One of resulting tests looks like:
TEST(regression, operate_with_inner_unions_test_3)
{
    signed char actual = operate_with_inner_unions({
        // .inner = {
            // .c = '\x0f'
            // .s = 15
        // }
        // .x = 15
        .y = 15LL
    });
    EXPECT_EQ('\x0f', actual);
}
  1. Comment initialization through .y and uncomment initialization with .s, so test becomes
TEST(regression, operate_with_inner_unions_test_3)
{
    signed char actual = operate_with_inner_unions({
        .inner = {
            // .c = '\x0f'
            .s = 15
        }
        // .x = 15
        // .y = 15LL
    });
    EXPECT_EQ('\x0f', actual);
}
  1. Run the test - it still green as expected.
  2. Comment line with .s and uncomment with .c, so test becomes
TEST(regression, operate_with_inner_unions_test_3)
{
    signed char actual = operate_with_inner_unions({
        .inner = {
            .c = '\x0f'
            // .s = 15
        }
        // .x = 15
        // .y = 15LL
    });
    EXPECT_EQ('\x0f', actual);
}
  1. Run the test again, now it fails with error:
Expected equality of these values:
  '\x0f'
    Which is: '\xF' (15)
  actual
    Which is: 'o' (111, 0x6F)

Expected that test still passes

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingverifiedBug fix is verified

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions