Skip to content

Commit 0904755

Browse files
Samat Gaynutdinovantipeon
Samat Gaynutdinov
authored andcommitted
portable tests
1 parent 5558e53 commit 0904755

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+823
-308
lines changed

.github/workflows/build-utbot.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,75 @@ 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+
98+
build-utbot-and-generate-test:
99+
needs: matrix-prep
100+
strategy:
101+
matrix: ${{ fromJson(needs.matrix-prep.outputs.matrix) }}
102+
runs-on: ubuntu-${{ matrix.OPERATING_SYSTEM_TAG }}
103+
container:
104+
image: ghcr.io/unittestbot/utbotcpp/base_env:${{ matrix.DOCKER_TAG }}
105+
credentials:
106+
username: ${{ github.actor }}
107+
password: ${{ secrets.GITHUB_TOKEN }}
108+
env:
109+
UTBOT_ALL: /utbot_distr
110+
UTBOT_INSTALL_DIR: /utbot_distr/install
111+
GRPC_PATH: /utbot_distr/install
112+
CLI_PATH: /utbot_distr/cli
113+
DOCKER_TAG: ${{ matrix.DOCKER_TAG }}
114+
ARTIFACT_DIR: utbot-artifact
115+
steps:
116+
- name: Checkout repository
117+
uses: actions/checkout@v2
118+
with:
119+
submodules: recursive
120+
121+
- name: Build UTBot
122+
run: |
123+
chmod +x docker/action-scripts/build-utbot.sh
124+
./docker/action-scripts/build-utbot.sh
125+
126+
- name: Generate tests
127+
run: |
128+
chmod +x docker/action-scripts/generate-tests.sh
129+
./docker/action-scripts/generate-tests.sh
130+
131+
- name: Upload generated tests for next job
132+
uses: actions/upload-artifact@v3
133+
with:
134+
name: project
135+
path: ./integration-tests/c-example
136+
137+
build-portable-container:
138+
needs: build-utbot-and-generate-test
139+
runs-on: ubuntu-18.04
140+
env:
141+
DOCKER_IMAGE_TAG: docker-image
142+
PORTABLE_CONTAINER_NAME: Portable
143+
steps:
144+
- name: Checkout repository
145+
uses: actions/checkout@v2
146+
with:
147+
submodules: recursive
148+
149+
- name: Install dependencies
150+
run: |
151+
chmod +x docker/action-scripts/install-dependencies-for-docker-image-without-utbot.sh
152+
./docker/action-scripts/install-dependencies-for-docker-image-without-utbot.sh
153+
mkdir -p ./c-example
154+
155+
- name: Download generated test
156+
uses: actions/download-artifact@v3
157+
with:
158+
name: project
159+
path: ./c-example
160+
161+
- name: Display structure of downloaded files
162+
run: ls -R
163+
working-directory: ./c-example
164+
165+
- name: Check test portability
166+
run: |
167+
rm -r /home/runner/work/UTBotCpp/UTBotCpp/c-example/build
168+
env make -f /home/runner/work/UTBotCpp/UTBotCpp/c-example/tests/lib/floats/floating_point_plain.mk run GTEST_FLAGS="--gtest_filter=*.plain_isnan_test_1" CLANG="/usr/bin/clang-10" CLANGXX="/usr/bin/clang++-10" GTEST="/gtest"

