| 1 |
From: Jakub Zelenka <[email protected]> |
| 2 |
Date: Fri, 20 Jun 2025 12:22:28 +0200 |
| 3 |
Subject: Fix ForkTest by exiting from child |
| 4 |
|
| 5 |
The ForkTest was causing a race conditions with other tests as the |
| 6 |
forked child continued to run. This is fixed by exiting from the |
| 7 |
child. |
| 8 |
--- |
| 9 |
src/lib/test/ForkTests.cpp | 15 ++++++++++----- |
| 10 |
1 file changed, 10 insertions(+), 5 deletions(-) |
| 11 |
|
| 12 |
diff --git a/src/lib/test/ForkTests.cpp b/src/lib/test/ForkTests.cpp |
| 13 |
index b260cba..1a73138 100644 |
| 14 |
--- a/src/lib/test/ForkTests.cpp |
| 15 |
+++ b/src/lib/test/ForkTests.cpp |
| 16 |
@@ -80,15 +80,17 @@ void ForkTests::testFork() |
| 17 |
case 0: |
| 18 |
rv = CRYPTOKI_F_PTR( C_Initialize(NULL_PTR) ); |
| 19 |
CPPUNIT_ASSERT(rv == CKR_CRYPTOKI_ALREADY_INITIALIZED); |
| 20 |
+ rv = CRYPTOKI_F_PTR( C_Finalize(NULL_PTR) ); |
| 21 |
+ CPPUNIT_ASSERT(rv == CKR_OK); |
| 22 |
+ _exit(0); |
| 23 |
break; |
| 24 |
default: |
| 25 |
rv = CRYPTOKI_F_PTR( C_Initialize(NULL_PTR) ); |
| 26 |
CPPUNIT_ASSERT(rv == CKR_CRYPTOKI_ALREADY_INITIALIZED); |
| 27 |
+ rv = CRYPTOKI_F_PTR( C_Finalize(NULL_PTR) ); |
| 28 |
+ CPPUNIT_ASSERT(rv == CKR_OK); |
| 29 |
break; |
| 30 |
} |
| 31 |
- |
| 32 |
- rv = CRYPTOKI_F_PTR( C_Finalize(NULL_PTR) ); |
| 33 |
- CPPUNIT_ASSERT(rv == CKR_OK); |
| 34 |
} |
| 35 |
|
| 36 |
void ForkTests::testResetOnFork() |
| 37 |
@@ -119,16 +121,19 @@ void ForkTests::testResetOnFork() |
| 38 |
/* For the child, the token is expected to be reset on fork */ |
| 39 |
rv = CRYPTOKI_F_PTR( C_Initialize(NULL_PTR) ); |
| 40 |
CPPUNIT_ASSERT(rv == CKR_OK); |
| 41 |
+ rv = CRYPTOKI_F_PTR( C_Finalize(NULL_PTR) ); |
| 42 |
+ CPPUNIT_ASSERT(rv == CKR_OK); |
| 43 |
+ _exit(0); |
| 44 |
break; |
| 45 |
default: |
| 46 |
/* For the parent, the token is expected to be still initialized */ |
| 47 |
rv = CRYPTOKI_F_PTR( C_Initialize(NULL_PTR) ); |
| 48 |
CPPUNIT_ASSERT(rv == CKR_CRYPTOKI_ALREADY_INITIALIZED); |
| 49 |
+ rv = CRYPTOKI_F_PTR( C_Finalize(NULL_PTR) ); |
| 50 |
+ CPPUNIT_ASSERT(rv == CKR_OK); |
| 51 |
break; |
| 52 |
} |
| 53 |
|
| 54 |
- rv = CRYPTOKI_F_PTR( C_Finalize(NULL_PTR) ); |
| 55 |
- CPPUNIT_ASSERT(rv == CKR_OK); |
| 56 |
|
| 57 |
#ifndef _WIN32 |
| 58 |
setenv("SOFTHSM2_CONF", "./softhsm2.conf", 1); |