diff mbox

[4/6] test_bpf: add module parameters to filter the tests to run.

Message ID 1438610528-14245-5-git-send-email-nschichan@freebox.fr
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Nicolas Schichan Aug. 3, 2015, 2:02 p.m. UTC
When developping on the interpreter or a particular JIT, it can be
insteresting to restrict the test list to a specific test or a
particular range of tests.

This patch adds the following module parameters to the test_bpf module:

* test_name=<string>: only the specified named test will be run.

* test_id=<number>: only the test with the specified id will be run
  (see the output of test_pbf without parameters to get the test id).

* test_range=<number>,<number>: only the tests with IDs in the
  specified id range are run (see the output of test_pbf without
  parameters to get the test ids).

Any invalid range, test id or test name will result in -EINVAL being
returned and no tests being run.

Signed-off-by: Nicolas Schichan <nschichan@freebox.fr>
---
 lib/test_bpf.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

Comments

Daniel Borkmann Aug. 3, 2015, 3:58 p.m. UTC | #1
On 08/03/2015 04:02 PM, Nicolas Schichan wrote:
> When developping on the interpreter or a particular JIT, it can be
> insteresting to restrict the test list to a specific test or a

s/insteresting/interesting/

> particular range of tests.
>
> This patch adds the following module parameters to the test_bpf module:
>
> * test_name=<string>: only the specified named test will be run.
>
> * test_id=<number>: only the test with the specified id will be run
>    (see the output of test_pbf without parameters to get the test id).

s/test_pbf/test_bpf/

> * test_range=<number>,<number>: only the tests with IDs in the
>    specified id range are run (see the output of test_pbf without

s/test_pbf/test_bpf/

>    parameters to get the test ids).
>
> Any invalid range, test id or test name will result in -EINVAL being
> returned and no tests being run.
>
> Signed-off-by: Nicolas Schichan <nschichan@freebox.fr>

Seems very useful for the test suite, thanks.

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

> ---
>   lib/test_bpf.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 73 insertions(+)
>
> diff --git a/lib/test_bpf.c b/lib/test_bpf.c
> index f5606fb..abd0507 100644
> --- a/lib/test_bpf.c
> +++ b/lib/test_bpf.c
> @@ -4870,10 +4870,72 @@ static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
>   	return err_cnt;
>   }
>
> +static char test_name[64];
> +module_param_string(test_name, test_name, sizeof(test_name), 0);
> +
> +static int test_id = -1;
> +module_param(test_id, int, 0);
> +
> +static int test_range[2] = { -1, -1 };
> +module_param_array(test_range, int, NULL, 0);
> +
> +static __init int find_test_index(const char *test_name)
> +{
> +	int i;
> +
> +	for (i = 0; i < ARRAY_SIZE(tests); i++) {
> +		if (!strcmp(tests[i].descr, test_name))
> +			return i;
> +	}
> +	return -1;
> +}
> +
>   static __init int prepare_bpf_tests(void)
>   {
>   	int i;
>
> +	if (test_id >= 0) {
> +		/*
> +		 * if a test_id was specified, use test_range to
> +		 * conver only that test.

s/conver/cover/

> +		 */
> +		if (test_id >= ARRAY_SIZE(tests)) {
> +			pr_err("test_bpf: invalid test_id specified.\n");
> +			return -EINVAL;
> +		}
[...]
> @@ -4893,6 +4955,14 @@ static __init void destroy_bpf_tests(void)
>   	}
>   }
>
> +static bool exclude_test(int test_id)
> +{
> +	if (test_range[0] >= 0 &&
> +	    (test_id < test_range[0] || test_id > test_range[1]))
> +		return true;
> +	return false;

Minor nit: could directly return it, f.e.:

	return test_range[0] >= 0 && (test_id < test_range[0] ||
                                       test_id > test_range[1]);

Btw, for the range test in prepare_bpf_tests(), you could also reject
a negative lower bound index right there.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Nicolas Schichan Aug. 3, 2015, 4:23 p.m. UTC | #2
On 08/03/2015 05:58 PM, Daniel Borkmann wrote:
> On 08/03/2015 04:02 PM, Nicolas Schichan wrote:
>> When developping on the interpreter or a particular JIT, it can be
>> insteresting to restrict the test list to a specific test or a
> 
> s/insteresting/interesting/
[...]
> s/test_pbf/test_bpf/
[...]
> s/test_pbf/test_bpf/
[...]
> s/conver/cover/

Sorry for the various typos, I'll fix that in a V2.

>> +         */
>> +        if (test_id >= ARRAY_SIZE(tests)) {
>> +            pr_err("test_bpf: invalid test_id specified.\n");
>> +            return -EINVAL;
>> +        }
> [...]
>> @@ -4893,6 +4955,14 @@ static __init void destroy_bpf_tests(void)
>>       }
>>   }
>>
>> +static bool exclude_test(int test_id)
>> +{
>> +    if (test_range[0] >= 0 &&
>> +        (test_id < test_range[0] || test_id > test_range[1]))
>> +        return true;
>> +    return false;
> 
> Minor nit: could directly return it, f.e.:
> 
>     return test_range[0] >= 0 && (test_id < test_range[0] ||
>                                       test_id > test_range[1]);

I will change that.

> Btw, for the range test in prepare_bpf_tests(), you could also reject
> a negative lower bound index right there.

I thought it was better to have all the sanity checks grouped in
prepare_bpf_tests() (with the checking of the test_name and test_id parameters
nearby) ? Also a negative lower bound is meaning that no range has been set so
all tests should be run.

Thanks,
Daniel Borkmann Aug. 3, 2015, 4:34 p.m. UTC | #3
On 08/03/2015 06:23 PM, Nicolas Schichan wrote:
...
>> Btw, for the range test in prepare_bpf_tests(), you could also reject
>> a negative lower bound index right there.
>
> I thought it was better to have all the sanity checks grouped in
> prepare_bpf_tests() (with the checking of the test_name and test_id parameters
> nearby) ? Also a negative lower bound is meaning that no range has been set so
> all tests should be run.

I just got a bit confused when loading test_range=-100,1 was not rejected, but
they do indeed all run in this case.

Thanks,
Daniel
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/test_bpf.c b/lib/test_bpf.c
index f5606fb..abd0507 100644
--- a/lib/test_bpf.c
+++ b/lib/test_bpf.c
@@ -4870,10 +4870,72 @@  static int run_one(const struct bpf_prog *fp, struct bpf_test *test)
 	return err_cnt;
 }
 
+static char test_name[64];
+module_param_string(test_name, test_name, sizeof(test_name), 0);
+
+static int test_id = -1;
+module_param(test_id, int, 0);
+
+static int test_range[2] = { -1, -1 };
+module_param_array(test_range, int, NULL, 0);
+
+static __init int find_test_index(const char *test_name)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (!strcmp(tests[i].descr, test_name))
+			return i;
+	}
+	return -1;
+}
+
 static __init int prepare_bpf_tests(void)
 {
 	int i;
 
+	if (test_id >= 0) {
+		/*
+		 * if a test_id was specified, use test_range to
+		 * conver only that test.
+		 */
+		if (test_id >= ARRAY_SIZE(tests)) {
+			pr_err("test_bpf: invalid test_id specified.\n");
+			return -EINVAL;
+		}
+
+		test_range[0] = test_id;
+		test_range[1] = test_id;
+	} else if (test_range[0] >= 0) {
+		/*
+		 * check that the supplied test_range is valid.
+		 */
+		if (test_range[0] >= ARRAY_SIZE(tests) ||
+		    test_range[1] >= ARRAY_SIZE(tests)) {
+			pr_err("test_bpf: test_range is out of bound.\n");
+			return -EINVAL;
+		}
+
+		if (test_range[1] < test_range[0]) {
+			pr_err("test_bpf: test_range is ending before it starts.\n");
+			return -EINVAL;
+		}
+	} else if (*test_name) {
+		/*
+		 * if a test_name was specified, find it and setup
+		 * test_range to cover only that test.
+		 */
+		int idx = find_test_index(test_name);
+
+		if (idx < 0) {
+			pr_err("test_bpf: no test named '%s' found.\n",
+			       test_name);
+			return -EINVAL;
+		}
+		test_range[0] = idx;
+		test_range[1] = idx;
+	}
+
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
 		if (tests[i].fill_helper &&
 		    tests[i].fill_helper(&tests[i]) < 0)
@@ -4893,6 +4955,14 @@  static __init void destroy_bpf_tests(void)
 	}
 }
 
+static bool exclude_test(int test_id)
+{
+	if (test_range[0] >= 0 &&
+	    (test_id < test_range[0] || test_id > test_range[1]))
+		return true;
+	return false;
+}
+
 static __init int test_bpf(void)
 {
 	int i, err_cnt = 0, pass_cnt = 0;
@@ -4902,6 +4972,9 @@  static __init int test_bpf(void)
 		struct bpf_prog *fp;
 		int err;
 
+		if (exclude_test(i))
+			continue;
+
 		pr_info("#%d %s ", i, tests[i].descr);
 
 		fp = generate_filter(i, &err);