Skip to content

Commit 04a2e06

Browse files
committed
Add CSmith GitHub action
Run 10 randomly generated CSmith tests as a GitHub action to perform an integration test involving CBMC and goto-instrument --dump-c. Each test is first compiled and run using GCC to obtain a checksum, which is then included as an assertion for CBMC to verify.
1 parent 8ea67e7 commit 04a2e06

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

.github/workflows/csmith.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Run CSmith
2+
3+
on:
4+
pull_request:
5+
branches: [ develop ]
6+
7+
jobs:
8+
CompileXen:
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- uses: actions/checkout@v2
12+
with:
13+
submodules: recursive
14+
- name: Fetch dependencies
15+
env:
16+
# This is needed in addition to -yq to prevent apt-get from asking for
17+
# user input
18+
DEBIAN_FRONTEND: noninteractive
19+
run: |
20+
sudo apt-get install --no-install-recommends -y build-essential flex bison maven ccache
21+
sudo apt-get install --no-install-recommends -y csmith libcsmith-dev
22+
make -C src minisat2-download
23+
- name: Prepare ccache
24+
uses: actions/cache@v2
25+
with:
26+
path: .ccache
27+
key: ${{ runner.os }}-20.04-make-${{ github.ref }}-${{ github.sha }}
28+
restore-keys: |
29+
${{ runner.os }}-20.04-make-${{ github.ref }}
30+
${{ runner.os }}-20.04-make
31+
- name: ccache environment
32+
run: |
33+
echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV
34+
echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV
35+
- name: Zero ccache stats and limit in size
36+
run: ccache -z --max-size=500M
37+
- name: Build with make
38+
run: |
39+
make -C src CXX='ccache /usr/bin/g++' cbmc.dir goto-cc.dir goto-instrument.dir -j2
40+
- name: Print ccache stats
41+
run: ccache -s
42+
- name: Run 10 randomly-generated CSmith tests
43+
run: |
44+
export PATH=$PWD/src/cbmc:$PWD/src/goto-cc:$PWD/src/goto-instrument:$PATH
45+
scripts/csmith.sh 10

scripts/csmith.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
workdir=$(mktemp -d csmith.XXX)
6+
print_dir() {
7+
echo "CSmith working directory: $workdir"
8+
}
9+
10+
csmith_test() {
11+
trap print_dir ERR
12+
13+
local f=$1
14+
local r=$(cbmc --version)
15+
local bn=`basename $f`
16+
bn=`basename $bn .c`
17+
18+
echo "Trying $f with build $r"
19+
20+
gcc -I/usr/include/csmith -w $f -o $bn
21+
check="`timeout 30 ./$bn | sed 's/checksum = /0x/'`"
22+
if [ -z "$check" ] ; then
23+
echo "TIMEOUT while executing CSmith test"
24+
return 0
25+
fi
26+
27+
gcc -E -I/usr/include/csmith -D__FRAMAC \
28+
-D'Frama_C_dump_assert_each()'="assert($check==(crc))" $f -o $bn.i
29+
ec=0
30+
/usr/bin/time -v timeout -k15 90 cbmc --unwind 257 --no-unwinding-assertions --object-bits 13 $bn.i || ec=$?
31+
if [ $ec -eq 124 ] || [ $ec -eq 137 ] ; then
32+
echo "TIMEOUT in CBMC"
33+
elif [ $ec -eq 6 ] ; then
34+
echo "Limitation in CBMC"
35+
elif [ $ec -ne 0 ] ; then
36+
cat $f
37+
return 1
38+
fi
39+
40+
goto-cc -I /usr/include/csmith $f -o $bn
41+
goto-instrument --dump-c $bn ${bn}_dumped.c
42+
gcc ${bn}_dumped.c -D__CPROVER_bool=_Bool -w -o $bn
43+
check_d="`timeout 30 ./$bn | sed 's/checksum = /0x/'`"
44+
if [ -z "$check_d" ] ; then
45+
echo "TIMEOUT while executing dumped CSmith test"
46+
return 0
47+
fi
48+
if [ "$check" != "$check_d" ] ; then
49+
echo "Checksum mismatch: GCC: $check dump-c: $check_d"
50+
cat $f
51+
return 1
52+
fi
53+
54+
echo "OK: $f"
55+
echo
56+
}
57+
58+
csmith_random_test() {
59+
trap print_dir ERR
60+
61+
for i in `seq 1 $1`; do
62+
csmith > t_$i.c
63+
csmith_test t_$i.c
64+
done
65+
}
66+
67+
N=$1
68+
if [ -z $N ] ; then
69+
N=1
70+
fi
71+
72+
basedir=$PWD
73+
cd $workdir
74+
75+
csmith_random_test $N
76+
77+
cd $basedir
78+
rm -rf $workdir

0 commit comments

Comments
 (0)