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