Skip to contentSkip to conversation

s390x: Add strict mode to specification exception interpretation test

PATCH Superseded Janis Schoetterl-Glausch 2 participants 3 messages Feb 25, 2022 – Mar 3, 2022

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x: Add strict mode to specification exception interpretation test

While specification exception interpretation is not required to occur, it can be useful for automatic regression testing to fail the test if it does not occur.
Add a --strict argument to enable this.
--strict takes a list of machine types (as reported by STIDP)
for which to enable strict mode, for example
--strict 8562,8561,3907,3906,2965,2964
will enable it for models z15 - z13.
Alternatively, strict mode can be enabled for all but the listed machine types by prefixing the list with a !, for example
--strict !1090,1091,2064,2066,2084,2086,2094,2096,2097,2098,2817,2818,2827,2828 will enable it for z/Architecture models except those older than z13.

---
Range-diff:

1:  5d91f693 < -:  -------- s390x: Add specification exception interception test
2:  950eafd7 ! 1:  e9c36970 s390x: Add strict mode to specification exception interpretation test
    @@ s390x/spec_ex-sie.c: static void reset_guest(void)
     -static void test_spec_ex_sie(void)
     +static void test_spec_ex_sie(bool strict)
      {
    ++	const char *msg;
    ++
      	setup_guest();
      
    + 	report_prefix_push("SIE spec ex interpretation");
     @@ s390x/spec_ex-sie.c: static void test_spec_ex_sie(void)
      	report(vm.sblk->icptcode == ICPT_PROGI
      	       && vm.sblk->iprcc == PGM_INT_CODE_SPECIFICATION,
      	       "Received specification exception intercept");
     -	if (vm.sblk->gpsw.addr == 0xdeadbeee)
     -		report_info("Interpreted initial exception, intercepted invalid program new PSW exception");
    --	else
    --		report_info("Did not interpret initial exception");
    -+	{
    -+		const char *msg;
    -+
    -+		msg = "Interpreted initial exception, intercepted invalid program new PSW exception";
    -+		if (strict)
    -+			report(vm.sblk->gpsw.addr == 0xdeadbeee, msg);
    -+		else if (vm.sblk->gpsw.addr == 0xdeadbeee)
    -+			report_info(msg);
    -+		else
    -+			report_info("Did not interpret initial exception");
    -+	}
    ++	msg = "Interpreted initial exception, intercepted invalid program new PSW exception";
    ++	if (strict)
    ++		report(vm.sblk->gpsw.addr == 0xdeadbeee, msg);
    ++	else if (vm.sblk->gpsw.addr == 0xdeadbeee)
    ++		report_info(msg);
    + 	else
    + 		report_info("Did not interpret initial exception");
      	report_prefix_pop();
      	report_prefix_pop();
      }
      
    -+static bool parse_strict(char **argv)
    ++static bool parse_strict(int argc, char **argv)
     +{
     +	uint16_t machine_id;
     +	char *list;
     +	bool ret;
     +
    -+	if (!*argv)
    ++	if (argc < 1)
     +		return false;
    -+	if (strcmp("--strict", *argv))
    ++	if (strcmp("--strict", argv[0]))
     +		return false;
     +
     +	machine_id = get_machine_id();
    -+	list = argv[1];
    -+	if (!list) {
    ++	if (argc < 2) {
     +		printf("No argument to --strict, ignoring\n");
     +		return false;
     +	}
    ++	list = argv[1];
     +	if (list[0] == '!') {
     +		ret = true;
     +		list++;
    @@ s390x/spec_ex-sie.c: int main(int argc, char **argv)
      	}
      
     -	test_spec_ex_sie();
    -+	test_spec_ex_sie(parse_strict(argv + 1));
    ++	test_spec_ex_sie(parse_strict(argc - 1, argv + 1));
      out:
      	return report_summary();
      }
 s390x/spec_ex-sie.c | 53 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 49 insertions(+), 4 deletions(-)
s390x/spec_ex-sie.c +49 -4
index 5dea4115..071110e3 100644
@@ -7,6 +7,7 @@
  * specification exception interpretation is off/on.
  */
 #include <libcflat.h>
+#include <stdlib.h>
 #include <sclp.h>
 #include <asm/page.h>
 #include <asm/arch_def.h>
@@ -36,8 +37,10 @@ static void reset_guest(void)
 	vm.sblk->icptcode = 0;
 }
 
