From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com>,
jbhayana@google.com, Lars-Peter Clausen <lars@metafoo.de>,
linux-iio <linux-iio@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Vasyl.Vavrychuk@opensynergy.com
Subject: Re: [PATCH v1 1/2] iio: test: Add check against NULL for buffer in tests.
Date: Sat, 27 Nov 2021 18:53:00 +0000 [thread overview]
Message-ID: <20211127185300.23b4f0df@jic23-huawei> (raw)
In-Reply-To: <20211113165214.1e84a925@jic23-huawei>
On Sat, 13 Nov 2021 16:52:14 +0000
Jonathan Cameron <jic23@kernel.org> wrote:
> On Fri, 5 Nov 2021 12:16:40 +0200
> Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
>
> > On Fri, Nov 5, 2021 at 12:05 PM Andriy Tryshnivskyy
> > <andriy.tryshnivskyy@opensynergy.com> wrote:
> > >
> > > Add KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf) for every test.
> > > Also use ARRAY_SIZE(values) where it is possible.
> >
> > Strictly speaking 'also' and similar in the commit message means you
> > have to split. Here are two patches in one. But these are test cases
> > and I don't care so much about the rules. Up to maintainers.
>
> Ideally I'd agree, but sometimes it's just not worth wasting anyones time
> if both parts are mechanical as here.
>
> Given this is Lars' code I'll leave a bit longer for him to give any tags
> he wishes before picking it up.
>
> Give me a poke if I seem to have lost it in a few weeks. In theory I
> shouldn't given I'm using patchwork as a backup tracker these days, but
> meh - I've lost series before!
Enough time I think. Applied to the togreg branch of iio.git and pushed out
as testing for 0-day to have a quick sanity check. I'll push it out so
linux-next picks it up later in the week.
Thanks,
Jonathan
>
> Thanks,
>
> Jonathan
>
> >
> > >
> > > Signed-off-by: Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com>
> > > ---
> > > drivers/iio/test/iio-test-format.c | 69 ++++++++++++++++++------------
> > > 1 file changed, 42 insertions(+), 27 deletions(-)
> > >
> > > diff --git a/drivers/iio/test/iio-test-format.c b/drivers/iio/test/iio-test-format.c
> > > index f1e951eddb43..b746d00bc0ea 100644
> > > --- a/drivers/iio/test/iio-test-format.c
> > > +++ b/drivers/iio/test/iio-test-format.c
> > > @@ -14,10 +14,13 @@
> > >
> > > static void iio_test_iio_format_value_integer(struct kunit *test)
> > > {
> > > - char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > + char *buf;
> > > int val;
> > > int ret;
> > >
> > > + buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> > > +
> > > val = 42;
> > > ret = iio_format_value(buf, IIO_VAL_INT, 1, &val);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "42\n");
> > > @@ -41,142 +44,154 @@ static void iio_test_iio_format_value_integer(struct kunit *test)
> > >
> > > static void iio_test_iio_format_value_fixedpoint(struct kunit *test)
> > > {
> > > - char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > int values[2];
> > > + char *buf;
> > > int ret;
> > >
> > > + buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> > > +
> > > /* positive >= 1 */
> > > values[0] = 1;
> > > values[1] = 10;
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "1.000010\n");
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO_DB, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO_DB, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "1.000010 dB\n");
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_NANO, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_NANO, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "1.000000010\n");
> > >
> > > /* positive < 1 */
> > > values[0] = 0;
> > > values[1] = 12;
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0.000012\n");
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO_DB, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO_DB, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0.000012 dB\n");
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_NANO, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_NANO, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0.000000012\n");
> > >
> > > /* negative <= -1 */
> > > values[0] = -1;
> > > values[1] = 10;
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-1.000010\n");
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO_DB, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO_DB, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-1.000010 dB\n");
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_NANO, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_NANO, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-1.000000010\n");
> > >
> > > /* negative > -1 */
> > > values[0] = 0;
> > > values[1] = -123;
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-0.000123\n");
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO_DB, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_MICRO_DB, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-0.000123 dB\n");
> > >
> > > - ret = iio_format_value(buf, IIO_VAL_INT_PLUS_NANO, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_INT_PLUS_NANO, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-0.000000123\n");
> > > }
> > >
> > > static void iio_test_iio_format_value_fractional(struct kunit *test)
> > > {
> > > - char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > int values[2];
> > > + char *buf;
> > > int ret;
> > >
> > > + buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> > > +
> > > /* positive < 1 */
> > > values[0] = 1;
> > > values[1] = 10;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0.100000000\n");
> > >
> > > /* positive >= 1 */
> > > values[0] = 100;
> > > values[1] = 3;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "33.333333333\n");
> > >
> > > /* negative > -1 */
> > > values[0] = -1;
> > > values[1] = 1000000000;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-0.000000001\n");
> > >
> > > /* negative <= -1 */
> > > values[0] = -200;
> > > values[1] = 3;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-66.666666666\n");
> > >
> > > /* Zero */
> > > values[0] = 0;
> > > values[1] = -10;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0.000000000\n");
> > > }
> > >
> > > static void iio_test_iio_format_value_fractional_log2(struct kunit *test)
> > > {
> > > - char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > int values[2];
> > > + char *buf;
> > > int ret;
> > >
> > > + buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> > > +
> > > /* positive < 1 */
> > > values[0] = 123;
> > > values[1] = 10;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0.120117187\n");
> > >
> > > /* positive >= 1 */
> > > values[0] = 1234567;
> > > values[1] = 10;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "1205.631835937\n");
> > >
> > > /* negative > -1 */
> > > values[0] = -123;
> > > values[1] = 10;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-0.120117187\n");
> > >
> > > /* negative <= -1 */
> > > values[0] = -1234567;
> > > values[1] = 10;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-1205.631835937\n");
> > >
> > > /* Zero */
> > > values[0] = 0;
> > > values[1] = 10;
> > > - ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, 2, values);
> > > + ret = iio_format_value(buf, IIO_VAL_FRACTIONAL_LOG2, ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0.000000000\n");
> > > }
> > >
> > > static void iio_test_iio_format_value_multiple(struct kunit *test)
> > > {
> > > - char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > int values[] = {1, -2, 3, -4, 5};
> > > + char *buf;
> > > int ret;
> > >
> > > + buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL);
> > > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> > > +
> > > ret = iio_format_value(buf, IIO_VAL_INT_MULTIPLE,
> > > ARRAY_SIZE(values), values);
> > > IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "1 -2 3 -4 5 \n");
> > > --
> > > 2.17.1
> > >
> >
> >
>
next prev parent reply other threads:[~2021-11-27 18:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-05 10:04 [PATCH v1 0/2] iio: test: Add test for IIO_VAL_INT_64 Andriy Tryshnivskyy
2021-11-05 10:05 ` [PATCH v1 1/2] iio: test: Add check against NULL for buffer in tests Andriy Tryshnivskyy
2021-11-05 10:16 ` Andy Shevchenko
2021-11-13 16:52 ` Jonathan Cameron
2021-11-27 18:53 ` Jonathan Cameron [this message]
2021-11-28 18:23 ` Andriy Tryshnivskyy
2021-11-05 10:05 ` [PATCH v1 2/2] iio: test: Add test for IIO_VAL_INT_64 Andriy Tryshnivskyy
2021-11-05 20:20 ` kernel test robot
2021-11-05 10:17 ` [PATCH v1 0/2] " Andy Shevchenko
2021-11-05 10:26 ` Andriy Tryshnivskyy
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=20211127185300.23b4f0df@jic23-huawei \
--to=jic23@kernel.org \
--cc=Vasyl.Vavrychuk@opensynergy.com \
--cc=andriy.tryshnivskyy@opensynergy.com \
--cc=andy.shevchenko@gmail.com \
--cc=jbhayana@google.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®