Skip to content

Feature/tests for sensitivity #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#include <assert.h>

int main(int argc, char *argv[])
{
// A uniform constant array
int a[3][3]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
// A non-uniform constant array
int b[3][3]={{0, 1, 2}, {3, 4, 5}, {6, 7, 8}};

// Test if we can represent uniform constant arrays
assert(a[1][2]==0);
assert(a[1][2]==1);

// Test if we can represent constant arrays which aren't uniform
assert(b[1][2]==5);
assert(b[1][2]==0);

// Test alternative syntax for accessing an array value
assert(*(b[1]+2)==5);
assert(*(b[1]+2)==0);
assert((*(b+1))[2]==5);
assert((*(b+1))[2]==0);
assert(*(*(b+1)+2)==5);
assert(*(*(b+1)+2)==0);
assert(1[b][2]==5);
assert(1[b][2]==0);
assert(*(1[b]+2)==5);
assert(*(1[b]+2)==0);
assert((*(1+b))[2]==5);
assert((*(1+b))[2]==0);
assert(*(*(1+b)+2)==5);
assert(*(*(1+b)+2)==0);
assert(2[1[b]]==5);
assert(2[1[b]]==0);
assert(*(2+1[b])==5);
assert(*(2+1[b])==0);
assert(*(2+*(1+b))==5);
assert(*(2+*(1+b))==0);

// Test how well we can deal with merging for an array value when there is one
// possible value
if(argc>2)
{
a[0][1]=0;
}
assert(a[0][1]==0);
assert(a[0][1]==1);
assert(a[0][2]==0);

// Test how well we can deal with merging for an array value when there are
// two possible values
if(argc>2)
{
b[0][1]=2;
}
assert(b[0][1]==2);
assert(b[0][1]==3);
assert(b[0][2]==2);

// Reset this change to ensure tests later work as expected
b[0][1]=1;

// The variables i, j and k will be used as indexes into arrays of size 3.
// They all require merging paths in the CFG. For i there is only one value on
// both paths, which is a valid index. The rest can each take two different
// values. For j both of these values are valid indexes. For k one is and one
// isn't.
int i=0;
int j=0;
int k=0;
if(argc>3)
{
i=0;
j=1;
k=100;
}

// Test how well we can deal with merging for an index on a uniform array when
// the index has one possible value
assert(a[i][1]==0);
assert(a[i][1]==1);
assert(a[1][i]==0);
assert(a[1][i]==1);
assert(a[i][i]==0);
assert(a[i][i]==1);

// Test how well we can deal with merging for an index on a uniform array when
// the index has two possible values
assert(a[j][1]==0);
assert(a[j][1]==1);
assert(a[1][j]==0);
assert(a[1][j]==1);
assert(a[j][j]==0);
assert(a[j][j]==1);

// Test how well we can deal with merging for an index on a non-uniform array

assert(b[i][1]==1);
assert(b[i][1]==11);
assert(b[1][i]==3);
assert(b[1][i]==11);
assert(b[i][i]==0);
assert(b[i][i]==11);

// Test how well we can deal with merging for an index on a non-uniform array
assert(b[j][1]==1);
assert(b[j][1]==11);
assert(b[1][j]==3);
assert(b[1][j]==11);
assert(b[j][j]==0);
assert(b[j][j]==11);

// Test how we deal with reading off the end of an array
assert(a[100][0]==0);
assert(a[0][100]==0);

// Test how we deal with writing off the end of an array
int c=0;
a[100][0]=1;
assert(c==0);
c=0;
a[0][100]=1;
assert(c==0);

// Test how we deal with merging for an index with one possible value when
// writing to an array
int ei[3][3]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
ei[i][1]=1;
assert(ei[0][1]==1);
assert(ei[0][1]==0);
assert(ei[2][1]==0);
assert(ei[2][1]==1);

// Test how we deal with merging for an index with two possible values when
// writing to an array
int ej[3][3]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
ej[j][1]=1;
assert(ej[0][1]==0);
assert(ej[2][1]==0);

// Test how we deal with merging for an index with two possible values when
// it means writing to an array element that may be out of bounds
int ek[3][3]={{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
c=0;
ek[k][1]=1;
assert(ek[0][1]==0);
assert(c==0);

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#include <assert.h>

int main(int argc, char *argv[])
{
// Test how well we can represent arrays of pointers
int a0=0;
int a1=1;
int a2=2;
int a3=3;
int b0=10;
int b1=11;
int b2=12;
int b3=13;
int c0=20;
int c1=21;
int c2=22;
int c3=23;
int d0=30;
int d1=31;
int d2=32;
int d3=33;
// A uniform constant array
int *a[3]={&a0, &a0, &a0};
// A non-uniform constant array
int *b[3]={&b0, &b1, &b2};

// Test if we can represent uniform constant arrays
assert(a[1]==&a0);
assert(a[1]==&a3);
assert(*a[1]==0);
assert(*a[1]==3);

// Test if we can represent constant arrays which aren't uniform
assert(b[1]==&b1);
assert(b[1]==&b3);
assert(*b[1]==11);
assert(*b[1]==13);

// Test alternative syntax for accessing an array value
assert(*(b+1)==&b1);
assert(*(b+1)==&b3);
assert(*(1+b)==&b1);
assert(*(1+b)==&b3);
assert(1[b]==&b1);
assert(1[b]==&b3);
assert(**(b+1)==11);
assert(**(b+1)==13);
assert(**(1+b)==11);
assert(**(1+b)==13);
assert(*1[b]==11);
assert(*1[b]==13);

// c and d are arrays whose values requiring merging paths in the CFG. For
// c[0] there is only one possibility after merging and for d[0] there are
// two.
int *c[3]={&c0, &c1, &c2};
int *d[3]={&d0, &d1, &d2};
if(argc>2)
{
c[0]=&c3;
d[0]=&d3;
}

// Test how well we can deal with merging for an array value
assert(c[0]==&c0);
assert(c[0]==&c3);
assert(d[0]==&d0);
assert(d[0]==&d3);
assert(*c[0]==20);
assert(*c[0]==23);
assert(*d[0]==30);
assert(*d[0]==33);

// The variables i, j and k will be used as indexes into arrays of size 3.
// They all require merging paths in the CFG. For i there is only one value on
// both paths, which is a valid index. The rest can each take two different
// values. For j both of these values are valid indexes. For k one is and one
// isn't.
int i=0;
int j=0;
int k=0;
if(argc>3)
{
i=0;
j=1;
k=100;
}

// Test how well we can deal with merging for an index on a uniform array
assert(a[i]==&a0);
assert(a[i]==&a3);
assert(a[j]==&a0);
assert(a[j]==&a3);
assert(*a[i]==0);
assert(*a[i]==3);
assert(*a[j]==0);
assert(*a[j]==3);

// Test how well we can deal with merging for an index on a non-uniform array
assert(b[i]==&b0);
assert(b[i]==&b1);
assert(b[j]==&b0);
assert(b[j]==&b3);
assert(*b[i]==10);
assert(*b[i]==11);
assert(*b[j]==10);
assert(*b[j]==13);

// Test how we deal with reading off the end of an array
assert(a[100]==&a2);
assert(*a[100]==2);

// Test how we deal with writing off the end of an array
a[100]=&a2;
assert(b[1]==&b1);
assert(*b[1]==11);

// Test how we deal with merging for an index with one possible value when
// writing to an array
int ei0=40;
int ei1=41;
int *ei[3]={&ei0, &ei0, &ei0};
ei[i]=&ei1;
assert(ei[0]==&ei1);
assert(ei[0]==&ei0);
assert(ei[2]==&ei0);
assert(ei[2]==&ei1);
assert(*ei[0]==41);
assert(*ei[0]==40);
assert(*ei[2]==40);
assert(*ei[2]==41);

// Test how we deal with merging for an index with two possible values when
// writing to an array
int ej0=50;
int ej1=51;
int *ej[3]={&ej0, &ej0, &ej0};
ej[j]=&ej1;
assert(ej[0]==&ej0);
assert(ej[2]==&ej0);
assert(ej[2]==&ej1);
assert(*ej[0]==50);
assert(*ej[2]==50);
assert(*ej[2]==51);

// Test how we deal with merging for an index with two possible values when
// it means writing to an array element that may be out of bounds
int ek0=60;
int ek1=61;
int *ek[3]={&ek0, &ek0, &ek0};
ek[k]=&ek1;
assert(ek[0]==&ek0);
assert(*ek[0]==60);

return 0;
}
Loading