Skip to content

Commit 1ef8bde

Browse files
committed
wolfHSM refactor: remove printf, new debug macros
1 parent 04b199f commit 1ef8bde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1313
-1511
lines changed

.github/workflows/build-and-bench.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ jobs:
3232
# Benchmark with everything enabled
3333
- name: Benchmark All
3434
run: cd benchmark && make clean && make WOLFSSL_DIR=../wolfssl DMA=1 && make run
35+
36+
# Benchmark with DEBUG_VERBOSE=1 (includes DEBUG)
37+
- name: Benchmark with DEBUG_VERBOSE
38+
run: cd benchmark && make clean && make -j DEBUG_VERBOSE=1 WOLFSSL_DIR=../wolfssl && make run

.github/workflows/build-and-run-examples.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
matrix:
1313
transport: [ 'tcp', 'shm', 'dma' ]
1414
asan: [ 'ASAN=1', 'ASAN=0' ]
15+
debug: [ '', 'DEBUG_VERBOSE=1' ]
1516
runs-on: ubuntu-latest
1617
timeout-minutes: 5
1718

@@ -29,16 +30,16 @@ jobs:
2930
- name: Build POSIX server
3031
run: |
3132
if [ "${{ matrix.transport }}" = "dma" ]; then
32-
cd examples/posix/wh_posix_server && ${{ matrix.asan }} DMA=1 make -j WOLFSSL_DIR=../../../wolfssl
33+
cd examples/posix/wh_posix_server && ${{ matrix.asan }} ${{ matrix.debug }} DMA=1 make -j WOLFSSL_DIR=../../../wolfssl
3334
else
34-
cd examples/posix/wh_posix_server && ${{ matrix.asan }} make -j WOLFSSL_DIR=../../../wolfssl
35+
cd examples/posix/wh_posix_server && ${{ matrix.asan }} ${{ matrix.debug }} make -j WOLFSSL_DIR=../../../wolfssl
3536
fi
3637
- name: Build POSIX client
3738
run: |
3839
if [ "${{ matrix.transport }}" = "dma" ]; then
39-
cd examples/posix/wh_posix_client && ${{ matrix.asan }} DMA=1 make -j WOLFSSL_DIR=../../../wolfssl
40+
cd examples/posix/wh_posix_client && ${{ matrix.asan }} ${{ matrix.debug }} DMA=1 make -j WOLFSSL_DIR=../../../wolfssl
4041
else
41-
cd examples/posix/wh_posix_client && ${{ matrix.asan }} make -j WOLFSSL_DIR=../../../wolfssl
42+
cd examples/posix/wh_posix_client && ${{ matrix.asan }} ${{ matrix.debug }} make -j WOLFSSL_DIR=../../../wolfssl
4243
fi
4344
4445
# Start the server in the background

.github/workflows/build-and-test-clientonly.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,25 @@ jobs:
5050
make clean
5151
make -j CLIENT_ONLY_TCP=1 SHE=1 ASAN=1 WOLFSSL_DIR=../wolfssl && make run
5252
53-
# Optional: Kill the server process if it doesn't exit on its own
53+
# Restart server with fresh state for second test run
54+
- name: Restart POSIX server
55+
run: |
56+
kill $TCP_SERVER_PID || true
57+
cd examples/posix/wh_posix_server
58+
rm -f *.bin || true
59+
./Build/wh_posix_server.elf &
60+
TCP_SERVER_PID=$!
61+
echo "TCP_SERVER_PID=$TCP_SERVER_PID" >> $GITHUB_ENV
62+
sleep 2
63+
64+
# Build and test client-only with DEBUG_VERBOSE=1 (includes DEBUG)
65+
- name: Build client-only unit tests with DEBUG_VERBOSE
66+
run: |
67+
cd test
68+
make clean
69+
make -j CLIENT_ONLY_TCP=1 SHE=1 DEBUG_VERBOSE=1 WOLFSSL_DIR=../wolfssl && make run
70+
71+
# Optional: Kill the server process if it doesn't exit on its own
5472
- name: Cleanup POSIX TCP server
5573
if: always()
5674
run: kill $TCP_SERVER_PID || true

.github/workflows/build-and-test-whnvmtool.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ jobs:
3737
- name: Build and test NVM tool with ASAN
3838
run: cd tools/whnvmtool && make clean && make check WOLFSSL_DIR=../../wolfssl ASAN=1
3939

40+
# Build and test with DEBUG=1
41+
- name: Build and test NVM tool with DEBUG
42+
run: cd tools/whnvmtool && make clean && make check WOLFSSL_DIR=../../wolfssl DEBUG=1
43+
44+
# Build and test with DEBUG_VERBOSE=1 (includes DEBUG)
45+
- name: Build and test NVM tool with DEBUG_VERBOSE
46+
run: cd tools/whnvmtool && make clean && make check WOLFSSL_DIR=../../wolfssl DEBUG_VERBOSE=1
47+

