Skip to content

Commit f6e4968

Browse files
committed
Enable running tests from CMake
1 parent e609bbb commit f6e4968

File tree

25 files changed

+263
-45
lines changed

25 files changed

+263
-45
lines changed

CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
cmake_minimum_required(VERSION 3.2)
22

3+
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
4+
35
include(GNUInstallDirs)
46

5-
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
7+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
8+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
9+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
610

711
add_subdirectory(src)
812

9-
enable_testing()
13+
set(enable_cbmc_tests on CACHE BOOL "Whether CBMC tests should be enabled")
14+
15+
if(${enable_cbmc_tests})
16+
enable_testing()
17+
endif()
1018
add_subdirectory(unit)
19+
add_subdirectory(regression)

regression/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
set(CMAKE_CXX_STANDARD 11)
2+
set(CMAKE_CXX_STANDARD_REQUIRED true)
3+
4+
set(test_pl_path "${CMAKE_CURRENT_SOURCE_DIR}/test.pl")
5+
6+
macro(add_test_pl_profile name cmdline flag profile)
7+
add_test(
8+
NAME "${name}-${profile}"
9+
COMMAND ${test_pl_path} -c ${cmdline} ${flag}
10+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
11+
)
12+
set_tests_properties("${name}-${profile}" PROPERTIES
13+
LABELS "${profile}"
14+
)
15+
endmacro(add_test_pl_profile)
16+
17+
macro(add_test_pl_tests name cmdline)
18+
add_test_pl_profile("${name}" "${cmdline}" -C CORE)
19+
add_test_pl_profile("${name}" "${cmdline}" -T THOROUGH)
20+
add_test_pl_profile("${name}" "${cmdline}" -F FUTURE)
21+
add_test_pl_profile("${name}" "${cmdline}" -K KNOWNBUG)
22+
endmacro(add_test_pl_tests)
23+
24+
add_subdirectory(ansi-c)
25+
add_subdirectory(cbmc)
26+
add_subdirectory(cbmc-java)
27+
add_subdirectory(cbmc-java-inheritance)
28+
add_subdirectory(cpp)
29+
add_subdirectory(goto-analyzer)
30+
add_subdirectory(goto-diff)
31+
add_subdirectory(goto-instrument)
32+
add_subdirectory(goto-instrument-typedef)
33+
add_subdirectory(invariants)
34+
add_subdirectory(strings)
35+
add_subdirectory(strings-smoke-tests)
36+
add_subdirectory(test-script)

regression/ansi-c/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"ansi-c"
3+
"$<TARGET_FILE:goto-cc>"
4+
)

regression/ansi-c/Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
default: tests.log
22

3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
exe=../../../src/goto-cc/goto-cl
8+
else
9+
exe=../../../src/goto-cc/goto-cc
10+
endif
11+
312
test:
4-
@if ! ../test.pl -c ../../../src/goto-cc/goto-cc ; then \
13+
@if ! ../test.pl -c $(exe) ; then \
514
../failed-tests-printer.pl ; \
615
exit 1 ; \
716
fi
817

918
tests.log: ../test.pl
10-
@if ! ../test.pl -c ../../../src/goto-cc/goto-cc ; then \
19+
@if ! ../test.pl -c $(exe) ; then \
1120
../failed-tests-printer.pl ; \
1221
exit 1 ; \
1322
fi
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"cbmc-java-inheritance"
3+
"$<TARGET_FILE:cbmc>"
4+
)

regression/cbmc-java/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"cbmc-java"
3+
"$<TARGET_FILE:cbmc>"
4+
)

regression/cbmc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"cbmc"
3+
"$<TARGET_FILE:cbmc>"
4+
)

regression/cpp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"cpp"
3+
"$<TARGET_FILE:goto-cc>"
4+
)

regression/cpp/Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
default: tests.log
22

3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
exe=../../../src/goto-cc/goto-cl
8+
else
9+
exe=../../../src/goto-cc/goto-cc
10+
endif
11+
312
test:
4-
@if ! ../test.pl -c ../../../src/goto-cc/goto-cc ; then \
13+
@if ! ../test.pl -c $(exe) ; then \
514
../failed-tests-printer.pl ; \
615
exit 1 ; \
716
fi
817

918
tests.log: ../test.pl
10-
@if ! ../test.pl -c ../../../src/goto-cc/goto-cc ; then \
19+
@if ! ../test.pl -c $(exe) ; then \
1120
../failed-tests-printer.pl ; \
1221
exit 1 ; \
1322
fi
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"goto-analyzer"
3+
"$<TARGET_FILE:goto-analyzer>"
4+
)

