forked from wolfSSL/wolfssl
wolfcrypt/test/test.c and wolfssl/test.h: implement DEBUG_STACK_SIZE_VERBOSE, measuring and reporting stack usage separately for each test. to use, ./configure --enable-stacksize && make CFLAGS+=-DDEBUG_STACK_SIZE_VERBOSE; also, remove a throwaway dev pragma that snuck into an earlier commit.
This commit is contained in:
@ -39,6 +39,9 @@
|
|||||||
#define err_sys err_sys_remap /* remap err_sys */
|
#define err_sys err_sys_remap /* remap err_sys */
|
||||||
#include <wolfssl/test.h>
|
#include <wolfssl/test.h>
|
||||||
#undef err_sys
|
#undef err_sys
|
||||||
|
#else
|
||||||
|
#define STACK_SIZE_CHECKPOINT(...) (__VA_ARGS__)
|
||||||
|
#define STACK_SIZE_INIT()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
@ -522,13 +525,13 @@ static int wolfssl_pb_print(const char* msg, ...)
|
|||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
printf(fmt, args);
|
STACK_SIZE_CHECKPOINT(printf(fmt, args));
|
||||||
va_end(args);
|
va_end(args);
|
||||||
TEST_SLEEP();
|
TEST_SLEEP();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* redirect to printf */
|
/* redirect to printf */
|
||||||
#define test_pass printf
|
#define test_pass(...) STACK_SIZE_CHECKPOINT(printf(__VA_ARGS__))
|
||||||
/* stub the sleep macro */
|
/* stub the sleep macro */
|
||||||
#define TEST_SLEEP()
|
#define TEST_SLEEP()
|
||||||
#endif
|
#endif
|
||||||
@ -540,6 +543,7 @@ int wolfcrypt_test(void* args)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
STACK_SIZE_INIT();
|
||||||
|
|
||||||
printf("------------------------------------------------------------------------------\n");
|
printf("------------------------------------------------------------------------------\n");
|
||||||
printf(" wolfSSL version %s\n", LIBWOLFSSL_VERSION_STRING);
|
printf(" wolfSSL version %s\n", LIBWOLFSSL_VERSION_STRING);
|
||||||
@ -12998,7 +13002,6 @@ exit_rsa:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_Pragma("GCC diagnostic ignored \"-Wunused-variable\"");
|
|
||||||
static int rsa_test(void)
|
static int rsa_test(void)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
111
wolfssl/test.h
111
wolfssl/test.h
@ -2002,12 +2002,19 @@ static WC_INLINE void CaCb(unsigned char* der, int sz, int type)
|
|||||||
typedef THREAD_RETURN WOLFSSL_THREAD (*thread_func)(void* args);
|
typedef THREAD_RETURN WOLFSSL_THREAD (*thread_func)(void* args);
|
||||||
#define STACK_CHECK_VAL 0x01
|
#define STACK_CHECK_VAL 0x01
|
||||||
|
|
||||||
|
#ifdef DEBUG_STACK_SIZE_VERBOSE
|
||||||
|
static unsigned char *StackSizeCheck_myStack = NULL;
|
||||||
|
static size_t StackSizeCheck_stackSize = 0;
|
||||||
|
static void *StackSizeCheck_stackOffsetPointer = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
static WC_INLINE int StackSizeCheck(func_args* args, thread_func tf)
|
static WC_INLINE int StackSizeCheck(func_args* args, thread_func tf)
|
||||||
{
|
{
|
||||||
int ret, i, used;
|
size_t i;
|
||||||
|
int ret, used;
|
||||||
void* status;
|
void* status;
|
||||||
unsigned char* myStack = NULL;
|
unsigned char* myStack = NULL;
|
||||||
int stackSize = 1024*176;
|
size_t stackSize = 1024*176;
|
||||||
pthread_attr_t myAttr;
|
pthread_attr_t myAttr;
|
||||||
pthread_t threadId;
|
pthread_t threadId;
|
||||||
|
|
||||||
@ -2022,6 +2029,11 @@ static WC_INLINE int StackSizeCheck(func_args* args, thread_func tf)
|
|||||||
|
|
||||||
XMEMSET(myStack, STACK_CHECK_VAL, stackSize);
|
XMEMSET(myStack, STACK_CHECK_VAL, stackSize);
|
||||||
|
|
||||||
|
#ifdef DEBUG_STACK_SIZE_VERBOSE
|
||||||
|
StackSizeCheck_myStack = myStack;
|
||||||
|
StackSizeCheck_stackSize = stackSize;
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = pthread_attr_init(&myAttr);
|
ret = pthread_attr_init(&myAttr);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
err_sys("attr_init failed");
|
err_sys("attr_init failed");
|
||||||
@ -2047,6 +2059,10 @@ static WC_INLINE int StackSizeCheck(func_args* args, thread_func tf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(myStack);
|
free(myStack);
|
||||||
|
#ifdef DEBUG_STACK_SIZE_VERBOSE
|
||||||
|
StackSizeCheck_myStack = 0;
|
||||||
|
return (int)((size_t)status);
|
||||||
|
#endif
|
||||||
|
|
||||||
used = stackSize - i;
|
used = stackSize - i;
|
||||||
printf("stack used = %d\n", used);
|
printf("stack used = %d\n", used);
|
||||||
@ -2054,9 +2070,100 @@ static WC_INLINE int StackSizeCheck(func_args* args, thread_func tf)
|
|||||||
return (int)((size_t)status);
|
return (int)((size_t)status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_STACK_SIZE_VERBOSE
|
||||||
|
|
||||||
|
static WC_INLINE int StackSizeSetOffset(void *p)
|
||||||
|
{
|
||||||
|
if (StackSizeCheck_myStack == NULL)
|
||||||
|
return -BAD_FUNC_ARG;
|
||||||
|
|
||||||
|
StackSizeCheck_stackOffsetPointer = p;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static WC_INLINE int StackSizeHWM(void)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int used;
|
||||||
|
|
||||||
|
if (StackSizeCheck_myStack == NULL)
|
||||||
|
return -BAD_FUNC_ARG;
|
||||||
|
|
||||||
|
for (i = 0; i < StackSizeCheck_stackSize; i++) {
|
||||||
|
if (StackSizeCheck_myStack[i] != STACK_CHECK_VAL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
used = StackSizeCheck_stackSize - i;
|
||||||
|
printf("stack used = %d\n", used);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static WC_INLINE ssize_t StackSizeHWM_OffsetCorrected(void)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
ssize_t used;
|
||||||
|
|
||||||
|
if (StackSizeCheck_myStack == NULL)
|
||||||
|
return -BAD_FUNC_ARG;
|
||||||
|
|
||||||
|
for (i = 0; i < StackSizeCheck_stackSize; i++) {
|
||||||
|
if (StackSizeCheck_myStack[i] != STACK_CHECK_VAL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
used = StackSizeCheck_stackSize - i;
|
||||||
|
if (StackSizeCheck_stackOffsetPointer)
|
||||||
|
used -= (ssize_t)(((char *)StackSizeCheck_myStack + StackSizeCheck_stackSize) - (char *)StackSizeCheck_stackOffsetPointer);
|
||||||
|
|
||||||
|
return used;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
#ifdef __GNUC__
|
||||||
|
__attribute__((unused)) __attribute__((noinline))
|
||||||
|
#endif
|
||||||
|
int StackSizeHWMReset(void)
|
||||||
|
{
|
||||||
|
volatile ssize_t i;
|
||||||
|
|
||||||
|
if (StackSizeCheck_myStack == NULL)
|
||||||
|
return -BAD_FUNC_ARG;
|
||||||
|
|
||||||
|
for (i = (ssize_t)((char *)&i - (char *)StackSizeCheck_myStack) - (ssize_t)sizeof i - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
StackSizeCheck_myStack[i] = STACK_CHECK_VAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define STACK_SIZE_CHECKPOINT(...) ({ \
|
||||||
|
ssize_t HWM = StackSizeHWM_OffsetCorrected(); \
|
||||||
|
int _ret = (__VA_ARGS__); \
|
||||||
|
printf("relative stack used = %ld\n", HWM); \
|
||||||
|
StackSizeHWMReset(); \
|
||||||
|
_ret; \
|
||||||
|
})
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define STACK_SIZE_INIT() (void)StackSizeSetOffset(__builtin_frame_address(0))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* DEBUG_STACK_SIZE_VERBOSE */
|
||||||
|
|
||||||
#endif /* HAVE_STACK_SIZE */
|
#endif /* HAVE_STACK_SIZE */
|
||||||
|
|
||||||
|
#ifndef STACK_SIZE_CHECKPOINT
|
||||||
|
#define STACK_SIZE_CHECKPOINT(...) (__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
#ifndef STACK_SIZE_INIT
|
||||||
|
#define STACK_SIZE_INIT()
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef STACK_TRAP
|
#ifdef STACK_TRAP
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user