Skip to contentSkip to conversation

Improve the output of test runners

PATCH In review Radim Krčmář 3 participants 35 messages May 11, 2016 – May 26, 2016

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover Improve the output of test runners

v3: http://www.spinics.net/lists/kvm/msg130911.html

Changes are described in each changed patch.

The output differs a bit from v3, because SKIP when QEMU didn't have a chance to run the test now prints the last line of stdout + stderr in summary.

PASS apic (14 tests)
PASS emulator (131 tests, 1 skipped)
PASS pmu (67 tests, 1 expected failures)
SKIP svm (0 tests)
SKIP taskswitch (i386 only)
PASS kvmclock_test
SKIP hyperv_synic (qemu-kvm: Property '.hv-synic' not found)

Radim Krčmář (13):
lib/report: allow test skipping
x86/*: report skipped tests
x86/unittests: remove svm-disabled
lib/string: add strncmp
lib/util: add args_parse_keyval
x86/pmu: expect failure with nmi_watchdog
lib/report: don't print 0 failed tests
scripts/runtime: consolidate summary tags
run_tests: print SUMMARY line in summary
run_tests: log stderr
scripts/runtime: skip tests that cannot run
scripts/arch-run: change QEMU failure detection
scripts/run: generalize check

 arm/run                 |  2 +-
 lib/libcflat.h          |  1 +
 lib/report.c            | 49 ++++++++++++++++++++++++-----------
 lib/string.c            | 17 ++++++++-----
 lib/string.h            |  1 +
 lib/util.c              | 17 +++++++++++++
 lib/util.h              | 10 ++++++++
 powerpc/run             |  2 +-
 run_tests.sh            | 15 ++++++-----
 scripts/arch-run.bash   |  2 +-
 scripts/mkstandalone.sh |  4 +++
 scripts/runtime.bash    | 68 ++++++++++++++++++++++++++++++++++++-------------
 x86/Makefile.common     |  1 +
 x86/apic.c              |  7 +++--
 x86/emulator.c          |  2 +-
 x86/hyperv_synic.c      |  2 +-
 x86/pku.c               |  2 +-
 x86/pmu.c               |  8 ++++--
 x86/smap.c              |  2 +-
 x86/svm.c               |  2 +-
 x86/tsc.c               |  2 +-
 x86/unittests.cfg       |  9 +------
 22 files changed, 156 insertions(+), 69 deletions(-)
Signature · 1 line
2.8.2
#1 lore raw

PATCH v4 1/13 lib/report: allow test skipping

We can now explicitly mark a unit-test as skipped.
If all unit-tests were skipped, the whole test is reported as skipped as well. This also includes the case where no tests were run, but still ended with report_summary().

When the whole test is skipped, ./run_tests.sh prints yellow "SKIP" instead of green "PASS".

Return value of 77 is used to please Autotools. I also renamed few things in reporting code and chose to refactor a logic while at it.

---
 lib/libcflat.h       |  1 +
 lib/report.c         | 45 +++++++++++++++++++++++++++++++--------------
 scripts/runtime.bash |  2 ++
 3 files changed, 34 insertions(+), 14 deletions(-)
lib/libcflat.h +1 -0
index df50615b4366..582e3fc60e28 100644
@@ -79,6 +79,7 @@ extern void report_prefix_pop(void);
 extern void report(const char *msg_fmt, bool pass, ...);
 extern void report_xfail(const char *msg_fmt, bool xfail, bool pass, ...);
 extern void report_abort(const char *msg_fmt, ...);
+extern void report_skip(const char *msg_fmt, ...);
 extern int report_summary(void);
 
 extern void dump_stack(void);
lib/report.c +31 -14

84 lines not on this page · raw message

scripts/runtime.bash +2 -0
index 0e055f0dddc2..ed073721216c 100644
@@ -51,6 +51,8 @@ function run()
 
     if [ $ret -eq 0 ]; then
         echo -e "\e[32mPASS\e[0m $1"
+    elif [ $ret -eq 77 ]; then
+        echo -e "\e[33mSKIP\e[0m $1"
     elif [ $ret -eq 124 ]; then
         echo -e "\e[31mFAIL\e[0m $1 (timeout; duration=$timeout)"
     else
Signature · 1 line
2.8.2
#2 lore raw

PATCH v4 2/13 x86/*: report skipped tests

In reply to Radim Krčmář

No care to consistency or exhaustivity was given.

Drew pointed out that tscdeadline_latency.c doesn't report skipped tests. tscdeadline_latency needs complete refactoring and is not run with ./run_tests, so I ignored it.

---
v4: explained the reason behind ignoring v3 review

 x86/apic.c         | 7 +++----
 x86/emulator.c     | 2 +-
 x86/hyperv_synic.c | 2 +-
 x86/pku.c          | 2 +-
 x86/pmu.c          | 2 +-
 x86/smap.c         | 2 +-
 x86/svm.c          | 2 +-
 x86/tsc.c          | 2 +-
 8 files changed, 10 insertions(+), 11 deletions(-)
x86/apic.c +3 -4
index 61a0a7659805..8b08a950a0c7 100644
@@ -27,7 +27,7 @@ static void tsc_deadline_timer_isr(isr_regs_t *regs)
     ++tdt_count;
 }
 
-static void start_tsc_deadline_timer(void)
+static void __test_tsc_deadline_timer(void)
 {
     handle_irq(TSC_DEADLINE_TIMER_VECTOR, tsc_deadline_timer_isr);
     irq_enable();
@@ -45,7 +45,6 @@ static int enable_tsc_deadline_timer(void)
     if (cpuid(1).c & (1 << 24)) {
         lvtt = TSC_DEADLINE_TIMER_MODE | TSC_DEADLINE_TIMER_VECTOR;
         apic_write(APIC_LVTT, lvtt);
-        start_tsc_deadline_timer();
         return 1;
     } else {
         return 0;
@@ -55,9 +54,9 @@ static int enable_tsc_deadline_timer(void)
 static void test_tsc_deadline_timer(void)
 {
     if(enable_tsc_deadline_timer()) {
-        printf("tsc deadline timer enabled\n");
+        __test_tsc_deadline_timer();
     } else {
-        printf("tsc deadline timer not detected\n");
+        report_skip("tsc deadline timer not detected");
     }
 }
 
x86/emulator.c +1 -1
index 3730721258bc..8d262d832112 100644
@@ -1082,7 +1082,7 @@ static void illegal_movbe_handler(struct ex_regs *regs)
 static void test_illegal_movbe(void)
 {
 	if (!(cpuid(1).c & (1 << 22))) {
-		printf("SKIP: illegal movbe\n");
+		report_skip("illegal movbe");
 		return;
 	}
 
x86/hyperv_synic.c +1 -1
index 6e088944be1f..f5eb82bb7336 100644
@@ -202,7 +202,7 @@ int main(int ac, char **av)
 
         report("Hyper-V SynIC test", ok);
     } else {
-        report("Hyper-V SynIC is not supported", true);
+        report_skip("Hyper-V SynIC is not supported");
     }
 
     return report_summary();
x86/pku.c +1 -1
index df51d1b59048..6214f0bc151f 100644
@@ -68,7 +68,7 @@ int main(int ac, char **av)
 
     if (!(cpuid_indexed(7, 0).c & (1 << X86_FEATURE_PKU))) {
         printf("PKU not enabled, aborting\n");
-        abort();
+        return report_summary();
     }
 
     setup_vm();
x86/pmu.c +1 -1
index 03f80190bb25..c68980044dee 100644
@@ -387,7 +387,7 @@ int main(int ac, char **av)
 
 	if (!eax.split.version_id) {
 		printf("No pmu is detected!\n");
-		return 1;
+		return report_summary();
 	}
 	printf("PMU version:         %d\n", eax.split.version_id);
 	printf("GP counters:         %d\n", eax.split.num_counters);
x86/smap.c +1 -1
index 69e71864dc9b..c9de081a474b 100644
@@ -93,7 +93,7 @@ int main(int ac, char **av)
 
 	if (!(cpuid_indexed(7, 0).b & (1 << X86_FEATURE_SMAP))) {
 		printf("SMAP not enabled, aborting\n");
-		abort();
+		return report_summary();
 	}
 
 	setup_vm();
x86/svm.c +1 -1
index 934b2ae91fa8..301cf8cb2d6b 100644
@@ -1064,7 +1064,7 @@ int main(int ac, char **av)
 
     if (!(cpuid(0x80000001).c & 4)) {
         printf("SVM not availble\n");
-        return 0;
+        return report_summary();
     }
 
     setup_svm();
x86/tsc.c +1 -1
index 6f89c911c2bc..62450e71725c 100644
@@ -43,5 +43,5 @@ int main()
 		test_rdtscp(0x100);
 	} else
 		printf("rdtscp not supported\n");
-	return 0;
+	return report_summary();
 }
Signature · 1 line
2.8.2
maintainer
#3 lore raw

Re: [kvm-unit-tests PATCH v4 02/13] x86/*: report skipped tests

Review

Quoted 5 lines · Radim Krčmář
 
     if (!(cpuid_indexed(7, 0).c & (1 << X86_FEATURE_PKU))) {
         printf("PKU not enabled, aborting\n");
(quoted diff) +1 -1
-        abort();
+        return report_summary();

Needs report_skip?

x86/pmu.c int main(int ac, char **av) · line 390

Quoted 13 lines
     }
 
     setup_vm();
x86/pmu.c +1 -1
index 03f80190bb25..c68980044dee 100644
@@ -387,7 +387,7 @@ int main(int ac, char **av)
 
 	if (!eax.split.version_id) {
 		printf("No pmu is detected!\n");
-		return 1;
+		return report_summary();

Needs report_skip?

x86/smap.c int main(int ac, char **av) · line 96

Quoted 13 lines
x86/pmu.c +0 -0
 	}
 	printf("PMU version:         %d\n", eax.split.version_id);
 	printf("GP counters:         %d\n", eax.split.num_counters);
x86/smap.c +1 -1
index 69e71864dc9b..c9de081a474b 100644
@@ -93,7 +93,7 @@ int main(int ac, char **av)
 
 	if (!(cpuid_indexed(7, 0).b & (1 << X86_FEATURE_SMAP))) {
 		printf("SMAP not enabled, aborting\n");
-		abort();
+		return report_summary();

Needs report_skip?

x86/svm.c int main(int ac, char **av) · line 1067

Quoted 13 lines
x86/smap.c +0 -0
 	}
 
 	setup_vm();
x86/svm.c +1 -1
index 934b2ae91fa8..301cf8cb2d6b 100644
@@ -1064,7 +1064,7 @@ int main(int ac, char **av)
 
     if (!(cpuid(0x80000001).c & 4)) {
         printf("SVM not availble\n");
-        return 0;
+        return report_summary();

Needs report_skip?

x86/tsc.c int main() · line 45

Quoted 11 lines
x86/svm.c +0 -0
     }
 
     setup_svm();
x86/tsc.c +0 -0
index 6f89c911c2bc..62450e71725c 100644
@@ -43,5 +43,5 @@ int main()
 		test_rdtscp(0x100);
 	} else
 		printf("rdtscp not supported\n");

Needs report_skip?

x86/tsc.c int main() · line 46

Quoted 2 lines
x86/tsc.c +1 -1
-	return 0;
+	return report_summary();

Just sending a fixup patch is enough.

Paolo

#4 lore raw

Re: [kvm-unit-tests PATCH v4 02/13] x86/*: report skipped tests

2016-05-17 14:19+0200, Paolo Bonzini:

Quoted 39 lines · Radim Krčmář

Review

Quoted 4 lines
     if (!(cpuid_indexed(7, 0).c & (1 << X86_FEATURE_PKU))) {
         printf("PKU not enabled, aborting\n");
(quoted diff) +1 -1
-        abort();
+        return report_summary();

Needs report_skip?

x86/pmu.c int main(int ac, char **av) · line 389

Quoted 6 lines
x86/pmu.c +1 -1
@@ -387,7 +387,7 @@ int main(int ac, char **av)
 	if (!eax.split.version_id) {
 		printf("No pmu is detected!\n");
-		return 1;
+		return report_summary();

Needs report_skip?

x86/smap.c int main(int ac, char **av) · line 95

Quoted 6 lines
x86/smap.c +1 -1
@@ -93,7 +93,7 @@ int main(int ac, char **av)
 	if (!(cpuid_indexed(7, 0).b & (1 << X86_FEATURE_SMAP))) {
 		printf("SMAP not enabled, aborting\n");
-		abort();
+		return report_summary();

Needs report_skip?

x86/svm.c

Quoted 5 lines
x86/svm.c +1 -1
     if (!(cpuid(0x80000001).c & 4)) {
         printf("SVM not availble\n");
-        return 0;
+        return report_summary();

Needs report_skip?

x86/tsc.c

Quoted 2 lines
x86/tsc.c +0 -0
 		printf("rdtscp not supported\n");

Needs report_skip?

Quoted 4 lines

x86/tsc.c

Quoted 2 lines
x86/tsc.c +1 -1
-	return 0;
+	return report_summary();

Just sending a fixup patch is enough.

report_skip is not needed, because the a test that ended in report_summary without any report is considered as skipped.

The fixup below turns printfs to report_skip is below. The difference is that summary will now print

SKIP pku (1 tests, 1 skipped)

instead of previous

SKIP pku (0 tests)

I like "0 tests" summary better and only x86/hyperv_synic does the opposite, so a fix could go both ways.

---8<---

x86/pku.c +1 -1
index 6214f0bc151f..4b418fdc8a20 100644
@@ -67,7 +67,7 @@ int main(int ac, char **av)
     unsigned int pkru_wd = 0x20;
 
     if (!(cpuid_indexed(7, 0).c & (1 << X86_FEATURE_PKU))) {
-        printf("PKU not enabled, aborting\n");
+        report_skip("PKU not enabled\n");
         return report_summary();
     }
 
x86/pmu.c +1 -1
index b0f9f81af68e..308274761336 100644
@@ -390,7 +390,7 @@ int main(int ac, char **av)
 	host_nmi_watchdog = atol_keyval(ac, av, "host_nmi_watchdog");
 
 	if (!eax.split.version_id) {
-		printf("No pmu is detected!\n");
+		report_skip("No pmu is detected!\n");
 		return report_summary();
 	}
 	printf("PMU version:         %d\n", eax.split.version_id);
x86/smap.c +1 -1
index c9de081a474b..23722beb00f5 100644
@@ -92,7 +92,7 @@ int main(int ac, char **av)
 	unsigned long i;
 
 	if (!(cpuid_indexed(7, 0).b & (1 << X86_FEATURE_SMAP))) {
-		printf("SMAP not enabled, aborting\n");
+		report_skip("SMAP not enabled\n");
 		return report_summary();
 	}
 
x86/svm.c +1 -1
index 301cf8cb2d6b..005cbf7c3352 100644
@@ -1063,7 +1063,7 @@ int main(int ac, char **av)
     smp_init();
 
     if (!(cpuid(0x80000001).c & 4)) {
-        printf("SVM not availble\n");
+        report_skip("SVM not availble\n");
         return report_summary();
     }
 
x86/tsc.c +1 -1
index 62450e71725c..33fdc114c04c 100644
@@ -42,6 +42,6 @@ int main()
 		test_rdtscp(10);
 		test_rdtscp(0x100);
 	} else
-		printf("rdtscp not supported\n");
+		report_skip("rdtscp not supported\n");
 	return report_summary();
 }
#5 lore raw

Re: [kvm-unit-tests PATCH v4 02/13] x86/*: report skipped tests

2016-05-25 19:19+0200, Radim Krčmář:

Quoted 10 lines

is that summary will now print

SKIP pku (1 tests, 1 skipped)

instead of previous

SKIP pku (0 tests)

I like "0 tests" summary better and only x86/hyperv_synic does the opposite, so a fix could go both ways.

The fixup below does the other way. And the commit message could read "Some care to consistency [...]" with either of them. :)

---8<---

x86/hyperv_synic.c +1 -1
index f5eb82bb7336..5a06fb724a87 100644
@@ -202,7 +202,7 @@ int main(int ac, char **av)
 
         report("Hyper-V SynIC test", ok);
     } else {
-        report_skip("Hyper-V SynIC is not supported");
+        printf("Hyper-V SynIC is not supported");
     }
 
     return report_summary();
x86/pku.c +1 -1
index 6214f0bc151f..488cce3c6fdf 100644
@@ -67,7 +67,7 @@ int main(int ac, char **av)
     unsigned int pkru_wd = 0x20;
 
     if (!(cpuid_indexed(7, 0).c & (1 << X86_FEATURE_PKU))) {
-        printf("PKU not enabled, aborting\n");
+        printf("PKU not enabled\n");
         return report_summary();
     }
 
x86/smap.c +1 -1
index c9de081a474b..69dd80915c4a 100644
@@ -92,7 +92,7 @@ int main(int ac, char **av)
 	unsigned long i;
 
 	if (!(cpuid_indexed(7, 0).b & (1 << X86_FEATURE_SMAP))) {
-		printf("SMAP not enabled, aborting\n");
+		printf("SMAP not enabled\n");
 		return report_summary();
 	}
 
maintainer
#6 lore raw

Re: [kvm-unit-tests PATCH v4 02/13] x86/*: report skipped tests

Quoted 31 lines · Radim Krčmář
x86/hyperv_synic.c +1 -1
index f5eb82bb7336..5a06fb724a87 100644
@@ -202,7 +202,7 @@ int main(int ac, char **av)
 
         report("Hyper-V SynIC test", ok);
     } else {
-        report_skip("Hyper-V SynIC is not supported");
+        printf("Hyper-V SynIC is not supported");
     }
 
     return report_summary();
x86/pku.c +1 -1
index 6214f0bc151f..488cce3c6fdf 100644
@@ -67,7 +67,7 @@ int main(int ac, char **av)
     unsigned int pkru_wd = 0x20;
 
     if (!(cpuid_indexed(7, 0).c & (1 << X86_FEATURE_PKU))) {
-        printf("PKU not enabled, aborting\n");
+        printf("PKU not enabled\n");
         return report_summary();
     }
 
x86/smap.c +0 -0
index c9de081a474b..69dd80915c4a 100644

x86/smap.c int main(int ac, char **av) · line 98

Quoted 8 lines
x86/smap.c +1 -1
@@ -92,7 +92,7 @@ int main(int ac, char **av)
 	unsigned long i;
 
 	if (!(cpuid_indexed(7, 0).b & (1 << X86_FEATURE_SMAP))) {
-		printf("SMAP not enabled, aborting\n");
+		printf("SMAP not enabled\n");
 		return report_summary();
 	}
 

This one looks good.

Thanks,

Paolo

#7 lore raw

PATCH v4 3/13 x86/unittests: remove svm-disabled

In reply to Radim Krčmář

svm-disabled says SKIP after the last patch. It's better than the FAIL it returned before (QEMU warns, so return 0 is treated as an error), but I don't think that the test is useful enough to be fixed to return PASS.

---
 x86/unittests.cfg | 6 ------
 1 file changed, 6 deletions(-)
x86/unittests.cfg +0 -6
index fcee6f98c598..60747cfca94e 100644
@@ -159,12 +159,6 @@ smp = 2
 extra_params = -cpu qemu64,+svm
 arch = x86_64
 
-[svm-disabled]
-file = svm.flat
-smp = 2
-extra_params = -cpu qemu64,-svm
-arch = x86_64
-
 [taskswitch]
 file = taskswitch.flat
 arch = i386
Signature · 1 line
2.8.2
#8 lore raw

PATCH v4 4/13 lib/string: add strncmp

In reply to Radim Krčmář

---
v4: new

 lib/string.c | 17 ++++++++++-------
 lib/string.h |  1 +
 2 files changed, 11 insertions(+), 7 deletions(-)
lib/string.c +10 -7
index e7bcfe945fcf..ee93e25e9821 100644
@@ -26,15 +26,18 @@ char *strcpy(char *dest, const char *src)
     return strcat(dest, src);
 }
 
+int strncmp(const char *a, const char *b, size_t n)
+{
+    for (; n--; ++a, ++b)
+        if (*a != *b || *a == '\0')
+            return *a - *b;
+
+    return 0;
+}
+
 int strcmp(const char *a, const char *b)
 {
-    while (*a == *b) {
-	if (*a == '\0') {
-	    break;
-	}
-	++a, ++b;
-    }
-    return *a - *b;
+    return strncmp(a, b, SIZE_MAX);
 }
 
 char *strchr(const char *s, int c)
lib/string.h +1 -0
index 4e24f54d9e23..2391013ad2b1 100644
@@ -5,6 +5,7 @@ extern unsigned long strlen(const char *buf);
 extern char *strcat(char *dest, const char *src);
 extern char *strcpy(char *dest, const char *src);
 extern int strcmp(const char *a, const char *b);
+extern int strncmp(const char *a, const char *b, size_t n);
 extern char *strchr(const char *s, int c);
 extern char *strstr(const char *haystack, const char *needle);
 extern void *memset(void *s, int c, size_t n);
Signature · 1 line
2.8.2
Reviewed-by on v4 4/13
#9 lore raw

Re: [kvm-unit-tests PATCH v4 04/13] lib/string: add strncmp

Quoted 7 lines · Radim Krčmář

---
v4: new

 lib/string.c | 17 ++++++++++-------
 lib/string.h |  1 +
 2 files changed, 11 insertions(+), 7 deletions(-)
Quoted 46 lines
lib/string.c +10 -7
index e7bcfe945fcf..ee93e25e9821 100644
@@ -26,15 +26,18 @@ char *strcpy(char *dest, const char *src)
     return strcat(dest, src);
 }
 
+int strncmp(const char *a, const char *b, size_t n)
+{
+    for (; n--; ++a, ++b)
+        if (*a != *b || *a == '\0')
+            return *a - *b;
+
+    return 0;
+}
+
 int strcmp(const char *a, const char *b)
 {
-    while (*a == *b) {
-	if (*a == '\0') {
-	    break;
-	}
-	++a, ++b;
-    }
-    return *a - *b;
+    return strncmp(a, b, SIZE_MAX);
 }
 
 char *strchr(const char *s, int c)
lib/string.h +1 -0
index 4e24f54d9e23..2391013ad2b1 100644
@@ -5,6 +5,7 @@ extern unsigned long strlen(const char *buf);
 extern char *strcat(char *dest, const char *src);
 extern char *strcpy(char *dest, const char *src);
 extern int strcmp(const char *a, const char *b);
+extern int strncmp(const char *a, const char *b, size_t n);
 extern char *strchr(const char *s, int c);
 extern char *strstr(const char *haystack, const char *needle);
 extern void *memset(void *s, int c, size_t n);
Signature · 1 line
2.8.2
#10 lore raw

PATCH v4 5/13 lib/util: add args_parse_keyval

In reply to Radim Krčmář

The function parses command line arguments in "key=val" format, and treats "key" as "key=1".

---
v4: new

 lib/util.c | 17 +++++++++++++++++
 lib/util.h | 10 ++++++++++
 2 files changed, 27 insertions(+)
lib/util.c +17 -0
index 69b18100c972..8b33d474f4c0 100644
@@ -16,3 +16,20 @@ int parse_keyval(char *s, long *val)
 	*val = atol(p+1);
 	return p - s;
 }
+
+long args_parse_keyval(int argc, char **argv, char *key)
+{
+	int i;
+	size_t keylen = strlen(key);
+
+	for (i = 1; i < argc; i++) {
+		if (keylen > 0 && strncmp(argv[i], key, keylen - 1))
+			continue;
+		if (argv[i][keylen] == '\0')
+			return 1;
+		if (argv[i][keylen] == '=')
+			return atol(argv[i] + keylen + 1);
+	}
+
+	return 0;
+}
lib/util.h +10 -0
index 4c4b44132277..d475b058526b 100644
@@ -20,4 +20,14 @@
  */
 extern int parse_keyval(char *s, long *val);
 
