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
This commit is contained in:
xbauch 2019-06-07 11:31:45 +01:00
parent 41a7af62ca
commit 8941f724bf
6 changed files with 144 additions and 0 deletions

View File

@ -0,0 +1,28 @@
#include <assert.h>
int foo(int i)
{
return i + 1;
}
int (*fun_ptr)(int);
void initialize()
{
fun_ptr = &foo;
}
void checkpoint()
{
}
int main()
{
initialize();
checkpoint();
assert(fun_ptr == &foo);
assert((*fun_ptr)(5) == 6);
assert((*fun_ptr)(5) == foo(5));
return 0;
}

View File

@ -0,0 +1,11 @@
CORE
main.c
fun_ptr --harness-type initialise-with-memory-snapshot --initial-goto-location main:4
^EXIT=0$
^SIGNAL=0$
\[main.assertion.1\] line [0-9]+ assertion fun_ptr == \&foo: SUCCESS
\[main.assertion.2\] line [0-9]+ assertion \(\*fun_ptr\)\(5\) == 6: SUCCESS
\[main.assertion.3\] line [0-9]+ assertion \(\*fun_ptr\)\(5\) == foo\(5\): SUCCESS
VERIFICATION SUCCESSFUL
--
^warning: ignoring

View File

@ -0,0 +1,37 @@
#include <assert.h>
int plus(int i)
{
return i + 1;
}
int minus(int i)
{
return i - 1;
}
int (*fun_ptr1)(int);
int (*fun_ptr2)(int);
void initialize()
{
fun_ptr1 = &plus;
fun_ptr2 = &minus;
}
void checkpoint()
{
}
int main()
{
initialize();
checkpoint();
assert(fun_ptr1 == &plus);
assert((*fun_ptr1)(5) == 6);
assert((*fun_ptr1)(5) == plus(5));
assert(fun_ptr2 != fun_ptr1);
assert((*fun_ptr2)(5) == 4);
return 0;
}

View File

@ -0,0 +1,13 @@
CORE
main.c
fun_ptr1,fun_ptr2 --harness-type initialise-with-memory-snapshot --initial-goto-location main:4
^EXIT=0$
^SIGNAL=0$
\[main.assertion.1\] line [0-9]+ assertion fun_ptr1 == \&plus: SUCCESS
\[main.assertion.2\] line [0-9]+ assertion \(\*fun_ptr1\)\(5\) == 6: SUCCESS
\[main.assertion.3\] line [0-9]+ assertion \(\*fun_ptr1\)\(5\) == plus\(5\): SUCCESS
\[main.assertion.4\] line [0-9]+ assertion fun_ptr2 \!= fun_ptr1: SUCCESS
\[main.assertion.5\] line [0-9]+ assertion \(\*fun_ptr2\)\(5\) == 4: SUCCESS
VERIFICATION SUCCESSFUL
--
^warning: ignoring

View File

@ -0,0 +1,42 @@
#include <assert.h>
int plus(int i)
{
return i + 1;
}
int minus(int i)
{
return i - 1;
}
typedef int (*fun_ptrt)(int);
fun_ptrt fun_array[2];
fun_ptrt fun_ptr1;
fun_ptrt fun_ptr2;
void initialize()
{
fun_array[0] = &plus;
fun_array[1] = &minus;
fun_ptr1 = *fun_array;
fun_ptr2 = fun_array[1];
}
void checkpoint()
{
}
int main()
{
initialize();
checkpoint();
assert(fun_ptr1 == &plus);
assert((*fun_ptr1)(5) == 6);
assert((*fun_ptr1)(5) == plus(5));
assert(fun_ptr2 != fun_ptr1);
assert((*fun_ptr2)(5) == 4);
return 0;
}

View File

@ -0,0 +1,13 @@
CORE
main.c
fun_array,fun_ptr1,fun_ptr2 --harness-type initialise-with-memory-snapshot --initial-goto-location main:4
^EXIT=0$
^SIGNAL=0$
\[main.assertion.1\] line [0-9]+ assertion fun_ptr1 == \&plus: SUCCESS
\[main.assertion.2\] line [0-9]+ assertion \(\*fun_ptr1\)\(5\) == 6: SUCCESS
\[main.assertion.3\] line [0-9]+ assertion \(\*fun_ptr1\)\(5\) == plus\(5\): SUCCESS
\[main.assertion.4\] line [0-9]+ assertion fun_ptr2 \!= fun_ptr1: SUCCESS
\[main.assertion.5\] line [0-9]+ assertion \(\*fun_ptr2\)\(5\) == 4: SUCCESS
VERIFICATION SUCCESSFUL
--
^warning: ignoring