Skip to content

Commit e7fb61e

Browse files
authored
Merge pull request #802 from diffblue/unit_tests
Add unit test setup
2 parents df16afd + 1c2ddaa commit e7fb61e

File tree

4 files changed

+131
-2
lines changed

4 files changed

+131
-2
lines changed

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

+53-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ jobs:
4343
make -C lib/cbmc/src minisat2-download
4444
- name: Build with make
4545
run: make -C src -j4 CXX="ccache g++"
46+
- name: Run unit tests
47+
run: make -C unit -j4 CXX="ccache g++"
4648
- name: Run the ebmc tests with SAT
4749
run: make -C regression/ebmc test
4850
- name: Run the ebmc tests with Z3
@@ -101,6 +103,8 @@ jobs:
101103
make -C lib/cbmc/src minisat2-download
102104
- name: Build with make
103105
run: make CXX="ccache clang++" -C src -j4
106+
- name: Run unit tests
107+
run: make -C unit -j4 CXX="ccache clang++"
104108
- name: Run the ebmc tests with SAT
105109
run: make -C regression/ebmc test
106110
- name: Run the ebmc tests with Z3
@@ -203,6 +207,8 @@ jobs:
203207
run: make -C lib/cbmc/src minisat2-download
204208
- name: Build with make
205209
run: make CXX="ccache g++ -Wno-class-memaccess" LIBS="-lstdc++fs" -C src -j4
210+
- name: Run unit tests
211+
run: make -C unit -j4 CXX="ccache g++ -Wno-class-memaccess" LIBS="-lstdc++fs"
206212
- name: Run the ebmc tests with SAT
207213
run: |
208214
rm regression/ebmc/neural-liveness/counter1.desc
@@ -246,6 +252,8 @@ jobs:
246252
run: make -C lib/cbmc/src minisat2-download
247253
- name: Build with make
248254
run: make YACC="/opt/homebrew/opt/bison/bin/bison" CXX="ccache clang++" -C src -j3
255+
- name: Run unit tests
256+
run: make -C unit -j3 CXX="ccache g++"
249257
- name: Run the ebmc tests with SAT
250258
run: make -C regression/ebmc test
251259
- name: Run the ebmc tests with Z3
@@ -279,6 +287,20 @@ jobs:
279287
run: |
280288
sudo apt-get update
281289
sudo apt-get install --no-install-recommends -yq emscripten flex bison libxml2-utils cpanminus ccache
290+
- name: Install node.js 23
291+
uses: actions/setup-node@v4
292+
with:
293+
node-version: 23
294+
- name: Install emscripten
295+
run: |
296+
# The emscripten package in Ubuntu is too far behind.
297+
git clone https://github.com/emscripten-core/emsdk.git
298+
cd emsdk
299+
git checkout 3.1.31
300+
./emsdk install latest
301+
./emsdk activate latest
302+
source ./emsdk_env.sh
303+
emcc --version
282304
- name: Prepare ccache
283305
uses: actions/cache@v4
284306
with:
@@ -297,9 +319,33 @@ jobs:
297319
- name: Get minisat
298320
run: make -C lib/cbmc/src minisat2-download
299321
- name: Build with make
300-
run: make -C src -j4 CXX="ccache emcc" HOSTCXX="ccache g++" BUILD_ENV=Unix LINKLIB="emar rc \$@ \$^" AR="emar" EXEEXT=".html"
322+
run: |
323+
source emsdk/emsdk_env.sh
324+
make -C src -j4 \
325+
BUILD_ENV=Unix \
326+
CXX="ccache emcc -fwasm-exceptions" \
327+
LINKFLAGS="-sEXPORTED_RUNTIME_METHODS=callMain" \
328+
LINKLIB="emar rc \$@ \$^" \
329+
AR="emar" \
330+
EXEEXT=".html" \
331+
HOSTCXX="ccache g++" \
332+
HOSTLINKFLAGS=""
301333
- name: print version number via node.js
302-
run: node --no-experimental-fetch src/ebmc/ebmc.js --version
334+
run: node --experimental-wasm-exnref src/ebmc/ebmc.js --version
335+
- name: Compile unit tests
336+
run: |
337+
source emsdk/emsdk_env.sh
338+
make -C unit unit_tests.html -j4 \
339+
BUILD_ENV=Unix \
340+
CXX="ccache emcc -fwasm-exceptions" \
341+
LINKFLAGS="-sEXPORTED_RUNTIME_METHODS=callMain" \
342+
LINKLIB="emar rc \$@ \$^" \
343+
AR="emar" \
344+
EXEEXT=".html" \
345+
HOSTCXX="ccache g++" \
346+
HOSTLINKFLAGS=""
347+
- name: Run unit tests
348+
run: node --experimental-wasm-exnref unit/unit_tests.js
303349
- name: Print ccache stats
304350
run: ccache -s
305351

