tests: robustify -k test

Split stack-fcall.c into several compilation units so that intermediate
function calls would not be optimized out by compiler.

* tests/stack-fcall.c: Move intermediate functions to ...
* tests/stack-fcall-*.c: ... new files.
* tests/Makefile.am (stack_fcall_SOURCES): Add stack-fcall-*.c.
This commit is contained in:
2014-06-16 21:45:52 +00:00
parent c588b205be
commit b076420692
6 changed files with 28 additions and 30 deletions

View File

@ -11,6 +11,8 @@ check_PROGRAMS = \
uio
uio_CFLAGS = $(AM_CFLAGS) -D_FILE_OFFSET_BITS=64
stack_fcall_SOURCES = stack-fcall.c \
stack-fcall-0.c stack-fcall-1.c stack-fcall-2.c stack-fcall-3.c
TESTS = \
ptrace_setoptions.test \

6
tests/stack-fcall-0.c Normal file
View File

@ -0,0 +1,6 @@
int f1(int i);
int f0(int i)
{
return f1(i) - i;
}

6
tests/stack-fcall-1.c Normal file
View File

@ -0,0 +1,6 @@
int f2(int i);
int f1(int i)
{
return f2(i) + i;
}

6
tests/stack-fcall-2.c Normal file
View File

@ -0,0 +1,6 @@
int f3(int i);
int f2(int i)
{
return f3(i) - i;
}

6
tests/stack-fcall-3.c Normal file
View File

@ -0,0 +1,6 @@
#include <unistd.h>
int f3(int i)
{
return getpid() + i;
}

View File

@ -1,35 +1,7 @@
#include <unistd.h>
#include <sys/types.h>
/* Use "volatile" to avoid compiler optimization. */
int f3(int i)
{
static pid_t (* volatile g)(void) = getpid;
return g() + i;
}
int f2(volatile int i)
{
static int (* volatile g)(int) = f3;
return g(i) - i;
}
int f1(volatile int i)
{
static int (* volatile g)(int) = f2;
return g(i) + i;
}
int f0(volatile int i)
{
static int (* volatile g)(int) = f1;
return g(i) - i;
}
int f0(int i);
int main(int argc, char** argv)
{
static int (* volatile g)(int) = f0;
g(argc);
f0(argc);
return 0;
}