diff mbox series

[kvm-unit-tests,v3,07/16] s390x: css: testing ssch errors

Message ID 1617694853-6881-8-git-send-email-pmorel@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: Testing SSCH, CSCH and HSCH for errors | expand

Commit Message

Pierre Morel April 6, 2021, 7:40 a.m. UTC
Setup testing environment and check privilege.

Signed-off-by: Pierre Morel <pmorel@linux.ibm.com>
---
 s390x/css.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 68 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/s390x/css.c b/s390x/css.c
index f4b7af1..da21ccc 100644
--- a/s390x/css.c
+++ b/s390x/css.c
@@ -15,17 +15,24 @@ 
 #include <interrupt.h>
 #include <asm/arch_def.h>
 #include <alloc_page.h>
+#include <alloc.h>
 
 #include <malloc_io.h>
 #include <css.h>
 #include <asm/barrier.h>
 
+struct tests {
+	const char *name;
+	void (*func)(void);
+};
+
 #define DEFAULT_CU_TYPE		0x3832 /* virtio-ccw */
 static unsigned long cu_type = DEFAULT_CU_TYPE;
 
 static int test_device_sid;
 static struct senseid *senseid;
 struct ccw1 *ccw;
+struct orb *orb;
 
 static void test_enumerate(void)
 {
@@ -46,6 +53,65 @@  static void test_enable(void)
 	report(cc == 0, "Enable subchannel %08x", test_device_sid);
 }
 
+/* orb_alloc
+ *
+ * We allocate and initialize for all tests:
+ * - the ORB on a global pointer without memory restrictions.
+ * - A CCW and the senseid structures in I/O memory.
+ * Every subtest is responsible to have them modified for their purpose.
+ */
+static void orb_alloc(void)
+{
+	senseid = alloc_io_mem(sizeof(*senseid), 0);
+	assert(senseid);
+
+	ccw = ccw_alloc(CCW_CMD_SENSE_ID, senseid, sizeof(*senseid), CCW_F_SLI);
+	assert(ccw);
+
+	orb = malloc(sizeof(*orb));
+	assert(orb);
+
+	orb->intparm = test_device_sid;
+	orb->ctrl = ORB_CTRL_ISIC | ORB_CTRL_FMT | ORB_LPM_DFLT;
+	orb->cpa = (long)ccw;
+}
+
+static void orb_free(void)
+{
+	free_io_mem(senseid, sizeof(*senseid));
+	free_io_mem(ccw, sizeof(struct ccw1));
+	free(orb);
+}
+
+static void ssch_privilege(void)
+{
+	enter_pstate();
+	expect_pgm_int();
+	ssch(test_device_sid, orb);
+	check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
+}
+
+static struct tests ssh_tests[] = {
+	{ "privilege", ssch_privilege },
+	{ NULL, NULL }
+};
+
+static void test_ssch(void)
+{
+	int i;
+
+	orb_alloc();
+	assert(css_enable(test_device_sid, 0) == 0);
+
+	for (i = 0; ssh_tests[i].name; i++) {
+		report_prefix_push(ssh_tests[i].name);
+		ssh_tests[i].func();
+		report_prefix_pop();
+	}
+
+	orb_free();
+}
+
 /*
  * test_sense
  * Pre-requisites:
@@ -311,12 +377,10 @@  static void test_schm_fmt1(void)
 	free_io_mem(mb1, sizeof(struct measurement_block_format1));
 }
 
-static struct {
-	const char *name;
-	void (*func)(void);
-} tests[] = {
+static struct tests tests[] = {
 	/* The css_init test is needed to initialize the CSS Characteristics */
 	{ "enable (msch)", test_enable },
+	{ "start subchannel", test_ssch },
 	{ "sense (ssch/tsch)", test_sense },
 	{ "measurement block (schm)", test_schm },
 	{ "measurement block format0", test_schm_fmt0 },