Skip to content

Enable cbmc-concurrency regression tests by default #4278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ add_subdirectory(goto-analyzer)
add_subdirectory(ansi-c)
add_subdirectory(goto-instrument)
add_subdirectory(cpp)
add_subdirectory(cbmc-concurrency)
add_subdirectory(cbmc-cover)
add_subdirectory(goto-instrument-typedef)
add_subdirectory(smt2_solver)
Expand Down
1 change: 1 addition & 0 deletions regression/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DIRS = cbmc \
ansi-c \
goto-instrument \
cpp \
cbmc-concurrency \
cbmc-cover \
goto-instrument-typedef \
smt2_solver \
Expand Down
13 changes: 13 additions & 0 deletions regression/cbmc-concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
if((NOT WIN32) AND (NOT APPLE))
add_test_pl_tests(
"$<TARGET_FILE:cbmc>"
)
else()
add_test_pl_tests(
"$<TARGET_FILE:cbmc>"
"cbmc-concurrency"
"$<TARGET_FILE:cbmc>"
"-C;-X;pthread"
"CORE"
)
endif()
13 changes: 11 additions & 2 deletions regression/cbmc-concurrency/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
default: tests.log

include ../../src/config.inc
include ../../src/common

ifeq ($(filter-out OSX MSVC,$(BUILD_ENV_)),)
# no POSIX threads on Windows
# for OSX we'd need sound handling of pointers in multi-threaded programs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? Why is that concern particular to OSX?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the difference is whether pthreadt is a typedef for a pointer type or not, which varies from platform to platform.

no_pthread = -X pthread
endif

test:
@../test.pl -c ../../../src/cbmc/cbmc
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(no_pthread)

tests.log: ../test.pl
@../test.pl -c ../../../src/cbmc/cbmc
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(no_pthread)

show:
@for dir in *; do \
Expand Down
4 changes: 2 additions & 2 deletions regression/cbmc-concurrency/atomic_section_sc6/test.desc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CORE
main.c

^EXIT=10$
^EXIT=6$
^SIGNAL=0$
^file main.c line 12 function spawn: start_thread in atomic section detected$
^spawning threads out of atomic sections is not allowed
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/conditional_spawn1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c

^EXIT=10$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/deadlock1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c

^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/deadlock2/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c

^EXIT=10$
Expand Down
4 changes: 0 additions & 4 deletions regression/cbmc-concurrency/malloc1/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdlib.h>
#include <pthread.h>

#define BUG

Expand All @@ -13,12 +12,9 @@ void* set_x(void* arg) {
}

int main() {
pthread_t thread;
x = malloc(sizeof(int));
#ifdef BUG
__CPROVER_ASYNC_1: set_x(NULL);
//pthread_create(&thread,NULL,set_x,NULL);
//pthread_join(thread,NULL);
__CPROVER_assume(set_done);
#else
set_x(NULL);
Expand Down
1 change: 0 additions & 1 deletion regression/cbmc-concurrency/malloc2/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <stdlib.h>
#include <pthread.h>

_Bool set_done;
int *ptr;
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/memory_barrier1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c
--unwind 1 --no-unwinding-assertions
^EXIT=0$
Expand Down
8 changes: 8 additions & 0 deletions regression/cbmc-concurrency/memory_barrier2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ volatile int flag1 = 0, flag2 = 0; // boolean flags
void* thr1(void * arg) { // frontend produces 12 transitions from this thread. It would be better if it would produce only 8!
flag1 = 1;
turn = 1;
#ifdef __GNUC__
__asm__ __volatile__ ("mfence": : :"memory");
#else
__CPROVER_fence("WWfence", "RRfence", "RWfence", "WRfence");
#endif
__CPROVER_assume(! (flag2==1 && turn==1) );
// begin: critical section
x = 0;
Expand All @@ -21,7 +25,11 @@ void* thr1(void * arg) { // frontend produces 12 transitions from this thread. I
void* thr2(void * arg) {
flag2 = 1;
turn = 0;
#ifdef __GNUC__
__asm__ __volatile__ ("mfence": : :"memory");
#else
__CPROVER_fence("WWfence", "RRfence", "RWfence", "WRfence");
#endif
__CPROVER_assume(! (flag1==1 && turn==0) );
// begin: critical section
x = 1;
Expand Down
2 changes: 2 additions & 0 deletions regression/cbmc-concurrency/memory_barrier2/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ main.c
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
--
Some past change broke this test such that we now report verification failures.
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/mutex2/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c
-DMUTEX
^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/norace_array1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
KNOWNBUG pthread
main.c

^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/norace_array2/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
KNOWNBUG pthread
main.c

^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/norace_scalar1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c

^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/norace_struct1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
KNOWNBUG pthread
main.c

^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/pthread_create_tso1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c
--mm tso
^EXIT=0$
Expand Down
6 changes: 3 additions & 3 deletions regression/cbmc-concurrency/pthread_join1/test.desc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CORE
CORE pthread
main.c
--all-properties
^EXIT=10$
^SIGNAL=0$
^\[main\.assertion\.1\] assertion i==1: FAILURE$
^\[main\.assertion\.2\] assertion i==2: SUCCESS$
^\[main\.assertion\.1\] line 21 assertion i==1: FAILURE$
^\[main\.assertion\.2\] line 22 assertion i==2: SUCCESS$
^\*\* 1 of 2 failed
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/pthread_join2/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c
--unwind 2
^EXIT=10$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/sc6/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c

^EXIT=0$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c
--error-label ERROR
^EXIT=0$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c
--error-label ERROR
^EXIT=10$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/thread_chain_posix1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c

^EXIT=10$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/thread_chain_posix2/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
KNOWNBUG pthread
main.c
-D_ENABLE_CHAIN_ --unwind 2
^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/thread_chain_posix3/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
KNOWNBUG pthread
main.c
-D_ENABLE_CHAIN_ -D_SANITY_CHECK_ --unwind 2
^EXIT=10$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/thread_local1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c

^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/trace1/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ main.c
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
^[[:space:]]*r2=1u \(.*\)$
^[[:space:]]*r2=1u(l)? \(.*\)$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/cbmc-concurrency/uf_with_threads1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE
CORE pthread
main.c

^EXIT=0$
Expand Down
37 changes: 16 additions & 21 deletions src/goto-programs/builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,15 +1065,14 @@ void goto_convertt::do_function_call_symbol(
throw 0;
}

goto_programt::targett t=dest.add_instruction(OTHER);
t->source_location=function.source_location();
t->code.set(ID_statement, ID_fence);

codet fence(ID_fence);
forall_expr(it, arguments)
{
const irep_idt kind=get_string_constant(*it);
t->code.set(kind, true);
fence.set(kind, true);
}

dest.add(goto_programt::make_other(fence, function.source_location()));
}
else if(identifier=="__builtin_prefetch")
{
Expand Down Expand Up @@ -1268,10 +1267,9 @@ void goto_convertt::do_function_call_symbol(
t3->code=code_assignt(deref_ptr, op_expr);

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

goto_programt::targett t5=dest.add_instruction(ATOMIC_END);
t5->source_location=function.source_location();
Expand Down Expand Up @@ -1339,10 +1337,9 @@ void goto_convertt::do_function_call_symbol(
}

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

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

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

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

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

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