Skip to content

Commit 550d9ad

Browse files
committed
Add testing for zephyr no malloc
1 parent 7ed5e0b commit 550d9ad

12 files changed

Lines changed: 124 additions & 36 deletions

File tree

.github/workflows/zephyr.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ jobs:
1414
zephyr-sdk: 0.16.1
1515
- zephyr-ref: v3.5.0
1616
zephyr-sdk: 0.16.3
17+
- zephyr-ref: v2.7.4
18+
zephyr-sdk: 0.16.3
1719
runs-on: ubuntu-latest
1820
# This should be a safe limit for the tests to run.
19-
timeout-minutes: 15
21+
timeout-minutes: 25
2022
steps:
2123
- name: Install dependencies
2224
run: |
@@ -75,15 +77,20 @@ jobs:
7577
run: |
7678
./zephyr/scripts/twister --testsuite-root modules/crypto/wolfssl --test zephyr/samples/wolfssl_test/sample.crypto.wolfssl_test -vvv
7779
rm -rf zephyr/twister-out
80+
./zephyr/scripts/twister --testsuite-root modules/crypto/wolfssl --test zephyr/samples/wolfssl_test/sample.crypto.wolfssl_test_no_malloc -vvv
81+
rm -rf zephyr/twister-out
7882
7983
- name: Run wolfssl TLS sock test
8084
id: wolfssl-tls-sock
8185
working-directory: zephyr
8286
run: |
8387
./zephyr/scripts/twister --testsuite-root modules/crypto/wolfssl --test zephyr/samples/wolfssl_tls_sock/sample.crypto.wolfssl_tls_sock -vvv
8488
rm -rf zephyr/twister-out
89+
./zephyr/scripts/twister --testsuite-root modules/crypto/wolfssl --test zephyr/samples/wolfssl_tls_sock/sample.crypto.wolfssl_tls_sock_no_malloc -vvv
90+
rm -rf zephyr/twister-out
8591
8692
- name: Run wolfssl TLS thread test
93+
if: ${{ matrix.config.zephyr-ref != 'v2.7.4' }}
8794
id: wolfssl-tls-thread
8895
working-directory: zephyr
8996
run: |

wolfcrypt/src/wc_port.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3687,7 +3687,6 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
36873687
* thread->threadStack = k_thread_stack_alloc(WOLFSSL_ZEPHYR_STACK_SZ,
36883688
* 0);
36893689
*/
3690-
printf("thread stack size is %ld\n", Z_KERNEL_STACK_SIZE_ADJUST(WOLFSSL_ZEPHYR_STACK_SZ));
36913690
thread->threadStack = (void*)XMALLOC(
36923691
Z_KERNEL_STACK_SIZE_ADJUST(WOLFSSL_ZEPHYR_STACK_SZ),
36933692
wolfsslThreadHeapHint, DYNAMIC_TYPE_TMP_BUFFER);

zephyr/Kconfig.tls-generic

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,4 @@ config WOLFSSL_HAVE_ASM
264264
of asymmetric cryptography, however this might have an impact on the
265265
code size.
266266

267-
config WOLFSSL_USER_SETTTINGS
268-
string "User settings file for wolfSSL"
269-
help
270-
User settings file that contains wolfSSL defines.
271-
272267
endmenu
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Configure stack and heap sizes
2+
CONFIG_MAIN_STACK_SIZE=655360
3+
#CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=65536
4+
5+
# Pthreads
6+
CONFIG_PTHREAD_IPC=y
7+
8+
# Clock for time()
9+
CONFIG_POSIX_CLOCK=y
10+
11+
# TLS configuration
12+
CONFIG_WOLFSSL_SETTINGS_FILE="user_settings-no-malloc.h"
13+
CONFIG_WOLFSSL=y
14+
CONFIG_WOLFSSL_BUILTIN=y
15+
16+
# Logging
17+
CONFIG_PRINTK=y
18+
CONFIG_CBPRINTF_LIBC_SUBSTS=y
19+
CONFIG_CBPRINTF_FP_SUPPORT=y
20+
CONFIG_CONSOLE=y
21+
CONFIG_LOG=y
22+
CONFIG_LOG_BACKEND_UART=y
23+
CONFIG_LOG_BUFFER_SIZE=15360
24+
CONFIG_LOG_MODE_IMMEDIATE=y
25+
#CONFIG_WOLFSSL_DEBUG=y
26+
27+
# Entropy
28+
CONFIG_TEST_RANDOM_GENERATOR=y
29+
CONFIG_ENTROPY_GENERATOR=y
30+
CONFIG_ENTROPY_DEVICE_RANDOM_GENERATOR=y

zephyr/samples/wolfssl_test/prj.conf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
21
# Configure stack and heap sizes
3-
CONFIG_MAIN_STACK_SIZE=655360
4-
#CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=65536
2+
CONFIG_MAIN_STACK_SIZE=32768
3+
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=16384
54

65
# Pthreads
76
CONFIG_PTHREAD_IPC=y

