summaryrefslogtreecommitdiff
path: root/usr/src/test/os-tests/tests/uccid/txn-pollerr.c
diff options
context:
space:
mode:
authorJason King <jasonbking@users.noreply.github.com>2020-01-14 09:57:36 -0600
committerGitHub <noreply@github.com>2020-01-14 09:57:36 -0600
commit81b0b97522c9ef54fd7ebae67bd982589417d656 (patch)
tree156c6754d5ce25731af47401a02cbdcad798054b /usr/src/test/os-tests/tests/uccid/txn-pollerr.c
parent8ec7a75c64b22baa6f1eea820d7c751da8259a68 (diff)
parentd55d490bff89f9cf4f0776544edf4bc3daa9e471 (diff)
downloadillumos-joyent-OS-7870.tar.gz
Merge branch 'master' into OS-7870OS-7870
Diffstat (limited to 'usr/src/test/os-tests/tests/uccid/txn-pollerr.c')
-rw-r--r--usr/src/test/os-tests/tests/uccid/txn-pollerr.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/usr/src/test/os-tests/tests/uccid/txn-pollerr.c b/usr/src/test/os-tests/tests/uccid/txn-pollerr.c
new file mode 100644
index 0000000000..b19598f711
--- /dev/null
+++ b/usr/src/test/os-tests/tests/uccid/txn-pollerr.c
@@ -0,0 +1,88 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2019, Joyent, Inc.
+ */
+
+/*
+ * Verify that closing a transaction while polling generates POLLERR.
+ */
+
+#include <err.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <strings.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/debug.h>
+#include <poll.h>
+#include <port.h>
+
+#include <sys/usb/clients/ccid/uccid.h>
+
+int
+main(int argc, char *argv[])
+{
+ int fd, port;
+ uccid_cmd_txn_end_t end;
+ uccid_cmd_txn_begin_t begin;
+ port_event_t pe;
+ timespec_t to;
+
+ if (argc != 2) {
+ errx(EXIT_FAILURE, "missing required ccid path");
+ }
+
+ if ((port = port_create()) == -1) {
+ err(EXIT_FAILURE, "failed to create event port: %d",
+ port);
+ }
+
+ if ((fd = open(argv[1], O_RDWR | O_EXCL)) < 0) {
+ err(EXIT_FAILURE, "failed to open %s", argv[1]);
+ }
+
+ bzero(&begin, sizeof (begin));
+ begin.uct_version = UCCID_CURRENT_VERSION;
+ if (ioctl(fd, UCCID_CMD_TXN_BEGIN, &begin) != 0) {
+ err(EXIT_FAILURE, "failed to issue begin ioctl");
+ }
+
+ /*
+ * Do not poll for pollout here, since by default, after grabbing a
+ * transaction, the device is writeable.
+ */
+ if (port_associate(port, PORT_SOURCE_FD, fd, POLLIN, NULL) != 0) {
+ err(EXIT_FAILURE, "failed to associate");
+ }
+
+ bzero(&end, sizeof (end));
+ end.uct_version = UCCID_CURRENT_VERSION;
+ end.uct_flags = UCCID_TXN_END_RELEASE;
+
+ if (ioctl(fd, UCCID_CMD_TXN_END, &end) != 0) {
+ err(EXIT_FAILURE, "failed to issue end ioctl");
+ }
+
+ bzero(&to, sizeof (timespec_t));
+ if (port_get(port, &pe, &to) != 0) {
+ err(EXIT_FAILURE, "failed to port_get()");
+ }
+
+ VERIFY3S(pe.portev_source, ==, PORT_SOURCE_FD);
+ VERIFY3S(pe.portev_object, ==, fd);
+ VERIFY3S(pe.portev_events & POLLERR, !=, 0);
+
+ return (0);
+}