tests: link them dynamically by default
. so that functionality is tested . add test63 that actually tests dlopen(), dlsym(), etc. functionality; only built if clang supports it . also test10 test to copy more of the executable
This commit is contained in:
		
							parent
							
								
									4b999f1962
								
							
						
					
					
						commit
						0c8e5ecc2e
					
				@ -14,6 +14,7 @@ CFLAGS.test52=-mhard-float
 | 
			
		||||
 | 
			
		||||
# Some have special libraries
 | 
			
		||||
LDADD.test59= -lmthread
 | 
			
		||||
LDFLAGS.mod= -shared	# make shared object
 | 
			
		||||
 | 
			
		||||
# Some have an extra file
 | 
			
		||||
OBJS.test57=test57loop.o
 | 
			
		||||
@ -26,7 +27,20 @@ OBJS.test57=test57loop.o
 | 
			
		||||
PROG+= test$(t)
 | 
			
		||||
.endfor
 | 
			
		||||
  
 | 
			
		||||
PROG+= t10a t11a t11b t40a t40b t40c t40d t40e t40f t60a t60b
 | 
			
		||||
PROG+= t10a t11a t11b t40a t40b t40c t40d t40e t40f t60a t60b 
 | 
			
		||||
 | 
			
		||||
.include <bsd.own.mk>
 | 
			
		||||
 | 
			
		||||
.if $(MKPIC) == "yes"
 | 
			
		||||
# Build them as dynamic executables by default if shared libraries
 | 
			
		||||
# are available; so that the building and executing of dynamic
 | 
			
		||||
# executables is tested
 | 
			
		||||
MINIXDYNAMIC?=yes
 | 
			
		||||
 | 
			
		||||
# Add test that must be linked dynamically, and its dynamically loaded
 | 
			
		||||
# module
 | 
			
		||||
PROG+= test63 mod
 | 
			
		||||
.endif
 | 
			
		||||
 | 
			
		||||
.include <bsd.prog.mk>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								test/magic.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								test/magic.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
 | 
			
		||||
#define MAGIC1 0x12C0ED
 | 
			
		||||
#define MAGIC2 0x12C0FF
 | 
			
		||||
#define MAGIC3 0x12D0FF
 | 
			
		||||
#define MAGIC4 0x13D0FE
 | 
			
		||||
#define MAGIC5 0x14D1FF
 | 
			
		||||
#define MAGIC6 0x17D1FF
 | 
			
		||||
 | 
			
		||||
long hellodriver(void);
 | 
			
		||||
							
								
								
									
										27
									
								
								test/mod.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								test/mod.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
			
		||||
 | 
			
		||||
/* Code for module to be loaded by test63. */
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <dlfcn.h>
 | 
			
		||||
 | 
			
		||||
#include "magic.h"
 | 
			
		||||
 | 
			
		||||
long cookie = 0;
 | 
			
		||||
 | 
			
		||||
void exithandler(void);
 | 
			
		||||
 | 
			
		||||
