4040#include " osmutex.h"
4141
4242#include < sys/types.h>
43+ #include < sys/wait.h>
4344#include < unistd.h>
4445
4546CPPUNIT_TEST_SUITE_REGISTRATION (ForkTests);
@@ -64,6 +65,7 @@ void ForkTests::testFork()
6465{
6566 CK_RV rv;
6667 pid_t pid;
68+ int status;
6769
6870 // Just make sure that we finalize any previous failed tests
6971 CRYPTOKI_F_PTR ( C_Finalize (NULL_PTR) );
@@ -78,12 +80,20 @@ void ForkTests::testFork()
7880 CPPUNIT_FAIL (" Fork failed" );
7981 break ;
8082 case 0 :
83+ /* For the child, the token is expected to still be initialized. */
8184 rv = CRYPTOKI_F_PTR ( C_Initialize (NULL_PTR) );
8285 CPPUNIT_ASSERT (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED);
86+ rv = CRYPTOKI_F_PTR ( C_Finalize (NULL_PTR) );
87+ CPPUNIT_ASSERT (rv == CKR_OK);
88+ _exit (EXIT_SUCCESS);
8389 break ;
8490 default :
91+ /* For the parent, the token is expected to still be initialized. */
8592 rv = CRYPTOKI_F_PTR ( C_Initialize (NULL_PTR) );
8693 CPPUNIT_ASSERT (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED);
94+ /* Wait for the child process to finish and check its status. */
95+ CPPUNIT_ASSERT (waitpid (pid, &status, 0 ) == pid);
96+ CPPUNIT_ASSERT (WIFEXITED (status) && WEXITSTATUS (status) == EXIT_SUCCESS);
8797 break ;
8898 }
8999
@@ -95,6 +105,7 @@ void ForkTests::testResetOnFork()
95105{
96106 CK_RV rv;
97107 pid_t pid;
108+ int status;
98109
99110 // Just make sure that we finalize any previous failed tests
100111 CRYPTOKI_F_PTR ( C_Finalize (NULL_PTR) );
@@ -118,11 +129,17 @@ void ForkTests::testResetOnFork()
118129 /* For the child, the token is expected to be reset on fork */
119130 rv = CRYPTOKI_F_PTR ( C_Initialize (NULL_PTR) );
120131 CPPUNIT_ASSERT (rv == CKR_OK);
132+ rv = CRYPTOKI_F_PTR ( C_Finalize (NULL_PTR) );
133+ CPPUNIT_ASSERT (rv == CKR_OK);
134+ _exit (EXIT_SUCCESS);
121135 break ;
122136 default :
123137 /* For the parent, the token is expected to be still initialized */
124138 rv = CRYPTOKI_F_PTR ( C_Initialize (NULL_PTR) );
125139 CPPUNIT_ASSERT (rv == CKR_CRYPTOKI_ALREADY_INITIALIZED);
140+ /* Wait for the child process to finish and check its status. */
141+ CPPUNIT_ASSERT (waitpid (pid, &status, 0 ) == pid);
142+ CPPUNIT_ASSERT (WIFEXITED (status) && WEXITSTATUS (status) == EXIT_SUCCESS);
126143 break ;
127144 }
128145
0 commit comments