Blame SOURCES/opencryptoki-3.16.0-d7de5092247a0efc2c397f12977a7c9925420143.patch

2c1758
commit d7de5092247a0efc2c397f12977a7c9925420143
2c1758
Author: Ingo Franzki <ifranzki@linux.ibm.com>
2c1758
Date:   Tue Feb 16 17:15:20 2021 +0100
2c1758
2c1758
    TESTCASES: Add event support tests
2c1758
    
2c1758
    Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
2c1758
2c1758
diff --git a/testcases/misc_tests/events.c b/testcases/misc_tests/events.c
2c1758
new file mode 100644
2c1758
index 00000000..fecc7bfe
2c1758
--- /dev/null
2c1758
+++ b/testcases/misc_tests/events.c
2c1758
@@ -0,0 +1,190 @@
2c1758
+/*
2c1758
+ * COPYRIGHT (c) International Business Machines Corp. 2021
2c1758
+ *
2c1758
+ * This program is provided under the terms of the Common Public License,
2c1758
+ * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this
2c1758
+ * software constitutes recipient's acceptance of CPL-1.0 terms which can be
2c1758
+ * found in the file LICENSE file or at
2c1758
+ * https://opensource.org/licenses/cpl1.0.php
2c1758
+ */
2c1758
+
2c1758
+
2c1758
+#include <stdio.h>
2c1758
+#include <stdlib.h>
2c1758
+#include <string.h>
2c1758
+
2c1758
+#include "event_client.h"
2c1758
+#include "regress.h"
2c1758
+#include "defs.h"
2c1758
+
2c1758
+const char payload[20] = "12345678901234567890";
2c1758
+
2c1758
+static inline void init_event_destination(struct event_destination *dest,
2c1758
+                                          unsigned int token_type,
2c1758
+                                          const char *label,
2c1758
+                                          pid_t process_id)
2c1758
+{
2c1758
+    size_t len;
2c1758
+
2c1758
+    dest->token_type = token_type;
2c1758
+    dest->process_id = process_id;
2c1758
+
2c1758
+    memset(dest->token_label, ' ', sizeof(dest->token_label));
2c1758
+    if (label != NULL) {
2c1758
+        len = strlen(label);
2c1758
+        memcpy(dest->token_label, label, len > sizeof(dest->token_label) ?
2c1758
+                                    sizeof(dest->token_label) : len);
2c1758
+    }
2c1758
+}
2c1758
+
2c1758
+int main(int argc, char **argv)
2c1758
+{
2c1758
+    CK_C_INITIALIZE_ARGS cinit_args;
2c1758
+    int rc, fd = -1, ret = 1;
2c1758
+    struct event_destination dest;
2c1758
+    struct event_reply reply;
2c1758
+
2c1758
+    UNUSED(argc);
2c1758
+    UNUSED(argv);
2c1758
+
2c1758
+    rc = do_GetFunctionList();
2c1758
+    if (!rc) {
2c1758
+        testcase_error("do_getFunctionList(), rc=%s", p11_get_ckr(rc));
2c1758
+        return rc;
2c1758
+    }
2c1758
+
2c1758
+    /*
2c1758
+     * Initialize Opencryptoki in this process, so that at least one
2c1758
+     * process is receiving the events.
2c1758
+     */
2c1758
+    memset(&cinit_args, 0x0, sizeof(cinit_args));
2c1758
+    cinit_args.flags = CKF_OS_LOCKING_OK;
2c1758
+    funcs->C_Initialize(&cinit_args);
2c1758
+
2c1758
+    testcase_setup(0);
2c1758
+    testcase_begin("Starting event tests");
2c1758
+
2c1758
+    // Test fork before C_Initialize
2c1758
+    testcase_new_assertion();
2c1758
+
2c1758
+    rc = send_event(-1, 0x12345, EVENT_FLAGS_NONE, 0, NULL, NULL, NULL);
2c1758
+    if (rc != 0) {
2c1758
+        testcase_fail("send_event (simple, one-shot) rc = %d (%s)", rc,
2c1758
+                      strerror(-rc));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("send_event (simple, one-shot)");
2c1758
+
2c1758
+    rc = send_event(-1, 0x12345, EVENT_FLAGS_NONE, sizeof(payload), payload,
2c1758
+                    NULL, NULL);
2c1758
+    if (rc != 0) {
2c1758
+        testcase_fail("send_event (payload, one-shot) rc = %d (%s)", rc,
2c1758
+                      strerror(-rc));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("send_event (payload, one-shot)");
2c1758
+
2c1758
+    init_event_destination(&dest, EVENT_TOK_TYPE_CCA, NULL, 0);
2c1758
+
2c1758
+    rc = send_event(-1, 0x12345, EVENT_FLAGS_NONE, 0, NULL, &dest, NULL);
2c1758
+    if (rc != 0) {
2c1758
+        testcase_fail("send_event (token-type, one-shot) rc = %d (%s)", rc,
2c1758
+                      strerror(-rc));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("send_event (token-type, one-shot)");
2c1758
+
2c1758
+    init_event_destination(&dest, EVENT_TOK_TYPE_ALL, "cca", 0);
2c1758
+
2c1758
+    rc = send_event(-1, 0x12345, EVENT_FLAGS_NONE, 0, NULL, &dest, NULL);
2c1758
+    if (rc != 0) {
2c1758
+        testcase_fail("send_event (token-label, one-shot) rc = %d (%s)", rc,
2c1758
+                      strerror(-rc));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("send_event (token-label, one-shot)");
2c1758
+
2c1758
+    init_event_destination(&dest, EVENT_TOK_TYPE_ALL, NULL, 12345);
2c1758
+
2c1758
+    rc = send_event(-1, 0x12345, EVENT_FLAGS_NONE, 0, NULL, &dest, NULL);
2c1758
+    if (rc != 0) {
2c1758
+        testcase_fail("send_event (pid, one-shot) rc = %d (%s)", rc,
2c1758
+                      strerror(-rc));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("send_event (pid, one-shot)");
2c1758
+
2c1758
+    memset(&reply, 0, sizeof(reply));
2c1758
+
2c1758
+    rc = send_event(-1, 0x12345, EVENT_FLAGS_REPLY_REQ, 0, NULL, NULL, &reply);
2c1758
+    if (rc != 0) {
2c1758
+        testcase_fail("send_event (reply, one-shot) rc = %d (%s)", rc,
2c1758
+                      strerror(-rc));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    printf("Reply: positive_replies:    %lu\n", reply.positive_replies);
2c1758
+    printf("       negative_replies:    %lu\n", reply.negative_replies);
2c1758
+    printf("       nothandled_replies:  %lu\n", reply.nothandled_replies);
2c1758
+    if (reply.positive_replies + reply.negative_replies +
2c1758
+            reply.nothandled_replies == 0) {
2c1758
+        testcase_fail("send_event (reply, one-shot) replies all zero");
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("send_event (reply, one-shot)");
2c1758
+
2c1758
+
2c1758
+    fd = init_event_client();
2c1758
+    if (fd < 0) {
2c1758
+        testcase_fail("init_event_client rc = %d (%s)", fd, strerror(-fd));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("init_event_client()");
2c1758
+
2c1758
+    rc = send_event(fd, 0x12345, EVENT_FLAGS_NONE, 0, NULL, NULL, NULL);
2c1758
+    if (rc != 0) {
2c1758
+        testcase_fail("send_event (simple) rc = %d (%s)", rc, strerror(-rc));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("send_event (simple)");
2c1758
+
2c1758
+    rc = send_event(fd, 0x12345, EVENT_FLAGS_NONE, sizeof(payload), payload,
2c1758
+                    NULL, NULL);
2c1758
+    if (rc != 0) {
2c1758
+        testcase_fail("send_event (payload) rc = %d (%s)", rc,
2c1758
+                      strerror(-rc));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("send_event (payload)");
2c1758
+
2c1758
+    memset(&reply, 0, sizeof(reply));
2c1758
+
2c1758
+    rc = send_event(-1, 0x12345, EVENT_FLAGS_REPLY_REQ, 0, NULL, NULL, &reply);
2c1758
+    if (rc != 0) {
2c1758
+        testcase_fail("send_event (reply) rc = %d (%s)", rc,
2c1758
+                      strerror(-rc));
2c1758
+        goto out;
2c1758
+    }
2c1758
+    printf("Reply: positive_replies:    %lu\n", reply.positive_replies);
2c1758
+    printf("       negative_replies:    %lu\n", reply.negative_replies);
2c1758
+    printf("       nothandled_replies:  %lu\n", reply.nothandled_replies);
2c1758
+    if (reply.positive_replies + reply.negative_replies +
2c1758
+            reply.nothandled_replies == 0) {
2c1758
+        testcase_fail("send_event (reply) replies all zero");
2c1758
+        goto out;
2c1758
+    }
2c1758
+    testcase_pass("send_event (reply)");
2c1758
+
2c1758
+    term_event_client(fd);
2c1758
+    fd = -1;
2c1758
+
2c1758
+    ret = 0;
2c1758
+
2c1758
+out:
2c1758
+    if (fd >= 0)
2c1758
+        term_event_client(fd);
2c1758
+
2c1758
+    funcs->C_Finalize(NULL);
2c1758
+
2c1758
+    testcase_print_result();
2c1758
+    return ret;
2c1758
+}
2c1758
diff --git a/testcases/misc_tests/misc_tests.mk b/testcases/misc_tests/misc_tests.mk
2c1758
index 3de11ebe..fb7cc0a1 100644
2c1758
--- a/testcases/misc_tests/misc_tests.mk
2c1758
+++ b/testcases/misc_tests/misc_tests.mk
2c1758
@@ -7,7 +7,8 @@ noinst_PROGRAMS +=							\
2c1758
 	testcases/misc_tests/fork testcases/misc_tests/multi_instance   \
2c1758
 	testcases/misc_tests/obj_lock testcases/misc_tests/tok2tok_transport \
2c1758
 	testcases/misc_tests/obj_lock testcases/misc_tests/reencrypt    \
2c1758
-	testcases/misc_tests/cca_export_import_test
2c1758
+	testcases/misc_tests/cca_export_import_test			\
2c1758
+	testcases/misc_tests/events
2c1758
 
2c1758
 testcases_misc_tests_obj_mgmt_tests_CFLAGS = ${testcases_inc}
2c1758
 testcases_misc_tests_obj_mgmt_tests_LDADD =				\
2c1758
@@ -73,3 +74,8 @@ testcases_misc_tests_cca_export_import_test_LDADD =			\
2c1758
 	testcases/common/libcommon.la
2c1758
 testcases_misc_tests_cca_export_import_test_SOURCES =			\
2c1758
 	testcases/misc_tests/cca_export_import_test.c
2c1758
+	
2c1758
+testcases_misc_tests_events_CFLAGS = ${testcases_inc}
2c1758
+testcases_misc_tests_events_LDADD = testcases/common/libcommon.la
2c1758
+testcases_misc_tests_events_SOURCES = testcases/misc_tests/events.c	\
2c1758
+	usr/lib/common/event_client.c
2c1758
diff --git a/testcases/ock_tests.sh.in b/testcases/ock_tests.sh.in
2c1758
index 64c77a7d..6558b031 100755
2c1758
--- a/testcases/ock_tests.sh.in
2c1758
+++ b/testcases/ock_tests.sh.in
2c1758
@@ -53,6 +53,7 @@ OCK_TESTS+=" pkcs11/findobjects pkcs11/generate_keypair"
2c1758
 OCK_TESTS+=" pkcs11/get_interface pkcs11/getobjectsize pkcs11/sess_opstate"
2c1758
 OCK_TESTS+=" misc_tests/fork misc_tests/obj_mgmt_tests" 
2c1758
 OCK_TESTS+=" misc_tests/obj_mgmt_lock_tests misc_tests/reencrypt"
2c1758
+OCK_TESTS+=" misc_tests/events"
2c1758
 OCK_TEST=""
2c1758
 OCK_BENCHS="pkcs11/*bench"
2c1758