Skip to content

Commit af7124f

Browse files
authored
Merge pull request #4278 from tautschnig/enable-concurrency-tests
Enable cbmc-concurrency regression tests by default
2 parents 5ab4e4a + 78437a1 commit af7124f

File tree

31 files changed

+77
-53
lines changed

31 files changed

+77
-53
lines changed

regression/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_subdirectory(goto-analyzer)
2929
add_subdirectory(ansi-c)
3030
add_subdirectory(goto-instrument)
3131
add_subdirectory(cpp)
32+
add_subdirectory(cbmc-concurrency)
3233
add_subdirectory(cbmc-cover)
3334
add_subdirectory(goto-instrument-typedef)
3435
add_subdirectory(smt2_solver)

regression/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ DIRS = cbmc \
77
ansi-c \
88
goto-instrument \
99
cpp \
10+
cbmc-concurrency \
1011
cbmc-cover \
1112
goto-instrument-typedef \
1213
smt2_solver \
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
if((NOT WIN32) AND (NOT APPLE))
2+
add_test_pl_tests(
3+
"$<TARGET_FILE:cbmc>"
4+
)
5+
else()
6+
add_test_pl_tests(
7+
"$<TARGET_FILE:cbmc>"
8+
"cbmc-concurrency"
9+
"$<TARGET_FILE:cbmc>"
10+
"-C;-X;pthread"
11+
"CORE"
12+
)
13+
endif()

regression/cbmc-concurrency/Makefile

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

3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(filter-out OSX MSVC,$(BUILD_ENV_)),)
7+
# no POSIX threads on Windows
8+
# for OSX we'd need sound handling of pointers in multi-threaded programs
9+
no_pthread = -X pthread
10+
endif
11+
312
test:
4-
@../test.pl -c ../../../src/cbmc/cbmc
13+
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(no_pthread)
514

615
tests.log: ../test.pl
7-
@../test.pl -c ../../../src/cbmc/cbmc
16+
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(no_pthread)
817

918
show:
1019
@for dir in *; do \
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CORE
22
main.c
33

4-
^EXIT=10$
4+
^EXIT=6$
55
^SIGNAL=0$
6-
^file main.c line 12 function spawn: start_thread in atomic section detected$
6+
^spawning threads out of atomic sections is not allowed
77
--
88
^warning: ignoring

regression/cbmc-concurrency/conditional_spawn1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33

44
^EXIT=10$

regression/cbmc-concurrency/deadlock1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33

44
^EXIT=0$

regression/cbmc-concurrency/deadlock2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33

44
^EXIT=10$

regression/cbmc-concurrency/malloc1/main.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <stdlib.h>
2-
#include <pthread.h>
32

43
#define BUG
54

@@ -13,12 +12,9 @@ void* set_x(void* arg) {
1312
}
1413

