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 contain field initialization with undeclared stubs #606

Closed
IDKWNTCMF opened this issue Jul 26, 2023 · 0 comments · Fixed by #607
Closed

Tests contain field initialization with undeclared stubs #606

IDKWNTCMF opened this issue Jul 26, 2023 · 0 comments · Fixed by #607
Labels
bug Something isn't working

Comments

@IDKWNTCMF
Copy link
Collaborator

Description
When UnitTestBot generates tests for structs with fields of function pointer type, these fields are initialized with generated stubs. But stubs are not generated for internal structs stored by pointers, so undeclared stubs are used.

Example

typedef int (*some_func)();

struct InnerStruct {
    some_func func;
    int func_id;
};

struct MainStruct {
    struct InnerStruct* inner;
};

int process_struct_with_func_pointer(struct MainStruct* str) {
    if (str && str->inner && str->inner->func_id != 0) {
        return 1;
    }
    return 0;
}

To Reproduce
Steps to reproduce the behavior:

  1. Copy example above to your project
  2. Generate tests for function process_struct_with_func_pointer
  3. Try to run generated tests

Expected behavior
Tests are supposed to be executed successfully.

Actual behavior
An error test is generated with information about errors.

Generated test

TEST(regression, process_struct_with_func_pointer_test2)
{
    struct MainStruct str = {
        .inner = NULL
    };
    struct InnerStruct utbotInnerVar1 = {
        .func = InnerStruct_func_stub,
        .func_id = 255
    };

    str.inner = (struct InnerStruct*) &utbotInnerVar1;

    int actual = process_struct_with_func_pointer(&str);
    EXPECT_EQ(1, actual);
    struct MainStruct expected_str = {
        .inner = NULL
    };
}

Logs

/home/utbot/UTBotCpp/integration-tests/c-example/utbot_tests/makefiles/lib/structures/structs/../../../../../utbot_tests/lib/structures/structs/complex_structs_dot_c_test.cpp:19:17: error: use of undeclared identifier 'InnerStruct_func_stub'
        .func = InnerStruct_func_stub,
                ^
/home/utbot/UTBotCpp/integration-tests/c-example/utbot_tests/makefiles/lib/structures/structs/../../../../../utbot_tests/lib/structures/structs/complex_structs_dot_c_test.cpp:38:17: error: use of undeclared identifier 'InnerStruct_func_stub'
        .func = InnerStruct_func_stub,
                ^
2 errors generated.
@IDKWNTCMF IDKWNTCMF added the bug Something isn't working label Jul 26, 2023
@IDKWNTCMF IDKWNTCMF linked a pull request Jul 26, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant