diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 1e426fbb3..2f1767cf8 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -47,12 +47,7 @@ enum { NUMARGS = 3 }; -#ifndef USE_WINDOWS_API - static const char outputName[] = "/tmp/output"; -#else - static const char outputName[] = "output"; -#endif - +static const char *outputName; int myoptind = 0; char* myoptarg = NULL; @@ -77,6 +72,16 @@ int testsuite_test(int argc, char** argv) tcp_ready ready; THREAD_TYPE serverThread; +#ifndef USE_WINDOWS_API + char tempName[] = "/tmp/output-XXXXXX"; + int len = 18; + int num = 6; +#else + char tempName[] = "fnXXXXXX"; + int len = 8; + int num = 6; +#endif + #ifdef HAVE_CAVIUM int ret = OpenNitroxDevice(CAVIUM_DIRECT, CAVIUM_DEV_ID); if (ret != 0) @@ -136,6 +141,13 @@ int testsuite_test(int argc, char** argv) echo_args.argc = 3; echo_args.argv = myArgv; + /* Create unique file name */ + outputName = mymktemp(tempName, len, num); + if (outputName == NULL) { + printf("Could not create unique file name"); + return EXIT_FAILURE; + } + strcpy(echo_args.argv[0], "echoclient"); strcpy(echo_args.argv[1], "input"); strcpy(echo_args.argv[2], outputName); diff --git a/wolfssl/test.h b/wolfssl/test.h index 11989cd4b..b500832eb 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -10,6 +10,7 @@ #include /* portability layer */ #include #include +#include #ifdef ATOMIC_USER #include @@ -17,7 +18,6 @@ #include #endif #ifdef HAVE_PK_CALLBACKS - #include #include #ifdef HAVE_ECC #include @@ -1791,5 +1791,44 @@ static INLINE char* strsep(char **stringp, const char *delim) #endif /* __hpux__ */ +/* Create unique filename, len is length of tempfn name, assuming + len does not include null terminating character, + num is number of characters in tempfn name to randomize */ +static INLINE const char* mymktemp(char *tempfn, int len, int num) +{ + int x, size; + static const char alphanum[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + RNG rng; + int out; + + if (tempfn == NULL || len < 1 || num < 1 || len <= num) { + printf("Bad input\n"); + return NULL; + } + + size = len - 1; + + if (wc_InitRng(&rng) != 0) { + printf("InitRng failed\n"); + return NULL; + } + + for (x = size; x > size - num; x--) { + if (wc_RNG_GenerateBlock(&rng,(byte*)&out, sizeof(out)) != 0) { + printf("RNG_GenerateBlock failed\n"); + return NULL; + } + tempfn[x] = alphanum[out % (sizeof(alphanum) - 1)]; + } + tempfn[len] = '\0'; + +#if defined(HAVE_HASHDRBG) + wc_FreeRng(&rng); +#endif + + return tempfn; +} + #endif /* wolfSSL_TEST_H */