-static void test_spec_ex_sie(void)
+static void test_spec_ex_sie(bool strict)
 {
+	const char *msg;
+
 	setup_guest();
 
 	report_prefix_push("SIE spec ex interpretation");
@@ -61,14 +64,56 @@ static void test_spec_ex_sie(void)
 	report(vm.sblk->icptcode == ICPT_PROGI
 	       && vm.sblk->iprcc == PGM_INT_CODE_SPECIFICATION,
 	       "Received specification exception intercept");
-	if (vm.sblk->gpsw.addr == 0xdeadbeee)
-		report_info("Interpreted initial exception, intercepted invalid program new PSW exception");
+	msg = "Interpreted initial exception, intercepted invalid program new PSW exception";
+	if (strict)
+		report(vm.sblk->gpsw.addr == 0xdeadbeee, msg);
+	else if (vm.sblk->gpsw.addr == 0xdeadbeee)
+		report_info(msg);
 	else
 		report_info("Did not interpret initial exception");
 	report_prefix_pop();
 	report_prefix_pop();
 }
 
+static bool parse_strict(int argc, char **argv)
+{
+	uint16_t machine_id;
+	char *list;
+	bool ret;
+
+	if (argc < 1)
+		return false;
+	if (strcmp("--strict", argv[0]))
+		return false;
+
+	machine_id = get_machine_id();
+	if (argc < 2) {
+		printf("No argument to --strict, ignoring\n");
+		return false;
+	}
+	list = argv[1];
+	if (list[0] == '!') {
+		ret = true;
+		list++;
+	} else
+		ret = false;
+	while (true) {
+		long input = 0;
+
+		if (strlen(list) == 0)
+			return ret;
+		input = strtol(list, &list, 16);
+		if (*list == ',')
+			list++;
+		else if (*list != '\0')
+			break;
+		if (input == machine_id)
+			return !ret;
+	}
+	printf("Invalid --strict argument \"%s\", ignoring\n", list);
+	return ret;
+}
+
 int main(int argc, char **argv)
 {
 	if (!sclp_facilities.has_sief2) {
@@ -76,7 +121,7 @@ int main(int argc, char **argv)
 		goto out;
 	}
 
-	test_spec_ex_sie();
+	test_spec_ex_sie(parse_strict(argc - 1, argv + 1));
 out:
 	return report_summary();
 }

base-commit: 257c962f3d1b2d0534af59de4ad18764d734903a

Signature · 1 line
2.33.1
#1 lore raw
Quoted 15 lines · On Fri, 25 Feb 2022 18:23:55 +0100 Janis Schoetterl-Glausch…

While specification exception interpretation is not required to occur, it can be useful for automatic regression testing to fail the test if it does not occur.
Add a --strict argument to enable this.
--strict takes a list of machine types (as reported by STIDP)
for which to enable strict mode, for example
--strict 8562,8561,3907,3906,2965,2964
will enable it for models z15 - z13.
Alternatively, strict mode can be enabled for all but the listed machine types by prefixing the list with a !, for example
--strict !1090,1091,2064,2066,2084,2086,2094,2096,2097,2098,2817,2818,2827,2828 will enable it for z/Architecture models except those older than z13.

---

[...]

Quoted 28 lines
s390x/spec_ex-sie.c +28 -0
+static bool parse_strict(int argc, char **argv)
+{
+	uint16_t machine_id;
+	char *list;
+	bool ret;
+
+	if (argc < 1)
+		return false;
+	if (strcmp("--strict", argv[0]))
+		return false;
+
+	machine_id = get_machine_id();
+	if (argc < 2) {
+		printf("No argument to --strict, ignoring\n");
+		return false;
+	}
+	list = argv[1];
+	if (list[0] == '!') {
+		ret = true;
+		list++;
+	} else
+		ret = false;
+	while (true) {
+		long input = 0;
+
+		if (strlen(list) == 0)
+			return ret;
+		input = strtol(list, &list, 16);

s390x/spec_ex-sie.c static void test_spec_ex_sie(void) · line 115

Quoted 10 lines
s390x/spec_ex-sie.c +10 -0
+		if (*list == ',')
+			list++;
+		else if (*list != '\0')
+			break;
+		if (input == machine_id)
+			return !ret;
+	}
+	printf("Invalid --strict argument \"%s\", ignoring\n", list);
+	return ret;
+}

