Skip to content

Commit fc37b79

Browse files
committed
Refactor restrict function pointers regression tests
1 parent 2b0ae44 commit fc37b79

File tree

19 files changed

+156
-93
lines changed
  • regression/goto-instrument
    • restrict-function-pointer-to-complex-expression
    • restrict-function-pointer-to-multiple-functions-code-check
    • restrict-function-pointer-to-multiple-functions-incorrectly
    • restrict-function-pointer-to-multiple-functions-via-file-and-command-line-options
    • restrict-function-pointer-to-multiple-functions-via-file
    • restrict-function-pointer-to-multiple-functions-via-multiple-files
    • restrict-function-pointer-to-multiple-functions
    • restrict-function-pointer-to-single-function-code-check
    • restrict-function-pointer-to-single-function-incorrectly
    • restrict-function-pointer-to-single-function

19 files changed

+156
-93
lines changed

regression/goto-instrument/restrict-function-pointer-to-complex-expression/test.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ void use_fg(int choice, fptr_t fptr, fptr_t gptr)
1010
assert((choice ? fptr : gptr)(10) == 10 + choice);
1111
}
1212

13-
// this is just here to distinguish the behavior from FP removal, which'd include g
14-
int g_always_false_cond = 0;
15-
1613
int main(void)
1714
{
1815
use_fg(0, get_f(), get_g());
@@ -34,9 +31,14 @@ int h(int x)
3431
return x / 2;
3532
}
3633

