All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Sergey Dyasli <sergey.dyasli@citrix.com>,
	Xen-devel <xen-devel@lists.xen.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH 3/3] tools/cpu-policy: Add unit tests and a fuzzing harness
Date: Mon, 07 Jan 2019 04:19:10 -0700	[thread overview]
Message-ID: <5C3335AE020000780020ACBD@prv1-mh.provo.novell.com> (raw)
In-Reply-To: <1546616022-32229-4-git-send-email-andrew.cooper3@citrix.com>

>>> On 04.01.19 at 16:33, <andrew.cooper3@citrix.com> wrote:
> The AFL harness currently notices that there are cases where we optimse the
> serialised stream by omitting data beyond the various maximum leaves.
> 
> Both sets of tests will be extended with further libx86 work.
> 
> Fix the sorting of the CPUID_GUEST_NR_* constants, noticed while writing the
> unit tests.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Wei Liu <wei.liu2@citrix.com>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> CC: Sergey Dyasli <sergey.dyasli@citrix.com>
> ---
>  tools/fuzz/cpu-policy/.gitignore          |   1 +
>  tools/fuzz/cpu-policy/Makefile            |  27 ++++
>  tools/fuzz/cpu-policy/afl-policy-fuzzer.c | 117 ++++++++++++++
>  tools/tests/Makefile                      |   1 +
>  tools/tests/cpu-policy/.gitignore         |   1 +

Did we somehow come to the conclusion that the central .gitignore
at the root of the tree is not the way to go in the future?

> --- /dev/null
> +++ b/tools/tests/cpu-policy/test-cpu-policy.c
> @@ -0,0 +1,247 @@
> +#include <assert.h>
> +#include <errno.h>
> +#include <stdbool.h>
> +#include <stdint.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +
> +#include <xen-tools/libs.h>
> +#include <xen/lib/x86/cpuid.h>
> +#include <xen/lib/x86/msr.h>
> +#include <xen/domctl.h>
> +
> +static void test_cpuid_serialise_success(void)
> +{
> +    static const struct test {
> +        struct cpuid_policy p;
> +        const char *name;
> +        unsigned int nr_leaves;
> +    } tests[] = {
> +        {
> +            .name = "empty policy",
> +            .nr_leaves = 4,
> +        },
> +    };
> +    unsigned int i;
> +
> +    printf("Testing CPUID serialise success:\n");
> +
> +    for ( i = 0; i < ARRAY_SIZE(tests); ++i )
> +    {
> +        const struct test *t = &tests[i];
> +        unsigned int nr = t->nr_leaves;
> +        xen_cpuid_leaf_t *leaves = malloc(nr * sizeof(*leaves));
> +        int rc;
> +
> +        if ( !leaves )
> +            goto test_done;

Shouldn't you leave some indication of the test not having got run?

> +static void test_cpuid_deserialise_failure(void)
> +{
> +    static const struct test {
> +        const char *name;
> +        xen_cpuid_leaf_t leaf;
> +    } tests[] = {
> +        {
> +            .name = "incorrect basic subleaf",
> +            .leaf = { .leaf = 0, .subleaf = 0 },
> +        },
> +        {
> +            .name = "incorrect hv1 subleaf",
> +            .leaf = { .leaf = 0x40000000, .subleaf = 0 },
> +        },
> +        {
> +            .name = "incorrect hv2 subleaf",
> +            .leaf = { .leaf = 0x40000100, .subleaf = 0 },
> +        },
> +        {
> +            .name = "incorrect extd subleaf",
> +            .leaf = { .leaf = 0x80000000, .subleaf = 0 },
> +        },
> +        {
> +            .name = "OoB basic leaf",
> +            .leaf = { .leaf = CPUID_GUEST_NR_BASIC },
> +        },
> +        {
> +            .name = "OoB cache leaf",
> +            .leaf = { .leaf = 0x4, .subleaf = CPUID_GUEST_NR_CACHE },
> +        },
> +        {
> +            .name = "OoB feat leaf",
> +            .leaf = { .leaf = 0x7, .subleaf = CPUID_GUEST_NR_FEAT },
> +        },
> +        {
> +            .name = "OoB topo leaf",
> +            .leaf = { .leaf = 0xb, .subleaf = CPUID_GUEST_NR_TOPO },
> +        },
> +        {
> +            .name = "OoB xstate leaf",
> +            .leaf = { .leaf = 0xd, .subleaf = CPUID_GUEST_NR_XSTATE },
> +        },
> +        {
> +            .name = "OoB extd leaf",
> +            .leaf = { .leaf = 0x80000000 | CPUID_GUEST_NR_EXTD },
> +        },
> +    };
> +    unsigned int i;
> +
> +    printf("Testing CPUID deserialise failure:\n");
> +
> +    for ( i = 0; i < ARRAY_SIZE(tests); ++i )
> +    {
> +        const struct test *t = &tests[i];
> +        uint32_t err_leaf = ~0u, err_subleaf = ~0u;
> +        int rc;
> +
> +        rc = x86_cpuid_copy_from_buffer(NULL, &t->leaf, 1,
> +                                        &err_leaf, &err_subleaf);
> +
> +        if ( rc != -ERANGE )
> +        {
> +            printf("  Test %s, expected rc %d, got %d\n",
> +                   t->name, -ERANGE, rc);
> +            continue;

Perhaps drop this? The subsequent test ought to apply regardless
of error code.

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-01-07 11:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-04 15:33 [PATCH 0/3] libx86: Remaining serialisation logic Andrew Cooper
2019-01-04 15:33 ` [PATCH 1/3] libx86: Introduce a helper to deserialise cpuid_policy objects Andrew Cooper
2019-01-07 10:52   ` Jan Beulich
2019-02-25 11:41     ` Andrew Cooper
2019-01-04 15:33 ` [PATCH 2/3] libx86: introduce a helper to deserialise msr_policy objects Andrew Cooper
2019-01-07 10:55   ` Jan Beulich
2019-01-04 15:33 ` [PATCH 3/3] tools/cpu-policy: Add unit tests and a fuzzing harness Andrew Cooper
2019-01-07 11:19   ` Jan Beulich [this message]
2019-02-25 11:56     ` Andrew Cooper
2019-02-25 12:23       ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5C3335AE020000780020ACBD@prv1-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=sergey.dyasli@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.