1514
int main() {
16-
pthread_t thread;
1715
x = malloc(sizeof(int));
1816
#ifdef BUG
1917
__CPROVER_ASYNC_1: set_x(NULL);
20-
//pthread_create(&thread,NULL,set_x,NULL);
21-
//pthread_join(thread,NULL);
2218
__CPROVER_assume(set_done);
2319
#else
2420
set_x(NULL);

regression/cbmc-concurrency/malloc2/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <stdlib.h>
2-
#include <pthread.h>
32

43
_Bool set_done;
54
int *ptr;

regression/cbmc-concurrency/memory_barrier1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33
--unwind 1 --no-unwinding-assertions
44
^EXIT=0$

regression/cbmc-concurrency/memory_barrier2/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ volatile int flag1 = 0, flag2 = 0; // boolean flags
99
void* thr1(void * arg) { // frontend produces 12 transitions from this thread. It would be better if it would produce only 8!
1010
flag1 = 1;
1111
turn = 1;
12+
#ifdef __GNUC__
1213
__asm__ __volatile__ ("mfence": : :"memory");
14+
#else
15+
__CPROVER_fence("WWfence", "RRfence", "RWfence", "WRfence");
16+
#endif
1317
__CPROVER_assume(! (flag2==1 && turn==1) );
1418
// begin: critical section
1519
x = 0;
@@ -21,7 +25,11 @@ void* thr1(void * arg) { // frontend produces 12 transitions from this thread. I
2125
void* thr2(void * arg) {
2226
flag2 = 1;
2327
turn = 0;
28+
#ifdef __GNUC__
2429
__asm__ __volatile__ ("mfence": : :"memory");
30+
#else
31+
__CPROVER_fence("WWfence", "RRfence", "RWfence", "WRfence");
32+
#endif
2533
__CPROVER_assume(! (flag1==1 && turn==0) );
2634
// begin: critical section
2735
x = 1;

regression/cbmc-concurrency/memory_barrier2/test.desc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ main.c
66
^VERIFICATION SUCCESSFUL$
77
--
88
^warning: ignoring
9+
--
10+
Some past change broke this test such that we now report verification failures.

regression/cbmc-concurrency/mutex2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33
-DMUTEX
44
^EXIT=0$

regression/cbmc-concurrency/norace_array1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33

44
^EXIT=0$

regression/cbmc-concurrency/norace_array2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33

44
^EXIT=0$

regression/cbmc-concurrency/norace_scalar1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33

44
^EXIT=0$

regression/cbmc-concurrency/norace_struct1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33

44
^EXIT=0$

regression/cbmc-concurrency/pthread_create_tso1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33
--mm tso
44
^EXIT=0$
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
CORE
1+
CORE pthread
22
main.c
33
--all-properties
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\[main\.assertion\.1\] assertion i==1: FAILURE$
7-
^\[main\.assertion\.2\] assertion i==2: SUCCESS$
6+
^\[main\.assertion\.1\] line 21 assertion i==1: FAILURE$
7+
^\[main\.assertion\.2\] line 22 assertion i==2: SUCCESS$
88
^\*\* 1 of 2 failed
99
--
1010
^warning: ignoring

regression/cbmc-concurrency/pthread_join2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33
--unwind 2
44
^EXIT=10$

regression/cbmc-concurrency/sc6/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33

44
^EXIT=0$

regression/cbmc-concurrency/svcomp13_fib_bench_longer_safe/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33
--error-label ERROR
44
^EXIT=0$

regression/cbmc-concurrency/svcomp13_fib_bench_longer_unsafe/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33
--error-label ERROR
44
^EXIT=10$

regression/cbmc-concurrency/thread_chain_posix1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33

44
^EXIT=10$

regression/cbmc-concurrency/thread_chain_posix2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
-D_ENABLE_CHAIN_ --unwind 2
44
^EXIT=0$

regression/cbmc-concurrency/thread_chain_posix3/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
-D_ENABLE_CHAIN_ -D_SANITY_CHECK_ --unwind 2
44
^EXIT=10$

regression/cbmc-concurrency/thread_local1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33

44
^EXIT=0$

regression/cbmc-concurrency/trace1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ main.c
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
7-
^[[:space:]]*r2=1u \(.*\)$
7+
^[[:space:]]*r2=1u(l)? \(.*\)$
88
--
99
^warning: ignoring

regression/cbmc-concurrency/uf_with_threads1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
CORE pthread
22
main.c
33

44
^EXIT=0$

src/goto-programs/builtin_functions.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,15 +1065,14 @@ void goto_convertt::do_function_call_symbol(
10651065
throw 0;
10661066
}
10671067

1068-
goto_programt::targett t=dest.add_instruction(OTHER);
1069-
t->source_location=function.source_location();
1070-
t->code.set(ID_statement, ID_fence);
1071-
1068+
codet fence(ID_fence);
10721069
forall_expr(it, arguments)
10731070
{
10741071
const irep_idt kind=get_string_constant(*it);
1075-
t->code.set(kind, true);
1072+
fence.set(kind, true);
10761073
}
1074+
1075+
dest.add(goto_programt::make_other(fence, function.source_location()));
10771076
}
10781077
else if(identifier=="__builtin_prefetch")
10791078
{
@@ -1268,10 +1267,9 @@ void goto_convertt::do_function_call_symbol(
12681267
t3->code=code_assignt(deref_ptr, op_expr);
12691268

12701269
// this instruction implies an mfence, i.e., WRfence
1271-
goto_programt::targett t4=dest.add_instruction(OTHER);
1272-
t4->source_location=function.source_location();
1273-
t4->code=codet(ID_fence);
1274-
t4->code.set(ID_WRfence, true);
1270+
codet fence(ID_fence);
1271+
fence.set(ID_WRfence, true);
1272+
dest.add(goto_programt::make_other(fence, function.source_location()));
12751273

12761274
goto_programt::targett t5=dest.add_instruction(ATOMIC_END);
12771275
t5->source_location=function.source_location();
@@ -1339,10 +1337,9 @@ void goto_convertt::do_function_call_symbol(
13391337
}
13401338

13411339
// this instruction implies an mfence, i.e., WRfence
1342-
goto_programt::targett t4=dest.add_instruction(OTHER);
1343-
t4->source_location=function.source_location();
1344-
t4->code=codet(ID_fence);
1345-
t4->code.set(ID_WRfence, true);
1340+
codet fence(ID_fence);
1341+
fence.set(ID_WRfence, true);
1342+
dest.add(goto_programt::make_other(fence, function.source_location()));
13461343

13471344
goto_programt::targett t5=dest.add_instruction(ATOMIC_END);
13481345
t5->source_location=function.source_location();
@@ -1410,10 +1407,9 @@ void goto_convertt::do_function_call_symbol(
14101407
t3->code=code_assignt(deref_ptr, if_expr);
14111408

14121409
// this instruction implies an mfence, i.e., WRfence
1413-
goto_programt::targett t4=dest.add_instruction(OTHER);
1414-
t4->source_location=function.source_location();
1415-
t4->code=codet(ID_fence);
1416-
t4->code.set(ID_WRfence, true);
1410+
codet fence(ID_fence);
1411+
fence.set(ID_WRfence, true);
1412+
dest.add(goto_programt::make_other(fence, function.source_location()));
14171413

14181414
goto_programt::targett t5=dest.add_instruction(ATOMIC_END);
14191415
t5->source_location=function.source_location();
@@ -1471,10 +1467,9 @@ void goto_convertt::do_function_call_symbol(
14711467
t3->code=code_assignt(deref_ptr, if_expr);
14721468

14731469
// this instruction implies an mfence, i.e., WRfence
1474-
goto_programt::targett t4=dest.add_instruction(OTHER);
1475-
t4->source_location=function.source_location();
1476-
t4->code=codet(ID_fence);
1477-
t4->code.set(ID_WRfence, true);
1470+
codet fence(ID_fence);
1471+
fence.set(ID_WRfence, true);
1472+
dest.add(goto_programt::make_other(fence, function.source_location()));
14781473

14791474
goto_programt::targett t5=dest.add_instruction(ATOMIC_END);
14801475
t5->source_location=function.source_location();

0 commit comments

Comments
 (0)