zephyr/samples/wolfssl_test/sample.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ tests:
1313
platform_allow: qemu_x86
1414
integration_platforms:
1515
- qemu_x86
16+
sample.crypto.wolfssl_test_no_malloc:
17+
timeout: 120
18+
platform_allow: qemu_x86
19+
extra_args: CONF_FILE="prj-no-malloc.conf"
20+
integration_platforms:
21+
- qemu_x86
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Kernel options
2+
CONFIG_MAIN_STACK_SIZE=655360
3+
CONFIG_ENTROPY_GENERATOR=y
4+
CONFIG_INIT_STACKS=y
5+
6+
# General config
7+
CONFIG_NEWLIB_LIBC=y
8+
9+
# Pthreads
10+
CONFIG_PTHREAD_IPC=y
11+
12+
# Clock for time()
13+
CONFIG_POSIX_CLOCK=y
14+
15+
# Networking config
16+
CONFIG_NETWORKING=y
17+
CONFIG_NET_IPV4=y
18+
CONFIG_NET_IPV6=n
19+
CONFIG_NET_TCP=y
20+
CONFIG_NET_SOCKETS=y
21+
CONFIG_NET_SOCKETS_POSIX_NAMES=y
22+
23+
CONFIG_NET_TEST=y
24+
CONFIG_NET_LOOPBACK=y
25+
26+
# Network driver config
27+
CONFIG_TEST_RANDOM_GENERATOR=y
28+
29+
# Network address config
30+
CONFIG_NET_CONFIG_SETTINGS=y
31+
CONFIG_NET_CONFIG_NEED_IPV4=y
32+
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
33+
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
34+
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
35+
36+
CONFIG_NET_PKT_TX_COUNT=10
37+
38+
# Network debug config
39+
#CONFIG_NET_LOG=y
40+
#CONFIG_NET_PKT_LOG_LEVEL_DBG=y
41+
42+
# Logging
43+
CONFIG_PRINTK=y
44+
#CONFIG_WOLFSSL_DEBUG=y
45+
CONFIG_LOG=y
46+
CONFIG_LOG_MODE_IMMEDIATE=y
47+
48+
# TLS configuration
49+
CONFIG_WOLFSSL_SETTINGS_FILE="user_settings-no-malloc.h"
50+
CONFIG_WOLFSSL=y
51+
CONFIG_WOLFSSL_BUILTIN=y
52+
53+
CONFIG_WOLFSSL_TLS_VERSION_1_2=y
54+
CONFIG_WOLFSSL_KEY_EXCHANGE_ALL_ENABLED=y
55+
CONFIG_WOLFSSL_CIPHER_ALL_ENABLED=y
56+
CONFIG_WOLFSSL_MAC_ALL_ENABLED=y
57+
CONFIG_WOLFSSL_HMAC_DRBG_ENABLED=y

zephyr/samples/wolfssl_tls_sock/prj.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Kernel options
2-
CONFIG_MAIN_STACK_SIZE=655360
2+
CONFIG_MAIN_STACK_SIZE=16384
33
CONFIG_ENTROPY_GENERATOR=y
44
CONFIG_INIT_STACKS=y
5-
#CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
5+
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
66

77
# General config
88
CONFIG_NEWLIB_LIBC=y
@@ -50,7 +50,7 @@ CONFIG_LOG_MODE_IMMEDIATE=y
5050
CONFIG_WOLFSSL=y
5151
CONFIG_WOLFSSL_BUILTIN=y
5252

53-
CONFIG_WOLFSSL_TLS_VERSION_1_2=y
53+
CONFIG_WOLFSSL_TLS_VERSION_1_3=y
5454
CONFIG_WOLFSSL_KEY_EXCHANGE_ALL_ENABLED=y
5555
CONFIG_WOLFSSL_CIPHER_ALL_ENABLED=y
5656
CONFIG_WOLFSSL_MAC_ALL_ENABLED=y

zephyr/samples/wolfssl_tls_sock/sample.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ common:
88
regex:
99
- "Server Return: 0"
1010
- "Client Return: 0"
11+
- "Done"
1112
tests:
1213
sample.crypto.wolfssl_tls_sock:
1314
timeout: 60
1415
platform_allow: qemu_x86
1516
integration_platforms:
1617
- qemu_x86
18+
sample.crypto.wolfssl_tls_sock_no_malloc:
19+
timeout: 60
20+
platform_allow: qemu_x86
21+
extra_args: CONF_FILE="prj-no-malloc.conf"
22+
integration_platforms:
23+
- qemu_x86

zephyr/samples/wolfssl_tls_sock/src/tls_sock.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -445,20 +445,8 @@ void client_thread()
445445
WOLFSSL* client_ssl = NULL;
446446
SOCKET_T sockfd = WOLFSSL_SOCKET_INVALID;
447447

448-
#ifdef WOLFSSL_STATIC_MEMORY
449-
//if (wc_LoadStaticMemory(&HEAP_HINT_CLIENT, gMemoryClient,
450-
// sizeof(gMemoryClient),
451-
// WOLFMEM_GENERAL | WOLFMEM_TRACK_STATS, 1) != 0) {
452-
// printf("unable to load static memory");
453-
// ret = -1;
454-
//}
455-
456-
if (ret == 0)
457-
#endif
458-
{
459-
/* Client connection */
460-
ret = wolfssl_client_new(&client_ctx, &client_ssl);
461-
}
448+
/* Client connection */
449+
ret = wolfssl_client_new(&client_ctx, &client_ssl);
462450

463451
if (ret == 0)
464452
ret = wolfssl_client_connect_tcp(client_ssl, &sockfd);
@@ -526,6 +514,9 @@ int main()
526514

527515
k_sleep(Z_TIMEOUT_TICKS(100));
528516
client_thread();
517+
/* Join is not working in qemu when the thread is still active. Wait for it
518+
* to shut down to join it. */
519+
k_sleep(Z_TIMEOUT_TICKS(100));
529520

530521
if (wolfSSL_JoinThread(serverThread) != 0) {
531522
printf("Failed to join server thread\n");

0 commit comments

Comments
 (0)