+/*
+ * argc and argv are standard C arguments to main().
+ * args_parse_keyval looks for an element of argv that matches the key.
+ * Returns val interpreted as a long if the element is in key=val format.
+ * Returns 1 if the element is key.
+ * Returns 0 otherwise.
+ *
+ */
+long args_parse_keyval(int argc, char **argv, char *key);
+
 #endif
Signature · 1 line
2.8.2
#11 lore raw

Re: [kvm-unit-tests PATCH v4 05/13] lib/util: add args_parse_keyval

Quoted 16 lines · Radim Krčmář

The function parses command line arguments in "key=val" format, and treats "key" as "key=1".

---
v4: new

 lib/util.c | 17 +++++++++++++++++
 lib/util.h | 10 ++++++++++
 2 files changed, 27 insertions(+)
lib/util.c +0 -0
index 69b18100c972..8b33d474f4c0 100644

lib/util.c int parse_keyval(char *s, long *val) · line 21

Quoted 6 lines
lib/util.c +3 -0
@@ -16,3 +16,20 @@ int parse_keyval(char *s, long *val)
 	*val = atol(p+1);
 	return p - s;
 }
+
+long args_parse_keyval(int argc, char **argv, char *key)
+{

I like this better than parse_keyval, except for...

lib/util.c int parse_keyval(char *s, long *val) · line 34

Quoted 13 lines
lib/util.c +13 -0
+	int i;
+	size_t keylen = strlen(key);
+
+	for (i = 1; i < argc; i++) {
+		if (keylen > 0 && strncmp(argv[i], key, keylen - 1))
+			continue;
+		if (argv[i][keylen] == '\0')
+			return 1;
+		if (argv[i][keylen] == '=')
+			return atol(argv[i] + keylen + 1);
+	}
+
+	return 0;

...this. Here we have ambiguous results. Either key was there and had a value of 0, or wasn't there, and we still get zero. How about merging the two, and then fixing-up the arm and powerpc uses of the old one. I'd drop the "args_" from the name then too.

Thanks,
drew

Quoted 27 lines
lib/util.c +1 -0
+}
lib/util.h +10 -0
index 4c4b44132277..d475b058526b 100644
@@ -20,4 +20,14 @@
  */
 extern int parse_keyval(char *s, long *val);
 
