Skip to content
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
48 changes: 48 additions & 0 deletions .github/workflows/build-utbot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build UTBot and run unit tests

on:
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-18.04
container:
# It is impossible to parametrize image via workflow environment,
# so its name is hard-coded.
# https://github.com/actions/runner/issues/480
image: ghcr.io/unittestbot/utbotcpp/base_env:20-10-2021
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
UTBOT_ALL: /utbot_distr
UTBOT_INSTALL_DIR: /utbot_distr/install
GRPC_PATH: /utbot_distr/install
CLI_PATH: /utbot_distr/cli
steps:
- name: Install git
run: |
apt install -y software-properties-common
apt update
add-apt-repository -y ppa:git-core/ppa
apt update
apt install -y git
- name: Checkout repository
uses: actions/checkout@v2
with:
submodules: recursive
- name: build UTBot and run unit tests
run: |
source docker/building_dependencies/runtime_env.sh
chmod +x build.sh
./build.sh
cd server/build
chmod +x UTBot_UnitTests
./UTBot_UnitTests info --log `pwd`
shell: bash
- uses: actions/upload-artifact@v2
if: failure()
with:
name: UTBot unit tests logs
path: server/build/logs
65 changes: 65 additions & 0 deletions .github/workflows/publish-base-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Publish UTBot base environment image
on:
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: base_env
TAG: 20-10-2021

jobs:
build-docker:
runs-on: ubuntu-18.04
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2

- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{env.IMAGE_NAME}}-${{ env.TAG }}
restore-keys: |
${{ runner.os }}-buildx-buildx

- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: ${{env.REGISTRY}}/${{github.repository}}/${{env.IMAGE_NAME}}
tags: |
type=raw,value=${{ env.TAG }}

- name: Build and push image
uses: docker/build-push-action@v2
with:
context: docker
push: true
builder: ${{ steps.buildx.outputs.name }}
file: docker/Dockerfile_base
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
build-args: |
OPERATING_SYSTEM_TAG=18.04
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
18 changes: 18 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[submodule "klee"]
path = klee
url = https://github.com/UnitTestBot/klee.git
[submodule "Bear"]
path = Bear
url = https://github.com/UnitTestBot/Bear.git
[submodule "loguru"]
path = loguru
url = https://github.com/emilk/loguru.git
[submodule "json"]
path = json
url = https://github.com/astoeckel/json.git
[submodule "ordered-map"]
path = ordered-map
url = https://github.com/Tessil/ordered-map
[submodule "parallel-hashmap"]
path = parallel-hashmap
url = https://github.com/greg7mdp/parallel-hashmap
1 change: 1 addition & 0 deletions Bear
Submodule Bear added at 7e6334
46 changes: 46 additions & 0 deletions DEVNOTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## How to build UTBotCpp from source

UTBot has many dependencies, so the easiest way to build the tool from source and develop it is to use the docker container.