docker/Dockerfile_image_without_utbot

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM ubuntu:18.04
2+
# use bash as default shell
3+
4+
SHELL ["/bin/bash", "--login", "-c"]
5+
6+
7+
# set user as root for running commands
8+
USER root
9+
10+
RUN apt update && apt install -y build-essential cmake
11+
12+
# install clang
13+
RUN apt update && apt -y install clang-10
14+
15+
# install wget for CMake
16+
# RUN apt update && apt -y install wget
17+
18+
19+
#install git for gtest
20+
RUN apt install -y software-properties-common
21+
RUN apt update
22+
RUN add-apt-repository -y ppa:git-core/ppa
23+
RUN apt update
24+
RUN apt install -y git libcurl4-openssl-dev
25+
26+
ENV INSTALL_DIR=/install
27+
ENV UTBOT_CMAKE_BINARY=cmake
28+
29+
RUN git config --global http.sslVerify "false"
30+
31+
#install gtest
32+
33+
RUN git clone --single-branch -b release-1.10.0 https://github.com/google/googletest.git /gtest
34+
RUN cd /gtest && mkdir build && cd build && \
35+
$UTBOT_CMAKE_BINARY -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR .. && \
36+
$UTBOT_CMAKE_BINARY --build . --target install && \
37+
cd /
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
#for fail-fast execution mode
4+
set -e
5+
6+
# set environment
7+
source docker/building_dependencies/runtime_env.sh
8+
9+
# Identify the directory where the current script is located
10+
CURRENT_FOLDER="$( cd $( dirname ${BASH_SOURCE[0]} ) && pwd )"
11+
PROJECT_DIR=$CURRENT_FOLDER/../..
12+
13+
# Generate tests
14+
TARGET_PROJECT=$PROJECT_DIR/integration-tests/c-example
15+
mkdir $TARGET_PROJECT/build
16+
cd $TARGET_PROJECT/build
17+
$UTBOT_INSTALL_DIR/bin/cmake ..
18+
rm -f *.json
19+
$UTBOT_ALL/bear/bin/bear make
20+
21+
$UTBOT_ALL/server-install/utbot generate \
22+
--project-path "$TARGET_PROJECT" file \
23+
--file-path "$TARGET_PROJECT/lib/floats/floating_point_plain.c"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
#for fail-fast execution mode
4+
set -e
5+
6+
sudo apt update && sudo apt install -y build-essential cmake
7+
8+
# install clang
9+
sudo apt update && sudo apt -y install clang-10
10+
11+
#install git for gtest
12+
sudo apt install -y software-properties-common
13+
sudo apt update
14+
sudo add-apt-repository -y ppa:git-core/ppa
15+
sudo apt update
16+
sudo apt install -y git libcurl4-openssl-dev
17+
18+
INSTALL_DIR=/install
19+
UTBOT_CMAKE_BINARY=cmake
20+
21+
sudo git config --global http.sslVerify "false"
22+
23+
#install gtest
24+
sudo git clone --single-branch -b release-1.10.0 https://github.com/google/googletest.git /gtest
25+
cd /gtest && sudo mkdir build && cd build && \
26+
sudo $UTBOT_CMAKE_BINARY -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR .. && \
27+
sudo $UTBOT_CMAKE_BINARY --build . --target install && \
28+
cd /

docker/release_distribution_scripts/utbot_run_system.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ then
112112

113113
#Server-specific parameters
114114
UTBOT_EXECUTABLE_PATH=$UTBOT_BINARIES_FOLDER/$UTBOT_PROCESS_PATTERN
115-
UTBOT_SERVER_OPTIONS="$UTBOT_MODE --port $UTBOT_PORT --log=$UTBOT_LOGS_FOLDER --tmp=$UTBOT_ALL"
115+
UTBOT_SERVER_OPTIONS="$UTBOT_MODE --port $UTBOT_PORT --log=$UTBOT_LOGS_FOLDER"
116116
UTBOT_STDOUT_LOG_FILE=$UTBOT_LOGS_FOLDER/logs/"latest.log"
117117

118118
log "Starting a new server process; logs are written into [$UTBOT_LOGS_FOLDER] folder"

server/src/BordersFinder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ BordersFinder::BordersFinder(const fs::path &filePath,
1717
const std::shared_ptr<CompilationDatabase> &compilationDatabase,
1818
const fs::path &compileCommandsJsonPath)
1919
: line(line), classBorder(std::nullopt), clangToolRunner(compilationDatabase) {
20-
buildRootPath = Paths::subtractPath(compileCommandsJsonPath.string(), CompilationUtils::MOUNTED_CC_JSON_DIR_NAME);
20+
buildRootPath = Paths::subtractPath(compileCommandsJsonPath.string(), CompilationUtils::UTBOT_BUILD_DIR_NAME);
2121
lineInfo.filePath = filePath;
2222
}
2323

