Skip to content

Commit f7846a3

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Regression tests for user-control havoc
Char-arrays don't work for now. Structs and non-char pointers do.
1 parent 9bfb0dd commit f7846a3

File tree

12 files changed

+277
-0
lines changed

12 files changed

+277
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
typedef struct st1
5+
{
6+
struct st2 *to_st2;
7+
int data;
8+
} st1_t;
9+
10+
typedef struct st2
11+
{
12+
struct st1 *to_st1;
13+
int data;
14+
} st2_t;
15+
16+
typedef struct st3
17+
{
18+
st1_t *array[3];
19+
} st3_t;
20+
21+
st3_t *p;
22+
23+
void initialize()
24+
{
25+
p = malloc(sizeof(st3_t));
26+
}
27+
28+
void checkpoint()
29+
{
30+
}
31+
32+
int main()
33+
{
34+
initialize();
35+
checkpoint();
36+
37+
assert(p != NULL);
38+
for(int index = 0; index < 3; index++)
39+
{
40+
// check that the arrays in structs (and structs in those arrays) were
41+
// initialized up-to the input depth
42+
assert(p->array[index]->to_st2 != NULL);
43+
assert(p->array[index]->to_st2->to_st1 != NULL);
44+
assert(p->array[index]->to_st2->to_st1->to_st2 == NULL);
45+
}
46+
47+
// non-deterministically initializated objects should not be equal
48+
assert(p->array[0] != p->array[1]);
49+
assert(p->array[1] != p->array[2]);
50+
assert(p->array[0] != p->array[2]);
51+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
p --harness-type initialise-with-memory-snapshot --initial-location main:4 --min-null-tree-depth 10 --max-nondet-tree-depth 4 --havoc-variables p
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
VERIFICATION SUCCESSFUL
7+
--
8+
^warning: ignoring
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
typedef struct st1
5+
{
6+
struct st2 *to_st2;
7+
int data;
8+
} st1_t;
9+
10+
typedef struct st2
11+
{
12+
struct st1 *to_st1;
13+
int data;
14+
} st2_t;
15+
16+
st1_t dummy1;
17+
st2_t dummy2;
18+
19+
st1_t *p;
20+
21+
void initialize()
22+
{
23+
}
24+
25+
void checkpoint()
26+
{
27+
}
28+
29+
int main()
30+
{
31+
initialize();
32+
checkpoint();
33+
34+
assert(p != NULL);
35+
assert(p->to_st2 != NULL);
36+
assert(p->to_st2->to_st1 != NULL);
37+
assert(p->to_st2->to_st1->to_st2 == NULL);
38+
39+
assert(p != &dummy1);
40+
assert(p->to_st2 != &dummy2);
41+
assert(p->to_st2->to_st1 != &dummy1);
42+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
p --harness-type initialise-with-memory-snapshot --initial-location main:4 --havoc-variables p --min-null-tree-depth 10 --max-nondet-tree-depth 3
4+
^SIGNAL=0$
5+
^EXIT=0$
6+
VERIFICATION SUCCESSFUL
7+
--
8+
unwinding assertion loop \d+: FAILURE
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <assert.h>
2+
#include <malloc.h>
3+
4+
char *first;
5+
char *second;
6+
int array_size;
7+
8+
void initialize()
9+
{
10+
first = malloc(sizeof(char) * 12);
11+
first = "1234567890a";
12+
second = first;
13+
array_size = 11;
14+
}
15+
16+
void checkpoint()
17+
{
18+
}
19+
20+
int main()
21+
{
22+
initialize();
23+
checkpoint();
24+
25+
assert(first == second);
26+
assert(second[array_size - 1] == 'a');
27+
// assert(second[10]=='0');
28+
return 0;
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
KNOWNBUG
2+
main.c
3+
first,second,array_size --harness-type initialise-with-memory-snapshot --initial-location main:4
4+
^SIGNAL=0$
5+
^EXIT=0$
6+
VERIFICATION SUCCESSFUL
7+
--
8+
unwinding assertion loop \d+: FAILURE
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <assert.h>
2+
3+
char *first = "12345678901";
4+
char *second;
5+
int string_size;
6+
const char *prefix;
7+
int prefix_size;
8+
9+
void initialize()
10+
{
11+
second = first;
12+
string_size = 11;
13+
}
14+
15+
void checkpoint()
16+
{
17+
}
18+
19+
int main()
20+
{
21+
initialize();
22+
checkpoint();
23+
24+
assert(first == second);
25+
if(prefix_size > 0)
26+
assert(second[prefix_size - 1] != 'a');
27+
28+
if(string_size < prefix_size)
29+
{
30+
return 0;
31+
}
32+
33+
for(int ix = 0; ix < prefix_size; ++ix)
34+
{
35+
if(second[ix] != prefix[ix])
36+
{
37+
return 0;
38+
}
39+
}
40+
return 1;
41+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
KNOWNBUG
2+
main.c
3+
first,second,string_size,prefix,prefix_size --harness-type initialise-with-memory-snapshot --initial-location main:4 --havoc-variables prefix,prefix_size --size-of-array prefix:prefix_size --max-array-size 5
4+
^SIGNAL=0$
5+
^EXIT=0$
6+
VERIFICATION SUCCESSFUL
7+
--
8+
unwinding assertion loop \d+: FAILURE
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <assert.h>
2+
#include <malloc.h>
3+
4+
int *first;
5+
int *second;
6+
int array_size;
7+
const int *prefix;
8+
int prefix_size;
9+
10+
void initialize()
11+
{
12+
first = malloc(sizeof(int) * 5);
13+
second = first;
14+
array_size = 5;
15+
}
16+
17+
void checkpoint()
18+
{
19+
}
20+
21+
int main()
22+
{
23+
initialize();
24+
checkpoint();
25+
26+
assert(first == second);
27+
assert(array_size >= prefix_size);
28+
assert(prefix_size >= 0);
29+
assert(second[prefix_size] != 6);
30+
31+
for(int i = 0; i < prefix_size; i++)
32+
assert(second[i] != prefix[i]);
33+
return 0;
34+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
KNOWNBUG
2+
main.c
3+
temp,first,second,array_size,prefix,prefix_size --harness-type initialise-with-memory-snapshot --initial-location main:4 --havoc-variables prefix --size-of-array prefix:prefix_size --max-array-size 4
4+
^SIGNAL=0$
5+
^EXIT=0$
6+
VERIFICATION SUCCESSFUL
7+
--
8+
unwinding assertion loop \d+: FAILURE
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <assert.h>
2+
3+
char tmp[12];
4+
char *first;
5+
char *second;
6+
int array_size;
7+
8+
void initialize()
9+
{
10+
tmp[0] = '1';
11+
tmp[9] = '0';
12+
tmp[10] = 'a';
13+
first = (char *)tmp;
14+
second = first;
15+
array_size = 11;
16+
}
17+
18+
void checkpoint()
19+
{
20+
}
21+
22+
int main()
23+
{
24+
initialize();
25+
checkpoint();
26+
27+
assert(first == second);
28+
assert(second[array_size - 1] == 'a');
29+
assert(first[0] == '1');
30+
assert(second[9] == '0');
31+
return 0;
32+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
tmp,first,second,array_size --harness-type initialise-with-memory-snapshot --initial-location main:4
4+
^SIGNAL=0$
5+
^EXIT=0$
6+
VERIFICATION SUCCESSFUL
7+
--
8+
unwinding assertion loop \d+: FAILURE

0 commit comments

Comments
 (0)