+/*
+ * argc and argv are standard C arguments to main().
+ * args_parse_keyval looks for an element of argv that matches the key.
+ * Returns val interpreted as a long if the element is in key=val format.
+ * Returns 1 if the element is key.
+ * Returns 0 otherwise.
+ *
+ */
+long args_parse_keyval(int argc, char **argv, char *key);
+
 #endif
Signature · 6 lines
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#12 lore raw

Re: [kvm-unit-tests PATCH v4 05/13] lib/util: add args_parse_keyval

2016-05-11 18:58+0200, Andrew Jones:

Quoted 26 lines · Radim Krčmář
Quoted 16 lines

The function parses command line arguments in "key=val" format, and treats "key" as "key=1".

---
v4: new

 lib/util.c | 17 +++++++++++++++++
 lib/util.h | 10 ++++++++++
 2 files changed, 27 insertions(+)
lib/util.c +0 -0
index 69b18100c972..8b33d474f4c0 100644

lib/util.c int parse_keyval(char *s, long *val) · line 21

Quoted 6 lines
lib/util.c +3 -0
@@ -16,3 +16,20 @@ int parse_keyval(char *s, long *val)
 	*val = atol(p+1);
 	return p - s;
 }
+
+long args_parse_keyval(int argc, char **argv, char *key)
+{

I like this better than parse_keyval, except for...

Quoted 16 lines

lib/util.c int parse_keyval(char *s, long *val) · line 34

Quoted 13 lines
lib/util.c +13 -0
+	int i;
+	size_t keylen = strlen(key);
+
+	for (i = 1; i < argc; i++) {
+		if (keylen > 0 && strncmp(argv[i], key, keylen - 1))
+			continue;
+		if (argv[i][keylen] == '\0')
+			return 1;
+		if (argv[i][keylen] == '=')
+			return atol(argv[i] + keylen + 1);
+	}
+
+	return 0;

...this. Here we have ambiguous results. Either key was there and had a value of 0, or wasn't there, and we still get zero.

Yes, I implied a boolean key.

Quoted 3 lines

How about merging the two, and then fixing-up the arm and powerpc uses of the old one. I'd drop the "args_" from the name then too.

Seems reasonable. I'll make a new series:
[1/3] add strncmp
[2/3] add a slightly modified args_parse_keyval,
int __parse_keyval(int argc, char **argv, char *key, long *val) that will return -1/0/1 on !key/key/key=val
[3/3] replace parse_keyval with renamed __parse_keyval

([2/3] and [3/3] may be squished) The series will depend on your "make argv[0] the program name" and v5 of mine will depend on it.

#13 lore raw

Re: [kvm-unit-tests PATCH v4 05/13] lib/util: add args_parse_keyval

In reply to Radim Krčmář
Quoted 16 lines · Radim Krčmář

The function parses command line arguments in "key=val" format, and treats "key" as "key=1".

---
v4: new

 lib/util.c | 17 +++++++++++++++++
 lib/util.h | 10 ++++++++++
 2 files changed, 27 insertions(+)
lib/util.c +0 -0
index 69b18100c972..8b33d474f4c0 100644

lib/util.c int parse_keyval(char *s, long *val) · line 25

Quoted 10 lines
lib/util.c +7 -0
@@ -16,3 +16,20 @@ int parse_keyval(char *s, long *val)
 	*val = atol(p+1);
 	return p - s;
 }
