X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/2d21ac55c334faf3a56e5634905ed6987fc787d4..99c3a10404e5d1ef94397ab4df5a8b74711fc4d3:/tools/tests/xnu_quick_test/misc.c diff --git a/tools/tests/xnu_quick_test/misc.c b/tools/tests/xnu_quick_test/misc.c index b274ddfd1..5e3706211 100644 --- a/tools/tests/xnu_quick_test/misc.c +++ b/tools/tests/xnu_quick_test/misc.c @@ -1,5 +1,6 @@ #include "tests.h" +#include /* * create_random_name - creates a file with a random / unique name in the given directory. @@ -83,13 +84,15 @@ int create_file_with_name( char *the_target_dirp, char *the_namep, int remove_ex int my_fd = -1; char * my_pathp = NULL; struct stat my_sb; - + kern_return_t my_kr; + create_test_file = 0; - my_pathp = (char *) malloc( PATH_MAX ); - if ( my_pathp == NULL ) { - printf( "malloc failed with error %d - \"%s\" \n", errno, strerror( errno) ); - goto failure_exit; - } + my_kr = vm_allocate((vm_map_t) mach_task_self(), (vm_address_t*)&my_pathp, PATH_MAX, VM_FLAGS_ANYWHERE); + if(my_kr != KERN_SUCCESS){ + printf( "vm_allocate failed with error %d - \"%s\" \n", errno, strerror( errno) ); + goto failure_exit; + } + strcpy( my_pathp, the_target_dirp ); strcat( my_pathp, the_namep ); @@ -136,6 +139,7 @@ int create_file_with_name( char *the_target_dirp, char *the_namep, int remove_ex printf( "open failed with error %d - \"%s\" \n", errno, strerror( errno) ); goto failure_exit; } + fcntl( my_fd, F_FULLFSYNC ); close( my_fd ); } goto routine_exit; @@ -147,7 +151,7 @@ routine_exit: if ( my_result == -1 && create_test_file ) { remove( my_pathp ); } - free( my_pathp ); + vm_deallocate(mach_task_self(), (vm_address_t)my_pathp, PATH_MAX); } return( my_result ); @@ -220,7 +224,12 @@ int do_execve_test(char * path, char * argv[], void * envp, int killwait) goto test_failed_exit; } - if ( WIFSIGNALED( my_status ) && WTERMSIG( my_status ) != SIGKILL ) { + if (!(WIFSIGNALED( my_status ))) { + printf( "child process was not signaled and should have been\n", my_status ); + goto test_failed_exit; + } + + if (WTERMSIG( my_status ) != SIGKILL) { printf( "wait4 returned wrong signal status - 0x%02X \n", my_status ); goto test_failed_exit; } @@ -246,7 +255,7 @@ int do_spawn_test(int arch, int shouldfail) posix_spawnattr_t attr; char * args[] = {"helpers/arch", NULL}; - + my_err = posix_spawnattr_init(&attr); if (my_err != 0) { printf("posix_spawnattr_init failed\n"); @@ -269,9 +278,12 @@ int do_spawn_test(int arch, int shouldfail) } my_err = 0; } else { - /* child should exit with return code == arch */ + /* + * child should exit with return code == arch; note that the + * posix_spawn error numers are *returned*, NOT set in errno!!! + */ if (my_err != 0) { - printf("posix_spawn failed with errno %d - %s\n", errno, strerror(errno)); + printf("posix_spawn failed with errno %d - %s\n", my_err, strerror(my_err)); goto done; } @@ -308,17 +320,16 @@ int get_architecture() char *errmsg = NULL; errmsg = "sysctlbyname() failed when getting hw.cputype"; - if (my_err = sysctlbyname("hw.cputype", NULL, &length, NULL, 0)) goto finished; /* get length of data */ + if ((my_err = sysctlbyname("hw.cputype", NULL, &length, NULL, 0))) goto finished; /* get length of data */ if (length != sizeof(buf)) goto finished; - if (my_err = sysctlbyname("hw.cputype", &buf, &length, NULL, 0)) goto finished; /* copy data */ + if ((my_err = sysctlbyname("hw.cputype", &buf, &length, NULL, 0))) goto finished; /* copy data */ switch (buf) { case CPU_TYPE_X86: case CPU_TYPE_X86_64: rval = INTEL; break; - case CPU_TYPE_POWERPC: - case CPU_TYPE_POWERPC64: - rval = POWERPC; + case CPU_TYPE_ARM: + rval = ARM; break; } @@ -364,3 +375,43 @@ finished: return rval; } +/* + * printf with a date and time stamp so that we can correlate printf's + * with the log files of a system in case of test failure. + * + * NB: MY_PRINTF_DATE_FMT chosen to look like syslog to aid "grep". + */ +#define MY_PRINTF_DATE_FMT "%b %e %T" +#undef printf /* was my_printf */ +int +my_printf(const char * __restrict fmt, ...) +{ + char *bufp; + char datebuf[256]; + struct tm *timeptr; + time_t result; + int rv; + va_list ap; + + /* Get the timestamp for this printf */ + result = time(NULL); + timeptr = localtime(&result); + strftime(datebuf, sizeof(datebuf), MY_PRINTF_DATE_FMT, timeptr); + + /* do the printf of the requested data to a local buffer */ + va_start(ap, fmt); + rv = vasprintf(&bufp, fmt, ap); + va_end(ap); + + /* + * if we successfully got a local buffer, then we want to + * print a timestamp plus what we would have printed before, + * then free the allocated memory. + */ + if (rv != -1) { + rv = printf("%s %s", datebuf, bufp); + free(bufp); + } + + return(rv); +}