regression/goto-diff/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"goto-diff"
3+
"$<TARGET_FILE:goto-diff>"
4+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if(WIN32)
2+
set(is_windows true)
3+
else()
4+
set(is_windows false)
5+
endif()
6+
7+
add_test_pl_tests(
8+
"goto-instrument-typedef"
9+
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-instrument> ${is_windows}"
10+
)

regression/goto-instrument-typedef/Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
21
default: tests.log
32

3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
exe=../../../src/goto-cc/goto-cl
8+
is_windows="true"
9+
else
10+
exe=../../../src/goto-cc/goto-cc
11+
is_windows="false"
12+
endif
13+
414
test:
5-
@if ! ../test.pl -c ../chain.sh ; then \
15+
@if ! ../test.pl -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument $(is_windows)' ; then \
616
../failed-tests-printer.pl ; \
717
exit 1; \
818
fi
919

1020
tests.log:
11-
@if ! ../test.pl -c ../chain.sh ; then \
21+
@if ! ../test.pl -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument $(is_windows)' ; then \
1222
../failed-tests-printer.pl ; \
1323
exit 1; \
1424
fi
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
#!/bin/bash
22

3-
SRC=../../../src
3+
GC=$1
4+
GI=$2
5+
is_windows=$3
46

5-
GC=$SRC/goto-cc/goto-cc
6-
GI=$SRC/goto-instrument/goto-instrument
7+
name=${*:$#}
8+
name=${name%.c}
79

8-
OPTS=$1
9-
NAME=${2%.c}
10+
args=${*:4:$#-4}
1011

11-
rm $NAME.gb
12-
$GC $NAME.c --function fun -o $NAME.gb
13-
echo $GI $OPTS $NAME.gb
14-
$GI $OPTS $NAME.gb
12+
rm "${name}.gb"
13+
if [[ "${is_windows}" == "true" ]]; then
14+
"$GC" "${name}.c" --function fun
15+
mv "${name}.exe" "${name}.gb"
16+
else
17+
"$GC" "${name}.c" --function fun -o "${name}.gb"
18+
fi
19+
20+
echo "$GI" ${args} "${name}.gb"
21+
"$GI" ${args} "${name}.gb"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
if(WIN32)
2+
set(is_windows true)
3+
else()
4+
set(is_windows false)
5+
endif()
6+
7+
add_test_pl_tests(
8+
"goto-instrument"
9+
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-instrument> $<TARGET_FILE:cbmc> ${is_windows}"
10+
)

regression/goto-instrument/Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
21
default: tests.log
32

3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
exe=../../../src/goto-cc/goto-cl
8+
is_windows="true"
9+
else
10+
exe=../../../src/goto-cc/goto-cc
11+
is_windows="false"
12+
endif
13+
414
test:
5-
@if ! ../test.pl -c ../chain.sh ; then \
15+
@if ! ../test.pl -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument ../../../src/cbmc/cbmc $(is_windows)' ; then \
616
../failed-tests-printer.pl ; \
717
exit 1; \
818
fi
919

1020
tests.log:
11-
@if ! ../test.pl -c ../chain.sh ; then \
21+
@if ! ../test.pl -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument ../../../src/cbmc/cbmc $(is_windows)' ; then \
1222
../failed-tests-printer.pl ; \
1323
exit 1; \
1424
fi

regression/goto-instrument/chain.sh

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,37 @@
22

33
set -e
44

5-
src=../../../src
6-
goto_cc=$src/goto-cc/goto-cc
7-
goto_instrument=$src/goto-instrument/goto-instrument
8-
cbmc=$src/cbmc/cbmc
5+
goto_cc=$1
6+
goto_instrument=$2
7+
cbmc=$3
8+
is_windows=$4
99

10-
name=${@:$#}
10+
name=${*:$#}
1111
name=${name%.c}
1212

13-
args=${@:1:$#-1}
14-
15-
$goto_cc -o $name.gb $name.c
16-
# $goto_instrument --show-goto-functions $name.gb
17-
$goto_instrument $args $name.gb ${name}-mod.gb
18-
if [ ! -e ${name}-mod.gb ] ; then
19-
cp $name.gb ${name}-mod.gb
20-
elif echo "$args" | grep -q -- "--dump-c" ; then
21-
mv ${name}-mod.gb ${name}-mod.c
22-
$goto_cc ${name}-mod.c -o ${name}-mod.gb
23-
rm ${name}-mod.c
13+
args=${*:5:$#-5}
14+
15+
if [[ "${is_windows}" == "true" ]]; then
16+
$goto_cc "${name}.c"
17+
mv "${name}.exe" "${name}.gb"
18+
else
19+
$goto_cc -o "${name}.gb" "${name}.c"
2420
fi
25-
$goto_instrument --show-goto-functions ${name}-mod.gb
26-
$cbmc ${name}-mod.gb
2721

22+
$goto_instrument ${args} "${name}.gb" "${name}-mod.gb"
23+
if [ ! -e "${name}-mod.gb" ] ; then
24+
cp "$name.gb" "${name}-mod.gb"
25+
elif echo $args | grep -q -- "--dump-c" ; then
26+
mv "${name}-mod.gb" "${name}-mod.c"
27+
28+
if [[ "${is_windows}" == "true" ]]; then
29+
$goto_cc "${name}-mod.c"
30+
mv "${name}-mod.exe" "${name}-mod.gb"
31+
else
32+
$goto_cc -o "${name}-mod.gb" "${name}-mod.c"
33+
fi
34+
35+
rm "${name}-mod.c"
36+
fi
37+
$goto_instrument --show-goto-functions "${name}-mod.gb"
38+
$cbmc "${name}-mod.gb"

regression/invariants/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_executable(driver driver.cpp)
2+
target_link_libraries(driver big-int util)
3+
4+
add_test_pl_tests(
5+
"invariants"
6+
"$<TARGET_FILE:driver>"
7+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"strings-smoke-test"
3+
"$<TARGET_FILE:cbmc>"
4+
)

regression/strings/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"strings"
3+
"$<TARGET_FILE:cbmc>"
4+
)

regression/test-script/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_test_pl_tests(
2+
"test-script"
3+
"${CMAKE_CURRENT_SOURCE_DIR}/program_runner.sh"
4+
)

src/ansi-c/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ function(make_inc name)
2020
)
2121
endfunction(make_inc)
2222

23+
################################################################################
24+
25+
if(MINGW)
26+
set(platform_unavail
27+
${CMAKE_CURRENT_SOURCE_DIR}/library/java.io.c
28+
${CMAKE_CURRENT_SOURCE_DIR}/library/err.c
29+
${CMAKE_CURRENT_SOURCE_DIR}/library/threads.c
30+
)
31+
else()
32+
set(platform_unavail
33+
${CMAKE_CURRENT_SOURCE_DIR}/library/java.io.c
34+
${CMAKE_CURRENT_SOURCE_DIR}/library/threads.c
35+
)
36+
endif()
37+
38+
file(GLOB library_check_sources "library/*.c")
39+
list(REMOVE_ITEM library_check_sources ${platform_unavail})
40+
41+
add_custom_target(library_check
42+
${CMAKE_CURRENT_SOURCE_DIR}/check_library.sh ${library_check_sources}
43+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
44+
)
45+
46+
################################################################################
47+
2348
make_inc(arm_builtin_headers)
2449
make_inc(clang_builtin_headers)
2550
make_inc(cw_builtin_headers)

src/ansi-c/check_library.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
for var in "$@"; do
4+
cp "${var}" __libcheck.c
5+
sed -i 's/__builtin_[^v]/s&/' __libcheck.c
6+
sed -i 's/__sync_/s&/' __libcheck.c
7+
sed -i 's/__noop/s&/' __libcheck.c
8+
cc -std=gnu99 -E -include library/cprover.h -D__CPROVER_bool=_Bool -D__CPROVER_thread_local=__thread -DLIBRARY_CHECK -o __libcheck.i __libcheck.c
9+
cc -S -Wall -Werror -pedantic -Wextra -std=gnu99 __libcheck.i -o __libcheck.s -Wno-unused-label -Wno-uninitialized
10+
11+
ec="$?"
12+
rm __libcheck.s __libcheck.i __libcheck.c
13+
[ "${ec}" -eq 0 ] || exit "${ec}"
14+
done

src/goto-cc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ add_if_library(goto-cc-lib jsil)
3535
# Executable
3636
add_executable(goto-cc goto_cc_main.cpp)
3737
target_link_libraries(goto-cc goto-cc-lib)
38+
39+
if(WIN32)
40+
set_target_properties(goto-cc PROPERTIES OUTPUT_NAME goto-cl)
41+
endif()

0 commit comments

Comments
 (0)