Skip to content

Commit 99f881a

Browse files
Alexey Pleshakovqrort
Alexey Pleshakov
authored andcommitted
fix gtest, add developers guide
1 parent 7b2b33b commit 99f881a

File tree

12 files changed

+164
-34
lines changed

12 files changed

+164
-34
lines changed

.github/workflows/build-utbot.yml

+7-28
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,17 @@ jobs:
3333
uses: actions/checkout@v2
3434
with:
3535
submodules: recursive
36-
- name: build UTBot
36+
- name: build UTBot and run unit tests
3737
run: |
3838
source docker/building_dependencies/runtime_env.sh
39-
chmod +x server/build.sh klee/build.sh
40-
cd klee && ./build.sh
41-
cd ..
42-
cd server && ./build.sh
43-
shell: bash
44-
- uses: actions/upload-artifact@v2
45-
with:
46-
name: UTBot unit tests binary
47-
path: build/UTBot_UnitTests
48-
test:
49-
needs: build
50-
runs-on: ubuntu-18.04
51-
container:
52-
image: ghcr.io/unittestbot/utbotcpp/base_env:20-10-2021
53-
credentials:
54-
username: ${{ github.actor }}
55-
password: ${{ secrets.GITHUB_TOKEN }}
56-
steps:
57-
- uses: actions/download-artifact@v2
58-
with:
59-
name: UTBot unit tests binary
60-
path: build/UTBot_UnitTests
61-
- name: run UTBot unit tests
62-
run: |
63-
cd build
39+
chmod +x build.sh
40+
./build.sh
41+
cd server/build
6442
chmod +x UTBot_UnitTests
65-
./UTBot_UnitTests info --log logs
43+
./UTBot_UnitTests info --log `pwd`
6644
shell: bash
6745
- uses: actions/upload-artifact@v2
46+
if: failure()
6847
with:
6948
name: UTBot unit tests logs
70-
path: logs
49+
path: server/build/logs

.github/workflows/publish-base-env.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: Publish UTBot base environment image
22
on:
3-
# push:
43
workflow_dispatch:
54

65
env:

