add --enable-stacksize to print out stack use info with pthreads for example client/server
This commit is contained in:
parent
f396de1191
commit
ee0595f543
15
configure.ac
15
configure.ac
@ -570,6 +570,21 @@ else
|
||||
fi
|
||||
|
||||
|
||||
# STACK SIZE info for examples
|
||||
AC_ARG_ENABLE([stacksize],
|
||||
[ --enable-stacksize Enable stack size info on examples (default: disabled)],
|
||||
[ ENABLED_STACKSIZE=$enableval ],
|
||||
[ ENABLED_STACKSIZE=no ]
|
||||
)
|
||||
|
||||
if test "$ENABLED_STACKSIZE" = "yes"
|
||||
then
|
||||
AC_CHECK_FUNC([posix_memalign], [], [AC_MSG_ERROR(stacksize needs posix_memalign)])
|
||||
AC_CHECK_FUNC([pthread_attr_setstack], [], [AC_MSG_ERROR(stacksize needs pthread_attr_setstack)])
|
||||
AM_CFLAGS="$AM_CFLAGS -DHAVE_STACK_SIZE -DTFM_TIMING_RESISTANT"
|
||||
fi
|
||||
|
||||
|
||||
# MEMORY
|
||||
AC_ARG_ENABLE([memory],
|
||||
[ --enable-memory Enable memory callbacks (default: enabled)],
|
||||
|
@ -1081,5 +1081,63 @@ static INLINE int CurrentDir(const char* str)
|
||||
|
||||
#endif /* USE_CYASSL_MEMORY */
|
||||
|
||||
|
||||
#ifdef HAVE_STACK_SIZE
|
||||
|
||||
typedef THREAD_RETURN CYASSL_THREAD (*thread_func)(void* args);
|
||||
|
||||
|
||||
static INLINE void StackSizeCheck(func_args* args, thread_func tf)
|
||||
{
|
||||
int ret, i, used;
|
||||
unsigned char* myStack;
|
||||
int stackSize = 1024*128;
|
||||
pthread_attr_t myAttr;
|
||||
pthread_t threadId;
|
||||
|
||||
#ifdef PTHREAD_STACK_MIN
|
||||
if (stackSize < PTHREAD_STACK_MIN)
|
||||
stackSize = PTHREAD_STACK_MIN;
|
||||
#endif
|
||||
|
||||
ret = posix_memalign((void**)&myStack, sysconf(_SC_PAGESIZE), stackSize);
|
||||
if (ret != 0)
|
||||
err_sys("posix_memalign failed\n");
|
||||
|
||||
memset(myStack, 0xee, stackSize);
|
||||
|
||||
ret = pthread_attr_init(&myAttr);
|
||||
if (ret != 0)
|
||||
err_sys("attr_init failed");
|
||||
|
||||
ret = pthread_attr_setstack(&myAttr, myStack, stackSize);
|
||||
if (ret != 0)
|
||||
err_sys("attr_setstackaddr failed");
|
||||
|
||||
ret = pthread_create(&threadId, &myAttr, tf, args);
|
||||
if (ret != 0) {
|
||||
perror("pthread_create failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
ret = pthread_join(threadId, NULL);
|
||||
if (ret != 0)
|
||||
err_sys("pthread_join failed");
|
||||
|
||||
for (i = 0; i < stackSize; i++) {
|
||||
if (myStack[i] != 0xee) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
used = stackSize - i;
|
||||
printf("stack used = %d\n", used);
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_STACK_SIZE */
|
||||
|
||||
|
||||
|
||||
#endif /* CyaSSL_TEST_H */
|
||||
|
||||
|
@ -114,7 +114,7 @@ static void Usage(void)
|
||||
}
|
||||
|
||||
|
||||
void client_test(void* args)
|
||||
THREAD_RETURN CYASSL_THREAD client_test(void* args)
|
||||
{
|
||||
SOCKET_T sockfd = 0;
|
||||
|
||||
@ -592,6 +592,8 @@ void client_test(void* args)
|
||||
if (trackMemory)
|
||||
ShowMemoryTracker();
|
||||
#endif /* USE_CYASSL_MEMORY */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -619,8 +621,12 @@ void client_test(void* args)
|
||||
#endif
|
||||
if (CurrentDir("client") || CurrentDir("build"))
|
||||
ChangeDirBack(2);
|
||||
|
||||
|
||||
#ifdef HAVE_STACK_SIZE
|
||||
StackSizeCheck(&args, client_test);
|
||||
#else
|
||||
client_test(&args);
|
||||
#endif
|
||||
CyaSSL_Cleanup();
|
||||
|
||||
#ifdef HAVE_CAVIUM
|
||||
|
@ -21,5 +21,5 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
void client_test(void* args);
|
||||
THREAD_RETURN CYASSL_THREAD client_test(void* args);
|
||||
|
||||
|
@ -458,7 +458,11 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
||||
if (CurrentDir("server") || CurrentDir("build"))
|
||||
ChangeDirBack(2);
|
||||
|
||||
#ifdef HAVE_STACK_SIZE
|
||||
StackSizeCheck(&args, server_test);
|
||||
#else
|
||||
server_test(&args);
|
||||
#endif
|
||||
CyaSSL_Cleanup();
|
||||
|
||||
#ifdef HAVE_CAVIUM
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* server.c
|
||||
/* server.h
|
||||
*
|
||||
* Copyright (C) 2006-2013 wolfSSL Inc.
|
||||
*
|
||||
|
@ -37,9 +37,9 @@
|
||||
#include "examples/echoclient/echoclient.h"
|
||||
#include "examples/echoserver/echoserver.h"
|
||||
#include "examples/server/server.h"
|
||||
#include "examples/client/client.h"
|
||||
#include "ctaocrypt/test/test.h"
|
||||
|
||||
void client_test(void*);
|
||||
|
||||
void file_test(const char* file, byte* hash);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user