kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests 00/15] Introduce an errata framework
@ 2017-01-13 18:15 Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 01/15] devicetree: improve dt_get_bootargs interface Andrew Jones
                   ` (14 more replies)
  0 siblings, 15 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

When using kvm-unit-tests to verify distributions (which use older,
stable KVM and QEMU), it's possible to get FAILs for tests of features
not implemented, or FAILs for fixes that are targeted for later
releases. This framework empowers unit test developers to more
generously apply report_skip and report_xfail by giving the user
run-time modifiable booleans to control the flow of tests. For example,
we can now do something like

  if (!ERRATA(PPC64_TM_01))
    report_skip("ERRATA_PPC64_TM_01 not set 'y', skipping...");
  else
    report(...);

ERRATA_PPC64_TM_01 is simply a unit test environment variable which
can have its value changed easily. E.g.

  $ echo ERRATA_PPC64_TM_01=y > ppc64.env
  $ ENV=ppc64.env ./run_tests.sh

will run all ppc64 unit tests, and any test that checks
ERRATA(PPC64_TM_01) will get a return value of true. Another
example is

  report_xfail("APIC test", !ERRATA_RELAXED(X86_APIC_01), ...);

allowing an APIC test to report FAIL when ERRATA_X86_APIC_01 is
'y', or non-exist, and the test fails, or XFAIL when it fails
with ERRATA_X86_APIC_01=n.

Getting report_skip/xfail patches upstream, and then using an environ
with the appropriate errata set downstream, should help avoid automated
test suites from flagging too many false alarms, and also avoid the
need to carry too many downstream patches.

Thanks,
drew


Andrew Jones (15):
  devicetree: improve dt_get_bootargs interface
  devicetree: introduce dt_get_initrd
  arm/arm64: better document setup
  powerpc: better document setup
  arm/arm64: import initrd
  powerpc: import initrd
  x86_64: mbi-cmdline is a 4 byte addr
  x86: import initrd
  lib/argv: fix coding style
  lib/argv: introduce setup_env and getenv
  arm/arm64: enable environ
  powerpc: enable environ
  x86: enable environ
  README: reserve some environment variables
  Introduce lib/errata.h

 arm/run             |   1 +
 powerpc/run         |   1 +
 x86/run             |   4 +-
 x86/Makefile.common |   1 +
 lib/devicetree.h    |  15 +++++-
 lib/errata.h        |  24 +++++++++
 lib/libcflat.h      |   1 +
 lib/argv.c          | 143 +++++++++++++++++++++++++++++++++++++++++-----------
 lib/arm/setup.c     |  55 +++++++++++++++++---
 lib/devicetree.c    |  39 ++++++++++++--
 lib/powerpc/setup.c |  55 +++++++++++++++++---
 lib/string.c        |  15 ++++++
 lib/x86/setup.c     |  47 +++++++++++++++++
 arm/cstart.S        |   1 +
 arm/cstart64.S      |   1 +
 powerpc/cstart64.S  |   5 +-
 x86/cstart.S        |   4 ++
 x86/cstart64.S      |   8 ++-
 README.md           |  24 +++++++++
 19 files changed, 391 insertions(+), 53 deletions(-)
 create mode 100644 lib/errata.h
 create mode 100644 lib/x86/setup.c

-- 
2.9.3


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 01/15] devicetree: improve dt_get_bootargs interface
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 02/15] devicetree: introduce dt_get_initrd Andrew Jones
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

Don't lie to callers when bootargs wasn't found, they can check
for themselves. Also document that when a failure occurs @bootargs
will be NULL.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/devicetree.h    | 5 +++--
 lib/arm/setup.c     | 2 +-
 lib/devicetree.c    | 5 ++---
 lib/powerpc/setup.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/devicetree.h b/lib/devicetree.h
index 0083587633d4..9a4d910b6450 100644
--- a/lib/devicetree.h
+++ b/lib/devicetree.h
@@ -202,10 +202,11 @@ extern int dt_get_reg(int fdtnode, int regidx, struct dt_reg *reg);
  **********************************************************************/
 
 /*
- * dt_get_bootargs gets a pointer to /chosen/bootargs
+ * dt_get_bootargs gets the string pointer from /chosen/bootargs
  * returns
  *  - zero on success
- *  - a negative FDT_ERR_* value on failure
+ *  - a negative FDT_ERR_* value on failure, and @bootargs
+ *    will be set to NULL
  */
 extern int dt_get_bootargs(const char **bootargs);
 
diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index 68eae91286d6..dc94d312b262 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -138,6 +138,6 @@ void setup(const void *fdt)
 	io_init();
 
 	ret = dt_get_bootargs(&bootargs);
-	assert(ret == 0);
+	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
 }
diff --git a/lib/devicetree.c b/lib/devicetree.c
index 671c64a2ca51..509649b917cf 100644
--- a/lib/devicetree.c
+++ b/lib/devicetree.c
@@ -256,11 +256,10 @@ int dt_get_bootargs(const char **bootargs)
 		return node;
 
 	prop = fdt_get_property(fdt, node, "bootargs", &len);
-	if (prop)
-		*bootargs = prop->data;
-	else if (len < 0 && len != -FDT_ERR_NOTFOUND)
+	if (!prop)
 		return len;
 
+	*bootargs = prop->data;
 	return 0;
 }
 
diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c
index d56de36410c7..00969da8f12c 100644
--- a/lib/powerpc/setup.c
+++ b/lib/powerpc/setup.c
@@ -176,6 +176,6 @@ void setup(const void *fdt)
 	io_init();
 
 	ret = dt_get_bootargs(&bootargs);
-	assert(ret == 0);
+	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
 }
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 02/15] devicetree: introduce dt_get_initrd
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 01/15] devicetree: improve dt_get_bootargs interface Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 03/15] arm/arm64: better document setup Andrew Jones
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

Allow DT users to find the initrd if one is passed on the
QEMU command line.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/devicetree.h | 10 ++++++++++
 lib/devicetree.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/lib/devicetree.h b/lib/devicetree.h
index 9a4d910b6450..93c7ebc63bd8 100644
--- a/lib/devicetree.h
+++ b/lib/devicetree.h
@@ -220,6 +220,16 @@ extern int dt_get_bootargs(const char **bootargs);
 extern int dt_get_default_console_node(void);
 
 /*
+ * dt_get_initrd gets the physical address of the initrd and its
+ * size from /chosen
+ * returns
+ *  - zero on success
+ *  - a negative FDT_ERR_* value on failure, and @initrd will be
+ *    set to NULL and @size set to zero
+ */
+extern int dt_get_initrd(const char **initrd, u32 *size);
+
+/*
  * dt_get_memory_params gets the memory parameters from the /memory node(s)
  * storing each memory region ("address size" tuple) in consecutive entries
  * of @regs, up to @nr_regs
diff --git a/lib/devicetree.c b/lib/devicetree.c
index 509649b917cf..2b89178a109b 100644
--- a/lib/devicetree.c
+++ b/lib/devicetree.c
@@ -282,6 +282,40 @@ int dt_get_default_console_node(void)
 	return fdt_path_offset(fdt, prop->data);
 }
 
+int dt_get_initrd(const char **initrd, u32 *size)
+{
+	const struct fdt_property *prop;
+	const char *start, *end;
+	int node, len;
+	u32 *data;
+
+	*initrd = NULL;
+	*size = 0;
+
+	node = fdt_path_offset(fdt, "/chosen");
+	if (node < 0)
+		return node;
+
+	prop = fdt_get_property(fdt, node, "linux,initrd-start", &len);
+	if (!prop)
+		return len;
+	data = (u32 *)prop->data;
+	start = (const char *)(unsigned long)fdt32_to_cpu(*data);
+
+	prop = fdt_get_property(fdt, node, "linux,initrd-end", &len);
+	if (!prop) {
+		assert(len != -FDT_ERR_NOTFOUND);
+		return len;
+	}
+	data = (u32 *)prop->data;
+	end = (const char *)(unsigned long)fdt32_to_cpu(*data);
+
+	*initrd = start;
+	*size = (unsigned long)end - (unsigned long)start;
+
+	return 0;
+}
+
 int dt_init(const void *fdt_ptr)
 {
 	int ret;
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 03/15] arm/arm64: better document setup
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 01/15] devicetree: improve dt_get_bootargs interface Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 02/15] devicetree: introduce dt_get_initrd Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 04/15] powerpc: " Andrew Jones
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

To prepare for another region illustrate where we move the FDT.
No functional change.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/setup.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index dc94d312b262..dcf25c2f4365 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -112,31 +112,51 @@ static void mem_init(phys_addr_t freemem_start)
 
 void setup(const void *fdt)
 {
+	void *freemem = &stacktop;
 	const char *bootargs;
 	u32 fdt_size;
 	int ret;
 
 	/*
-	 * Move the fdt to just above the stack. The free memory
-	 * then starts just after the fdt.
+	 * Before calling mem_init we need to move the fdt to a safe
+	 * location. We move it above the stack to construct the memory
+	 * map illustrated below:
+	 *
+	 *    +----------------------+   <-- top of physical memory
+	 *    |                      |
+	 *    ~                      ~
+	 *    |                      |
+	 *    +----------------------+   <-- top of FDT
+	 *    |                      |
+	 *    +----------------------+   <-- top of cpu0's stack
+	 *    |                      |
+	 *    +----------------------+   <-- top of text/data/bss sections,
+	 *    |                      |       see arm/flat.lds
+	 *    |                      |
+	 *    +----------------------+   <-- load address
+	 *    |                      |
+	 *    +----------------------+
 	 */
 	fdt_size = fdt_totalsize(fdt);
-	ret = fdt_move(fdt, &stacktop, fdt_size);
+	ret = fdt_move(fdt, freemem, fdt_size);
 	assert(ret == 0);
-	ret = dt_init(&stacktop);
+	ret = dt_init(freemem);
 	assert(ret == 0);
+	freemem += fdt_size;
 
+	/* call init functions */
 	cpu_init();
 
 	/* cpu_init must be called before thread_info_init */
 	thread_info_init(current_thread_info(), 0);
 
 	/* thread_info_init must be called before mem_init */
-	mem_init(PAGE_ALIGN((unsigned long)&stacktop + fdt_size));
+	mem_init(PAGE_ALIGN((unsigned long)freemem));
 
 	/* mem_init must be called before io_init */
 	io_init();
 
+	/* finish setup */
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 04/15] powerpc: better document setup
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (2 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 03/15] arm/arm64: better document setup Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 05/15] arm/arm64: import initrd Andrew Jones
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

To prepare for another region illustrate where we move the FDT.
No functional change.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/powerpc/setup.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c
index 00969da8f12c..f55b23fb5080 100644
--- a/lib/powerpc/setup.c
+++ b/lib/powerpc/setup.c
@@ -153,28 +153,48 @@ static void mem_init(phys_addr_t freemem_start)
 
 void setup(const void *fdt)
 {
+	void *freemem = &stacktop;
 	const char *bootargs;
 	u32 fdt_size;
 	int ret;
 
 	/*
-	 * Move the fdt to just above the stack. The free memory
-	 * then starts just after the fdt.
+	 * Before calling mem_init we need to move the fdt to a safe
+	 * location. We move it above the stack to construct the memory
+	 * map illustrated below:
+	 *
+	 * +----------------------+   <-- top of physical memory
+	 * |                      |
+	 * ~                      ~
+	 * |                      |
+	 * +----------------------+   <-- top of FDT
+	 * |                      |
+	 * +----------------------+   <-- top of cpu0's stack
+	 * |                      |
+	 * +----------------------+   <-- top of text/data/bss sections,
+	 * |                      |       see arm/flat.lds
+	 * |                      |
+	 * +----------------------+   <-- load address
+	 * |                      |
+	 * +----------------------+
 	 */
 	fdt_size = fdt_totalsize(fdt);
-	ret = fdt_move(fdt, &stacktop, fdt_size);
+	ret = fdt_move(fdt, freemem, fdt_size);
 	assert(ret == 0);
-	ret = dt_init(&stacktop);
+	ret = dt_init(freemem);
 	assert(ret == 0);
+	freemem += fdt_size;
 
+	/* call init functions */
 	cpu_init();
 
 	/* cpu_init must be called before mem_init */
-	mem_init(PAGE_ALIGN((unsigned long)&stacktop + fdt_size));
+	mem_init(PAGE_ALIGN((unsigned long)freemem));
 
 	/* mem_init must be called before io_init */
 	io_init();
 
+	/* finish setup */
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 05/15] arm/arm64: import initrd
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (3 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 04/15] powerpc: " Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 06/15] powerpc: " Andrew Jones
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

If an initrd is provided on the qemu command line, then "import"
it by copying it to a safe location during setup.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/arm/setup.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index dcf25c2f4365..c4d69ae2c143 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -24,6 +24,9 @@ extern unsigned long stacktop;
 extern void io_init(void);
 extern void setup_args_progname(const char *args);
 
+char *initrd;
+u32 initrd_size;
+
 u64 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (u64)~0 };
 int nr_cpus;
 
@@ -113,19 +116,21 @@ static void mem_init(phys_addr_t freemem_start)
 void setup(const void *fdt)
 {
 	void *freemem = &stacktop;
-	const char *bootargs;
+	const char *bootargs, *tmp;
 	u32 fdt_size;
 	int ret;
 
 	/*
-	 * Before calling mem_init we need to move the fdt to a safe
-	 * location. We move it above the stack to construct the memory
+	 * Before calling mem_init we need to move the fdt and initrd
+	 * to safe locations. We move them to construct the memory
 	 * map illustrated below:
 	 *
 	 *    +----------------------+   <-- top of physical memory
 	 *    |                      |
 	 *    ~                      ~
 	 *    |                      |
+	 *    +----------------------+   <-- top of initrd
+	 *    |                      |
 	 *    +----------------------+   <-- top of FDT
 	 *    |                      |
 	 *    +----------------------+   <-- top of cpu0's stack
@@ -144,6 +149,14 @@ void setup(const void *fdt)
 	assert(ret == 0);
 	freemem += fdt_size;
 
+	ret = dt_get_initrd(&tmp, &initrd_size);
+	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+	if (ret == 0) {
+		initrd = freemem;
+		memmove(initrd, tmp, initrd_size);
+		freemem += initrd_size;
+	}
+
 	/* call init functions */
 	cpu_init();
 
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 06/15] powerpc: import initrd
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (4 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 05/15] arm/arm64: import initrd Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 07/15] x86_64: mbi-cmdline is a 4 byte addr Andrew Jones
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

If an initrd is provided on the qemu command line, then "import"
it by copying it to a safe location during setup.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/powerpc/setup.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c
index f55b23fb5080..f2dc10e01352 100644
--- a/lib/powerpc/setup.c
+++ b/lib/powerpc/setup.c
@@ -22,6 +22,9 @@ extern unsigned long stacktop;
 extern void io_init(void);
 extern void setup_args_progname(const char *args);
 
+char *initrd;
+u32 initrd_size;
+
 u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
 int nr_cpus;
 uint64_t tb_hz;
@@ -154,19 +157,21 @@ static void mem_init(phys_addr_t freemem_start)
 void setup(const void *fdt)
 {
 	void *freemem = &stacktop;
-	const char *bootargs;
+	const char *bootargs, *tmp;
 	u32 fdt_size;
 	int ret;
 
 	/*
-	 * Before calling mem_init we need to move the fdt to a safe
-	 * location. We move it above the stack to construct the memory
+	 * Before calling mem_init we need to move the fdt and initrd
+	 * to safe locations. We move them to construct the memory
 	 * map illustrated below:
 	 *
 	 * +----------------------+   <-- top of physical memory
 	 * |                      |
 	 * ~                      ~
 	 * |                      |
+	 * +----------------------+   <-- top of initrd
+	 * |                      |
 	 * +----------------------+   <-- top of FDT
 	 * |                      |
 	 * +----------------------+   <-- top of cpu0's stack
@@ -185,6 +190,14 @@ void setup(const void *fdt)
 	assert(ret == 0);
 	freemem += fdt_size;
 
+	ret = dt_get_initrd(&tmp, &initrd_size);
+	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
+	if (ret == 0) {
+		initrd = freemem;
+		memmove(initrd, tmp, initrd_size);
+		freemem += initrd_size;
+	}
+
 	/* call init functions */
 	cpu_init();
 
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 07/15] x86_64: mbi-cmdline is a 4 byte addr
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (5 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 06/15] powerpc: " Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 08/15] x86: import initrd Andrew Jones
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

Treating mbi-cmdline as an 8 byte addr includes mbi-mods-count,
which only works as long as there are no mods.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 x86/cstart64.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/x86/cstart64.S b/x86/cstart64.S
index e94788832267..0240507519cd 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -198,7 +198,7 @@ start64:
 	call smp_init
 	call enable_x2apic
 	mov mb_boot_info(%rip), %rax
-	mov mb_cmdline(%rax), %rax
+	mov mb_cmdline(%rax), %eax
 	mov %rax, __args(%rip)
 	call __setup_args
 	mov __argc(%rip), %edi
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 08/15] x86: import initrd
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (6 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 07/15] x86_64: mbi-cmdline is a 4 byte addr Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 09/15] lib/argv: fix coding style Andrew Jones
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

If an initrd is provided on the qemu command line, then set a
pointer to it during setup.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 x86/Makefile.common |  1 +
 lib/x86/setup.c     | 31 +++++++++++++++++++++++++++++++
 x86/cstart.S        |  2 ++
 x86/cstart64.S      |  6 ++++--
 4 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 lib/x86/setup.c

diff --git a/x86/Makefile.common b/x86/Makefile.common
index 1dad18ba26e1..fbab82c85c00 100644
--- a/x86/Makefile.common
+++ b/x86/Makefile.common
@@ -4,6 +4,7 @@ all: test_cases
 
 cflatobjs += lib/pci.o
 cflatobjs += lib/pci-edu.o
+cflatobjs += lib/x86/setup.o
 cflatobjs += lib/x86/io.o
 cflatobjs += lib/x86/smp.o
 cflatobjs += lib/x86/vm.o
diff --git a/lib/x86/setup.c b/lib/x86/setup.c
new file mode 100644
index 000000000000..e5df6ce95b64
--- /dev/null
+++ b/lib/x86/setup.c
@@ -0,0 +1,31 @@
+/*
+ * Initialize machine setup information
+ *
+ * Copyright (C) 2017, Red Hat Inc, Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include "libcflat.h"
+
+#define MBI_MODS_COUNT	20
+#define MBI_MODS_ADDR	24
+#define MB_MOD_START	 0
+#define MB_MOD_END	 4
+
+char *initrd;
+u32 initrd_size;
+
+void setup_get_initrd(u8 *bootinfo)
+{
+	u32 *mods_addr, *mod_start, *mod_end;
+
+	if (*((u32 *)&bootinfo[MBI_MODS_COUNT]) != 1)
+		return;
+
+	mods_addr = (u32 *)&bootinfo[MBI_MODS_ADDR];
+	mod_start = (u32 *)(ulong)(*mods_addr + MB_MOD_START);
+	mod_end = (u32 *)(ulong)(*mods_addr + MB_MOD_END);
+
+	initrd = (char *)(ulong)*mod_start;
+	initrd_size = *mod_end - *mod_start;
+}
diff --git a/x86/cstart.S b/x86/cstart.S
index 3dc8e710925a..7ab99cd20b7f 100644
--- a/x86/cstart.S
+++ b/x86/cstart.S
@@ -94,6 +94,8 @@ MSR_GS_BASE = 0xc0000101
 
 .globl start
 start:
+        push %ebx
+        call setup_get_initrd
         mov mb_cmdline(%ebx), %eax
         mov %eax, __args
         call __setup_args
diff --git a/x86/cstart64.S b/x86/cstart64.S
index 0240507519cd..1c5182043703 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -197,8 +197,10 @@ start64:
 	call enable_apic
 	call smp_init
 	call enable_x2apic
-	mov mb_boot_info(%rip), %rax
-	mov mb_cmdline(%rax), %eax
+	mov mb_boot_info(%rip), %rbx
+	mov %rbx, %rdi
+	call setup_get_initrd
+	mov mb_cmdline(%rbx), %eax
 	mov %rax, __args(%rip)
 	call __setup_args
 	mov __argc(%rip), %edi
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 09/15] lib/argv: fix coding style
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (7 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 08/15] x86: import initrd Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 10/15] lib/argv: introduce setup_env and getenv Andrew Jones
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

The next patch will double the amount of code in the file,
so let's fix its coding style first. No functional change.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/argv.c | 55 ++++++++++++++++++++++++++-----------------------------
 1 file changed, 26 insertions(+), 29 deletions(-)

diff --git a/lib/argv.c b/lib/argv.c
index 482ed004ee64..fe8826255c18 100644
--- a/lib/argv.c
+++ b/lib/argv.c
@@ -8,49 +8,46 @@ char *__args;
 static char args_copy[1000];
 static char *copy_ptr = args_copy;
 
-static bool isblank(char p)
-{
-    return p == ' ' || p == '\t';
-}
+#define isblank(c) ((c) == ' ' || (c) == '\t')
 
 static char *skip_blanks(char *p)
 {
-    while (isblank(*p))
-        ++p;
-    return p;
+	while (isblank(*p))
+		++p;
+	return p;
 }
 
 void __setup_args(void)
 {
-    char *args = __args;
-    char **argv = __argv + __argc;
-
-    while (*(args = skip_blanks(args)) != '\0') {
-        *argv++ = copy_ptr;
-        while (*args != '\0' && !isblank(*args))
-            *copy_ptr++ = *args++;
-        *copy_ptr++ = '\0';
-    }
-    __argc = argv - __argv;
+	char *args = __args;
+	char **argv = __argv + __argc;
+
+	while (*(args = skip_blanks(args)) != '\0') {
+		*argv++ = copy_ptr;
+		while (*args != '\0' && !isblank(*args))
+			*copy_ptr++ = *args++;
+		*copy_ptr++ = '\0';
+	}
+	__argc = argv - __argv;
 }
 
 void setup_args(char *args)
 {
-    if (!args)
-        return;
+	if (!args)
+		return;
 
-    __args = args;
-    __setup_args();
+	__args = args;
+	__setup_args();
 }
 
 void setup_args_progname(char *args)
 {
-    __argv[0] = copy_ptr;
-    strcpy(__argv[0], auxinfo.progname);
-    copy_ptr += strlen(auxinfo.progname) + 1;
-    ++__argc;
-    if (args) {
-        __args = args;
-        __setup_args();
-    }
+	__argv[0] = copy_ptr;
+	strcpy(__argv[0], auxinfo.progname);
+	copy_ptr += strlen(auxinfo.progname) + 1;
+	++__argc;
+	if (args) {
+		__args = args;
+		__setup_args();
+	}
 }
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 10/15] lib/argv: introduce setup_env and getenv
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (8 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 09/15] lib/argv: fix coding style Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 11/15] arm/arm64: enable environ Andrew Jones
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

Provide a function that imports an environ (a list of key=value
environment variables). The list may be delimited by either
'\0' or '\n'. If the list is delimited by '\n', then we assume
it's user input and do additional sanity checking, as well as
allow variables to be commented out with '#'. We also provide
getenv() to lookup the variables.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/libcflat.h |  1 +
 lib/argv.c     | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/string.c   | 15 ++++++++++
 3 files changed, 105 insertions(+), 1 deletion(-)

diff --git a/lib/libcflat.h b/lib/libcflat.h
index e80fc5071f61..96a37926f302 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -85,6 +85,7 @@ extern void puts(const char *s);
 extern void exit(int code);
 extern void abort(void);
 extern long atol(const char *ptr);
+extern char *getenv(const char *name);
 
 extern int printf(const char *fmt, ...)
 					__attribute__((format(printf, 1, 2)));
diff --git a/lib/argv.c b/lib/argv.c
index fe8826255c18..a37fc8792a92 100644
--- a/lib/argv.c
+++ b/lib/argv.c
@@ -2,13 +2,18 @@
 #include "auxinfo.h"
 
 int __argc;
-char *__argv[100];
 char *__args;
+char *__argv[100];
+char *__environ[200];
+
+char **environ = __environ;
 
 static char args_copy[1000];
 static char *copy_ptr = args_copy;
 
 #define isblank(c) ((c) == ' ' || (c) == '\t')
+#define isalpha(c) (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z') || (c) == '_')
+#define isalnum(c) (isalpha(c) || ((c) >= '0' && (c) <= '9'))
 
 static char *skip_blanks(char *p)
 {
@@ -51,3 +56,86 @@ void setup_args_progname(char *args)
 		__setup_args();
 	}
 }
+
+static char *env_eol(char *env)
+{
+	while (*env && *env != '\n')
+		++env;
+	return env;
+}
+
+static char *env_invalid_eol(char *env)
+{
+	char *eol = env_eol(env);
+	char eol_old = *eol;
+
+	*eol = '\0';
+	printf("Invalid environment variable: %s\n", env);
+	*eol = eol_old;
+	return eol;
+}
+
+static char *env_next(char *env)
+{
+	char *p;
+
+	if (!*env)
+		return env;
+
+	if (isalpha(*env)) {
+		bool invalid = false;
+
+		p = env + 1;
+		while (*p && *p != '=' && *p != '\n') {
+			if (!isalnum(*p))
+				invalid = true;
+			++p;
+		}
+
+		if (*p != '=')
+			invalid = true;
+
+		if (invalid) {
+			env = env_invalid_eol(env);
+			return *env ? env_next(env + 1) : env;
+		}
+		return env;
+	}
+
+	p = env;
+	while (isblank(*p))
+		++p;
+
+	if (*p == '\n')
+		return env_next(p + 1);
+
+	if (*p == '#')
+		env = env_eol(env);
+	else
+		env = env_invalid_eol(env);
+
+	return *env ? env_next(env + 1) : env;
+}
+
+void setup_env(char *env, int size)
+{
+	char *eof = env + size, *p = env;
+	bool newline = false;
+	int i = 0;
+
+	while (*p)
+		++p;
+	if (p == eof)
+		newline = true;
+
+	while (env < eof) {
+		if (newline)
+			env = env_next(env);
+		if (!*env || env >= eof)
+			break;
+		__environ[i++] = env;
+		while (env < eof && *env && !(newline && *env == '\n'))
+			++env;
+		*env++ = '\0';
+	}
+}
diff --git a/lib/string.c b/lib/string.c
index ee93e25e9821..833f22be48c5 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -158,3 +158,18 @@ long atol(const char *ptr)
 
     return acc;
 }
+
+extern char **environ;
+
+char *getenv(const char *name)
+{
+    char **envp = environ, *delim;
+
+    while (*envp) {
+        delim = strchr(*envp, '=');
+        if (delim && strncmp(name, *envp, delim - *envp) == 0)
+            return delim + 1;
+        ++envp;
+    }
+    return NULL;
+}
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 11/15] arm/arm64: enable environ
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (9 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 10/15] lib/argv: introduce setup_env and getenv Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 12/15] powerpc: " Andrew Jones
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

Give arm/arm64 unit tests access to environment variables.
The environment variables are passed to the unit test with
'-initrd env-file'.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/run         | 1 +
 lib/arm/setup.c | 8 ++++++++
 arm/cstart.S    | 1 +
 arm/cstart64.S  | 1 +
 4 files changed, 11 insertions(+)

diff --git a/arm/run b/arm/run
index 1c40ab02eb57..2134c9efb1bd 100755
--- a/arm/run
+++ b/arm/run
@@ -79,6 +79,7 @@ fi
 
 M+=",accel=$ACCEL"
 command="$qemu -nodefaults $M -cpu $processor $chr_testdev $pci_testdev"
+[ -f "$ENV" ] && command+=" -initrd $ENV"
 command+=" -display none -serial stdio -kernel"
 command="$(timeout_cmd) $command"
 echo $command "$@"
diff --git a/lib/arm/setup.c b/lib/arm/setup.c
index c4d69ae2c143..689c211d3018 100644
--- a/lib/arm/setup.c
+++ b/lib/arm/setup.c
@@ -23,6 +23,7 @@
 extern unsigned long stacktop;
 extern void io_init(void);
 extern void setup_args_progname(const char *args);
+extern void setup_env(char *env, int size);
 
 char *initrd;
 u32 initrd_size;
@@ -173,4 +174,11 @@ void setup(const void *fdt)
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
+
+	if (initrd) {
+		/* environ is currently the only file in the initrd */
+		char *env = malloc(initrd_size);
+		memcpy(env, initrd, initrd_size);
+		setup_env(env, initrd_size);
+	}
 }
diff --git a/arm/cstart.S b/arm/cstart.S
index 9822fb7ba637..12461d104dad 100644
--- a/arm/cstart.S
+++ b/arm/cstart.S
@@ -62,6 +62,7 @@ start:
 	ldr	r0, =__argc
 	ldr	r0, [r0]
 	ldr	r1, =__argv
+	ldr	r2, =__environ
 	bl	main
 	bl	exit
 	b	halt
diff --git a/arm/cstart64.S b/arm/cstart64.S
index 44cff32d0f18..7738babc4109 100644
--- a/arm/cstart64.S
+++ b/arm/cstart64.S
@@ -43,6 +43,7 @@ start:
 	adr	x0, __argc
 	ldr	x0, [x0]
 	adr	x1, __argv
+	adr	x2, __environ
 	bl	main
 	bl	exit
 	b	halt
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 12/15] powerpc: enable environ
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (10 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 11/15] arm/arm64: enable environ Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 13/15] x86: " Andrew Jones
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

Give powerpc unit tests access to environment variables.
The environment variables are passed to the unit test with
'-initrd env-file'.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 powerpc/run         | 1 +
 lib/powerpc/setup.c | 8 ++++++++
 powerpc/cstart64.S  | 5 +++--
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/powerpc/run b/powerpc/run
index afdd487bfc35..6269abb9fe7f 100755
--- a/powerpc/run
+++ b/powerpc/run
@@ -44,6 +44,7 @@ fi
 M='-machine pseries'
 M+=",accel=$ACCEL"
 command="$qemu -nodefaults $M -bios $FIRMWARE"
+[ -f "$ENV" ] && command+=" -initrd $ENV"
 command+=" -display none -serial stdio -kernel"
 command="$(timeout_cmd) $command"
 echo $command "$@"
diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c
index f2dc10e01352..8d44311cac3b 100644
--- a/lib/powerpc/setup.c
+++ b/lib/powerpc/setup.c
@@ -21,6 +21,7 @@
 extern unsigned long stacktop;
 extern void io_init(void);
 extern void setup_args_progname(const char *args);
+extern void setup_env(char *env, int size);
 
 char *initrd;
 u32 initrd_size;
@@ -211,4 +212,11 @@ void setup(const void *fdt)
 	ret = dt_get_bootargs(&bootargs);
 	assert(ret == 0 || ret == -FDT_ERR_NOTFOUND);
 	setup_args_progname(bootargs);
+
+	if (initrd) {
+		/* environ is currently the only file in the initrd */
+		char *env = malloc(initrd_size);
+		memcpy(env, initrd, initrd_size);
+		setup_env(env, initrd_size);
+	}
 }
diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S
index 2d660325e854..2204e3bbe44e 100644
--- a/powerpc/cstart64.S
+++ b/powerpc/cstart64.S
@@ -94,9 +94,10 @@ start:
 	bl	setup
 
 	/* run the test */
-	LOAD_REG_ADDR(r5, __argc)
+	LOAD_REG_ADDR(r3, __argc)
 	LOAD_REG_ADDR(r4, __argv)
-	lwz	r3, 0(r5)
+	LOAD_REG_ADDR(r5, __environ)
+	lwz	r3, 0(r3)
 	bl	main
 	bl	exit
 	b	halt
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 13/15] x86: enable environ
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (11 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 12/15] powerpc: " Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 14/15] README: reserve some environment variables Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 15/15] Introduce lib/errata.h Andrew Jones
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

Give x86 unit tests access to environment variables. The
environment variables are passed to the unit test with
'-initrd env-file'.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 x86/run         |  4 +++-
 lib/x86/setup.c | 16 ++++++++++++++++
 x86/cstart.S    |  2 ++
 x86/cstart64.S  |  2 ++
 4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/x86/run b/x86/run
index 10a6e6d3421c..867a1cccd3ba 100755
--- a/x86/run
+++ b/x86/run
@@ -42,7 +42,9 @@ else
 	pc_testdev="-device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out"
 fi
 
-command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev -kernel"
+command="${qemu} -nodefaults -enable-kvm $pc_testdev -vnc none -serial stdio $pci_testdev $hyperv_testdev"
+[ -f "$ENV" ] && command+=" -initrd $ENV"
+command+=" -kernel"
 command="$(timeout_cmd) $command"
 echo ${command} "$@"
 
diff --git a/lib/x86/setup.c b/lib/x86/setup.c
index e5df6ce95b64..804ba3a1b86e 100644
--- a/lib/x86/setup.c
+++ b/lib/x86/setup.c
@@ -12,9 +12,15 @@
 #define MB_MOD_START	 0
 #define MB_MOD_END	 4
 
+#define ENV_SIZE 16384
+
+extern void setup_env(char *env, int size);
+
 char *initrd;
 u32 initrd_size;
 
+static char env[ENV_SIZE];
+
 void setup_get_initrd(u8 *bootinfo)
 {
 	u32 *mods_addr, *mod_start, *mod_end;
@@ -29,3 +35,13 @@ void setup_get_initrd(u8 *bootinfo)
 	initrd = (char *)(ulong)*mod_start;
 	initrd_size = *mod_end - *mod_start;
 }
+
+void setup_environ(void)
+{
+	if (initrd) {
+		/* environ is currently the only file in the initrd */
+		u32 size = MIN(initrd_size, ENV_SIZE);
+		memcpy(env, initrd, size);
+		setup_env(env, size);
+	}
+}
diff --git a/x86/cstart.S b/x86/cstart.S
index 7ab99cd20b7f..69b5c332cbcc 100644
--- a/x86/cstart.S
+++ b/x86/cstart.S
@@ -96,6 +96,7 @@ MSR_GS_BASE = 0xc0000101
 start:
         push %ebx
         call setup_get_initrd
+        call setup_environ
         mov mb_cmdline(%ebx), %eax
         mov %eax, __args
         call __setup_args
@@ -149,6 +150,7 @@ start32:
 	call enable_apic
 	call smp_init
 	call enable_x2apic
+        push $__environ
         push $__argv
         push __argc
         call main
diff --git a/x86/cstart64.S b/x86/cstart64.S
index 1c5182043703..004c014b5ba2 100644
--- a/x86/cstart64.S
+++ b/x86/cstart64.S
@@ -200,11 +200,13 @@ start64:
 	mov mb_boot_info(%rip), %rbx
 	mov %rbx, %rdi
 	call setup_get_initrd
+	call setup_environ
 	mov mb_cmdline(%rbx), %eax
 	mov %rax, __args(%rip)
 	call __setup_args
 	mov __argc(%rip), %edi
 	lea __argv(%rip), %rsi
+	lea __environ(%rip), %rdx
 	call main
 	mov %eax, %edi
 	call exit
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 14/15] README: reserve some environment variables
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (12 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 13/15] x86: " Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 15/15] Introduce lib/errata.h Andrew Jones
  14 siblings, 0 replies; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 README.md | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/README.md b/README.md
index b6f011d44568..49fbc9c50bce 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,30 @@ environment variable:
 
     QEMU=/tmp/qemu/x86_64-softmmu/qemu-system-x86_64 ./x86-run ./x86/msr.flat
 
+# Unit test inputs
+
+Unit tests use QEMU's '-append <args...>' parameter for command line
+inputs, i.e. all args will be available as argv strings in main().
+Additionally a file of the form
+
+KEY=VAL
+KEY2=VAL
+...
+
+may be passed with '-initrd <file>' to become the unit test's environ,
+which can then be accessed in the usual ways, e.g. VAL = getenv("KEY")
+Any key=val strings can be passed, but some have reserved meanings in
+the framework. The list of reserved environment variables is below
+
+ QEMU_ACCEL            ... either kvm or tcg
+ QEMU_VERSION_STRING   ... string of the form `qemu -h | head -1`
+ KERNEL_VERSION_STRING ... string of the form `uname -r`
+
+Additionally these self-explanatory variables are reserved
+
+ QEMU_MAJOR, QEMU_MINOR, QEMU_MICRO, KERNEL_VERSION, KERNEL_PATCHLEVEL,
+ KERNEL_SUBLEVEL, KERNEL_EXTRAVERSION
+
 # Contributing
 
 ## Directory structure
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH kvm-unit-tests 15/15] Introduce lib/errata.h
  2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
                   ` (13 preceding siblings ...)
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 14/15] README: reserve some environment variables Andrew Jones
@ 2017-01-13 18:15 ` Andrew Jones
  2017-03-03 14:40   ` Radim Krčmář
  14 siblings, 1 reply; 17+ messages in thread
From: Andrew Jones @ 2017-01-13 18:15 UTC (permalink / raw)
  To: kvm; +Cc: rkrcmar, pbonzini, lvivier, thuth

Now that we have environment variables we can apply them to
defining errata booleans to determine behavior of report_skip
or report_xfail in tests. lib/errata.h provides handy wrappers
allowing one to do things like:

 Only running dangerous tests (host crashers) when the errata
 has been applied

   if (!ERRATA(PPC64_TM_01))
     report_skip("ERRATA_PPC64_TM_01 not set 'y', skipping...");
   else
     report(...);

 Trigger an XFAIL vs. a FAIL, when set to 'n'

   report_xfail("APIC test", !ERRATA_RELAXED(x86_APIC_01), ...);

The xfail example uses ERRATA_RELAXED to ensure we have the same
behavior as now (assuming the software under test should pass, i.e
output FAIL if it does not), when testing without the optional
environ.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/errata.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 lib/errata.h

diff --git a/lib/errata.h b/lib/errata.h
new file mode 100644
index 000000000000..5e63f73b3727
--- /dev/null
+++ b/lib/errata.h
@@ -0,0 +1,24 @@
+#ifndef _ERRATA_H_
+#define _ERRATA_H_
+
+#define _ERRATA(erratum) errata("ERRATA_" # erratum)
+#define ERRATA(erratum) _ERRATA(erratum)
+
+#define _ERRATA_RELAXED(erratum) errata_relaxed("ERRATA_" # erratum)
+#define ERRATA_RELAXED(erratum) _ERRATA_RELAXED(erratum)
+
+static inline bool errata(const char *erratum)
+{
+	char *s = getenv(erratum);
+
+	return s && (*s == '1' || *s == 'y' || *s == 'Y');
+}
+
+static inline bool errata_relaxed(const char *erratum)
+{
+	char *s = getenv(erratum);
+
+	return !(s && (*s == '0' || *s == 'n' || *s == 'N'));
+}
+
+#endif
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH kvm-unit-tests 15/15] Introduce lib/errata.h
  2017-01-13 18:15 ` [PATCH kvm-unit-tests 15/15] Introduce lib/errata.h Andrew Jones
@ 2017-03-03 14:40   ` Radim Krčmář
  0 siblings, 0 replies; 17+ messages in thread
