Skip to content

Commit 88fa5f3

Browse files
authored
Fix stubs (#648)
* Fix stubs value generation * Disable clion integration tests
1 parent 7444333 commit 88fa5f3

27 files changed

+288
-230
lines changed

.github/workflows/build-utbot.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,23 @@ jobs:
9494
./docker/action-scripts/build-vsix.sh
9595
chmod +x docker/action-scripts/integration-tests.sh
9696
./docker/action-scripts/integration-tests.sh
97-
- name: Setup Java for building CLion plugin
98-
uses: actions/setup-java@v3
99-
with:
100-
distribution: zulu
101-
java-version: 11
102-
- name: Run CLion integration tests
103-
run: |
104-
chmod +x docker/action-scripts/runClionIntegrationTests.sh
105-
./docker/action-scripts/runClionIntegrationTests.sh
106-
- name: Upload logs
107-
uses: actions/upload-artifact@v3
108-
if: failure()
109-
with:
110-
name: test-report
111-
path: |
112-
/github/home/logs
113-
clion-plugin/build/reports/tests/**/*
97+
# - name: Setup Java for building CLion plugin
98+
# uses: actions/setup-java@v3
99+
# with:
100+
# distribution: zulu
101+
# java-version: 11
102+
# - name: Run CLion integration tests
103+
# run: |
104+
# chmod +x docker/action-scripts/runClionIntegrationTests.sh
105+
# ./docker/action-scripts/runClionIntegrationTests.sh
106+
# - name: Upload logs
107+
# uses: actions/upload-artifact@v3
108+
# if: failure()
109+
# with:
110+
# name: test-report
111+
# path: |
112+
# /github/home/logs
113+
# clion-plugin/build/reports/tests/**/*
114114

115115
build-utbot-and-generate-test:
116116
needs: matrix-prep

server/src/ReturnTypesFetcher.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,32 @@
33
#include "fetchers/Fetcher.h"
44
#include "testgens/BaseTestGen.h"
55

6-
void ReturnTypesFetcher::fetch(ProgressWriter *const progressWriter,
7-
const CollectionUtils::FileSet &allFiles) {
8-
tests::TestsMap testsMap;
9-
for (const auto &filePath : allFiles) {
10-
testsMap[filePath];
11-
}
12-
Fetcher(Fetcher::Options::Value::RETURN_TYPE_NAMES_ONLY,
13-
testGen->getTargetBuildDatabase()->compilationDatabase, testsMap, nullptr, nullptr,
14-
testGen->compileCommandsJsonPath, false)
15-
.fetchWithProgress(progressWriter, "Fetching return types for functions", true);
16-
for (auto const &[sourceFilePath, test] : testsMap) {
17-
for (const auto& [methodName, methodDescription]: test.methods) {
18-
auto returnTypedefName = PrinterUtils::getReturnMangledName(methodDescription.name);
19-
if (CollectionUtils::containsKey(methodDescription.functionPointers, returnTypedefName)) {
20-
types::Type returnTypeCopy = methodDescription.returnType;
21-
returnTypeCopy.replaceUsedType(returnTypedefName);
22-
testGen->methodNameToReturnTypeMap[methodName] = returnTypeCopy;
23-
} else {
24-
testGen->methodNameToReturnTypeMap[methodName] = methodDescription.returnType;
6+
void ReturnTypesFetcher::fetch(const ProgressWriter *progressWriter) {
7+
const std::shared_ptr<CompilationDatabase> buildDatabases[] = {
8+
testGen->getTargetBuildDatabase()->compilationDatabase,
9+
testGen->getProjectBuildDatabase()->compilationDatabase};
10+
for (const auto &buildDatabase: buildDatabases) {
11+
tests::TestsMap testsMap;
12+
for (const auto &filePath: buildDatabase->getAllFiles()) {
13+
testsMap[filePath];
14+
}
15+
Fetcher(Fetcher::Options::Value::RETURN_TYPE_NAMES_ONLY,
16+
buildDatabase, testsMap, nullptr, nullptr,
17+
testGen->compileCommandsJsonPath, false)
18+
.fetchWithProgress(progressWriter, "Fetching return types for functions", true);
19+
for (auto const &[sourceFilePath, test]: testsMap) {
20+
for (const auto &[methodName, methodDescription]: test.methods) {
21+
if (testGen->methodNameToReturnTypeMap.count(methodName)) {
22+
continue;
23+
}
24+
auto returnTypedefName = PrinterUtils::getReturnMangledName(methodDescription.name);
25+
if (CollectionUtils::containsKey(methodDescription.functionPointers, returnTypedefName)) {
26+
types::Type returnTypeCopy = methodDescription.returnType;
27+
returnTypeCopy.replaceUsedType(returnTypedefName);
28+
testGen->methodNameToReturnTypeMap[methodName] = returnTypeCopy;
29+
} else {
30+
testGen->methodNameToReturnTypeMap[methodName] = methodDescription.returnType;
31+
}
2532
}
2633
}
2734
}

server/src/ReturnTypesFetcher.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ReturnTypesFetcher {
1818
explicit ReturnTypesFetcher(BaseTestGen *testGen) : testGen(testGen) {
1919
}
2020

21-
void fetch(ProgressWriter *const progressWriter, const CollectionUtils::FileSet &allFiles);
21+
void fetch(const ProgressWriter *progressWriter);
2222
};
2323

2424

server/src/Server.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
206206
types::TypesHandler typesHandler{testGen.types, sizeContext};
207207
testGen.progressWriter->writeProgress("Generating stub files", 0.0);
208208
StubGen stubGen(testGen);
209-
210-
Synchronizer synchronizer(&testGen, &sizeContext);
211-
synchronizer.synchronize(typesHandler);
212-
209+
{
210+
Synchronizer synchronizer(&testGen, &sizeContext);
211+
synchronizer.synchronize(typesHandler);
212+
}
213213
std::shared_ptr<LineInfo> lineInfo = nullptr;
214214
auto lineTestGen = dynamic_cast<LineTestGen *>(&testGen);
215215

@@ -253,9 +253,10 @@ Status Server::TestsGenServiceImpl::ProcessBaseTestRequest(BaseTestGen &testGen,
253253
}
254254
}
255255
auto generator = std::make_shared<KleeGenerator>(&testGen, typesHandler, pathSubstitution);
256-
257-
ReturnTypesFetcher returnTypesFetcher{&testGen};
258-
returnTypesFetcher.fetch(testGen.progressWriter, synchronizer.getTargetSourceFiles());
256+
{
257+
ReturnTypesFetcher returnTypesFetcher(&testGen);
258+
returnTypesFetcher.fetch(testGen.progressWriter);
259+
}
259260
LOG_S(DEBUG) << "Temporary build directory path: " << testGen.serverBuildDir;
260261
generator->buildKleeFiles(testGen.tests, lineInfo);
261262
generator->handleFailedFunctions(testGen.tests);
@@ -562,8 +563,10 @@ Status Server::TestsGenServiceImpl::ProcessProjectStubsRequest(BaseTestGen *test
562563
testGen->compileCommandsJsonPath, false);
563564

564565
fetcher.fetchWithProgress(testGen->progressWriter, logMessage);
565-
Synchronizer synchronizer(testGen, &sizeContext);
566-
synchronizer.synchronize(typesHandler);
566+
{
567+
Synchronizer synchronizer(testGen, &sizeContext);
568+
synchronizer.synchronize(typesHandler);
569+
}
567570
stubsWriter->writeResponse(testGen->synchronizedStubs, testGen->projectContext.testDirPath);
568571
return Status::OK;
569572
}

server/src/Synchronizer.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ bool Synchronizer::isProbablyOutdatedWrappers(const fs::path &srcFilePath) const
8888
}
8989

9090
CollectionUtils::FileSet Synchronizer::getOutdatedSourcePaths() const {
91-
auto allFiles = getTargetSourceFiles();
92-
auto outdatedSources = CollectionUtils::filterOut(getTargetSourceFiles(), [this](fs::path const &sourcePath) {
93-
return !isProbablyOutdatedWrappers(sourcePath);
94-
});
91+
auto allFiles = testGen->getTargetSourceFiles();
92+
auto outdatedSources = CollectionUtils::filterOut(testGen->getTargetSourceFiles(),
93+
[this](fs::path const &sourcePath) {
94+
return !isProbablyOutdatedWrappers(sourcePath);
95+
});
9596
return outdatedSources;
9697
}
9798

@@ -199,15 +200,14 @@ void Synchronizer::synchronizeStubs(StubSet &outdatedStubs,
199200
for (const StubOperator &outdatedStub : outdatedStubs) {
200201
fs::path stubPath = outdatedStub.getStubPath(testGen->projectContext);
201202
Tests const &methodDescription = stubFilesMap[stubPath];
203+
tests::Tests tests = StubGen::mergeSourceFileIntoStub(
204+
methodDescription, sourceFilesMap.at(outdatedStub.getSourceFilePath()));
202205
if (outdatedStub.isHeader()) {
203-
std::string code = sourceToHeaderRewriter.generateStubHeader(outdatedStub.getSourceFilePath());
206+
std::string code = sourceToHeaderRewriter.generateStubHeader(tests, outdatedStub.getSourceFilePath());
204207
testGen->synchronizedStubs.emplace_back(stubPath, code);
205208
} else {
206-
tests::Tests newStubFile = StubGen::mergeSourceFileIntoStub(
207-
methodDescription, sourceFilesMap.at(outdatedStub.getSourceFilePath()));
208209
printer::StubsPrinter stubsPrinter(Paths::getSourceLanguage(stubPath));
209-
Stubs stubFile =
210-
stubsPrinter.genStubFile(newStubFile, typesHandler, testGen->projectContext);
210+
Stubs stubFile = stubsPrinter.genStubFile(tests, typesHandler, testGen->projectContext);
211211
testGen->synchronizedStubs.emplace_back(stubFile);
212212
}
213213
}
@@ -227,7 +227,7 @@ Synchronizer::createStubsCompilationDatabase(StubSet &stubFiles,
227227
void Synchronizer::synchronizeWrappers(const CollectionUtils::FileSet &outdatedSourcePaths,
228228
const types::TypesHandler &typesHandler) const {
229229
auto sourceFilesNeedToRegenerateWrappers = outdatedSourcePaths;
230-
for (fs::path const &sourceFilePath : getTargetSourceFiles()) {
230+
for (fs::path const &sourceFilePath: testGen->getTargetSourceFiles()) {
231231
if (!CollectionUtils::contains(sourceFilesNeedToRegenerateWrappers, sourceFilePath)) {
232232
auto wrapperFilePath =
233233
Paths::getWrapperFilePath(testGen->projectContext, sourceFilePath);
@@ -247,27 +247,19 @@ void Synchronizer::synchronizeWrappers(const CollectionUtils::FileSet &outdatedS
247247
});
248248
}
249249

250-
const CollectionUtils::FileSet &Synchronizer::getTargetSourceFiles() const {
251-
return testGen->getTargetBuildDatabase()->compilationDatabase->getAllFiles();
252-
}
253-
254-
const CollectionUtils::FileSet &Synchronizer::getProjectSourceFiles() const {
255-
return testGen->getProjectBuildDatabase()->compilationDatabase->getAllFiles();
256-
}
257-
258250
StubSet Synchronizer::getStubsFiles() const {
259251
return getStubSetFromSources(testGen->getProjectBuildDatabase()->compilationDatabase->getAllFiles());
260252
}
261253

262254
void Synchronizer::prepareDirectory(const fs::path &stubDirectory) {
263255
fs::create_directories(stubDirectory);
264-
for (const auto &entry : fs::recursive_directory_iterator(stubDirectory)) {
256+
for (const auto &entry: fs::recursive_directory_iterator(stubDirectory)) {
265257
if (entry.is_regular_file()) {
266258
fs::path stubPath = entry.path();
267259
if (!Paths::isHeaderFile(stubPath)) {
268260
fs::path sourcePath =
269-
Paths::stubPathToSourcePath(testGen->projectContext, stubPath);
270-
if (!CollectionUtils::contains(getProjectSourceFiles(), sourcePath)) {
261+
Paths::stubPathToSourcePath(testGen->projectContext, stubPath);
262+
if (!CollectionUtils::contains(testGen->getProjectSourceFiles(), sourcePath)) {
271263
LOG_S(DEBUG) << "Found extra file in stub directory: " << stubPath
272264
<< ". Removing it.";
273265
fs::remove(stubPath);

server/src/Synchronizer.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,33 @@ class Synchronizer {
2727

2828
[[nodiscard]] std::unordered_set<StubOperator, HashUtils::StubHash> getOutdatedStubs() const;
2929

30-
long long getFileOutdatedTime(const fs::path &filePath) const;
30+
[[nodiscard]] long long getFileOutdatedTime(const fs::path &filePath) const;
3131

32-
bool isProbablyOutdatedStubs(const fs::path &srcFilePath) const;
32+
[[nodiscard]] bool isProbablyOutdatedStubs(const fs::path &srcFilePath) const;
3333

34-
bool isProbablyOutdatedWrappers(const fs::path &srcFilePath) const;
34+
[[nodiscard]] bool isProbablyOutdatedWrappers(const fs::path &srcFilePath) const;
3535

36-
bool removeStubIfSourceAbsent(const StubOperator &stub) const;
36+
[[nodiscard]] bool removeStubIfSourceAbsent(const StubOperator &stub) const;
3737

3838
void synchronizeStubs(std::unordered_set<StubOperator, HashUtils::StubHash> &outdatedStubs,
3939
const types::TypesHandler &typesHandler);
40+
4041
void synchronizeWrappers(const CollectionUtils::FileSet &outdatedSourcePaths,
4142
const types::TypesHandler &typesHandler) const;
4243

4344
std::shared_ptr<CompilationDatabase>
4445
createStubsCompilationDatabase(
45-
std::unordered_set<StubOperator, HashUtils::StubHash> &stubFiles,
46-
const fs::path &ccJsonStubDirPath) const;
46+
std::unordered_set<StubOperator, HashUtils::StubHash> &stubFiles,
47+
const fs::path &ccJsonStubDirPath) const;
4748

48-
void prepareDirectory(fs::path const& stubDirectory);
49+
void prepareDirectory(fs::path const &stubDirectory);
4950

5051
static std::unordered_set<StubOperator, HashUtils::StubHash>
5152

5253
getStubSetFromSources(const CollectionUtils::FileSet &paths);
54+
55+
[[nodiscard]] std::unordered_set<StubOperator, HashUtils::StubHash> getStubsFiles() const;
56+
5357
public:
5458
static std::unordered_set<StubOperator, HashUtils::StubHash>
5559

@@ -60,10 +64,6 @@ class Synchronizer {
6064
Synchronizer(BaseTestGen *testGen, types::TypesHandler::SizeContext *sizeContext);
6165

6266
void synchronize(const types::TypesHandler &typesHandler);
63-
64-
[[nodiscard]] const CollectionUtils::FileSet &getTargetSourceFiles() const;
65-
[[nodiscard]] const CollectionUtils::FileSet &getProjectSourceFiles() const;
66-
[[nodiscard]] std::unordered_set<StubOperator, HashUtils::StubHash> getStubsFiles() const;
6767
};
6868

6969

0 commit comments

Comments
 (0)