server/src/KleeGenerator.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ KleeGenerator::buildByCDb(const CollectionUtils::MapFileTo<fs::path> &filesToBui
4949
for (const auto &compileCommand : compileCommands) {
5050
fs::path output = compileCommand.getOutput();
5151
outfilePaths.emplace_back(output);
52-
makefilePrinter.declareTarget(output, { compileCommand.getSourcePath() },
53-
{ compileCommand.toStringWithChangingDirectory() });
52+
utbot::CompileCommand compileCommandWithChangingDirectory{compileCommand, true};
53+
makefilePrinter.declareTarget(output, { compileCommandWithChangingDirectory.getSourcePath() },
54+
{ compileCommandWithChangingDirectory.toStringWithChangingDirectory() });
5455
}
5556

5657
makefilePrinter.declareTarget("all", outfilePaths, {});

server/src/Paths.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace Paths {
1919
}
2020

2121
fs::path logPath = getHomeDir();
22-
fs::path tmpPath = getHomeDir();
2322

2423
CollectionUtils::FileSet
2524
filterPathsByDirNames(const CollectionUtils::FileSet &paths,
@@ -193,19 +192,24 @@ namespace Paths {
193192
return getArtifactsRootDir(projectContext) / "tests";
194193
}
195194
fs::path getMakefileDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
196-
return getArtifactsRootDir(projectContext) / "make" / getRelativeDirPath(projectContext, sourceFilePath);
195+
return getPathDirRelativeToTestDir(projectContext, sourceFilePath);
197196
}
198197
fs::path getGeneratedHeaderDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
198+
return getPathDirRelativeToTestDir(projectContext, sourceFilePath);
199+
}
200+
201+
fs::path getPathDirRelativeToTestDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
199202
return projectContext.testDirPath / getRelativeDirPath(projectContext, sourceFilePath);
200203
}
204+
201205
fs::path getRecompiledDir(const utbot::ProjectContext &projectContext) {
202-
return getTmpDir(projectContext.projectName) / "recompiled";
206+
return getUtbotBuildDir(projectContext) / "recompiled";
203207
}
204208
fs::path getTestObjectDir(const utbot::ProjectContext &projectContext) {
205-
return getTmpDir(projectContext.projectName) / "test_objects";
209+
return getUtbotBuildDir(projectContext) / "test_objects";
206210
}
207211
fs::path getCoverageDir(const utbot::ProjectContext &projectContext) {
208-
return getTmpDir(projectContext.projectName) / "coverage";
212+
return getUtbotBuildDir(projectContext) / "coverage";
209213
}
210214
fs::path getClangCoverageDir(const utbot::ProjectContext &projectContext) {
211215
return getCoverageDir(projectContext) / "lcov";
@@ -248,22 +252,22 @@ namespace Paths {
248252

249253
fs::path getBuildFilePath(const utbot::ProjectContext &projectContext,
250254
const fs::path &sourceFilePath) {
251-
fs::path path = getTmpDir(projectContext.projectName) /
255+
fs::path path = getUtbotBuildDir(projectContext) /
252256
getRelativeDirPath(projectContext, sourceFilePath) /
253257
sourceFilePath.filename();
254258
return addExtension(path, ".o");
255259
}
256260

257261
fs::path getStubBuildFilePath(const utbot::ProjectContext &projectContext,
258262
const fs::path &sourceFilePath) {
259-
fs::path path = getTmpDir(projectContext.projectName) /
263+
fs::path path = getUtbotBuildDir(projectContext) /
260264
getRelativeDirPath(projectContext, sourceFilePath) /
261265
sourcePathToStubName(sourceFilePath);
262266
return addExtension(path, ".o");
263267
}
264268

265269
fs::path getWrapperDirPath(const utbot::ProjectContext &projectContext) {
266-
return getArtifactsRootDir(projectContext) / "wrapper";
270+
return projectContext.testDirPath / "wrapper";
267271
}
268272

269273
fs::path getWrapperFilePath(const utbot::ProjectContext &projectContext,
@@ -277,11 +281,12 @@ namespace Paths {
277281
//endregion
278282

279283
//region transformation
280-
static const std::string MAKEFILE_EXTENSION = ".mk";
281-
static const std::string TEST_SUFFIX = "_test";
282-
static const std::string STUB_SUFFIX = "_stub";
283-
static const std::string DOT_SEP = "_dot_";
284-
static const char dot = '.';
284+
const std::string MAKEFILE_EXTENSION = ".mk";
285+
const std::string TEST_SUFFIX = "_test";
286+
const std::string STUB_SUFFIX = "_stub";
287+
const std::string DOT_SEP = "_dot_";
288+
const std::string MAKE_WRAPPER_SUFFIX = "_wrapper";
289+
const char dot = '.';
285290

286291
fs::path sourcePathToTestPath(const utbot::ProjectContext &projectContext,
287292
const fs::path &sourceFilePath) {
@@ -391,6 +396,18 @@ namespace Paths {
391396
return fs::relative(source.parent_path(), projectContext.projectPath);
392397
}
393398

399+
std::optional<std::string> getRelativePathWithShellVariable(const fs::path &shellVariableForBase,
400+
const std::string &base,
401+
const std::string &source) {
402+
std::string returnPath = source;
403+
if (StringUtils::startsWith(source, base)) {
404+
StringUtils::replaceFirst(returnPath, base, shellVariableForBase.string());
405+
return returnPath;
406+
}
407+
return std::nullopt;
408+
}
409+
410+
394411
fs::path stubPathToSourcePath(const utbot::ProjectContext &projectContext,
395412
const fs::path &stubPath) {
396413
fs::path sourceFilePath =
@@ -402,8 +419,8 @@ namespace Paths {
402419
bool isHeadersEqual(const fs::path &srcPath, const fs::path &headerPath) {
403420
return removeSuffix(srcPath, STUB_SUFFIX).stem() == headerPath.stem();
404421
}
405-
fs::path getBuildDir(const utbot::ProjectContext &projectContext) {
406-
return getTmpDir(projectContext.projectName) / "build";
422+
fs::path getUtbotBuildDir(const utbot::ProjectContext &projectContext) {
423+
return projectContext.buildDir / CompilationUtils::UTBOT_BUILD_DIR_NAME;
407424
}
408425

409426
//endregion

0 commit comments

Comments
 (0)