long modfunction(long v1, long *argcookie, long v2) {
 | 
			
		||||
  if(v1 != MAGIC4 || v2 != MAGIC5) {
 | 
			
		||||
	fprintf(stderr, "wrong args to modfunction\n");
 | 
			
		||||
	exit(1);
 | 
			
		||||
  }
 | 
			
		||||
  *argcookie = MAGIC3;
 | 
			
		||||
  cookie = MAGIC2;
 | 
			
		||||
  atexit(exithandler);
 | 
			
		||||
  return MAGIC1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void exithandler(void) {
 | 
			
		||||
	/* OK */
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								test/run
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								test/run
									
									
									
									
									
								
							@ -14,7 +14,7 @@ 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \
 | 
			
		||||
         61 62 \
 | 
			
		||||
         61 62 63 \
 | 
			
		||||
	 sh1.sh sh2.sh interp.sh"
 | 
			
		||||
tests_no=`expr 0`
 | 
			
		||||
 | 
			
		||||
@ -33,6 +33,9 @@ clr
 | 
			
		||||
echo "Running POSIX compliance test suite. There are $tests_no tests in total."
 | 
			
		||||
echo " "
 | 
			
		||||
 | 
			
		||||
# Provide an argument for test63
 | 
			
		||||
ARGS_63=`pwd`/mod
 | 
			
		||||
 | 
			
		||||
# Run all the tests, keeping track of who failed.
 | 
			
		||||
for i in `echo $tests`
 | 
			
		||||
do
 | 
			
		||||
@ -40,9 +43,11 @@ do
 | 
			
		||||
   then
 | 
			
		||||
      total=`expr $total + 1`
 | 
			
		||||
      FAIL=0
 | 
			
		||||
      unset ARG
 | 
			
		||||
      ARG=`eval echo "\\${ARGS_$i}"`
 | 
			
		||||
      if [ "$USER" = root ]
 | 
			
		||||
         then su - bin -c "cd `pwd`; ./test$i" || FAIL=1
 | 
			
		||||
         else ./test$i || FAIL=1
 | 
			
		||||
         else echo ./test$i $ARG || FAIL=1
 | 
			
		||||
      fi
 | 
			
		||||
      if [ $FAIL -eq 0 ]
 | 
			
		||||
         then passed=`expr $passed + 1`
 | 
			
		||||
 | 
			
		||||
@ -114,10 +114,7 @@ int size;
 | 
			
		||||
{
 | 
			
		||||
  int fd;
 | 
			
		||||
 | 
			
		||||
#if (CHIP == SPARC)
 | 
			
		||||
  size += 4000;
 | 
			
		||||
#endif
 | 
			
		||||
  prog[6] = (long) size;
 | 
			
		||||
  size += 3000;
 | 
			
		||||
  fd = creat(name, 0755);
 | 
			
		||||
  write(fd, (char *) prog, psize);
 | 
			
		||||
  close(fd);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										58
									
								
								test/test63.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								test/test63.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,58 @@
 | 
			
		||||
 | 
			
		||||
/* Code to test runtime linking functionality.
 | 
			
		||||
 * Load a shared object at runtime and verify that arguments passed to
 | 
			
		||||
 * and from a function that is dynamically looked up make sense.
 | 
			
		||||
 * This tests that (a) dynamic linking works at all (otherwise all the dl*
 | 
			
		||||
 * functions don't work) and (b) the dynamic loading functionality works
 | 
			
		||||
 * and (c) the PLT is sane and calling convention makes sense.
 | 
			
		||||
 *
 | 
			
		||||
 * We have to pass an absolute path to dlopen() for which we rely on 
 | 
			
		||||
 * the test run script.
 | 
			
		||||
 *
 | 
			
		||||
 * The module we load is in mod.c.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <dlfcn.h>
 | 
			
		||||
 | 
			
		||||
#define MAX_ERROR 2
 | 
			
		||||
 | 
			
		||||
#include "magic.h"
 | 
			
		||||
#include "common.c"
 | 
			
		||||
 | 
			
		||||
int main (int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
  void *dlhandle;
 | 
			
		||||
  long (*modf) (long, long *, long);
 | 
			
		||||
  long v, *cookie = NULL, cookie2 = 0;
 | 
			
		||||
  
 | 
			
		||||
  start(63);
 | 
			
		||||
 | 
			
		||||
  if(argc != 2) {
 | 
			
		||||
	fprintf(stderr, "Usage: %s <module>\n", argv[0]);
 | 
			
		||||
	exit(1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if(!(dlhandle = dlopen(argv[1], RTLD_LAZY))) e(1);
 | 
			
		||||
 | 
			
		||||
  if(!(modf = dlsym(dlhandle, "modfunction"))) e(2);
 | 
			
		||||
  if(!(cookie = (long *) dlsym(dlhandle, "cookie"))) e(3);
 | 
			
		||||
 | 
			
		||||
  if(*cookie == MAGIC2) { fprintf(stderr, "cookie already set\n"); e(4); }
 | 
			
		||||
  if(cookie2 == MAGIC3) { fprintf(stderr, "cookie2 already set\n"); e(5); }
 | 
			
		||||
 | 
			
		||||
  v = modf(MAGIC4, &cookie2, MAGIC5);
 | 
			
		||||
 | 
			
		||||
  if(v != MAGIC1) { fprintf(stderr, "return value wrong\n"); e(9); }
 | 
			
		||||
  if(*cookie != MAGIC2) { fprintf(stderr, "cookie set wrongly\n"); e(6); }
 | 
			
		||||
  if(cookie2 != MAGIC3) { fprintf(stderr, "cookie2 set wrongly\n"); e(7); }
 | 
			
		||||
 | 
			
		||||
  dlclose(dlhandle);
 | 
			
		||||
 | 
			
		||||
  if(v != MAGIC1) { fprintf(stderr, "wrong return value.\n"); e(8); }
 | 
			
		||||
 | 
			
		||||
  quit();
 | 
			
		||||
 | 
			
		||||
  return(0);
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user