lkml.org 
[lkml]   [2020]   [May]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC v4][PATCH part-3 11/14] asidrv/asicmd: Introduce the asicmd command
Date
The asicmd command is a userland CLI to interact with the ASI driver
(asidrv), in particular it provides an interface for running ASI
test sequences.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
drivers/staging/asi/Makefile | 6 ++
drivers/staging/asi/asicmd.c | 120 +++++++++++++++++++++++++++++++++++
2 files changed, 126 insertions(+)
create mode 100644 drivers/staging/asi/asicmd.c

diff --git a/drivers/staging/asi/Makefile b/drivers/staging/asi/Makefile
index a48487e48d7c..847d4732c229 100644
--- a/drivers/staging/asi/Makefile
+++ b/drivers/staging/asi/Makefile
@@ -5,3 +5,9 @@
#
obj-m += asi.o
asi-y := asidrv.o
+
+#
+# asicmd command
+#
+hostprogs-y := asicmd
+always := $(hostprogs-y)
diff --git a/drivers/staging/asi/asicmd.c b/drivers/staging/asi/asicmd.c
new file mode 100644
index 000000000000..4d6a347a6d29
--- /dev/null
+++ b/drivers/staging/asi/asicmd.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2020, Oracle and/or its affiliates.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "asidrv.h"
+
+struct asidrv_test {
+ char *name; /* test name */
+ enum asidrv_seqnum seqnum; /* sequence */
+ bool asi_active; /* ASI active at the end of test? */
+ char *desc; /* test description */
+};
+
+struct asidrv_test test_list[] = {
+ { "nop", ASIDRV_SEQ_NOP, true,
+ "enter/exit ASI and nothing else" },
+};
+
+#define TEST_LIST_SIZE (sizeof(test_list) / sizeof(test_list[0]))
+
+static void usage(void)
+{
+ int i;
+
+ printf("Usage: asicmd (<cmd>|<test>...)\n");
+ printf("\n");
+ printf("Commands:\n");
+ printf(" all - run all tests\n");
+ printf("\n");
+ printf("Tests:\n");
+ for (i = 0; i < TEST_LIST_SIZE; i++)
+ printf(" %-10s - %s\n", test_list[i].name, test_list[i].desc);
+}
+
+static void asidrv_run_test(int fd, struct asidrv_test *test)
+{
+ struct asidrv_run_param rparam;
+ int err;
+
+ printf("Test %s (sequence %d)\n", test->name, test->seqnum);
+
+ rparam.sequence = test->seqnum;
+
+ err = ioctl(fd, ASIDRV_IOCTL_RUN_SEQUENCE, &rparam);
+
+ printf(" - rv = %d ; ", err);
+ if (err < 0) {
+ printf("error %d\n", errno);
+ } else {
+ printf("result = %d ; ", rparam.run_error);
+ printf("%s\n",
+ rparam.asi_active ? "asi active" : "asi inactive");
+ }
+
+ printf(" - expect = %s\n",
+ test->asi_active ? "asi active" : "asi inactive");
+
+ if (err < 0)
+ printf("ERROR - error %d\n", errno);
+ else if (rparam.run_error != ASIDRV_RUN_ERR_NONE)
+ printf("TEST ERROR - error %d\n", rparam.run_error);
+ else if (test->asi_active != rparam.asi_active)
+ printf("TEST FAILED - unexpected ASI state\n");
+ else
+ printf("TEST OK\n");
+}
+
+int main(int argc, char *argv[])
+{
+ bool run_all, run;
+ int i, j, fd;
+ char *test;
+
+ if (argc <= 1) {
+ usage();
+ return 2;
+ }
+
+ fd = open("/dev/asi", O_RDONLY);
+ if (fd == -1) {
+ perror("open /dev/asi");
+ return 1;
+ }
+
+ for (i = 1; i < argc; i++) {
+ test = argv[i];
+
+ if (!strcmp(test, "all"))
+ run_all = true;
+ else
+ run_all = false;
+
+ run = false;
+ for (j = 0; j < TEST_LIST_SIZE; j++) {
+ if (run_all || !strcmp(test, test_list[j].name)) {
+ asidrv_run_test(fd, &test_list[j]);
+ run = true;
+ }
+ }
+
+ if (!run)
+ printf("Unknown test '%s'\n", test);
+ }
+
+ close(fd);
+
+ return 0;
+}
--
2.18.2
\
 
 \ /
  Last update: 2020-05-04 17:06    [W:0.051 / U:1.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site