UTBot has a published package called [base_env](https://github.com/UnitTestBot/UTBotCpp/pkgs/container/utbotcpp%2Fbase_env).
It contains all the needed dependencies such as Git, LLVM, GRPC, GoogleTest and so on. **base_env** has multiple versions tagged with dates.
If you are developing the tool, you are most likely to need the most recent version.

To build UTBot from sources:
1. Install [docker](https://docs.docker.com/engine/install/ubuntu/)
2. Run the command
```
docker plugin install lebokus/bindfs
```
3. Run `utbot_docker_dev.sh` script. It will unpack the docker image and mount UTBot sources inside it.
UTBot binary can be built in the docker and run in it.
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.
4. Get access to the container via

`ssh utbot@host -p $port`

If you are prompted a password, type in `utbot`.

5. `cd` into `UTBotCpp` directory and run `build.sh` — it is the script that builds KLEE UTBot and runs UTBot unit tests
6. Navigate to `UTBotCpp/server/build` directory and launch the binary with `./utbot server` command. Now the server is running.
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.
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.
9. When UTBot Quickstart Wizard requests you to enter server host and port, specify `localhost` and UTBot server run port, respectively.
![Oops, something went wrong! Please look at wizardInstall.gif](media/wizardInstall.gif "UTBot Wizard Demo")
6. Select project path as `/home/utbot/UTBotCpp/integration-tests/c-example`;
7. You are now ready to experience UTBot capabilities! You can view possible commands in Command Palette (Press F1 and type in UTBot).

If you want to change UTBot test generation preferences, you can edit them in File > Preferences > Settings > Extensions > UnitTestBot.
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.

## How to develop UTBotCpp with an IDE

You can edit UTBot sources, rebuild and rerun the server with an IDE. Usually, CLion *Remote host* toolchain is used for it.

To setup it:
1. Open UTBotCpp project with CLion on your local machine.
2. Open **Settings > Build, Execution, Deployment > Toolchains**.
3. Add a new *Remote Host* toolchain.
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.
5. All other fields should fill in automatically.

12 changes: 12 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#
# Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
#

set -e
set -o pipefail
pwd=$PWD
chmod +x $pwd/klee/build.sh $pwd/Bear/build.sh $pwd/server/build.sh
cd $pwd/klee && ./build.sh
cd $pwd/Bear && ./build.sh
cd $pwd/server && ./build.sh
176 changes: 176 additions & 0 deletions docker/Dockerfile_base
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
#
# Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
#

# This is a base dockerfile for UTBot. It's image can be used as a development environment and as a first step in building UTBot, it's release build and integration tests.
# This dockerfile installs grpc, cmake, llvm, uclibc, z3. Also it installs such packages as ssh, git, openssh-server, nodejs, python and others.
# You need to build this dockerfile inside UnitTestBot/UTBotCpp/docker directory.

ARG OPERATING_SYSTEM_TAG
FROM ubuntu:$OPERATING_SYSTEM_TAG as base_env
LABEL maintainer="Huawei UTBot cloud team"
SHELL ["/bin/bash", "--login", "-c"]

ENV CC=gcc
ENV UTBOT_ALL=/utbot_distr
ENV WORKSPACE=/github/workspace/

USER root

# Handle sudo annoying bug https://bugzilla.redhat.com/show_bug.cgi?id=1773148
RUN echo "Set disable_coredump false" >> /etc/sudo.conf

WORKDIR docker

# Install required system packages
RUN apt update && DEBIAN_FRONTEND=noninteractive apt -y --no-install-recommends install sudo file python3-dateutil wget fakeroot libssl-dev build-essential software-properties-common
RUN echo "check_certificate = off" > /etc/wgetrc

# We use C++ 17 for UnitTestBot, it is available in gcc-9; default gcc for ubuntu:18.04 is gcc-7
RUN add-apt-repository ppa:ubuntu-toolchain-r/test
RUN apt remove --purge -y gcc g++
RUN apt update && apt install -y --no-install-recommends gcc-9 g++-9
RUN ln -s /usr/bin/gcov-9 /usr/bin/gcov
RUN ln -s /usr/bin/gcc-9 /usr/bin/gcc
RUN ln -s /usr/bin/g++-9 /usr/bin/g++

#install git
RUN apt install -y software-properties-common
RUN apt update
RUN add-apt-repository -y ppa:git-core/ppa
RUN apt update
RUN apt install -y git
RUN apt -y install libcurl4-openssl-dev

RUN mkdir $UTBOT_ALL && cd $UTBOT_ALL

# Install latest CMake
ENV UTBOT_INSTALL_DIR=$UTBOT_ALL/install
ENV UTBOT_CMAKE_BINARY=$UTBOT_INSTALL_DIR/bin/cmake
RUN wget https://github.com/Kitware/CMake/releases/download/v3.17.2/cmake-3.17.2.tar.gz -O /tmp/cmake_src.tar.gz
RUN tar xfz /tmp/cmake_src.tar.gz -C $UTBOT_ALL
RUN cd $UTBOT_ALL/cmake-3.17.2/ && ./bootstrap --prefix=$UTBOT_INSTALL_DIR --parallel=`nproc` && make -j`nproc` && make install && cd $UTBOT_ALL && rm -rf $UTBOT_ALL/cmake-3.17.2

# Install llvm
RUN mkdir $UTBOT_ALL/llvm_gold_plugin
COPY building_dependencies/llvm_gold_plugin/plugin-api.h $UTBOT_ALL/llvm_gold_plugin

RUN apt install -y --no-install-recommends ninja-build python3-setuptools
RUN git clone -b llvmorg-10.0.0 --depth=1 https://github.com/llvm/llvm-project.git $UTBOT_ALL/llvm
WORKDIR $UTBOT_ALL/llvm
RUN mkdir build && cd build \
&& $UTBOT_CMAKE_BINARY -DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_INSTALL_PREFIX=$UTBOT_INSTALL_DIR \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_BINUTILS_INCDIR=$UTBOT_ALL/llvm_gold_plugin \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_ENABLE_EH=ON \
-DLLVM_TARGETS_TO_BUILD="host" \
-DLLVM_ENABLE_PROJECTS="clang;compiler-rt;libc;libclc;libcxx;libcxxabi;lld;lldb;clang-tools-extra" -G "Ninja" ../llvm \
&& $UTBOT_CMAKE_BINARY --build . --target install \
&& cd $UTBOT_ALL \
&& rm -rf $UTBOT_ALL/llvm

RUN rm -rf $UTBOT_ALL/llvm_gold_plugin

# Install GRPC
FROM base_env
RUN apt -y install autoconf libtool
RUN git clone -b v1.29.0 --depth=1 https://github.com/grpc/grpc $UTBOT_ALL/grpc
RUN cd $UTBOT_ALL/grpc && git submodule update --init
RUN cd $UTBOT_ALL/grpc \
&& mkdir -p cmake/build \
&& cd cmake/build \
&& $UTBOT_CMAKE_BINARY -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=$UTBOT_INSTALL_DIR ../.. \
&& make -j`nproc` \
&& make install \
&& cd $UTBOT_ALL \
&& rm -rf $UTBOT_ALL/grpc

# Create user
RUN useradd -m utbot && \
echo utbot:utbot | chpasswd && \
cp /etc/sudoers /etc/sudoers.bak && \
echo 'utbot ALL=(root) NOPASSWD: ALL' >> /etc/sudoers

USER utbot
WORKDIR /home/utbot

# Get gtest
USER root
RUN git clone -b release-1.10.0 https://github.com/google/googletest.git $UTBOT_ALL/gtest
RUN cd $UTBOT_ALL/gtest && mkdir build && cd build && \
$UTBOT_CMAKE_BINARY -G "Ninja" -DCMAKE_INSTALL_PREFIX=$UTBOT_INSTALL_DIR .. && \
$UTBOT_CMAKE_BINARY --build . --target install && \
cd $UTBOT_ALL
USER utbot

# Install KLEE dependencies
RUN sudo -E apt install -y --no-install-recommends curl libcap-dev libncurses5-dev unzip libtcmalloc-minimal4 libgoogle-perftools-dev libsqlite3-dev doxygen python3-pip
ENV CURL_CA_BUNDLE=""
RUN sudo -E pip3 install tabulate==0.8.7 \
typing==3.7.4.3

# Install z3
USER root
RUN git clone -b z3-4.8.7 --depth=1 https://github.com/Z3Prover/z3.git $UTBOT_ALL/z3-src
RUN cd $UTBOT_ALL/z3-src && mkdir build && cd build && \
$UTBOT_CMAKE_BINARY -G "Ninja" -DCMAKE_INSTALL_PREFIX=$UTBOT_INSTALL_DIR .. && \
$UTBOT_CMAKE_BINARY --build . --target install && \
cd $UTBOT_ALL && \
rm -rf $UTBOT_ALL/z3-src
USER utbot

# Add ssh authorization key
RUN mkdir -p /home/utbot/.ssh/
RUN echo "StrictHostKeyChecking no" >> /home/utbot/.ssh/config

USER root
ARG OPERATING_SYSTEM_TAG
RUN if [[ "$OPERATING_SYSTEM_TAG" = "18.04" ]] ; then apt update && apt install -y --no-install-recommends nodejs-dev node-gyp libssl1.0-dev ; fi
RUN apt update && apt install -y --no-install-recommends nodejs npm openssh-server net-tools gdb vim-nox rsync
RUN pip3 install git+https://chromium.googlesource.com/external/gyp

# Update node and npm since defaults on ubuntu:18.04 have reached end of life
RUN npm config set strict-ssl false
RUN npm cache clean -f
RUN sudo -E npm install -g n
RUN echo insecure > ~/.curlrc
RUN sudo -E n stable
RUN sudo -E apt remove -y --purge nodejs npm

# Install cmake which can generate link_commands.json. Installing cmake the second time in order to build base image faster since this cmake may be changed frequently.
RUN git clone -b utbot-0.1.2b --depth=1 https://github.com/Software-Analysis-Team/CMake.git $UTBOT_ALL/cmake
RUN cd $UTBOT_ALL/cmake && $UTBOT_CMAKE_BINARY -DCMAKE_INSTALL_PREFIX=$UTBOT_INSTALL_DIR . && \
make -j`nproc` && make install && cd $UTBOT_ALL && rm -rf $UTBOT_ALL/cmake

## Setup ssh
RUN mkdir -p /var/run/sshd
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

# Append installation paths
RUN mkdir $UTBOT_ALL/klee && chown utbot: $UTBOT_ALL/klee/
RUN mkdir $UTBOT_ALL/server-install && chown utbot: $UTBOT_ALL/server-install/

#Installing patched version of lit to handle Klee unit-test execution properly
USER root
COPY building_dependencies/patches/lit.py /usr/local/bin/lit
RUN chmod +x /usr/local/bin/lit

RUN sudo rm /usr/bin/python
RUN sudo ln -s /usr/bin/python3 /usr/bin/python

# Download CLI11 and Rang libs for nice CLI
RUN wget https://github.com/CLIUtils/CLI11/releases/download/v1.9.1/CLI11.hpp -P $UTBOT_ALL/cli
RUN wget https://github.com/agauniyal/rang/releases/download/v3.1.0/rang.hpp -P $UTBOT_ALL/cli

#Applying environment variables to all users
COPY building_dependencies/runtime_env.sh /home/utbot/.bashrc
COPY building_dependencies/runtime_env.sh /root/.bashrc

RUN chsh -s /bin/bash utbot
EXPOSE 2020
CMD ["/usr/sbin/sshd", "-D", "-p 2020"]
Loading