Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-cs committed Feb 2, 2024
1 parent 5bdff46 commit e656e9a
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 0 deletions.
19 changes: 19 additions & 0 deletions regression/cbmc/loop-busy-wait/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <assert.h>

volatile char zero_to_unlock;

void busy_wait (void) {
while (zero_to_unlock);
return;
}

int main (int argc, char **argv) {
// Obviously we would need to spawn some other threads here...

zero_to_unlock = 1;
busy_wait();

assert(0);

return 0;
}
11 changes: 11 additions & 0 deletions regression/cbmc/loop-busy-wait/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
^\[main.assertion.1\] line \d+ assertion 0: SUCCESS$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
--
Relies on symex converting empty loops into assumptions
14 changes: 14 additions & 0 deletions regression/cbmc/loop-empty/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <assert.h>

void empty_loop (void) {
loop : goto loop;
return;
}

int main (int argc, char **argv) {
empty_loop();

assert(0);

return 0;
}
11 changes: 11 additions & 0 deletions regression/cbmc/loop-empty/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
^\[main.assertion.1\] line \d+ assertion 0: SUCCESS$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
--
Relies on symex converting empty loops into assumptions
70 changes: 70 additions & 0 deletions regression/cbmc/loop-sequence-of-instructions/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <assert.h>
#include <stdio.h>

unsigned int control = 0;
unsigned int history = 0;

unsigned int choose (void) {
unsigned int lsb = control & 0x1u;
control = control >> 1;
history = (history << 1) | lsb;
return lsb;
}

void red (void) {
printf("Red\n");
}
void blue (void) {
printf("Blue\n");
}

void test (void) {
while (choose()) {
if (choose()) {
red(); // Is this in the loop?
break;

} else if (choose()) {
goto out;
}
}

if (0) {
out: blue(); // What about this?
}

return;
}


int main (int argc, char **argv) {
scanf("%u", &control);

test();

printf("%u\n", history);
// History is (100)*(0|11|101)

// Let's check that
if (history == 0u) {
// Fine
} else {
if ((history & 0x7) == 0x5) {
history = history >> 3;
} else if ((history & 0x3) == 0x3) {
history = history >> 2;
} else if ((history & 0x1) == 0x0) {
history = history >> 1;
} else {
assert(0);
}

while ((history & 0x7) == 0x4) {
history = history >> 3;
}

assert(history == 0);
}

return 0;
}
12 changes: 12 additions & 0 deletions regression/cbmc/loop-sequence-of-instructions/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--unwind 22
^EXIT=0$
^SIGNAL=0$
^\[main.assertion.\d+\] line \d+ assertion 0: SUCCESS$
^\[main.assertion.\d+\] line \d+ assertion history == 0: SUCCESS$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
--
This investigates whether red or blue is in the loop.

0 comments on commit e656e9a

Please sign in to comment.