]> granicus.if.org Git - p11-kit/commitdiff
test: Check exhaustion of fixed closures
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Wed, 30 Nov 2016 14:20:24 +0000 (15:20 +0100)
committerDaiki Ueno <ueno@gnu.org>
Tue, 24 Jan 2017 11:36:06 +0000 (12:36 +0100)
p11-kit/test-managed.c
p11-kit/test-modules.c

index fc673eaa4167b5b5d04907bf05d64b87478e6bf6..27c52e331df1de4d2e94bc8cb61cd8965dcaf61a 100644 (file)
@@ -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
 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");
index 837e7ff9d9db7674d71a6e9ddb0df583fccf656a..4bdf11acde5e4fd065bfea8279aa7b7db544c1d6 100644 (file)
@@ -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");