Skip to content

Commit 8941f72

Browse files
committed
Regression tests for function pointers
1. one function one pointer 2. two functions two pointers, check they point to the right ones 3. two functions, array of function pointers, pointers initialised from the array
1 parent 41a7af6 commit 8941f72

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <assert.h>
2+
3+
int foo(int i)
4+
{
5+
return i + 1;
6+
}
7+
8+
int (*fun_ptr)(int);
9+
10+
void initialize()
11+
{
12+
fun_ptr = &foo;
13+
}
14+
15+
void checkpoint()
16+
{
17+
}
18+
19+
int main()
20+
{
21+
initialize();
22+
checkpoint();
23+
24+
assert(fun_ptr == &foo);
25+
assert((*fun_ptr)(5) == 6);
26+
assert((*fun_ptr)(5) == foo(5));
27+
return 0;
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CORE
2+
main.c
3+
fun_ptr --harness-type initialise-with-memory-snapshot --initial-goto-location main:4
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line [0-9]+ assertion fun_ptr == \&foo: SUCCESS
7+
\[main.assertion.2\] line [0-9]+ assertion \(\*fun_ptr\)\(5\) == 6: SUCCESS
8+
\[main.assertion.3\] line [0-9]+ assertion \(\*fun_ptr\)\(5\) == foo\(5\): SUCCESS
9+
VERIFICATION SUCCESSFUL
10+
--
11+
^warning: ignoring
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <assert.h>
2+
3+
int plus(int i)
4+
{
5+
return i + 1;
6+
}
7+
8+
int minus(int i)
9+
{
10+
return i - 1;
11+
}
12+
13+
int (*fun_ptr1)(int);
14+
int (*fun_ptr2)(int);
15+
16+
void initialize()
17+
{
18+
fun_ptr1 = &plus;
19+
fun_ptr2 = &minus;
20+
}
21+
22+
void checkpoint()
23+
{
24+
}
25+
26+
int main()
27+
{
28+
initialize();
29+
checkpoint();
30+
31+
assert(fun_ptr1 == &plus);
32+
assert((*fun_ptr1)(5) == 6);
33+
assert((*fun_ptr1)(5) == plus(5));
34+
assert(fun_ptr2 != fun_ptr1);
35+
assert((*fun_ptr2)(5) == 4);
36+
return 0;
37+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
fun_ptr1,fun_ptr2 --harness-type initialise-with-memory-snapshot --initial-goto-location main:4
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line [0-9]+ assertion fun_ptr1 == \&plus: SUCCESS
7+
\[main.assertion.2\] line [0-9]+ assertion \(\*fun_ptr1\)\(5\) == 6: SUCCESS
8+
\[main.assertion.3\] line [0-9]+ assertion \(\*fun_ptr1\)\(5\) == plus\(5\): SUCCESS
9+
\[main.assertion.4\] line [0-9]+ assertion fun_ptr2 \!= fun_ptr1: SUCCESS
10+
\[main.assertion.5\] line [0-9]+ assertion \(\*fun_ptr2\)\(5\) == 4: SUCCESS
11+
VERIFICATION SUCCESSFUL
12+
--
13+
^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+
3+
int plus(int i)
4+
{
5+
return i + 1;
6+
}
7+
8+
int minus(int i)
9+
{
10+
return i - 1;
11+
}
12+
13+
typedef int (*fun_ptrt)(int);
14+
fun_ptrt fun_array[2];
15+
16+
fun_ptrt fun_ptr1;
17+
fun_ptrt fun_ptr2;
18+
19+
void initialize()
20+
{
21+
fun_array[0] = &plus;
22+
fun_array[1] = &minus;
23+
fun_ptr1 = *fun_array;
24+
fun_ptr2 = fun_array[1];
25+
}
26+
27+
void checkpoint()
28+
{
29+
}
30+
31+
int main()
32+
{
33+
initialize();
34+
checkpoint();
35+
36+
assert(fun_ptr1 == &plus);
37+
assert((*fun_ptr1)(5) == 6);
38+
assert((*fun_ptr1)(5) == plus(5));
39+
assert(fun_ptr2 != fun_ptr1);
40+
assert((*fun_ptr2)(5) == 4);
41+
return 0;
42+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
fun_array,fun_ptr1,fun_ptr2 --harness-type initialise-with-memory-snapshot --initial-goto-location main:4
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
\[main.assertion.1\] line [0-9]+ assertion fun_ptr1 == \&plus: SUCCESS
7+
\[main.assertion.2\] line [0-9]+ assertion \(\*fun_ptr1\)\(5\) == 6: SUCCESS
8+
\[main.assertion.3\] line [0-9]+ assertion \(\*fun_ptr1\)\(5\) == plus\(5\): SUCCESS
9+
\[main.assertion.4\] line [0-9]+ assertion fun_ptr2 \!= fun_ptr1: SUCCESS
10+
\[main.assertion.5\] line [0-9]+ assertion \(\*fun_ptr2\)\(5\) == 4: SUCCESS
11+
VERIFICATION SUCCESSFUL
12+
--
13+
^warning: ignoring

0 commit comments

Comments
 (0)