@@ -358,5 +404,10 @@ jobs:
358404
# disable MSYS file-name mangling
359405
MSYS2_ARG_CONV_EXCL: "*"
360406
run: make CXX=clcache BUILD_ENV=MSVC -j4 -C src
407+
- name: Run unit tests
408+
env:
409+
# disable MSYS file-name mangling
410+
MSYS2_ARG_CONV_EXCL: "*"
411+
run: make CXX=clcache BUILD_ENV=MSVC -j4 -C unit
361412
- name: Print ccache stats
362413
run: clcache -s

unit/Makefile

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.PHONY: test
2+
3+
# Main
4+
SRC = unit_tests.cpp
5+
6+
# Test source files
7+
SRC += temporal-logic/nnf.cpp \
8+
# Empty last line
9+
10+
INCLUDES= -I ../src/ -I . -I $(CPROVER_DIR)/unit -I $(CPROVER_DIR)/src
11+
12+
CPROVER_DIR = ../lib/cbmc
13+
14+
include $(CPROVER_DIR)/src/config.inc
15+
include $(CPROVER_DIR)/src/common
16+
17+
CXXFLAGS += -D'LOCAL_IREP_IDS=<hw_cbmc_irep_ids.h>'
18+
19+
OBJ += ../src/temporal-logic/temporal-logic$(LIBEXT)
20+
21+
cprover.dir:
22+
$(MAKE) $(MAKEARGS) -C ../src
23+
24+
CPROVER_LIBS = $(CPROVER_DIR)/src/util/util$(LIBEXT) \
25+
$(CPROVER_DIR)/src/big-int/big-int$(LIBEXT) \
26+
# Empty last line
27+
28+
OBJ += $(CPROVER_LIBS)
29+
30+
all: test
31+
32+
test: unit_tests$(EXEEXT)
33+
./unit_tests$(EXEEXT)
34+
35+
###############################################################################
36+
37+
unit_tests$(EXEEXT): $(OBJ)
38+
$(LINKBIN)

unit/temporal-logic/nnf.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*******************************************************************\
2+
3+
Module: NNF Unit Tests
4+
5+
Author: Daniel Kroening, Amazon, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include <temporal-logic/ltl.h>
10+
#include <temporal-logic/nnf.h>
11+
#include <testing-utils/use_catch.h>
12+
13+
SCENARIO("Generating NNF")
14+
{
15+
GIVEN("A formula not in NNF")
16+
{
17+
auto p = symbol_exprt{"p", bool_typet{}};
18+
auto formula = not_exprt{G_exprt{p}};
19+
REQUIRE(property_nnf(formula) == F_exprt{not_exprt{p}});
20+
}
21+
}

unit/unit_tests.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*******************************************************************\
2+
3+
Module: Unit Tests Main
4+
5+
Author: Daniel Kroening, Amazon, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#define CATCH_CONFIG_MAIN
10+
#include <util/irep.h>
11+
12+
#include <testing-utils/use_catch.h>
13+
14+
// Debug printer for irept
15+
std::ostream &operator<<(std::ostream &os, const irept &value)
16+
{
17+
os << value.pretty();
18+
return os;
19+
}

0 commit comments

Comments
 (0)