lkml.org 
[lkml]   [2021]   [May]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2 2/2] lib/math/rational: Add Kunit test cases
On Tue, 25 May 2021 07:42:50 -0700 Trent Piepho <tpiepho@gmail.com> wrote:

> Adds a number of test cases that cover a range of possible code paths.
>
> --- /dev/null
> +++ b/lib/math/rational-test.c
> @@ -0,0 +1,56 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <kunit/test.h>
> +
> +#include <linux/rational.h>
> +
> +struct rational_test_param {
> + unsigned long num, den;
> + unsigned long max_num, max_den;
> + unsigned long exp_num, exp_den;
> +
> + const char *name;
> +};
> +
> +static const struct rational_test_param test_parameters[] = {
> + { 1230, 10, 100, 20, 100, 1, "Exceeds bounds, semi-convergent term > ½ last term" },
> + { 34567,100, 120, 20, 120, 1, "Exceeds bounds, semi-convergent term < ½ last term" },

It seems to be asking for trouble to use these characters in kernel
output - heaven knows what sort of weird output devices people
are using. So I think I'll switch to "1/2", OK?

> + { 1, 30, 100, 10, 0, 1, "Closest to zero" },
> + { 1, 19, 100, 10, 1, 10, "Closest to smallest non-zero" },
> + { 27,32, 16, 16, 11, 13, "Use convergent" },
> + { 1155, 7735, 255, 255, 33, 221, "Exact answer" },
> + { 87, 32, 70, 32, 68, 25, "Semiconvergent, numerator limit" },
> + { 14533, 4626, 15000, 2400, 7433, 2366, "Semiconvergent, demominator limit" },
> +};
> ...
> +static struct kunit_case rational_test_cases[] = {
> + KUNIT_CASE_PARAM(rational_test, rational_gen_params),
> + {}
> +};
> +
> +static struct kunit_suite rational_test_suite = {
> + .name = "rational",
> + .test_cases = rational_test_cases,
> +};

And let's use tabs to indent here. checkpatch detects this.

\
 
 \ /
  Last update: 2021-05-25 23:50    [W:0.126 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site