Skip to content

Commit 3d9a71b

Browse files
authored
Merge pull request #4482 from xbauch/feature/user-control-havoc
User controlled havoc(ing) for memory-snapshot harness
2 parents 0142834 + e0d3e5e commit 3d9a71b

File tree

30 files changed

+925
-188
lines changed

30 files changed

+925
-188
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-goto-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-goto-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
return 0;
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
first,second,array_size --harness-type initialise-with-memory-snapshot --initial-goto-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+
CORE
2+
main.c
3+
first,second,string_size,prefix,prefix_size --harness-type initialise-with-memory-snapshot --initial-goto-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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <assert.h>
2+
#include <malloc.h>
3+
4+
int *first;
5+
int *second;
6+
int *third;
7+
int array_size;
8+
const int *prefix;
9+
int prefix_size;
10+
11+
void initialize()
12+
{
13+
first = (int *)malloc(sizeof(int) * 5);
14+
first[0] = 0;
15+
first[1] = 1;
16+
first[2] = 2;
17+
first[3] = 3;
18+
first[4] = 4;
19+
second = first;
20+
array_size = 5;
21+
third = &array_size;
22+
}
23+
24+
void checkpoint()
25+
{
26+
}
27+
28+
int main()
29+
{
30+
initialize();
31+
checkpoint();
32+
33+
assert(first == second);
34+
// The following assertions will be check in the following PR once
35+
// dynamically allocated snapshots are properly implemented.
36+
/* assert(array_size >= prefix_size); */
37+
/* assert(prefix_size >= 0); */
38+
/* assert(second[prefix_size] != 6); */
39+
/* assert(second[4] == 4); */
40+
41+
/* for(int i = 0; i < prefix_size; i++) */
42+
/* assert(second[i] != prefix[i]); */
43+
return 0;
44+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
first,second,array_size,prefix,prefix_size --harness-type initialise-with-memory-snapshot --initial-goto-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

0 commit comments

Comments
 (0)