Skip to content

Commit 291c973

Browse files
authored
Merge pull request #5715 from NlightNFotis/dockerfile
Introduction of Dockerfile for building and running CBMC in a Docker container.
2 parents deba4ae + fbcc05b commit 291c973

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

.github/workflows/pull-request-checks.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,24 @@ jobs:
349349
- uses: actions/checkout@v2
350350
- name: Check for unused irep ids
351351
run: ./scripts/string_table_check.sh
352+
353+
check-docker-image:
354+
runs-on: ubuntu-20.04
355+
steps:
356+
- uses: actions/checkout@v2
357+
with:
358+
submodules: recursive
359+
- name: Download test dependencies
360+
run: sudo apt install openjdk-11-jdk-headless
361+
- name: Build docker image
362+
run: docker build -t cbmc .
363+
- name: Smoke test goto-cc
364+
run: docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc goto-cc -o /mnt/smoke/test.goto /mnt/smoke/test.c
365+
- name: Smoke test cbmc
366+
run: docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc cbmc /mnt/smoke/test.goto
367+
- name: Smoke test jbmc
368+
run: |
369+
javac .github/workflows/smoke_test_assets/Test.java
370+
docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc jbmc --classpath /mnt/smoke Test
371+
- name: Smoke test goto-analyzer
372+
run: docker run -v ${PWD}/.github/workflows/smoke_test_assets:/mnt/smoke -t cbmc goto-analyzer /mnt/smoke/test.goto --unreachable-functions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class Test {
2+
public static void main(String[] args) {
3+
System.out.println("Hi");
4+
assert(1 == 1);
5+
}
6+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <assert.h>
2+
3+
#define return_val 0;
4+
5+
int main(void)
6+
{
7+
assert(1 == 1);
8+
return return_val;
9+
}

COMPILING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ the need to integrate JBMC as a separate project. Be aware that you need to
301301
change the build location (Select project in Eclipse -> Properties -> C/C++
302302
Build) to one of the src directories.
303303
304+
# WORKING WITH DOCKER
305+
306+
To compile and run the tools in a Docker container, do the following:
307+
308+
1. From the root folder of the project, run `$ docker build -t cbmc .`
309+
2. After the building phase has finished, there should be a new
310+
image with the CProver binaries installed under `/usr/local/bin/`.
311+
312+
To start a container using that image as a base, run `$ docker run -i -t cbmc`
313+
This will result in dropping you to a new terminal inside the container. To
314+
load files for analysis into the container, one way is by mounting the folder
315+
that contains the tests to the container. A possible invocation that does that
316+
is: `$ docker run --mount type=bind,source=local/path/with/files,target=/mnt/analysis -i t cbmc`. In the
317+
resulting container, the files present in the local file system under
318+
`local/path/with/files` will be present under `/mnt/analysis`.
304319
305320
# OPTIONS AND VARIABLES
306321

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM ubuntu:20.04 as builder
2+
ENV DEBIAN_FRONTEND noninteractive
3+
ENV DEBCONF_NONINTERACTIVE_SEEN true
4+
# Timezone data is needed during the installation of dependencies,
5+
# since cmake depends on the tzdata package. In an interactive terminal,
6+
# the user selects the timezone at installation time. Since this needs
7+
# to be a non-interactive terminal, we need to setup some sort of default.
8+
# The UTC one seemed the most suitable one.
9+
RUN echo 'tzdata tzdata/Areas select Etc' | debconf-set-selections; \
10+
echo 'tzdata tzdata/Zones/Etc select UTC' | debconf-set-selections; \
11+
apt-get update && apt-get upgrade -y && apt-get install --no-install-recommends -y \
12+
cmake \
13+
ninja-build \
14+
gcc \
15+
g++ \
16+
maven \
17+
flex \
18+
bison \
19+
libxml2-utils \
20+
patch
21+
COPY . /tmp/cbmc
22+
WORKDIR /tmp/cbmc
23+
RUN cmake -S . -Bbuild -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ && cd build; ninja -j2
24+
25+
FROM ubuntu:20.04 as runner
26+
COPY --from=builder /tmp/cbmc/build/bin/* /usr/local/bin/
27+
RUN apt-get update && apt-get install -y gcc

0 commit comments

Comments
 (0)