Skip to content

Commit 2fa05f4

Browse files
author
Daniel Kroening
authored
Merge pull request #566 from owen-jones-diffblue/feature/tests-for-sensitivity
Feature/tests for sensitivity
2 parents fae3cd8 + 2a86ae3 commit 2fa05f4

File tree

74 files changed

+1804
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1804
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#include <assert.h>
2+
3+
int main(int argc, char *argv[])
4+
{
5+
// A uniform constant array
6+
int a[3][3]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
7+
// A non-uniform constant array
8+
int b[3][3]={{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};
9+
10+
// Test if we can represent uniform constant arrays
11+
assert(a[1][2]==0);
12+
assert(a[1][2]==1);
13+
14+
// Test if we can represent constant arrays which aren't uniform
15+
assert(b[1][2]==5);
16+
assert(b[1][2]==0);
17+
18+
// Test alternative syntax for accessing an array value
19+
assert(*(b[1]+2)==5);
20+
assert(*(b[1]+2)==0);
21+
assert((*(b+1))[2]==5);
22+
assert((*(b+1))[2]==0);
23+
assert(*(*(b+1)+2)==5);
24+
assert(*(*(b+1)+2)==0);
25+
assert(1[b][2]==5);
26+
assert(1[b][2]==0);
27+
assert(*(1[b]+2)==5);
28+
assert(*(1[b]+2)==0);
29+
assert((*(1+b))[2]==5);
30+
assert((*(1+b))[2]==0);
31+
assert(*(*(1+b)+2)==5);
32+
assert(*(*(1+b)+2)==0);
33+
assert(2[1[b]]==5);
34+
assert(2[1[b]]==0);
35+
assert(*(2+1[b])==5);
36+
assert(*(2+1[b])==0);
37+
assert(*(2+*(1+b))==5);
38+
assert(*(2+*(1+b))==0);
39+
40+
// Test how well we can deal with merging for an array value when there is one
41+
// possible value
42+
if(argc>2)
43+
{
44+
a[0][1]=0;
45+
}
46+
assert(a[0][1]==0);
47+
assert(a[0][1]==1);
48+
assert(a[0][2]==0);
49+
50+
// Test how well we can deal with merging for an array value when there are
51+
// two possible values
52+
if(argc>2)
53+
{
54+
b[0][1]=2;
55+
}
56+
assert(b[0][1]==2);
57+
assert(b[0][1]==3);
58+
assert(b[0][2]==2);
59+
60+
// Reset this change to ensure tests later work as expected
61+
b[0][1]=1;
62+
63+
// The variables i, j and k will be used as indexes into arrays of size 3.
64+
// They all require merging paths in the CFG. For i there is only one value on
65+
// both paths, which is a valid index. The rest can each take two different
66+
// values. For j both of these values are valid indexes. For k one is and one
67+
// isn't.
68+
int i=0;
69+
int j=0;
70+
int k=0;
71+
if(argc>3)
72+
{
73+
i=0;
74+
j=1;
75+
k=100;
76+
}
77+
78+
// Test how well we can deal with merging for an index on a uniform array when
79+
// the index has one possible value
80+
assert(a[i][1]==0);
81+
assert(a[i][1]==1);
82+
assert(a[1][i]==0);
83+
assert(a[1][i]==1);
84+
assert(a[i][i]==0);
85+
assert(a[i][i]==1);
86+
87+
// Test how well we can deal with merging for an index on a uniform array when
88+
// the index has two possible values
89+
assert(a[j][1]==0);
90+
assert(a[j][1]==1);
91+
assert(a[1][j]==0);
92+
assert(a[1][j]==1);
93+
assert(a[j][j]==0);
94+
assert(a[j][j]==1);
95+
96+
// Test how well we can deal with merging for an index on a non-uniform array
97+
98+
assert(b[i][1]==1);
99+
assert(b[i][1]==11);
100+
assert(b[1][i]==3);
101+
assert(b[1][i]==11);
102+
assert(b[i][i]==0);
103+
assert(b[i][i]==11);
104+
105+
// Test how well we can deal with merging for an index on a non-uniform array
106+
assert(b[j][1]==1);
107+
assert(b[j][1]==11);
108+
assert(b[1][j]==3);
109+
assert(b[1][j]==11);
110+
assert(b[j][j]==0);
111+
assert(b[j][j]==11);
112+
113+
// Test how we deal with reading off the end of an array
114+
assert(a[100][0]==0);
115+
assert(a[0][100]==0);
116+
117+
// Test how we deal with writing off the end of an array
118+
int c=0;
119+
a[100][0]=1;
120+
assert(c==0);
121+
c=0;
122+
a[0][100]=1;
123+
assert(c==0);
124+
125+
// Test how we deal with merging for an index with one possible value when
126+
// writing to an array
127+
int ei[3][3]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
128+
ei[i][1]=1;
129+
assert(ei[0][1]==1);
130+
assert(ei[0][1]==0);
131+
assert(ei[2][1]==0);
132+
assert(ei[2][1]==1);
133+
134+
// Test how we deal with merging for an index with two possible values when
135+
// writing to an array
136+
int ej[3][3]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
137+
ej[j][1]=1;
138+
assert(ej[0][1]==0);
139+
assert(ej[2][1]==0);
140+
141+
// Test how we deal with merging for an index with two possible values when
142+
// it means writing to an array element that may be out of bounds
143+
int ek[3][3]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
144+
c=0;
145+
ek[k][1]=1;
146+
assert(ek[0][1]==0);
147+
assert(c==0);
148+
149+
return 0;
150+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#include <assert.h>
2+
3+
int main(int argc, char *argv[])
4+
{
5+
// Test how well we can represent arrays of pointers
6+
int a0=0;
7+
int a1=1;
8+
int a2=2;
9+
int a3=3;
10+
int b0=10;
11+
int b1=11;
12+
int b2=12;
13+
int b3=13;
14+
int c0=20;
15+
int c1=21;
16+
int c2=22;
17+
int c3=23;
18+
int d0=30;
19+
int d1=31;
20+
int d2=32;
21+
int d3=33;
22+
// A uniform constant array
23+
int *a[3]={&a0, &a0, &a0};
24+
// A non-uniform constant array
25+
int *b[3]={&b0, &b1, &b2};
26+
27+
// Test if we can represent uniform constant arrays
28+
assert(a[1]==&a0);
29+
assert(a[1]==&a3);
30+
assert(*a[1]==0);
31+
assert(*a[1]==3);
32+
33+
// Test if we can represent constant arrays which aren't uniform
34+
assert(b[1]==&b1);
35+
assert(b[1]==&b3);
36+
assert(*b[1]==11);
37+
assert(*b[1]==13);
38+
39+
// Test alternative syntax for accessing an array value
40+
assert(*(b+1)==&b1);
41+
assert(*(b+1)==&b3);
42+
assert(*(1+b)==&b1);
43+
assert(*(1+b)==&b3);
44+
assert(1[b]==&b1);
45+
assert(1[b]==&b3);
46+
assert(**(b+1)==11);
47+
assert(**(b+1)==13);
48+
assert(**(1+b)==11);
49+
assert(**(1+b)==13);
50+
assert(*1[b]==11);
51+
assert(*1[b]==13);
52+
53+
// c and d are arrays whose values requiring merging paths in the CFG. For
54+
// c[0] there is only one possibility after merging and for d[0] there are
55+
// two.
56+
int *c[3]={&c0, &c1, &c2};
57+
int *d[3]={&d0, &d1, &d2};
58+
if(argc>2)
59+
{
60+
c[0]=&c3;
61+
d[0]=&d3;
62+
}
63+
64+
// Test how well we can deal with merging for an array value
65+
assert(c[0]==&c0);
66+
assert(c[0]==&c3);
67+
assert(d[0]==&d0);
68+
assert(d[0]==&d3);
69+
assert(*c[0]==20);
70+
assert(*c[0]==23);
71+
assert(*d[0]==30);
72+
assert(*d[0]==33);
73+
74+
// The variables i, j and k will be used as indexes into arrays of size 3.
75+
// They all require merging paths in the CFG. For i there is only one value on
76+
// both paths, which is a valid index. The rest can each take two different
77+
// values. For j both of these values are valid indexes. For k one is and one
78+
// isn't.
79+
int i=0;
80+
int j=0;
81+
int k=0;
82+
if(argc>3)
83+
{
84+
i=0;
85+
j=1;
86+
k=100;
87+
}
88+
89+
// Test how well we can deal with merging for an index on a uniform array
90+
assert(a[i]==&a0);
91+
assert(a[i]==&a3);
92+
assert(a[j]==&a0);
93+
assert(a[j]==&a3);
94+
assert(*a[i]==0);
95+
assert(*a[i]==3);
96+
assert(*a[j]==0);
97+
assert(*a[j]==3);
98+
99+
// Test how well we can deal with merging for an index on a non-uniform array
100+
assert(b[i]==&b0);
101+
assert(b[i]==&b1);
102+
assert(b[j]==&b0);
103+
assert(b[j]==&b3);
104+
assert(*b[i]==10);
105+
assert(*b[i]==11);
106+
assert(*b[j]==10);
107+
assert(*b[j]==13);
108+
109+
// Test how we deal with reading off the end of an array
110+
assert(a[100]==&a2);
111+
assert(*a[100]==2);
112+
113+
// Test how we deal with writing off the end of an array
114+
a[100]=&a2;
115+
assert(b[1]==&b1);
116+
assert(*b[1]==11);
117+
118+
// Test how we deal with merging for an index with one possible value when
119+
// writing to an array
120+
int ei0=40;
121+
int ei1=41;
122+
int *ei[3]={&ei0, &ei0, &ei0};
123+
ei[i]=&ei1;
124+
assert(ei[0]==&ei1);
125+
assert(ei[0]==&ei0);
126+
assert(ei[2]==&ei0);
127+
assert(ei[2]==&ei1);
128+
assert(*ei[0]==41);
129+
assert(*ei[0]==40);
130+
assert(*ei[2]==40);
131+
assert(*ei[2]==41);
132+
133+
// Test how we deal with merging for an index with two possible values when
134+
// writing to an array
135+
int ej0=50;
136+
int ej1=51;
137+
int *ej[3]={&ej0, &ej0, &ej0};
138+
ej[j]=&ej1;
139+
assert(ej[0]==&ej0);
140+
assert(ej[2]==&ej0);
141+
assert(ej[2]==&ej1);
142+
assert(*ej[0]==50);
143+
assert(*ej[2]==50);
144+
assert(*ej[2]==51);
145+
146+
// Test how we deal with merging for an index with two possible values when
147+
// it means writing to an array element that may be out of bounds
148+
int ek0=60;
149+
int ek1=61;
150+
int *ek[3]={&ek0, &ek0, &ek0};
151+
ek[k]=&ek1;
152+
assert(ek[0]==&ek0);
153+
assert(*ek[0]==60);
154+
155+
return 0;
156+
}

0 commit comments

Comments
 (0)