From: Radim Krčmář @ 2017-03-03 14:40 UTC (permalink / raw)
  To: Andrew Jones; +Cc: kvm, pbonzini, lvivier, thuth

2017-01-13 19:15+0100, Andrew Jones:
> Now that we have environment variables we can apply them to
> defining errata booleans to determine behavior of report_skip
> or report_xfail in tests. lib/errata.h provides handy wrappers
> allowing one to do things like:
> 
>  Only running dangerous tests (host crashers) when the errata
>  has been applied
> 
>    if (!ERRATA(PPC64_TM_01))
>      report_skip("ERRATA_PPC64_TM_01 not set 'y', skipping...");
>    else
>      report(...);
> 
>  Trigger an XFAIL vs. a FAIL, when set to 'n'
> 
>    report_xfail("APIC test", !ERRATA_RELAXED(x86_APIC_01), ...);

I changed the examples to use commit hashes as errata IDs (as we agreed)
and applied, thanks.

> The xfail example uses ERRATA_RELAXED to ensure we have the same
> behavior as now (assuming the software under test should pass, i.e
> output FAIL if it does not), when testing without the optional
> environ.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  lib/errata.h | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>  create mode 100644 lib/errata.h
> 
> diff --git a/lib/errata.h b/lib/errata.h
> new file mode 100644
> index 000000000000..5e63f73b3727
> --- /dev/null
> +++ b/lib/errata.h
> @@ -0,0 +1,24 @@
> +#ifndef _ERRATA_H_
> +#define _ERRATA_H_
> +
> +#define _ERRATA(erratum) errata("ERRATA_" # erratum)
> +#define ERRATA(erratum) _ERRATA(erratum)
> +
> +#define _ERRATA_RELAXED(erratum) errata_relaxed("ERRATA_" # erratum)
> +#define ERRATA_RELAXED(erratum) _ERRATA_RELAXED(erratum)
> +
> +static inline bool errata(const char *erratum)
> +{
> +	char *s = getenv(erratum);
> +
> +	return s && (*s == '1' || *s == 'y' || *s == 'Y');
> +}
> +
> +static inline bool errata_relaxed(const char *erratum)
> +{
> +	char *s = getenv(erratum);
> +
> +	return !(s && (*s == '0' || *s == 'n' || *s == 'N'));
> +}
> +
> +#endif
> -- 
> 2.9.3
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-03-03 14:47 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-13 18:15 [PATCH kvm-unit-tests 00/15] Introduce an errata framework Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 01/15] devicetree: improve dt_get_bootargs interface Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 02/15] devicetree: introduce dt_get_initrd Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 03/15] arm/arm64: better document setup Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 04/15] powerpc: " Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 05/15] arm/arm64: import initrd Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 06/15] powerpc: " Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 07/15] x86_64: mbi-cmdline is a 4 byte addr Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 08/15] x86: import initrd Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 09/15] lib/argv: fix coding style Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 10/15] lib/argv: introduce setup_env and getenv Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 11/15] arm/arm64: enable environ Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 12/15] powerpc: " Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 13/15] x86: " Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 14/15] README: reserve some environment variables Andrew Jones
2017-01-13 18:15 ` [PATCH kvm-unit-tests 15/15] Introduce lib/errata.h Andrew Jones
2017-03-03 14:40   ` Radim Krčmář

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).