diff options
-rw-r--r-- | p11-kit/test-managed.c | 49 | ||||
-rw-r--r-- | p11-kit/test-modules.c | 38 |
2 files changed, 82 insertions, 5 deletions
diff --git a/p11-kit/test-managed.c b/p11-kit/test-managed.c index fc673ea..27c52e3 100644 --- a/p11-kit/test-managed.c +++ b/p11-kit/test-managed.c @@ -41,6 +41,7 @@ #include "modules.h" #include "p11-kit.h" #include "virtual.h" +#include "virtual-fixed.h" #include <sys/types.h> #ifdef OS_UNIX @@ -54,18 +55,23 @@ static CK_FUNCTION_LIST_PTR setup_mock_module (CK_SESSION_HANDLE *session) { - CK_FUNCTION_LIST_PTR module; + CK_FUNCTION_LIST_PTR module = NULL; CK_RV rv; p11_lock (); rv = p11_module_load_inlock_reentrant (&mock_module, 0, &module); - assert (rv == CKR_OK); - assert_ptr_not_null (module); - assert (p11_virtual_is_wrapper (module)); p11_unlock (); + if (rv == CKR_OK) { + assert_ptr_not_null (module); + assert (p11_virtual_is_wrapper (module)); + } else { + assert_ptr_eq (NULL, module); + return NULL; + } + rv = p11_kit_module_initialize (module); assert (rv == CKR_OK); @@ -168,7 +174,9 @@ test_separate_close_all_sessions (void) CK_RV rv; first = setup_mock_module (&s1); + assert_ptr_not_null (first); second = setup_mock_module (&s2); + assert_ptr_not_null (second); rv = first->C_GetSessionInfo (s1, &info); assert (rv == CKR_OK); @@ -198,6 +206,38 @@ test_separate_close_all_sessions (void) teardown_mock_module (second); } +#define MAX_MODS (P11_VIRTUAL_MAX_FIXED+10) +static void +test_max_session_load (void) +{ + CK_FUNCTION_LIST *list[MAX_MODS]; + CK_SESSION_HANDLE s1; + CK_SESSION_INFO info; + CK_RV rv; + unsigned i; + unsigned registered = 0; + + for (i = 0; i < MAX_MODS; i++) { + list[i] = setup_mock_module (&s1); + if (list[i] != NULL) + registered++; + } + + assert_num_cmp (registered + 1, >=, P11_VIRTUAL_MAX_FIXED); + + for (i = 0; i < registered; i++) { + rv = list[i]->C_GetSessionInfo (s1, &info); + assert (rv == CKR_OK); + + list[i]->C_CloseAllSessions (MOCK_SLOT_ONE_ID); + assert (rv == CKR_OK); + } + + for (i = 0; i < registered; i++) { + teardown_mock_module (list[i]); + } +} + #ifdef OS_UNIX static void @@ -258,6 +298,7 @@ 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_max_session_load, "/managed/test_max_session_load"); #ifdef OS_UNIX p11_test (test_fork_and_reinitialize, "/managed/fork-and-reinitialize"); diff --git a/p11-kit/test-modules.c b/p11-kit/test-modules.c index 837e7ff..4bdf11a 100644 --- a/p11-kit/test-modules.c +++ b/p11-kit/test-modules.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015 Red Hat Inc + * Copyright (c) 2012, 2015, 2016 Red Hat Inc * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -99,6 +99,41 @@ test_no_duplicates (void) finalize_and_free_modules (modules); } +static void +test_exceed_max (void) +{ + CK_FUNCTION_LIST_PTR_PTR modules; + p11_dict *paths; + p11_dict *funcs; + char *path; + int i; + + modules = initialize_and_get_modules (); + paths = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, NULL, NULL); + funcs = p11_dict_new (p11_dict_direct_hash, p11_dict_direct_equal, NULL, NULL); + + /* The loaded modules should not contain duplicates */ + for (i = 0; modules[i] != NULL; i++) { + path = p11_kit_config_option (modules[i], "module"); + + if (p11_dict_get (funcs, modules[i])) + assert_fail ("found duplicate function list pointer", NULL); + if (p11_dict_get (paths, path)) + assert_fail ("found duplicate path name", NULL); + + if (!p11_dict_set (funcs, modules[i], "")) + assert_not_reached (); + if (!p11_dict_set (paths, path, "")) + assert_not_reached (); + + free (path); + } + + p11_dict_free (paths); + p11_dict_free (funcs); + finalize_and_free_modules (modules); +} + static CK_FUNCTION_LIST_PTR lookup_module_with_name (CK_FUNCTION_LIST_PTR_PTR modules, const char *name) @@ -437,6 +472,7 @@ main (int argc, p11_test (test_filename, "/modules/test_filename"); p11_test (test_no_duplicates, "/modules/test_no_duplicates"); + p11_test (test_exceed_max, "/modules/test_exceed_max"); p11_test (test_disable, "/modules/test_disable"); p11_test (test_disable_later, "/modules/test_disable_later"); p11_test (test_enable, "/modules/test_enable"); |