Skip to content

Generate stubs for function pointers of inner structs #607

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions server/src/visitors/FunctionPointerForStubsVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ namespace visitor {
const tests::AbstractValueView *view,
const std::string &access,
int depth) {
if (depth == 0) {
AbstractValueViewVisitor::visitPointer(type, name, view, access, depth);
}
AbstractValueViewVisitor::visitPointer(type, name, view, access, depth);
}

void FunctionPointerForStubsVisitor::visitArray(const types::Type &type,
Expand Down
38 changes: 38 additions & 0 deletions server/test/framework/Server_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,4 +2141,42 @@ namespace {
StatusCountMap expectedStatusCountMap{ { testsgen::TEST_PASSED, 3 } };
testUtils::checkStatuses(resultsMap, tests);
}

TEST_F(Server_Test, Run_Tests_For_Structs_With_Pointers) {
fs::path structs_with_pointers_c = getTestFilePath("structs_with_pointers.c");
auto request = testUtils::createFileRequest(projectName, suitePath, buildDirRelativePath,
srcPaths, structs_with_pointers_c,
GrpcUtils::UTBOT_AUTO_TARGET_PATH, true, false);
auto testGen = FileTestGen(*request, writer.get(), TESTMODE);
Status status = Server::TestsGenServiceImpl::ProcessBaseTestRequest(testGen, writer.get());
ASSERT_TRUE(status.ok()) << status.error_message();
EXPECT_GE(testUtils::getNumberOfTests(testGen.tests), 3);

fs::path testsDirPath = getTestFilePath("tests");

fs::path structs_with_pointers_test_cpp = Paths::sourcePathToTestPath(
utbot::ProjectContext(projectName, suitePath, testsDirPath, buildDirRelativePath, clientProjectPath),
structs_with_pointers_c);
auto testFilter = GrpcUtils::createTestFilterForFile(structs_with_pointers_test_cpp);
auto runRequest = testUtils::createCoverageAndResultsRequest(
projectName, suitePath, testsDirPath, buildDirRelativePath, std::move(testFilter));

static auto coverageAndResultsWriter =
std::make_unique<ServerCoverageAndResultsWriter>(nullptr);
CoverageAndResultsGenerator coverageGenerator{ runRequest.get(),
coverageAndResultsWriter.get() };
utbot::SettingsContext settingsContext{
true, false, 45, 0, false, false, ErrorMode::FAILING, false
};
coverageGenerator.generate(false, settingsContext);

EXPECT_FALSE(coverageGenerator.hasExceptions());
ASSERT_TRUE(coverageGenerator.getCoverageMap().empty());

auto resultsMap = coverageGenerator.getTestResultMap();
auto tests = coverageGenerator.getTestsToLaunch();

StatusCountMap expectedStatusCountMap{ { testsgen::TEST_PASSED, 3 } };
testUtils::checkStatuses(resultsMap, tests);
}
}
1 change: 1 addition & 0 deletions server/test/suites/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ add_executable(server
simple_structs.c
simple_unions.c
struct_with_union.c
structs_with_pointers.c
complex_structs.c
typedefs.c
types.c
Expand Down
8 changes: 8 additions & 0 deletions server/test/suites/server/structs_with_pointers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "structs_with_pointers.h"

int process_struct_with_func_pointer(struct MainStruct* str) {
if (str && str->inner && str->inner->func_id != 0) {
return 1;
}
return 0;
}
17 changes: 17 additions & 0 deletions server/test/suites/server/structs_with_pointers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef UNITTESTBOT_STRUCTS_WITH_POINTERS_H
#define UNITTESTBOT_STRUCTS_WITH_POINTERS_H

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);

#endif // UNITTESTBOT_STRUCTS_WITH_POINTERS_H