Skip to content

Commit 994b258

Browse files
committed
Add unit test setup
1 parent a7b8510 commit 994b258

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

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

Lines changed: 23 additions & 1 deletion
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,9 @@ 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+
- uses: actions/setup-node@v4
291+
with:
292+
node-version: 22
282293
- name: Prepare ccache
283294
uses: actions/cache@v4
284295
with:
@@ -299,7 +310,13 @@ jobs:
299310
- name: Build with make
300311
run: make -C src -j4 CXX="ccache emcc" HOSTCXX="ccache g++" BUILD_ENV=Unix LINKLIB="emar rc \$@ \$^" AR="emar" EXEEXT=".html"
301312
- name: print version number via node.js
302-
run: node --no-experimental-fetch src/ebmc/ebmc.js --version
313+
run: |
314+
node --version
315+
# node --experimental-wasm-exnref --no-experimental-fetch src/ebmc/ebmc.js --version
316+
- name: Run unit tests
317+
run: |
318+
make -C unit -j4 unit_tests.html CXX="ccache emcc" BUILD_ENV=Unix LINKLIB="emar rc \$@ \$^" AR="emar" EXEEXT=".html"
319+
# node --experimental-wasm-exnref --no-experimental-fetch unit/unit_tests.js
303320
- name: Print ccache stats
304321
run: ccache -s
305322

@@ -358,5 +375,10 @@ jobs:
358375
# disable MSYS file-name mangling
359376
MSYS2_ARG_CONV_EXCL: "*"
360377
run: make CXX=clcache BUILD_ENV=MSVC -j4 -C src
378+
- name: Run unit tests
379+
env:
380+
# disable MSYS file-name mangling
381+
MSYS2_ARG_CONV_EXCL: "*"
382+
run: make CXX=clcache BUILD_ENV=MSVC -j4 -C unit
361383
- name: Print ccache stats
362384
run: clcache -s

unit/Makefile

Lines changed: 38 additions & 0 deletions
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 19 additions & 0 deletions
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)