summaryrefslogtreecommitdiff
path: root/p11-kit/tests
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2014-07-03 10:26:16 +0200
committerStef Walter <stef@thewalter.net>2014-07-04 14:23:15 +0200
commit25e8999fd11d0b2c156f3bdd8597142dedd042cb (patch)
treea4b76d584756f8ede20d9d29766e9eea6defb0c9 /p11-kit/tests
parenta2bd1a8c5ba3c611899f7dfc27d553010899eeec (diff)
p11-kit: Handle managed modules correctly when forking
Correctly allow reinitialization when a process forks. We don't yet implement checks on all entry points of a managed module, but this allows callers to call C_Initialize again after forking, as outlined by the PKCS#11 v2 spec.
Diffstat (limited to 'p11-kit/tests')
-rw-r--r--p11-kit/tests/test-managed.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/p11-kit/tests/test-managed.c b/p11-kit/tests/test-managed.c
index 9fc9ffb..c4ccd9a 100644
--- a/p11-kit/tests/test-managed.c
+++ b/p11-kit/tests/test-managed.c
@@ -42,6 +42,8 @@
#include "p11-kit.h"
#include "virtual.h"
+#include <sys/types.h>
+#include <sys/wait.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
@@ -194,6 +196,49 @@ test_separate_close_all_sessions (void)
teardown_mock_module (second);
}
+static void
+test_fork_and_reinitialize (void)
+{
+ CK_FUNCTION_LIST *module;
+ CK_INFO info;
+ int status;
+ CK_RV rv;
+ pid_t pid;
+ int i;
+
+ module = setup_mock_module (NULL);
+ assert_ptr_not_null (module);
+
+ pid = fork ();
+ assert_num_cmp (pid, >=, 0);
+
+ /* The child */
+ if (pid == 0) {
+ rv = (module->C_Initialize) (NULL);
+ assert_num_eq (CKR_OK, rv);
+
+ for (i = 0; i < 32; i++) {
+ rv = (module->C_GetInfo) (&info);
+ assert_num_eq (CKR_OK, rv);
+ }
+
+ rv = (module->C_Finalize) (NULL);
+ assert_num_eq (CKR_OK, rv);
+
+ _exit (66);
+ }
+
+ for (i = 0; i < 128; i++) {
+ rv = (module->C_GetInfo) (&info);
+ assert_num_eq (CKR_OK, rv);
+ }
+
+ assert_num_eq (waitpid (pid, &status, 0), pid);
+ assert_num_eq (WEXITSTATUS (status), 66);
+
+ teardown_mock_module (module);
+}
+
/* Bring in all the mock module tests */
#include "test-mock.c"
@@ -207,6 +252,8 @@ main (int argc,
p11_test (test_initialize_finalize, "/managed/test_initialize_finalize");
p11_test (test_initialize_fail, "/managed/test_initialize_fail");
p11_test (test_separate_close_all_sessions, "/managed/test_separate_close_all_sessions");
+ p11_test (test_fork_and_reinitialize, "/managed/fork-and-reinitialize");
+
test_mock_add_tests ("/managed");
p11_kit_be_quiet ();