probably I should write a few parsing functions for command line arguments, so we don't have to re-invent the wheel every time

s390x/spec_ex-sie.c int main(int argc, char **argv) · line 124

Quoted 10 lines
s390x/spec_ex-sie.c +2 -1
+
 int main(int argc, char **argv)
 {
 	if (!sclp_facilities.has_sief2) {
@@ -76,7 +121,7 @@ int main(int argc, char **argv)
 		goto out;
 	}
 
-	test_spec_ex_sie();
+	test_spec_ex_sie(parse_strict(argc - 1, argv + 1));

hmmm... maybe it would be more readable and more uniform with the other tests to parse the command line during initialization of the unit test, and set a global flag.

Quoted 5 lines
s390x/spec_ex-sie.c +0 -0
 out:
 	return report_summary();
 }

base-commit: 257c962f3d1b2d0534af59de4ad18764d734903a

#2 lore raw
Quoted 54 lines · Claudio Imbrenda
Quoted 15 lines · On Fri, 25 Feb 2022 18:23:55 +0100 Janis Schoetterl-Glausch…

While specification exception interpretation is not required to occur, it can be useful for automatic regression testing to fail the test if it does not occur.
Add a --strict argument to enable this.
--strict takes a list of machine types (as reported by STIDP)
for which to enable strict mode, for example
--strict 8562,8561,3907,3906,2965,2964
will enable it for models z15 - z13.
Alternatively, strict mode can be enabled for all but the listed machine types by prefixing the list with a !, for example
--strict !1090,1091,2064,2066,2084,2086,2094,2096,2097,2098,2817,2818,2827,2828 will enable it for z/Architecture models except those older than z13.

---

[...]

Quoted 33 lines
s390x/spec_ex-sie.c +33 -0
+static bool parse_strict(int argc, char **argv)
+{
+	uint16_t machine_id;
+	char *list;
+	bool ret;
+
+	if (argc < 1)
+		return false;
+	if (strcmp("--strict", argv[0]))
+		return false;
+
+	machine_id = get_machine_id();
+	if (argc < 2) {
+		printf("No argument to --strict, ignoring\n");
+		return false;
+	}
+	list = argv[1];
+	if (list[0] == '!') {
+		ret = true;
+		list++;
+	} else
+		ret = false;
+	while (true) {
+		long input = 0;
+
+		if (strlen(list) == 0)
+			return ret;
+		input = strtol(list, &list, 16);
+		if (*list == ',')
+			list++;
+		else if (*list != '\0')
+			break;
+		if (input == machine_id)
Quoted 8 lines

s390x/spec_ex-sie.c static void test_spec_ex_sie(void) · line 115

Quoted 5 lines
s390x/spec_ex-sie.c +5 -0
+			return !ret;
+	}
+	printf("Invalid --strict argument \"%s\", ignoring\n", list);
+	return ret;
+}

probably I should write a few parsing functions for command line arguments, so we don't have to re-invent the wheel every time

Maybe, would depend on what you have in mind, I'm not sure most use cases can be covered by a reasonable set of abstractions.

Quoted 9 lines
Quoted 9 lines
s390x/spec_ex-sie.c +1 -0
+
 int main(int argc, char **argv)
 {
 	if (!sclp_facilities.has_sief2) {
@@ -76,7 +121,7 @@ int main(int argc, char **argv)
 		goto out;
 	}
 
Quoted 6 lines

s390x/spec_ex-sie.c int main(int argc, char **argv) · line 124

Quoted 2 lines
s390x/spec_ex-sie.c +1 -1
-	test_spec_ex_sie();
+	test_spec_ex_sie(parse_strict(argc - 1, argv + 1));

hmmm... maybe it would be more readable and more uniform with the other tests to parse the command line during initialization of the unit test, and set a global flag.

More uniform maybe, but I tend to dislike globals from a readability point of view. I'm inclined to keep it as is.

Quoted 7 lines
Quoted 6 lines
s390x/spec_ex-sie.c +0 -0
 out:
 	return report_summary();
 }

base-commit: 257c962f3d1b2d0534af59de4ad18764d734903a