diff mbox

[kvm-unit-tests,15/15] Introduce lib/errata.h

Message ID 20170113181533.15145-16-drjones@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Andrew Jones Jan. 13, 2017, 6:15 p.m. UTC
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

Comments

Radim Krčmář March 3, 2017, 2:40 p.m. UTC | #1
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
>
diff mbox

Patch

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