.github/workflows/build-and-test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ jobs:
5656
# Build and test with SHE and ASAN
5757
- name: Build and test ASAN SHE
5858
run: cd test && make clean && make -j SHE=1 ASAN=1 WOLFSSL_DIR=../wolfssl && make run
59+
60+
# Build and test with DEBUG=1
61+
- name: Build and test with DEBUG
62+
run: cd test && make clean && make -j DEBUG=1 WOLFSSL_DIR=../wolfssl && make run
63+
64+
# Build and test with DEBUG_VERBOSE=1 (includes DEBUG)
65+
- name: Build and test with DEBUG_VERBOSE
66+
run: cd test && make clean && make -j DEBUG_VERBOSE=1 WOLFSSL_DIR=../wolfssl && make run

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
.PHONY: all test benchmark tools examples clean
33

4+
export DEBUG
5+
export DEBUG_VERBOSE
6+
47
all: test benchmark tools examples
58

69
test:

benchmark/Makefile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ ifeq ($(DEBUG),1)
7171
DBGFLAGS = -ggdb -g3
7272
CFLAGS += $(DBGFLAGS)
7373
LDFLAGS += $(DBGFLAGS)
74+
DEF += -DWOLFHSM_CFG_DEBUG
75+
endif
76+
77+
# Check if DEBUG_VERBOSE is set to 1 and enable verbose WOLFHSM debug output
78+
# Note: DEBUG_VERBOSE implies DEBUG
79+
ifeq ($(DEBUG_VERBOSE),1)
80+
DBGFLAGS = -ggdb -g3
81+
CFLAGS += $(DBGFLAGS)
82+
LDFLAGS += $(DBGFLAGS)
83+
DEF += -DWOLFHSM_CFG_DEBUG -DWOLFHSM_CFG_DEBUG_VERBOSE
7484
endif
7585

7686
ifneq ($(DEBUG),1)
@@ -89,15 +99,6 @@ ifeq ($(DEBUG_WOLFSSL),1)
8999
DEF += -DDEBUG_WOLFSSL
90100
endif
91101

92-
ifeq ($(DEBUG_CRYPTOCB),1)
93-
DEF += -DDEBUG_CRYPTOCB
94-
endif
95-
96-
ifeq ($(DEBUG_CRYPTOCB_VERBOSE),1)
97-
DEF += -DDEBUG_CRYPTOCB -DDEBUG_CRYPTOCB_VERBOSE
98-
endif
99-
100-
101102
## wolfHSM defines
102103
ifeq ($(NOCRYPTO),1)
103104
DEF += -DWOLFHSM_CFG_NO_CRYPTO

benchmark/config/user_settings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ extern "C" {
3535
/* #define WC_NO_ASYNC_THREADING */
3636

3737
/*
38-
#define DEBUG_CRYPTOCB
39-
#define DEBUG_CRYPTOCB_VERBOSE
38+
#define WOLFHSM_CFG_DEBUG
39+
#define WOLFHSM_CFG_DEBUG_VERBOSE
4040
*/
4141

4242
/** wolfHSM required settings for wolfCrypt */

benchmark/wh_bench.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static int _whBench_ClientCfg_PosixDmaHeap(posixTransportShmContext* shmCtx)
586586

587587
ret = posixTransportShm_GetDma(shmCtx, &dma, &dmaSz);
588588
if (ret != 0) {
589-
printf("Failed to get DMA\n");
589+
WOLFHSM_CFG_PRINTF("Failed to get DMA\n");
590590
return ret;
591591
}
592592

benchmark/wh_bench_main.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
void Usage(const char* exeName)
3131
{
32-
printf("Usage: %s --type <type> --module <module> --list\n", exeName);
33-
printf("Type: mem, shm, tcp, dma\n");
34-
printf("Module: index of the module to run\n");
35-
printf("List: list all modules\n");
32+
WOLFHSM_CFG_PRINTF("Usage: %s --type <type> --module <module> --list\n", exeName);
33+
WOLFHSM_CFG_PRINTF("Type: mem, shm, tcp, dma\n");
34+
WOLFHSM_CFG_PRINTF("Module: index of the module to run\n");
35+
WOLFHSM_CFG_PRINTF("List: list all modules\n");
3636
exit(1);
3737
}
3838

@@ -62,7 +62,7 @@ int main(int argc, char** argv)
6262
transport = WH_BENCH_TRANSPORT_POSIX_DMA;
6363
}
6464
else {
65-
printf("Invalid transport type: %s\n", type);
65+
WOLFHSM_CFG_PRINTF("Invalid transport type: %s\n", type);
6666
Usage(argv[0]);
6767
return -1;
6868
}
@@ -75,7 +75,7 @@ int main(int argc, char** argv)
7575
return 0;
7676
}
7777
else {
78-
printf("Invalid argument: %s\n", argv[i]);
78+
WOLFHSM_CFG_PRINTF("Invalid argument: %s\n", argv[i]);
7979
Usage(argv[0]);
8080
return -1;
8181
}

0 commit comments

Comments
 (0)