mirror of https://github.com/wolfSSL/wolfssl.git
add mymktemp function for random output file name in test.h
parent
db5a95b370
commit
ed80732957
|
@ -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);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <cyassl/ssl.h> /* portability layer */
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
#include <wolfssl/wolfcrypt/random.h>
|
||||
|
||||
#ifdef ATOMIC_USER
|
||||
#include <wolfssl/wolfcrypt/aes.h>
|
||||
|
@ -17,7 +18,6 @@
|
|||
#include <wolfssl/wolfcrypt/hmac.h>
|
||||
#endif
|
||||
#ifdef HAVE_PK_CALLBACKS
|
||||
#include <wolfssl/wolfcrypt/random.h>
|
||||
#include <wolfssl/wolfcrypt/asn.h>
|
||||
#ifdef HAVE_ECC
|
||||
#include <wolfssl/wolfcrypt/ecc.h>
|
||||
|
@ -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 */
|
||||
|
||||
|
|
Loading…
Reference in New Issue