In this first part, our goal is to assess the correctness of an implementation of the binary search algorithm in the C language, using software testing.
The C file binsearch1.c contains an implementation of the binary search algorithm.
binsearch1.c
with
command
cc -std=c99 -Wall -O0 -g -o binsearch1 binsearch1.c
.
Then run several tests to assess the termination and the correctness of
this implementation.gdb
,
lldb
,…) to simulate the execution of program
binsearch1
and understand the bug.We propose an alternative implementation of the binary search algorithm in file binsearch2.c. Without looking at the code, compile and test the new implementation. What can you conclude?
In this second part, we use model-checking to check the correctness of a TLA+ model of the binary search algorithm.
Finally, we assess the correctness of the binary search algorithm using the Dafny prover.
We consider a program with N
processes that share an
integer variable x
. Each thread first stores the value of
x
in a local variable y
, and then, writes the
value of y+1
in x
. We expect that the value of
x
has increased by N
when all processes have
terminated.
cc -std=c99 -Wall -o concurrent_inc concurrent_inc.c -lpthread
.
The resulting executable concurrent_inc
takes a number
N
of processes on the command line, and runs N
concurrent processes as described above. Test the program for several
values of N
. What can you conclude?