Skip to content

Commit d407df9

Browse files
author
Samat Gaynutdinov
committed
portable tests
1 parent 58cd8ce commit d407df9

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
@@ -91,3 +91,75 @@ jobs:
9191
./docker/action-scripts/build-vsix.sh
9292
chmod +x docker/action-scripts/integration-tests.sh
9393
./docker/action-scripts/integration-tests.sh
94+
95+
build-utbot-and-generate-test:
96+
needs: matrix-prep
97+
strategy:
98+
matrix: ${{ fromJson(needs.matrix-prep.outputs.matrix) }}
99+
runs-on: ubuntu-${{ matrix.OPERATING_SYSTEM_TAG }}
100+
container:
101+
image: ghcr.io/unittestbot/utbotcpp/base_env:${{ matrix.DOCKER_TAG }}
102+
credentials:
103+
username: ${{ github.actor }}
104+
password: ${{ secrets.GITHUB_TOKEN }}
105+
env:
106+
UTBOT_ALL: /utbot_distr
107+
UTBOT_INSTALL_DIR: /utbot_distr/install
108+
GRPC_PATH: /utbot_distr/install
109+
CLI_PATH: /utbot_distr/cli
110+
DOCKER_TAG: ${{ matrix.DOCKER_TAG }}
111+
ARTIFACT_DIR: utbot-artifact
112+
steps:
113+
- name: Checkout repository
114+
uses: actions/checkout@v2
115+
with:
116+
submodules: recursive
117+
118+
- name: Build UTBot
119+
run: |
120+
chmod +x docker/action-scripts/build-utbot.sh
121+
./docker/action-scripts/build-utbot.sh
122+
123+
- name: Generate tests
124+
run: |
125+
chmod +x docker/action-scripts/generate-tests.sh
126+
./docker/action-scripts/generate-tests.sh
127+
128+
- name: Upload generated tests for next job
129+
uses: actions/upload-artifact@v3
130+
with:
131+
name: project
132+
path: ./integration-tests/c-example
133+
134+
build-portable-container:
135+
needs: build-utbot-and-generate-test
136+
runs-on: ubuntu-18.04
137+
env:
138+
DOCKER_IMAGE_TAG: docker-image
139+
PORTABLE_CONTAINER_NAME: Portable
140+
steps:
141+
- name: Checkout repository
142+
uses: actions/checkout@v2
143+
with:
144+
submodules: recursive
145+
146+
- name: Install dependencies
147+
run: |
148+
chmod +x docker/action-scripts/install-dependencies-for-docker-image-without-utbot.sh
149+
./docker/action-scripts/install-dependencies-for-docker-image-without-utbot.sh
150+
mkdir -p ./c-example
151+
152+
- name: Download generated test
153+
uses: actions/download-artifact@v3
154+
with:
155+
name: project
156+
path: ./c-example
157+
158+
- name: Display structure of downloaded files
159+
run: ls -R
160+
working-directory: ./c-example
161+
162+
- name: Check test portability
163+
run: |
164+
rm -r /home/runner/work/UTBotCpp/UTBotCpp/c-example/build
165+
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"
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,
@@ -190,19 +189,24 @@ namespace Paths {
190189
return getArtifactsRootDir(projectContext) / "tests";
191190
}
192191
fs::path getMakefileDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
193-
return getArtifactsRootDir(projectContext) / "make" / getRelativeDirPath(projectContext, sourceFilePath);
192+
return getPathDirRelativeToTestDir(projectContext, sourceFilePath);
194193
}
195194
fs::path getGeneratedHeaderDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
195+
return getPathDirRelativeToTestDir(projectContext, sourceFilePath);
196+
}
197+
198+
fs::path getPathDirRelativeToTestDir(const utbot::ProjectContext &projectContext, const fs::path &sourceFilePath) {
196199
return projectContext.testDirPath / getRelativeDirPath(projectContext, sourceFilePath);
197200
}
201+
198202
fs::path getRecompiledDir(const utbot::ProjectContext &projectContext) {
199-
return getTmpDir(projectContext.projectName) / "recompiled";
203+
return getUtbotBuildDir(projectContext) / "recompiled";
200204
}
201205
fs::path getTestObjectDir(const utbot::ProjectContext &projectContext) {
202-
return getTmpDir(projectContext.projectName) / "test_objects";
206+
return getUtbotBuildDir(projectContext) / "test_objects";
203207
}
204208
fs::path getCoverageDir(const utbot::ProjectContext &projectContext) {
205-
return getTmpDir(projectContext.projectName) / "coverage";
209+
return getUtbotBuildDir(projectContext) / "coverage";
206210
}
207211
fs::path getClangCoverageDir(const utbot::ProjectContext &projectContext) {
208212
return getCoverageDir(projectContext) / "lcov";
@@ -245,22 +249,22 @@ namespace Paths {
245249

246250
fs::path getBuildFilePath(const utbot::ProjectContext &projectContext,
247251
const fs::path &sourceFilePath) {
248-
fs::path path = getTmpDir(projectContext.projectName) /
252+
fs::path path = getUtbotBuildDir(projectContext) /
249253
getRelativeDirPath(projectContext, sourceFilePath) /
250254
sourceFilePath.filename();
251255
return addExtension(path, ".o");
252256
}
253257

254258
fs::path getStubBuildFilePath(const utbot::ProjectContext &projectContext,
255259
const fs::path &sourceFilePath) {
256-
fs::path path = getTmpDir(projectContext.projectName) /
260+
fs::path path = getUtbotBuildDir(projectContext) /
257261
getRelativeDirPath(projectContext, sourceFilePath) /
258262
sourcePathToStubName(sourceFilePath);
259263
return addExtension(path, ".o");
260264
}
261265

262266
fs::path getWrapperDirPath(const utbot::ProjectContext &projectContext) {
263-
return getArtifactsRootDir(projectContext) / "wrapper";
267+
return projectContext.testDirPath / "wrapper";
264268
}
265269

266270
fs::path getWrapperFilePath(const utbot::ProjectContext &projectContext,
@@ -274,11 +278,12 @@ namespace Paths {
274278
//endregion
275279

276280
//region transformation
277-
static const std::string MAKEFILE_EXTENSION = ".mk";
278-
static const std::string TEST_SUFFIX = "_test";
279-
static const std::string STUB_SUFFIX = "_stub";
280-
static const std::string DOT_SEP = "_dot_";
281-
static const char dot = '.';
281+
const std::string MAKEFILE_EXTENSION = ".mk";
282+
const std::string TEST_SUFFIX = "_test";
283+
const std::string STUB_SUFFIX = "_stub";
284+
const std::string DOT_SEP = "_dot_";
285+
const std::string MAKE_WRAPPER_SUFFIX = "_wrapper";
286+
const char dot = '.';
282287

283288
fs::path sourcePathToTestPath(const utbot::ProjectContext &projectContext,
284289
const fs::path &sourceFilePath) {
@@ -388,6 +393,18 @@ namespace Paths {
388393
return fs::relative(source.parent_path(), projectContext.projectPath);
389394
}
390395

396+
std::optional<std::string> getRelativePathWithShellVariable(const fs::path &shellVariableForBase,
397+
const std::string &base,
398+
const std::string &source) {
399+
std::string returnPath = source;
400+
if (StringUtils::startsWith(source, base)) {
401+
StringUtils::replaceFirst(returnPath, base, shellVariableForBase.string());
402+
return returnPath;
403+
}
404+
return std::nullopt;
405+
}
406+
407+
391408
fs::path stubPathToSourcePath(const utbot::ProjectContext &projectContext,
392409
const fs::path &stubPath) {
393410
fs::path sourceFilePath =
@@ -399,8 +416,8 @@ namespace Paths {
399416
bool isHeadersEqual(const fs::path &srcPath, const fs::path &headerPath) {
400417
return removeSuffix(srcPath, STUB_SUFFIX).stem() == headerPath.stem();
401418
}
402-
fs::path getBuildDir(const utbot::ProjectContext &projectContext) {
403-
return getTmpDir(projectContext.projectName) / "build";
419+
fs::path getUtbotBuildDir(const utbot::ProjectContext &projectContext) {
420+
return projectContext.buildDir / CompilationUtils::UTBOT_BUILD_DIR_NAME;
404421
}
405422

406423
//endregion

0 commit comments

Comments
 (0)