+
+long args_parse_keyval(int argc, char **argv, char *key)
+{
+	int i;
+	size_t keylen = strlen(key);
+
+	for (i = 1; i < argc; i++) {

Forgot to mention that I like this 'i = 1' here because it's motivation to merge a series[*] I have in flight :-)

[*] http://www.spinics.net/lists/kvm/msg131243.html

Quoted 36 lines
lib/util.c +10 -0
+		if (keylen > 0 && strncmp(argv[i], key, keylen - 1))
+			continue;
+		if (argv[i][keylen] == '\0')
+			return 1;
+		if (argv[i][keylen] == '=')
+			return atol(argv[i] + keylen + 1);
+	}
+
+	return 0;
+}
lib/util.h +10 -0
index 4c4b44132277..d475b058526b 100644
@@ -20,4 +20,14 @@
  */
 extern int parse_keyval(char *s, long *val);
 
+/*
+ * argc and argv are standard C arguments to main().
+ * args_parse_keyval looks for an element of argv that matches the key.
+ * Returns val interpreted as a long if the element is in key=val format.
+ * Returns 1 if the element is key.
+ * Returns 0 otherwise.
+ *
+ */
+long args_parse_keyval(int argc, char **argv, char *key);
+
 #endif
Signature · 6 lines
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#14 lore raw

PATCH v4 6/13 x86/pmu: expect failure with nmi_watchdog

In reply to Radim Krčmář

Host's nmi_watchdog takes one slot, making the "all counters" unit-test fail. We know exactly what happens, mark it as expected failure.

PMU test is now executed regardless of host_nmi_watchdog.

---
v4: improved command line parsing [Drew]

 x86/Makefile.common | 1 +
 x86/pmu.c           | 6 +++++-
 x86/unittests.cfg   | 3 +--
 3 files changed, 7 insertions(+), 3 deletions(-)
x86/Makefile.common +1 -0
index 356d879a986b..4951210f3331 100644
@@ -3,6 +3,7 @@
 all: test_cases
 
 cflatobjs += lib/pci.o
+cflatobjs += lib/util.o
 cflatobjs += lib/x86/io.o
 cflatobjs += lib/x86/smp.o
 cflatobjs += lib/x86/vm.o
x86/pmu.c +5 -1
index c68980044dee..a4b88b410904 100644
@@ -8,6 +8,7 @@
 #include "x86/vm.h"
 
 #include "libcflat.h"
+#include <util.h>
 #include <stdint.h>
 
 #define FIXED_CNT_INDEX 32
@@ -92,6 +93,7 @@ struct pmu_event {
 };
 
 static int num_counters;
+static bool host_nmi_watchdog;
 
 char *buf;
 
@@ -291,7 +293,7 @@ static void check_counters_many(void)
 		if (!verify_counter(&cnt[i]))
 			break;
 
-	report("all counters", i == n);
+	report_xfail("all counters", host_nmi_watchdog, i == n);
 }
 
 static void check_counter_overflow(void)
@@ -385,6 +387,8 @@ int main(int ac, char **av)
 	ebx.full = id.b;
 	edx.full = id.d;
 
+	host_nmi_watchdog = args_parse_keyval(ac, av, "host_nmi_watchdog");
+
 	if (!eax.split.version_id) {
 		printf("No pmu is detected!\n");
 		return report_summary();
x86/unittests.cfg +1 -2
index 60747cfca94e..3852b40a2927 100644
@@ -121,8 +121,7 @@ file = msr.flat
 
 [pmu]
 file = pmu.flat
-extra_params = -cpu host
-check = /proc/sys/kernel/nmi_watchdog=0
+extra_params = -cpu host -append "host_nmi_watchdog=`cat /proc/sys/kernel/nmi_watchdog`"
 
 [port80]
 file = port80.flat
Signature · 1 line
2.8.2
Reviewed-by on v4 6/13
#15 lore raw

Re: [kvm-unit-tests PATCH v4 06/13] x86/pmu: expect failure with nmi_watchdog

Quoted 5 lines · Radim Krčmář

Host's nmi_watchdog takes one slot, making the "all counters" unit-test fail. We know exactly what happens, mark it as expected failure.

PMU test is now executed regardless of host_nmi_watchdog.

Quoted 8 lines

---
v4: improved command line parsing [Drew]

 x86/Makefile.common | 1 +
 x86/pmu.c           | 6 +++++-
 x86/unittests.cfg   | 3 +--
 3 files changed, 7 insertions(+), 3 deletions(-)
Quoted 72 lines
x86/Makefile.common +1 -0
index 356d879a986b..4951210f3331 100644
@@ -3,6 +3,7 @@
 all: test_cases
 
 cflatobjs += lib/pci.o
+cflatobjs += lib/util.o
 cflatobjs += lib/x86/io.o
 cflatobjs += lib/x86/smp.o
 cflatobjs += lib/x86/vm.o
x86/pmu.c +5 -1
index c68980044dee..a4b88b410904 100644
@@ -8,6 +8,7 @@
 #include "x86/vm.h"
 
 #include "libcflat.h"
+#include <util.h>
 #include <stdint.h>
 
 #define FIXED_CNT_INDEX 32
@@ -92,6 +93,7 @@ struct pmu_event {
 };
 
 static int num_counters;
+static bool host_nmi_watchdog;
 
 char *buf;
 
@@ -291,7 +293,7 @@ static void check_counters_many(void)
 		if (!verify_counter(&cnt[i]))
 			break;
 
-	report("all counters", i == n);
+	report_xfail("all counters", host_nmi_watchdog, i == n);
 }
 
 static void check_counter_overflow(void)