34+
// Below we take the address of f, g, and h. Thus remove_function_pointers()
35+
// would create a case distinction involving f, g, and h in the function
36+
// use_fg() above.
37+
int always_false_cond = 0;
38+
3739
fptr_t get_f(void)
3840
{
39-
if(!g_always_false_cond)
41+
if(!always_false_cond)
4042
{
4143
return f;
4244
}
@@ -48,7 +50,7 @@ fptr_t get_f(void)
4850

4951
fptr_t get_g(void)
5052
{
51-
if(!g_always_false_cond)
53+
if(!always_false_cond)
5254
{
5355
return g;
5456
}

regression/goto-instrument/restrict-function-pointer-to-complex-expression/test.desc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ test.c
55
\[use_fg.assertion.1\] line \d+ dereferenced function pointer at use_fg.function_pointer_call.1 must be one of \[(f|g), (f|g)\]: SUCCESS
66
^EXIT=0$
77
^SIGNAL=0$
8+
--
9+
--
10+
This test checks that the selected function pointer is replaced by a case
11+
distinction over both functions f and g.

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-code-check/test.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,41 @@ int f(int x)
2525
{
2626
return x + 1;
2727
}
28+
2829
int g(int x)
2930
{
3031
return x;
3132
}
33+
3234
int h(int x)
3335
{
3436
return x - 1;
3537
}
3638

37-
int g_select_function = 0;
39+
int select_function = 0;
3840

3941
void select_f(void)
4042
{
41-
g_select_function = 0;
43+
select_function = 0;
4244
}
45+
4346
void select_g(void)
4447
{
45-
g_select_function = 1;
48+
select_function = 1;
4649
}
50+
4751
void select_h(void)
4852
{
49-
g_select_function = 2;
53+
select_function = 2;
5054
}
5155

5256
fptr_t get_f(void)
5357
{
54-
if(g_select_function == 0)
58+
if(select_function == 0)
5559
{
5660
return f;
5761
}
58-
else if(g_select_function == 1)
62+
else if(select_function == 1)
5963
{
6064
return g;
6165
}

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-code-check/test.desc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ g\(10\)
77
^SIGNAL=0$
88
--
99
h\(10\)
10+
--
11+
This test checks that no call to g appears in the goto program after the
12+
transformation by the restrict function pointer feature.

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-incorrectly/test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ int f(int x)
2727
{
2828
return x + 1;
2929
}
30+
3031
int g(int x)
3132
{
3233
return x;
3334
}
35+
3436
int h(int x)
3537
{
3638
return x - 1;
@@ -42,10 +44,12 @@ void select_f(void)
4244
{
4345
g_select_function = 0;
4446
}
47+
4548
void select_g(void)
4649
{
4750
g_select_function = 1;
4851
}
52+
4953
void select_h(void)
5054
{
5155
g_select_function = 2;

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-incorrectly/test.desc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@ test.c
44
\[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be one of \[(f|g), (f|g)\]: FAILURE
55
^EXIT=10$
66
^SIGNAL=0$
7+
--
8+
--
9+
This test checks that multiple restrictions for a given function pointer can be
10+
given.
11+
12+
The test further checks that the correct safety assertions are generated. The
13+
function pointer restriction feature outputs safety assertions for all calls
14+
that it replaces. That is, when it replaces a call with a case distinction over
15+
a given set of functions, it adds an assertion checking that in the original
16+
program, indeed no other function could have been called at that location. In
17+
this case, the function h could also be called, but the given restrictions only
18+
include f and g, hence the safety assertion fails.

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-via-file-and-command-line-options/test.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,41 @@ int f(int x)
2727
{
2828
return x + 1;
2929
}
30+
3031
int g(int x)
3132
{
3233
return x;
3334
}
35+
3436
int h(int x)
3537
{
3638
return x - 1;
3739
}
3840

39-
int g_select_function = 0;
41+
int select_function = 0;
4042

4143
void select_f(void)
4244
{
43-
g_select_function = 0;
45+
select_function = 0;
4446
}
47+
4548
void select_g(void)
4649
{
47-
g_select_function = 1;
50+
select_function = 1;
4851
}
52+
4953
void select_h(void)
5054
{
51-
g_select_function = 2;
55+
select_function = 2;
5256
}
5357

5458
fptr_t get_f(void)
5559
{
56-
if(g_select_function == 0)
60+
if(select_function == 0)
5761
{
5862
return f;
5963
}
60-
else if(g_select_function == 1)
64+
else if(select_function == 1)
6165
{
6266
return g;
6367
}

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-via-file-and-command-line-options/test.desc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@ test.c
44
\[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be one of \[(f|g), (f|g)\]: FAILURE
55
^EXIT=10$
66
^SIGNAL=0$
7+
--
8+
--
9+
This test checks that the restrictions for a function pointer are the union of
10+
the restrictions given in a file and on the command line.
11+
12+
The test further checks that the correct safety assertions are generated. The
13+
function pointer restriction feature outputs safety assertions for all calls
14+
that it replaces. That is, when it replaces a call with a case distinction over
15+
a given set of functions, it adds an assertion checking that in the original
16+
program, indeed no other function could have been called at that location. In
17+
this case, the function h could also be called, but the given restrictions only
18+
include f and g, hence the safety assertion fails.

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-via-file/test.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,41 @@ int f(int x)
2727
{
2828
return x + 1;
2929
}
30+
3031
int g(int x)
3132
{
3233
return x;
3334
}
35+
3436
int h(int x)
3537
{
3638
return x - 1;
3739
}
3840

39-
int g_select_function = 0;
41+
int select_function = 0;
4042

4143
void select_f(void)
4244
{
43-
g_select_function = 0;
45+
select_function = 0;
4446
}
47+
4548
void select_g(void)
4649
{
47-
g_select_function = 1;
50+
select_function = 1;
4851
}
52+
4953
void select_h(void)
5054
{
51-
g_select_function = 2;
55+
select_function = 2;
5256
}
5357

5458
fptr_t get_f(void)
5559
{
56-
if(g_select_function == 0)
60+
if(select_function == 0)
5761
{
5862
return f;
5963
}
60-
else if(g_select_function == 1)
64+
else if(select_function == 1)
6165
{
6266
return g;
6367
}

regression/goto-instrument/restrict-function-pointer-to-multiple-functions-via-file/test.desc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@ test.c
44
\[use_f\.assertion\.1\] line \d+ dereferenced function pointer at use_f.function_pointer_call.1 must be one of \[(f|g), (f|g)\]: FAILURE
55
^EXIT=10$
66
^SIGNAL=0$
7+
--
8+
--
9+
This test checks the reading of function pointer restrictions from a given json
10+
file.
11+
12+
The test further checks that the correct safety assertions are generated. The
13+
function pointer restriction feature outputs safety assertions for all calls
14+
that it replaces. That is, when it replaces a call with a case distinction over
15+
a given set of functions, it adds an assertion checking that in the original
16+
program, indeed no other function could have been called at that location. In
17+
this case, the function h could also be called, but the given restrictions only
18+
include f and g, hence the safety assertion fails.

0 commit comments

Comments
 (0)