- Add test52 to test FPU context switching

- Make test/run count how many tests it's going to perform instead of having to
  manually update it ourselves.
This commit is contained in:
Thomas Veerman 2010-05-03 15:12:39 +00:00
parent cfd28b671a
commit 4ae9c03147
3 changed files with 210 additions and 8 deletions

View file

@ -3,7 +3,8 @@
CC = exec cc
GCC = /usr/gnu/bin/gcc
CFLAGS= -O -D_MINIX -D_POSIX_SOURCE
CFLAGS-GCC= $(CFLAGS) -Wall
CFLAGS-GCC= $(CFLAGS) -Wall
CFLAGS-GCCFPU= $(CFLAGS) -Wall -mhard-float
CFLAGS-GCCFPU= $(CFLAGS-GCC) -W -mhard-float
OBJ= test1 test2 test3 test4 test5 test6 test7 test8 test9 \
@ -11,12 +12,12 @@ OBJ= test1 test2 test3 test4 test5 test6 test7 test8 test9 \
test21 test22 test23 test25 test26 test27 test28 test29 \
test30 test31 test32 test34 test35 test36 test37 test38 \
test39 t10a t11a t11b test40 t40a t40b t40c t40d t40e t40f test41 \
test42 test44 test45 test47 test48 test49 test50 test51
test42 test44 test45 test47 test48 test49 test50 test51 test52
BIGOBJ= test20 test24
ROOTOBJ= test11 test33 test43 test46
GCCOBJ= test45-gcc test49-gcc
GCCFPUOBJ= test51-gcc
GCCFPUOBJ= test51-gcc test52-gcc
all: $(OBJ) $(BIGOBJ) $(GCCOBJ) $(GCCFPUOBJ) $(ROOTOBJ)
chmod 755 *.sh run
@ -106,4 +107,6 @@ test49-gcc: test49.c
test50: test50.c
test51: test51.c
test51-gcc: test51.c
test52: test52.c
test52-gcc: test52.c

View file

@ -11,17 +11,28 @@ skipped=`expr 0` # count number of tests that were skipped
total=`expr 0` # total number of tests tried
badones= # list of tests that failed
tests=" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
41 42 43 44 45 45-gcc 46 47 48 49 49-gcc 50 \
51 51-gcc 52 52-gcc \
sh1.sh sh2.sh"
tests_no=`expr 0`
for i in `echo $tests`; do
if [ -x ./test$i ]; then
tests_no=`expr $tests_no + 1`
fi
done
# Print test welcome message
clr
echo "Running POSIX compliance test suite. There are 56 tests in total."
echo "Running POSIX compliance test suite. There are $tests_no tests in total."
echo " "
# Run all the tests, keeping track of who failed.
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \
41 42 43 44 45 45-gcc 46 47 48 49 49-gcc 50 51 51-gcc sh1.sh sh2.sh
for i in `echo $tests`
do
if [ -x ./test$i ]
if [ -x ./test$i ]
then
total=`expr $total + 1`
FAIL=0

188
test/test52.c Normal file
View file

@ -0,0 +1,188 @@
#define _POSIX_SOURCE 1
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <math.h>
#define ROUNDS 20
#define SWAPS 40
#define MAX_ERROR 5
int pipefdc[2];
int pipefdp[2];
int subtest = 0, errct = 0;
int child_is_dead = 0;
void dead_child(int n);
void do_child(void);
void do_parent(void);
void do_calcs(void);
void err(int n);
void quit(void);
void err(int n)
{
printf("Subtest %d, error %d\n", subtest, n);
if (errct++ > MAX_ERROR) {
printf("Too many errors; test aborted\n");
exit(1);
}
}
void quit(void)
{
if (errct == 0) {
printf("ok\n");
exit(0);
} else {
printf("%d errors\n", errct);
exit(1);
}
}
void do_calcs(void)
{
float a, b, c, d, e;
float foo, bar;
int i;
subtest = 3;
a = 1.1;
b = 2.2;
c = 3.3;
d = 4.4;
e = 5.5;
foo = a * b; /* 2.42 */
bar = c * d; /* 14.52 */
i = 0;
while(i < ROUNDS) {
foo += c; /* 5.72 */
foo *= d; /* 25.168 */
foo /= e; /* 4.5760 */
bar -= a; /* 13.42 */
bar *= b; /* 29.524 */
bar /= e; /* 5.3680 */
/* Undo */
foo *= e;
foo /= d;
foo -= c;
bar *= e;
bar /= b;
bar += a;
i++;
}
if (fabs(foo - (a * b)) > 0.0001) err(1);
if (fabs(bar - (c * d)) > 0.0001) err(2);
}
void dead_child(int n)
{
int status;
subtest = 4;
n = n;
if (wait(&status) == -1) err(1);
if (!WIFEXITED(status)) {
err(2);
quit();
} else {
errct += WEXITSTATUS(status);
child_is_dead = 1;
}
}
void do_child(void)
{
char buf[2];
int s;
s = 0;
close(pipefdp[0]);
close(pipefdc[1]);
while(s < SWAPS) {
do_calcs();
/* Wake up parent */
write(pipefdp[1], buf, 1);
/* Wait for parent to wake me up */
read(pipefdc[0], buf, 1);
s++;
}
exit(0);
}
void do_parent(void)
{
int s;
char buf[2];
struct sigaction sa;
subtest = 2;
sa.sa_handler = dead_child;
sa.sa_flags = 0;
if (sigaction(SIGCHLD, &sa, NULL) == -1) err(1);
s = 0;
close(pipefdp[1]);
close(pipefdc[0]);
while(s < SWAPS) {
/* Wait for child to wake me up */
read(pipefdp[0], buf, 1);
do_calcs();
/* Wake up child */
write(pipefdc[1], buf, 1);
s++;
}
while(child_is_dead == 0) { fflush(stdout); } /* Busy wait */
quit();
}
int main(void)
{
pid_t r;
subtest = 1;
#ifdef __GNUC__
printf("Test 52 (GCC) ");
#else
printf("Test 52 (ACK) ");
#endif
fflush(stdout);
if (pipe(pipefdc) == -1) err(1);
if (pipe(pipefdp) == -1) err(2);
r = fork();
if(r < 0) {
err(3);
} else if(r == 0) {
/* Child */
do_child();
} else {
/* Parent */
do_parent();
}
return(0); /* Never reached */
}