DEVNOTE.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## How to build UTBotCpp from source
2+
3+
UTBot has many dependencies, so the easiest way to build the tool from source and develop it is to use the docker container.
4+
5+
UTBot has a published package called [base_env](https://github.com/UnitTestBot/UTBotCpp/pkgs/container/utbotcpp%2Fbase_env).
6+
It contains all the needed dependencies such as Git, LLVM, GRPC, GoogleTest and so on. **base_env** has multiple versions tagged with dates.
7+
If you are developing the tool, you are most likely to need the most recent version.
8+
9+
To build UTBot from sources:
10+
1. Install [docker](https://docs.docker.com/engine/install/ubuntu/)
11+
2. Run the command
12+
```
13+
docker plugin install lebokus/bindfs
14+
```
15+
3. Run `utbot_docker_dev.sh` script. It will unpack the docker image and mount UTBot sources inside it.
16+
UTBot binary can be built in the docker and run in it.
17+
The script will prompt you to enter an `ssh` port required to ssh into the container using `ssh utbot@host -p $port`, where `host` is docker host IP address (it may be `localhost`). Please, specify a port that is not taken by any process. Also, you will be prompted to enter a port where UTBot itself will be run.
18+
4. Get access to the container via
19+
20+
`ssh utbot@host -p $port`
21+
22+
If you are prompted a password, type in `utbot`.
23+
24+
5. `cd` into `UTBotCpp` directory and run `build.sh` — it is the script that builds KLEE UTBot and runs UTBot unit tests
25+
6. Navigate to `UTBotCpp/server/build` directory and launch the binary with `./utbot server` command. Now the server is running.
26+
7. Launch VS Code on your local machine. Use VS Code [Remote-SSH](https://code.visualstudio.com/docs/remote/ssh) to get access to the docker insides. Navigate to `UTBotCpp/vscode-plugin` directory and press F5. This will build and run UTBot VS Code plugin.
27+
8. A new VS Code window will open; this window will have UTBot VS Code plugin enabled. In this new folder, open `UTBotCpp/integration-tests/c-example` directory.
28+
9. When UTBot Quickstart Wizard requests you to enter server host and port, specify `localhost` and UTBot server run port, respectively.
29+
![Oops, something went wrong! Please look at wizardInstall.gif](media/wizardInstall.gif "UTBot Wizard Demo")
30+
6. Select project path as `/home/utbot/UTBotCpp/integration-tests/c-example`;
31+
7. You are now ready to experience UTBot capabilities! You can view possible commands in Command Palette (Press F1 and type in UTBot).
32+
33+
If you want to change UTBot test generation preferences, you can edit them in File > Preferences > Settings > Extensions > UnitTestBot.
34+
After UTBot configuration, you can select your source directories with the tab on the VSCode toolbar on the left. Then, you can generate tests with the use of Command Palette. Press **F1** and type in "UTBot": You will see tests generation options.
35+
36+
## How to develop UTBotCpp with an IDE
37+
38+
You can edit UTBot sources, rebuild and rerun the server with an IDE. Usually, CLion *Remote host* toolchain is used for it.
39+
40+
To setup it:
41+
1. Open UTBotCpp project with CLion on your local machine.
42+
2. Open **Settings > Build, Execution, Deployment > Toolchains**.
43+
3. Add a new *Remote Host* toolchain.
44+
4. In *Credentials* section, set up an `ssh` connection to the UTBot docker container you have. Consider enabling connection via OpehSSH authentification agent to ease files synchronization.
45+
5. All other fields should fill in automatically.
46+

build.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
4+
#
5+
6+
set -e
7+
set -o pipefail
8+
pwd=$PWD
9+
chmod +x $pwd/klee/build.sh $pwd/Bear/build.sh $pwd/server/build.sh
10+
cd $pwd/klee && ./build.sh
11+
cd $pwd/Bear && ./build.sh
12+
cd $pwd/server && ./build.sh

docker/building_dependencies/runtime_env.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
export UTBOT_ALL=/utbot_distr
99
export UTBOT_INSTALL_DIR=$UTBOT_ALL/install
1010
export UTBOT_CMAKE_BINARY=$UTBOT_INSTALL_DIR/bin/cmake
11-
export C_INCLUDE_PATH=$UTBOT_INSTALL_DIR/lib/clang/10.0.0/include/
11+
export C_INCLUDE_PATH=$UTBOT_INSTALL_DIR/lib/clang/10.0.0/include/:$UTBOT_ALL/gtest/googletest/include
1212
export LLVM_INCLUDE_DIRS=$UTBOT_ALL/llvm/llvm
1313
export CMAKE_CXX_STANDARD=17
1414
export CMAKE_CXX_STANDARD_REQUIRED=ON

docker/utbot_docker_dev.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
5+
#
6+
7+
# This script is used to pull base docker image where klee and UTBot can be built.
8+
9+
CONTAINER_NAME=$USER-utbot-dev
10+
MOUNT_NAME=$USER-utbot
11+
MOUNT_LOCAL_NAME=$MOUNT_NAME-local-mnt
12+
13+
read -e -p "Enter base image tag: " IMAGE_TAG
14+
IMAGE="docker pull ghcr.io/unittestbot/utbotcpp/base_env:$IMAGE_TAG"
15+
16+
echo "Pulling docker image '$IMAGE'"
17+
if ! docker pull $IMAGE > /dev/null; then
18+
echo "Failed to fetch the image. Aborting.."
19+
exit 1
20+
fi
21+
set +e
22+
docker exec "$CONTAINER_NAME" ls > /dev/null 2>&1
23+
if [ $? -eq 0 ]
24+
then
25+
UTBOT_SSH_PORT=`(docker port $CONTAINER_NAME | egrep '2020/tcp ->' | tail -c 5)`
26+
UTBOT_SERVER_PORT=`(docker port $CONTAINER_NAME | egrep '2121/tcp ->' | tail -c 5)`
27+
echo "Found running '$CONTAINER_NAME' container. Reusing its ssh ($UTBOT_SSH_PORT) and utbot ($UTBOT_SERVER_PORT) port mapping"
28+
docker stop $CONTAINER_NAME > /dev/null && docker rm $CONTAINER_NAME > /dev/null
29+
else
30+
docker rm $CONTAINER_NAME > /dev/null 2>&1
31+
# Get ssh port
32+
read -e -p "Enter ssh port to listen: " -i "$UTBOT_SSH_PORT" UTBOT_SSH_PORT
33+
# Get UTBot server port
34+
read -e -p "Enter UTBot server port: " -i "$UTBOT_SERVER_PORT" UTBOT_SERVER_PORT
35+
fi
36+
set -e
37+
38+
# Define local mount folder
39+
read -e -p "Enter local folder to mount in UTBot: " -i "$PWD" PROJECT_SRC
40+
if docker volume inspect $MOUNT_LOCAL_NAME > /dev/null 2>&1 ; then
41+
docker volume rm $MOUNT_LOCAL_NAME > /dev/null
42+
fi
43+
docker volume create --driver lebokus/bindfs:latest -o sourcePath=$PROJECT_SRC -o map=$UID/1000:@$UID/@1000 $MOUNT_LOCAL_NAME > /dev/null
44+
echo "'$MOUNT_LOCAL_NAME' docker volume created."
45+
46+
echo "Recreating docker container..."
47+
docker run -d --restart=unless-stopped \
48+
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined --security-opt apparmor=unconfined \
49+
--name=$CONTAINER_NAME \
50+
-p $UTBOT_SSH_PORT:2020 \
51+
-p $UTBOT_SERVER_PORT:2121 \
52+
-v $MOUNT_NAME:/home/utbot \
53+
-v $MOUNT_LOCAL_NAME:/home/utbot/mnt \
54+
-v /etc/localtime:/etc/localtime:ro \
55+
$IMAGE > /dev/null
56+
echo "Container '$CONTAINER_NAME' is up and running."
57+
echo "UTBOT_SSH_PORT=$UTBOT_SSH_PORT"
58+
echo "UTBOT_SERVER_PORT=$UTBOT_SERVER_PORT"

media/wizardInstall.gif

590 KB
Loading

server/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ add_executable(
148148
UTBot_UnitTests
149149
${ALL_TESTS}
150150
)
151-
target_include_directories(UTBot_UnitTests PUBLIC src src/include)
151+
target_include_directories(UTBot_UnitTests PUBLIC src src/include $ENV{UTBOT_ALL}/gtest/googletest)
152152
target_link_libraries(
153153
UTBot_UnitTests
154154
PUBLIC

server/build.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ mkdir -p build
22
cd build
33
$UTBOT_CMAKE_BINARY -G "Ninja" -DCMAKE_INSTALL_PREFIX=$UTBOT_ALL/server-install ..
44
$UTBOT_CMAKE_BINARY --build .
5-
$UTBOT_CMAKE_BINARY --install .
5+
$UTBOT_CMAKE_BINARY --install .
6+
7+
./UTBot_UnitTests info

server/src/printers/NativeMakefilePrinter.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ namespace printer {
160160
fs::path gtestMainObjectFile = gtestBuildDir / "gtest_main.cc.o";
161161

162162
auto gtestCompilationArguments = defaultCompileCommand;
163+
gtestCompilationArguments.addFlagsToBegin(
164+
{stringFormat("-I%s", Paths::getGtestLibPath() / "googletest/include"),
165+
stringFormat("-I%s", Paths::getGtestLibPath() / "googletest")});
163166
gtestCompilationArguments.setSourcePath(gtestMainSourceFile);
164167
gtestCompilationArguments.setOutput(gtestMainObjectFile);
165168
declareTarget(gtestMainObjectFile, { gtestMainSourceFile },
@@ -241,6 +244,7 @@ namespace printer {
241244
testCompilationCommand.setOptimizationLevel(OPTIMIZATION_FLAG);
242245
testCompilationCommand.filterCFlags();
243246
testCompilationCommand.removeIncludeFlags();
247+
testCompilationCommand.addFlagToBegin(stringFormat("-I%s", Paths::getGtestLibPath() / "googletest/include"));
244248
testCompilationCommand.addFlagToBegin(FPIC_FLAG);
245249
testCompilationCommand.addFlagsToBegin(SANITIZER_NEEDED_FLAGS);
246250

server/test/suites/char/tests/CMakeLists.txt

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@ set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77
set(CMAKE_C_STANDARD_REQUIRED ON)
88

9-
include_directories("${PROJECT_SOURCE_DIR}" "../")
10-
119
add_library(char_test
1210
char_literals_test.cpp)
11+
12+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
13+
add_subdirectory($ENV{UTBOT_ALL}/gtest
14+
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
15+
EXCLUDE_FROM_ALL)
16+
file(GLOB ALL_TESTS "${PROJECT_SOURCE_DIR}/test/framework/*.cpp")
17+
18+
target_include_directories(char_test PUBLIC "${PROJECT_SOURCE_DIR}" "../" $ENV{UTBOT_ALL}/gtest/googletest)
19+
20+
target_link_libraries(
21+
char_test
22+
PUBLIC
23+
gtest_main
24+
)
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.PHONY: all clean
2+
3+
all: exe
4+
5+
clean:
6+
rm exe lib.a lib1.o lib2.o
7+
8+
lib1.o: lib1.c
9+
clang -c -o lib1.o lib1.c
10+
11+
lib2.o: lib2.c
12+
clang -c -o lib2.o lib2.c
13+
14+
lib.a: lib1.o lib2.o
15+
ar crs -o lib.a lib1.o lib2.o
16+
17+
exe: source1.c source2.c lib.a
18+
clang -o exe source1.c source2.c lib.a

0 commit comments

Comments
 (0)