@@ -385,6 +387,8 @@ int main(int ac, char **av)
 	ebx.full = id.b;
 	edx.full = id.d;
 
+	host_nmi_watchdog = args_parse_keyval(ac, av, "host_nmi_watchdog");
+
 	if (!eax.split.version_id) {
 		printf("No pmu is detected!\n");
 		return report_summary();
x86/unittests.cfg +1 -2
index 60747cfca94e..3852b40a2927 100644
@@ -121,8 +121,7 @@ file = msr.flat
 
 [pmu]
 file = pmu.flat
-extra_params = -cpu host
-check = /proc/sys/kernel/nmi_watchdog=0
+extra_params = -cpu host -append "host_nmi_watchdog=`cat /proc/sys/kernel/nmi_watchdog`"
 
 [port80]
 file = port80.flat
Signature · 6 lines
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#16 lore raw

PATCH v4 7/13 lib/report: don't print 0 failed tests

In reply to Radim Krčmář
---
 lib/report.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/report.c +3 -1
index 430b2aeaecbd..4cd75534f978 100644
@@ -95,7 +95,9 @@ int report_summary(void)
 {
 	spin_lock(&lock);
 
-	printf("\nSUMMARY: %d tests, %d unexpected failures", tests, failures);
+	printf("\nSUMMARY: %d tests", tests);
+	if (failures)
+		printf(", %d unexpected failures", failures);
 	if (xfailures)
 		printf(", %d expected failures", xfailures);
 	if (skipped)
Signature · 1 line
2.8.2
#17 lore raw

PATCH v4 8/13 scripts/runtime: consolidate summary tags

In reply to Radim Krčmář

Turn skip into yellow SKIP and add reusable definitions of all tags.

---
 scripts/runtime.bash | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
scripts/runtime.bash +10 -6
index ed073721216c..8d374103a71c 100644
@@ -2,6 +2,10 @@
 : ${MAX_SMP:=$(getconf _NPROCESSORS_CONF)}
 : ${TIMEOUT:=90s}
 
+PASS() { echo -ne "\e[32mPASS\e[0m"; }
+SKIP() { echo -ne "\e[33mSKIP\e[0m"; }
+FAIL() { echo -ne "\e[31mFAIL\e[0m"; }
+
 function run()
 {
     local testname="$1"
@@ -23,7 +27,7 @@ function run()
     fi
 
     if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then
-        echo "skip $1 ($arch only)"
+        echo "`SKIP` $1 ($arch only)"
         return 2
     fi
 
@@ -34,7 +38,7 @@ function run()
         path=${check_param%%=*}
         value=${check_param#*=}
         if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then
-            echo "skip $1 ($path not equal to $value)"
+            echo "`SKIP` $1 ($path not equal to $value)"
             return 2
         fi
     done
@@ -50,13 +54,13 @@ function run()
     ret=$?
 
     if [ $ret -eq 0 ]; then
-        echo -e "\e[32mPASS\e[0m $1"
+        echo "`PASS` $1"
     elif [ $ret -eq 77 ]; then
-        echo -e "\e[33mSKIP\e[0m $1"
+        echo "`SKIP` $1"
     elif [ $ret -eq 124 ]; then
-        echo -e "\e[31mFAIL\e[0m $1 (timeout; duration=$timeout)"
+        echo "`FAIL` $1 (timeout; duration=$timeout)"
     else
-        echo -e "\e[31mFAIL\e[0m $1"
+        echo "`FAIL` $1"
     fi
 
     return $ret
Signature · 1 line
2.8.2
maintainer
#18 lore raw

Re: [kvm-unit-tests PATCH v4 08/13] scripts/runtime: consolidate summary tags

Quoted 13 lines · Radim Krčmář

Turn skip into yellow SKIP and add reusable definitions of all tags.

---
 scripts/runtime.bash | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
scripts/runtime.bash +0 -0
index ed073721216c..8d374103a71c 100644

scripts/runtime.bash line 7

Quoted 6 lines
scripts/runtime.bash +3 -0
@@ -2,6 +2,10 @@
 : ${MAX_SMP:=$(getconf _NPROCESSORS_CONF)}
 : ${TIMEOUT:=90s}
 
+PASS() { echo -ne "\e[32mPASS\e[0m"; }
+SKIP() { echo -ne "\e[33mSKIP\e[0m"; }
+FAIL() { echo -ne "\e[31mFAIL\e[0m"; }

If you use for example $'\e[32mPASS\e[0m', then you can use variables instead of functions.

Quoted 41 lines
scripts/runtime.bash +7 -6
+
 function run()
 {
     local testname="$1"
@@ -23,7 +27,7 @@ function run()
     fi
 
     if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then
-        echo "skip $1 ($arch only)"
+        echo "`SKIP` $1 ($arch only)"
         return 2
     fi
 
@@ -34,7 +38,7 @@ function run()
         path=${check_param%%=*}
         value=${check_param#*=}
         if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then
-            echo "skip $1 ($path not equal to $value)"
+            echo "`SKIP` $1 ($path not equal to $value)"
             return 2
         fi
     done
@@ -50,13 +54,13 @@ function run()
     ret=$?
 
     if [ $ret -eq 0 ]; then
-        echo -e "\e[32mPASS\e[0m $1"
+        echo "`PASS` $1"
     elif [ $ret -eq 77 ]; then
-        echo -e "\e[33mSKIP\e[0m $1"
+        echo "`SKIP` $1"
     elif [ $ret -eq 124 ]; then
-        echo -e "\e[31mFAIL\e[0m $1 (timeout; duration=$timeout)"
+        echo "`FAIL` $1 (timeout; duration=$timeout)"
     else
-        echo -e "\e[31mFAIL\e[0m $1"
+        echo "`FAIL` $1"
     fi
 
     return $ret
#19 lore raw

Re: [kvm-unit-tests PATCH v4 08/13] scripts/runtime: consolidate summary tags

2016-05-17 14:22+0200, Paolo Bonzini:

Quoted 17 lines · Radim Krčmář
Quoted 16 lines

Turn skip into yellow SKIP and add reusable definitions of all tags.

---
 scripts/runtime.bash | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
scripts/runtime.bash +0 -0
index ed073721216c..8d374103a71c 100644
@@ -2,6 +2,10 @@
 : ${MAX_SMP:=$(getconf _NPROCESSORS_CONF)}
 : ${TIMEOUT:=90s}
 
Quoted 6 lines

scripts/runtime.bash line 7

Quoted 3 lines
scripts/runtime.bash +3 -0
+PASS() { echo -ne "\e[32mPASS\e[0m"; }
+SKIP() { echo -ne "\e[33mSKIP\e[0m"; }
+FAIL() { echo -ne "\e[31mFAIL\e[0m"; }

If you use for example $'\e[32mPASS\e[0m', then you can use variables instead of functions.

Great, thanks. A fixup is below

---8<---

scripts/runtime.bash +10 -10
index 39a9072ed103..2bbdb864c889 100644
@@ -2,9 +2,9 @@
 : ${MAX_SMP:=$(getconf _NPROCESSORS_CONF)}
 : ${TIMEOUT:=90s}
 
-PASS() { echo -ne "\e[32mPASS\e[0m"; }
-SKIP() { echo -ne "\e[33mSKIP\e[0m"; }
-FAIL() { echo -ne "\e[31mFAIL\e[0m"; }
+PASS=$'\e[32mPASS\e[0m'
+SKIP=$'\e[33mSKIP\e[0m'
+FAIL=$'\e[31mFAIL\e[0m'
 
 extract_summary()
 {
@@ -53,18 +53,18 @@ function run()
     fi
 
     if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then
-        echo "`SKIP` $1 ($arch only)"
+        echo "$SKIP $1 ($arch only)"
         return 2
     fi
 
     eval $check || {
         echo "skipped $testname (\`$check\` returned $?)" | RUNTIME_log_stderr
-        echo "`SKIP` $testname (check failed)"
+        echo "$SKIP $testname (check failed)"
         return 77
     }
 
     last_line=$(premature_failure) && {
-        echo "`SKIP` $1 ($last_line)"
+        echo "$SKIP $1 ($last_line)"
         return 77
     }
 
@@ -80,13 +80,13 @@ function run()
     ret=$?
 
     if [ $ret -eq 0 ]; then
-        echo "`PASS` $1 $summary"
+        echo "$PASS $1 $summary"
     elif [ $ret -eq 77 ]; then
-        echo "`SKIP` $1 $summary"
+        echo "$SKIP $1 $summary"
     elif [ $ret -eq 124 ]; then
-        echo "`FAIL` $1 (timeout; duration=$timeout)"
+        echo "$FAIL $1 (timeout; duration=$timeout)"
     else
-        echo "`FAIL` $1 $summary"
+        echo "$FAIL $1 $summary"
     fi
 
     return $ret
#20 lore raw

PATCH v4 9/13 run_tests: print SUMMARY line in summary

In reply to Radim Krčmář

SUMMARY line is present if the test uses lib/report. Summary contains some interesting information, so duplicating the output isn't that big of a cost. Our log redirection got more complicated, though.

---
v4:
* less ev[ai]l [Paolo]
* didn't include Drew's r-b

 run_tests.sh            | 14 ++++++++------
 scripts/mkstandalone.sh |  3 +++
 scripts/runtime.bash    | 15 ++++++++++-----
 3 files changed, 21 insertions(+), 11 deletions(-)
run_tests.sh +8 -6
index 7e0237f3aa11..b634e472a834 100755
@@ -46,13 +46,15 @@ while getopts "g:hv" opt; do
     esac
 done
 
-if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then
-	log_redir="> >(./scripts/pretty_print_stacks.py \$kernel >> test.log)"
-else
-	log_redir=">> test.log"
-fi
+RUNTIME_log_stdout () {
+    if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then
+        ./scripts/pretty_print_stacks.py $1 >> test.log
+    else
+        cat >> test.log
+    fi
+}
+
 
-RUNTIME_arch_run="./$TEST_DIR/run $log_redir"
 config=$TEST_DIR/unittests.cfg
 rm -f test.log
 printf "BUILD_HEAD=$(cat build-head)\n\n" > test.log
scripts/mkstandalone.sh +3 -0
index 26094dfba373..77793fd64c76 100755
@@ -68,6 +68,9 @@ generate_test ()
 	(echo "#!/bin/bash"
 	 cat scripts/arch-run.bash "$TEST_DIR/run") | temp_file RUNTIME_arch_run
 
+	echo "exec {stdout}>&1"
+	echo "RUNTIME_log_stdout () { cat >&\$stdout; }"
+
 	cat scripts/runtime.bash
 
 	echo "run ${args[@]}"
scripts/runtime.bash +10 -5
index 8d374103a71c..6d9d8bffb82f 100644
@@ -6,6 +6,11 @@ PASS() { echo -ne "\e[32mPASS\e[0m"; }
 SKIP() { echo -ne "\e[33mSKIP\e[0m"; }
 FAIL() { echo -ne "\e[31mFAIL\e[0m"; }
 
+extract_summary()
+{
+    tail -1 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/$/)/'
+}
+
 function run()
 {
     local testname="$1"
@@ -49,18 +54,18 @@ function run()
     fi
 
     # extra_params in the config file may contain backticks that need to be
-    # expanded, so use eval to start qemu
-    eval $cmdline
+    # expanded, so use eval to start qemu.  Same for $RUNTIME_log_stdout.
+    summary=$(eval $cmdline > >(tee >(RUNTIME_log_stdout $kernel) | extract_summary))
     ret=$?
 
     if [ $ret -eq 0 ]; then
-        echo "`PASS` $1"
+        echo "`PASS` $1 $summary"
     elif [ $ret -eq 77 ]; then
-        echo "`SKIP` $1"
+        echo "`SKIP` $1 $summary"
     elif [ $ret -eq 124 ]; then
         echo "`FAIL` $1 (timeout; duration=$timeout)"
     else
-        echo "`FAIL` $1"
+        echo "`FAIL` $1 $summary"
     fi
 
     return $ret
Signature · 1 line
2.8.2
Reviewed-by on v4 9/13
#21 lore raw

Re: [kvm-unit-tests PATCH v4 09/13] run_tests: print SUMMARY line in summary

Quoted 10 lines · Radim Krčmář

SUMMARY line is present if the test uses lib/report. Summary contains some interesting information, so duplicating the output isn't that big of a cost. Our log redirection got more complicated, though.

---
v4:
* less ev[ai]l [Paolo]
* didn't include Drew's r-b

Quoted 4 lines
 run_tests.sh            | 14 ++++++++------
 scripts/mkstandalone.sh |  3 +++
 scripts/runtime.bash    | 15 ++++++++++-----
 3 files changed, 21 insertions(+), 11 deletions(-)
Quoted 88 lines
run_tests.sh +8 -6
index 7e0237f3aa11..b634e472a834 100755
@@ -46,13 +46,15 @@ while getopts "g:hv" opt; do
     esac
 done
 
-if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then
-	log_redir="> >(./scripts/pretty_print_stacks.py \$kernel >> test.log)"
-else
-	log_redir=">> test.log"
-fi
+RUNTIME_log_stdout () {
+    if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then
+        ./scripts/pretty_print_stacks.py $1 >> test.log
+    else
+        cat >> test.log
+    fi
+}
+
 
-RUNTIME_arch_run="./$TEST_DIR/run $log_redir"
 config=$TEST_DIR/unittests.cfg
 rm -f test.log
 printf "BUILD_HEAD=$(cat build-head)\n\n" > test.log
scripts/mkstandalone.sh +3 -0
index 26094dfba373..77793fd64c76 100755
@@ -68,6 +68,9 @@ generate_test ()
 	(echo "#!/bin/bash"
 	 cat scripts/arch-run.bash "$TEST_DIR/run") | temp_file RUNTIME_arch_run
 
+	echo "exec {stdout}>&1"
+	echo "RUNTIME_log_stdout () { cat >&\$stdout; }"
+
 	cat scripts/runtime.bash
 
 	echo "run ${args[@]}"
scripts/runtime.bash +10 -5
index 8d374103a71c..6d9d8bffb82f 100644
@@ -6,6 +6,11 @@ PASS() { echo -ne "\e[32mPASS\e[0m"; }
 SKIP() { echo -ne "\e[33mSKIP\e[0m"; }
 FAIL() { echo -ne "\e[31mFAIL\e[0m"; }
 
+extract_summary()
+{
+    tail -1 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/$/)/'
+}
+
 function run()
 {
     local testname="$1"
@@ -49,18 +54,18 @@ function run()
     fi
 
     # extra_params in the config file may contain backticks that need to be
-    # expanded, so use eval to start qemu
-    eval $cmdline
+    # expanded, so use eval to start qemu.  Same for $RUNTIME_log_stdout.
+    summary=$(eval $cmdline > >(tee >(RUNTIME_log_stdout $kernel) | extract_summary))
     ret=$?
 
     if [ $ret -eq 0 ]; then
-        echo "`PASS` $1"
+        echo "`PASS` $1 $summary"
     elif [ $ret -eq 77 ]; then
-        echo "`SKIP` $1"
+        echo "`SKIP` $1 $summary"
     elif [ $ret -eq 124 ]; then
         echo "`FAIL` $1 (timeout; duration=$timeout)"
     else
-        echo "`FAIL` $1"
+        echo "`FAIL` $1 $summary"
     fi
 
     return $ret
Signature · 6 lines
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#22 lore raw

Re: [kvm-unit-tests PATCH v4 09/13] run_tests: print SUMMARY line in summary

In reply to Radim Krčmář
Quoted 1 line · Radim Krčmář

+ # expanded, so use eval to start qemu. Same for $RUNTIME_log_stdout.

Luckily the second part is not true anymore. Fixed it myself.

Paolo

Quoted 1 line

+ summary=$(eval $cmdline > >(tee >(RUNTIME_log_stdout $kernel) | extract_summary))

#23 lore raw

Re: [kvm-unit-tests PATCH v4 09/13] run_tests: print SUMMARY line in summary

2016-05-17 14:32+0200, Paolo Bonzini:

Quoted 4 lines · Radim Krčmář
Quoted 1 line

+ # expanded, so use eval to start qemu. Same for $RUNTIME_log_stdout.

Luckily the second part is not true anymore. Fixed it myself.

Thanks.

#24 lore raw

PATCH v4 10/13 run_tests: log stderr

In reply to Radim Krčmář

Summary should provide all important information.

---
v4: new

 run_tests.sh            | 1 +
 scripts/mkstandalone.sh | 1 +
 scripts/runtime.bash    | 3 ++-
 3 files changed, 4 insertions(+), 1 deletion(-)
run_tests.sh +1 -0
index b634e472a834..254129d8723c 100755
@@ -46,6 +46,7 @@ while getopts "g:hv" opt; do
     esac
 done
 
+RUNTIME_log_stderr () { cat >> test.log; }
 RUNTIME_log_stdout () {
     if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then
         ./scripts/pretty_print_stacks.py $1 >> test.log
scripts/mkstandalone.sh +1 -0
index 77793fd64c76..d2bae1922f4b 100755
@@ -70,6 +70,7 @@ generate_test ()
 
 	echo "exec {stdout}>&1"
 	echo "RUNTIME_log_stdout () { cat >&\$stdout; }"
+	echo "RUNTIME_log_stderr () { cat >&2; }"
 
 	cat scripts/runtime.bash
 
scripts/runtime.bash +2 -1
index 6d9d8bffb82f..deae077e50a1 100644
@@ -55,7 +55,8 @@ function run()
 
     # extra_params in the config file may contain backticks that need to be
     # expanded, so use eval to start qemu.  Same for $RUNTIME_log_stdout.
-    summary=$(eval $cmdline > >(tee >(RUNTIME_log_stdout $kernel) | extract_summary))
+    summary=$(eval $cmdline 2> >(RUNTIME_log_stderr) \
+                             > >(tee >(RUNTIME_log_stdout $kernel) | extract_summary))
     ret=$?
 
     if [ $ret -eq 0 ]; then
Signature · 1 line
2.8.2
#25 lore raw

PATCH v4 11/13 scripts/runtime: skip tests that cannot run

A case where QEMU won't run the kernel should be considered as skipped. Hyper-V tests used to FAIL on old QEMUs. The infamous QEMU=/dev/null FAIL streak is covered too. Some error messages in arch/run were reworded, because they are now visible in summary.

---
v4:
* clarified "kvm only" error message [Drew+Lukáš]
* used _NO_FILE_4Uhere_ instead of /dev/null [Drew]
* completely reworked output, now prints the last line

 arm/run              |  2 +-
 powerpc/run          |  2 +-
 scripts/runtime.bash | 28 +++++++++++++++++++++++++++-
 3 files changed, 29 insertions(+), 3 deletions(-)
arm/run +1 -1
index ebf703d5757c..a2f35ef6a7e6 100755
@@ -19,7 +19,7 @@ if [ -c /dev/kvm ]; then
 fi
 
 if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
-	echo "skip $TESTNAME (kvm only)"
+	echo "KVM is needed, but not available on this host"
 	exit 2
 fi
 
powerpc/run +1 -1
index 56698e622592..14988a75b1e2 100755
@@ -16,7 +16,7 @@ if [ -c /dev/kvm ]; then
 fi
 
 if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
-	echo "skip $TESTNAME (kvm only)"
+	echo "KVM is needed, but not available on this host"
 	exit 2
 fi
 
scripts/runtime.bash +27 -1
index deae077e50a1..c9ab9ba47d81 100644
@@ -11,6 +11,27 @@ extract_summary()
     tail -1 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/$/)/'
 }
 
+# We assume that QEMU is going to work if it tried to load the kernel
+premature_failure()
+{
+    local log="$(eval $(get_cmdline _NO_FILE_4Uhere_) 2>&1)"
+    local last_line=$(tail -1 <<< "$log")
+
+    echo "$last_line" | grep -qi "could not load kernel" &&
+        return 1
+
+    RUNTIME_log_stderr <<< "$log"
+
+    echo "$last_line"
+    return 0
+}
+
+get_cmdline()
+{
+    local kernel=$1
+    echo "TESTNAME=$testname TIMEOUT=$timeout ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
+}
+
 function run()
 {
     local testname="$1"
@@ -48,7 +69,12 @@ function run()
         fi
     done
 
-    cmdline="TESTNAME=$testname TIMEOUT=$timeout ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
+    last_line=$(premature_failure) && {
+        echo "`SKIP` $1 ($last_line)"
+        return 77
+    }
+
+    cmdline=$(get_cmdline $kernel)
     if [ "$verbose" = "yes" ]; then
         echo $cmdline
     fi
Signature · 1 line
2.8.2
Reviewed-by on v4 11/13
#26 lore raw

Re: [kvm-unit-tests PATCH v4 11/13] scripts/runtime: skip tests that cannot run

Quoted 12 lines · Radim Krčmář

A case where QEMU won't run the kernel should be considered as skipped. Hyper-V tests used to FAIL on old QEMUs. The infamous QEMU=/dev/null FAIL streak is covered too. Some error messages in arch/run were reworded, because they are now visible in summary.

---
v4:
* clarified "kvm only" error message [Drew+Lukáš]
* used _NO_FILE_4Uhere_ instead of /dev/null [Drew]
* completely reworked output, now prints the last line

Quoted 4 lines
 arm/run              |  2 +-
 powerpc/run          |  2 +-
 scripts/runtime.bash | 28 +++++++++++++++++++++++++++-
 3 files changed, 29 insertions(+), 3 deletions(-)
Quoted 80 lines
arm/run +1 -1
index ebf703d5757c..a2f35ef6a7e6 100755
@@ -19,7 +19,7 @@ if [ -c /dev/kvm ]; then
 fi
 
 if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
-	echo "skip $TESTNAME (kvm only)"
+	echo "KVM is needed, but not available on this host"
 	exit 2
 fi
 
powerpc/run +1 -1
index 56698e622592..14988a75b1e2 100755
@@ -16,7 +16,7 @@ if [ -c /dev/kvm ]; then
 fi
 
 if [ "$ACCEL" = "kvm" ] && [ "$kvm_available" != "yes" ]; then
-	echo "skip $TESTNAME (kvm only)"
+	echo "KVM is needed, but not available on this host"
 	exit 2
 fi
 
scripts/runtime.bash +27 -1
index deae077e50a1..c9ab9ba47d81 100644
@@ -11,6 +11,27 @@ extract_summary()
     tail -1 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/$/)/'
 }
 
+# We assume that QEMU is going to work if it tried to load the kernel
+premature_failure()
+{
+    local log="$(eval $(get_cmdline _NO_FILE_4Uhere_) 2>&1)"
+    local last_line=$(tail -1 <<< "$log")
+
+    echo "$last_line" | grep -qi "could not load kernel" &&
+        return 1
+
+    RUNTIME_log_stderr <<< "$log"
+
+    echo "$last_line"
+    return 0
+}
+
+get_cmdline()
+{
+    local kernel=$1
+    echo "TESTNAME=$testname TIMEOUT=$timeout ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
+}
+
 function run()
 {
     local testname="$1"
@@ -48,7 +69,12 @@ function run()
         fi
     done
 
-    cmdline="TESTNAME=$testname TIMEOUT=$timeout ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
+    last_line=$(premature_failure) && {
+        echo "`SKIP` $1 ($last_line)"
+        return 77
+    }
+
+    cmdline=$(get_cmdline $kernel)
     if [ "$verbose" = "yes" ]; then
         echo $cmdline
     fi
Signature · 6 lines
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#27 lore raw

PATCH v4 12/13 scripts/arch-run: change QEMU failure detection

In reply to Radim Krčmář

We FAIL the test whenever there is an output on stderr. QEMU or its libraries can warn and the test could still work, so ignore any line that has a warning keyword.

---
v4: new

 scripts/arch-run.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/arch-run.bash +1 -1
index 8ef4ff5634a0..8e75c6ed6e17 100644
@@ -55,7 +55,7 @@ run_qemu ()
 		# Even when ret==1 (unittest success) if we also got stderr
 		# logs, then we assume a QEMU failure. Otherwise we translate
 		# status of 1 to 0 (SUCCESS)
-		if [ -z "$errors" ]; then
+		if [ -z "$(echo "$errors" | grep -vi warning)" ]; then
 			ret=0
 		fi
 	fi
Signature · 1 line
2.8.2
Reviewed-by on v4 12/13
#28 lore raw

Re: [kvm-unit-tests PATCH v4 12/13] scripts/arch-run: change QEMU failure detection

Quoted 10 lines · Radim Krčmář

We FAIL the test whenever there is an output on stderr. QEMU or its libraries can warn and the test could still work, so ignore any line that has a warning keyword.

---
v4: new

 scripts/arch-run.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 21 lines
scripts/arch-run.bash +1 -1
index 8ef4ff5634a0..8e75c6ed6e17 100644
@@ -55,7 +55,7 @@ run_qemu ()
 		# Even when ret==1 (unittest success) if we also got stderr
 		# logs, then we assume a QEMU failure. Otherwise we translate
 		# status of 1 to 0 (SUCCESS)
-		if [ -z "$errors" ]; then
+		if [ -z "$(echo "$errors" | grep -vi warning)" ]; then
 			ret=0
 		fi
 	fi
Signature · 6 lines
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#29 lore raw

PATCH v4 13/13 scripts/run: generalize check

In reply to Radim Krčmář

config attribute "check" is currently unused and a simpler imlementation has better chances of being used.

---
v4: new

 scripts/runtime.bash | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
scripts/runtime.bash +5 -11
index c9ab9ba47d81..7f9bf9a2de0e 100644
@@ -57,17 +57,11 @@ function run()
         return 2
     fi
 
-    # check a file for a particular value before running a test
-    # the check line can contain multiple files to check separated by a space
-    # but each check parameter needs to be of the form <path>=<value>
-    for check_param in ${check[@]}; do
-        path=${check_param%%=*}
-        value=${check_param#*=}
-        if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then
-            echo "`SKIP` $1 ($path not equal to $value)"
-            return 2
-        fi
-    done
+    eval $check || {
+        echo "skipped $testname (\`$check\` returned $?)" | RUNTIME_log_stderr
+        echo "`SKIP` $testname (check failed)"
+        return 77
+    }
 
     last_line=$(premature_failure) && {
         echo "`SKIP` $1 ($last_line)"
Signature · 1 line
2.8.2
#30 lore raw

Re: [kvm-unit-tests PATCH v4 13/13] scripts/run: generalize check

Quoted 28 lines · Radim Krčmář

config attribute "check" is currently unused and a simpler imlementation has better chances of being used.

---
v4: new

 scripts/runtime.bash | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
scripts/runtime.bash +0 -9
index c9ab9ba47d81..7f9bf9a2de0e 100644
@@ -57,17 +57,11 @@ function run()
         return 2
     fi
 
-    # check a file for a particular value before running a test
-    # the check line can contain multiple files to check separated by a space
-    # but each check parameter needs to be of the form <path>=<value>
-    for check_param in ${check[@]}; do
-        path=${check_param%%=*}
-        value=${check_param#*=}
-        if [ "$path" ] && [ "$(cat $path)" != "$value" ]; then
-            echo "`SKIP` $1 ($path not equal to $value)"
-            return 2

scripts/runtime.bash function run() · line 67

Quoted 10 lines
scripts/runtime.bash +5 -2
-        fi
-    done
+    eval $check || {
+        echo "skipped $testname (\`$check\` returned $?)" | RUNTIME_log_stderr
+        echo "`SKIP` $testname (check failed)"
+        return 77
+    }
 
     last_line=$(premature_failure) && {
         echo "`SKIP` $1 ($last_line)"

Good, except you need to update all the unittests.cfg headers where check is documented. Maybe something like

check = <bash-expr> # check an expression is true before running the test

Thanks,
drew

Reviewed-by on v4 10/13
#31 lore raw

Re: [kvm-unit-tests PATCH v4 10/13] run_tests: log stderr

In reply to Radim Krčmář
Quoted 10 lines · Radim Krčmář

Summary should provide all important information.

---
v4: new

 run_tests.sh            | 1 +
 scripts/mkstandalone.sh | 1 +
 scripts/runtime.bash    | 3 ++-
 3 files changed, 4 insertions(+), 1 deletion(-)
Quoted 46 lines
run_tests.sh +1 -0
index b634e472a834..254129d8723c 100755
@@ -46,6 +46,7 @@ while getopts "g:hv" opt; do
     esac
 done
 
+RUNTIME_log_stderr () { cat >> test.log; }
 RUNTIME_log_stdout () {
     if [ "$PRETTY_PRINT_STACKS" = "yes" ]; then
         ./scripts/pretty_print_stacks.py $1 >> test.log
scripts/mkstandalone.sh +1 -0
index 77793fd64c76..d2bae1922f4b 100755
@@ -70,6 +70,7 @@ generate_test ()
 
 	echo "exec {stdout}>&1"
 	echo "RUNTIME_log_stdout () { cat >&\$stdout; }"
+	echo "RUNTIME_log_stderr () { cat >&2; }"
 
 	cat scripts/runtime.bash
 
scripts/runtime.bash +2 -1
index 6d9d8bffb82f..deae077e50a1 100644
@@ -55,7 +55,8 @@ function run()
 
     # extra_params in the config file may contain backticks that need to be
     # expanded, so use eval to start qemu.  Same for $RUNTIME_log_stdout.
-    summary=$(eval $cmdline > >(tee >(RUNTIME_log_stdout $kernel) | extract_summary))
+    summary=$(eval $cmdline 2> >(RUNTIME_log_stderr) \
+                             > >(tee >(RUNTIME_log_stdout $kernel) | extract_summary))
     ret=$?
 
     if [ $ret -eq 0 ]; then
Signature · 6 lines
2.8.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#32 lore raw
In reply to Radim Krčmář
Quoted 6 lines · Radim Krčmář

Radim Krčmář (13):
lib/report: allow test skipping
x86/*: report skipped tests
x86/unittests: remove svm-disabled
lib/string: add strncmp
lib/util: add args_parse_keyval

Quoted 8 lines

x86/pmu: expect failure with nmi_watchdog
lib/report: don't print 0 failed tests
scripts/runtime: consolidate summary tags
run_tests: print SUMMARY line in summary
run_tests: log stderr
scripts/runtime: skip tests that cannot run
scripts/arch-run: change QEMU failure detection
scripts/run: generalize check

Applying everything except 5, 6, 13. It would be nice to get the fixup for patch 3 before I push...

Paolo

Quoted 24 lines
 arm/run                 |  2 +-
 lib/libcflat.h          |  1 +
 lib/report.c            | 49 ++++++++++++++++++++++++-----------
 lib/string.c            | 17 ++++++++-----
 lib/string.h            |  1 +
 lib/util.c              | 17 +++++++++++++
 lib/util.h              | 10 ++++++++
 powerpc/run             |  2 +-
 run_tests.sh            | 15 ++++++-----
 scripts/arch-run.bash   |  2 +-
 scripts/mkstandalone.sh |  4 +++
 scripts/runtime.bash    | 68 ++++++++++++++++++++++++++++++++++++-------------
 x86/Makefile.common     |  1 +
 x86/apic.c              |  7 +++--
 x86/emulator.c          |  2 +-
 x86/hyperv_synic.c      |  2 +-
 x86/pku.c               |  2 +-
 x86/pmu.c               |  8 ++++--
 x86/smap.c              |  2 +-
 x86/svm.c               |  2 +-
 x86/tsc.c               |  2 +-
 x86/unittests.cfg       |  9 +------
 22 files changed, 156 insertions(+), 69 deletions(-)
#33 lore raw

2016-05-17 14:29+0200, Paolo Bonzini:

Quoted 16 lines · Radim Krčmář
Quoted 6 lines

Radim Krčmář (13):
lib/report: allow test skipping
x86/*: report skipped tests
x86/unittests: remove svm-disabled
lib/string: add strncmp
lib/util: add args_parse_keyval

Quoted 8 lines

x86/pmu: expect failure with nmi_watchdog
lib/report: don't print 0 failed tests
scripts/runtime: consolidate summary tags
run_tests: print SUMMARY line in summary
run_tests: log stderr
scripts/runtime: skip tests that cannot run
scripts/arch-run: change QEMU failure detection
scripts/run: generalize check

Quoted 2 lines

Applying everything except 5, 6, 13. It would be nice to get the fixup for patch 3 before I push...

Sorry for the delay ... I am overloaded for the next month as well, so improved versions of 5 and 6 seem unlikely before July.

maintainer
#34 lore raw
Quoted 17 lines · Radim Krčmář

2016-05-17 14:29+0200, Paolo Bonzini:

Quoted 16 lines · Radim Krčmář
Quoted 14 lines

Radim Krčmář (13):
lib/report: allow test skipping
x86/*: report skipped tests
x86/unittests: remove svm-disabled
lib/string: add strncmp
lib/util: add args_parse_keyval
x86/pmu: expect failure with nmi_watchdog
lib/report: don't print 0 failed tests
scripts/runtime: consolidate summary tags
run_tests: print SUMMARY line in summary
run_tests: log stderr
scripts/runtime: skip tests that cannot run
scripts/arch-run: change QEMU failure detection
scripts/run: generalize check

Quoted 5 lines
Quoted 2 lines

Applying everything except 5, 6, 13. It would be nice to get the fixup for patch 3 before I push...

Sorry for the delay ... I am overloaded for the next month as well, so improved versions of 5 and 6 seem unlikely before July.

Applying the fixup to patch 2 and pushing to git.kernel.org, thanks.

Thanks,

Paolo