Message ID | 20211102073300.13376-1-andriy.tryshnivskyy@opensynergy.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | None | expand |
On Tue, Nov 2, 2021 at 9:33 AM Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com> wrote: > Now it's good with format, but you have missed the commit message. > Signed-off-by: Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com> ... > +static void iio_test_iio_format_value_integer_64(struct kunit *test) > +{ > + char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL); Shouldn't this be checked against NULL? > + s64 value; > + int values[2]; > + int ret; Reversed xmas tree ordering? > + value = 24; > + values[0] = lower_32_bits(value); > + values[1] = upper_32_bits(value); > + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); ARRAY_SIZE()? > + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "24\n"); > + > + value = -24; > + values[0] = lower_32_bits(value); > + values[1] = upper_32_bits(value); > + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); > + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-24\n"); > + > + value = 0; > + values[0] = lower_32_bits(value); > + values[1] = upper_32_bits(value); > + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); > + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0\n"); > + > + value = 4294967295; Is this UINT_MAX? > + values[0] = lower_32_bits(value); > + values[1] = upper_32_bits(value); > + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); > + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "4294967295\n"); > + value = -4294967295; Is this -UINT_MAX? > + values[0] = lower_32_bits(value); > + values[1] = upper_32_bits(value); > + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); > + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-4294967295\n"); > + > + value = LLONG_MAX; > + values[0] = lower_32_bits(value); > + values[1] = upper_32_bits(value); > + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); > + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "9223372036854775807\n"); > + > + value = LLONG_MIN; > + values[0] = lower_32_bits(value); > + values[1] = upper_32_bits(value); > + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); > + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-9223372036854775808\n"); > +}
On 02.11.21 10:11, Andy Shevchenko wrote: > CAUTION: This email originated from outside of the organization. > Do not click links or open attachments unless you recognize the sender and know the content is safe. > > > On Tue, Nov 2, 2021 at 9:33 AM Andriy Tryshnivskyy > <andriy.tryshnivskyy@opensynergy.com> wrote: > Now it's good with format, but you have missed the commit message. Actually commit massage contains a header only (no body message), but I can add body message too. Thanks! > >> Signed-off-by: Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com> > ... > >> +static void iio_test_iio_format_value_integer_64(struct kunit *test) >> +{ >> + char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL); > Shouldn't this be checked against NULL? Good question. Truly speaking I've made new test similar to other. And no other tests has a check for NULL. >> + s64 value; >> + int values[2]; >> + int ret; > Reversed xmas tree ordering? I will correct it. Thanks! >> + value = 24; >> + values[0] = lower_32_bits(value); >> + values[1] = upper_32_bits(value); >> + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); > ARRAY_SIZE()? Will use ARRAY_SIZE(). Thanks! >> + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "24\n"); >> + >> + value = -24; >> + values[0] = lower_32_bits(value); >> + values[1] = upper_32_bits(value); >> + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); >> + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-24\n"); >> + >> + value = 0; >> + values[0] = lower_32_bits(value); >> + values[1] = upper_32_bits(value); >> + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); >> + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0\n"); >> + >> + value = 4294967295; > Is this UINT_MAX? Yes. It's UINT_MAX. I will use a constant. Thanks! >> + values[0] = lower_32_bits(value); >> + values[1] = upper_32_bits(value); >> + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); >> + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "4294967295\n"); >> + value = -4294967295; > Is this -UINT_MAX? Yes. It's -UINT_MAX. I will use a constant. Thanks! >> + values[0] = lower_32_bits(value); >> + values[1] = upper_32_bits(value); >> + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); >> + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-4294967295\n"); >> + >> + value = LLONG_MAX; >> + values[0] = lower_32_bits(value); >> + values[1] = upper_32_bits(value); >> + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); >> + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "9223372036854775807\n"); >> + >> + value = LLONG_MIN; >> + values[0] = lower_32_bits(value); >> + values[1] = upper_32_bits(value); >> + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); >> + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-9223372036854775808\n"); >> +} > -- > With Best Regards, > Andy Shevchenko > Thank you for review! Regards, Andriy.
On 11/5/21 9:45 AM, Andriy Tryshnivskyy wrote: > On 02.11.21 10:11, Andy Shevchenko wrote: > >> CAUTION: This email originated from outside of the organization. >> Do not click links or open attachments unless you recognize the >> sender and know the content is safe. >> >> >> On Tue, Nov 2, 2021 at 9:33 AM Andriy Tryshnivskyy >> <andriy.tryshnivskyy@opensynergy.com> wrote: >> Now it's good with format, but you have missed the commit message. > > Actually commit massage contains a header only (no body message), but > I can add body message too. > Thanks! > >> >>> Signed-off-by: Andriy Tryshnivskyy >>> <andriy.tryshnivskyy@opensynergy.com> >> ... >> >>> +static void iio_test_iio_format_value_integer_64(struct kunit *test) >>> +{ >>> + char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL); >> Shouldn't this be checked against NULL? > > Good question. Truly speaking I've made new test similar to other. And > no other tests has a check for NULL. > The other tests not having it is my fault. There should be a KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf) under the allocation.
On 05.11.21 10:50, Lars-Peter Clausen wrote: > CAUTION: This email originated from outside of the organization. > Do not click links or open attachments unless you recognize the sender > and know the content is safe. > > > On 11/5/21 9:45 AM, Andriy Tryshnivskyy wrote: >> On 02.11.21 10:11, Andy Shevchenko wrote: >> >>> CAUTION: This email originated from outside of the organization. >>> Do not click links or open attachments unless you recognize the >>> sender and know the content is safe. >>> >>> >>> On Tue, Nov 2, 2021 at 9:33 AM Andriy Tryshnivskyy >>> <andriy.tryshnivskyy@opensynergy.com> wrote: >>> Now it's good with format, but you have missed the commit message. >> >> Actually commit massage contains a header only (no body message), but >> I can add body message too. >> Thanks! >> >>> >>>> Signed-off-by: Andriy Tryshnivskyy >>>> <andriy.tryshnivskyy@opensynergy.com> >>> ... >>> >>>> +static void iio_test_iio_format_value_integer_64(struct kunit *test) >>>> +{ >>>> + char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL); >>> Shouldn't this be checked against NULL? >> >> Good question. Truly speaking I've made new test similar to other. And >> no other tests has a check for NULL. >> > The other tests not having it is my fault. There should be a > KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf) under the allocation. > Understood. Then If you wouldn't mind I will add assert to other tests too.
On 11/5/21 9:55 AM, Andriy Tryshnivskyy wrote: > > On 05.11.21 10:50, Lars-Peter Clausen wrote: >> CAUTION: This email originated from outside of the organization. >> Do not click links or open attachments unless you recognize the >> sender and know the content is safe. >> >> >> On 11/5/21 9:45 AM, Andriy Tryshnivskyy wrote: >>> On 02.11.21 10:11, Andy Shevchenko wrote: >>> >>>> CAUTION: This email originated from outside of the organization. >>>> Do not click links or open attachments unless you recognize the >>>> sender and know the content is safe. >>>> >>>> >>>> On Tue, Nov 2, 2021 at 9:33 AM Andriy Tryshnivskyy >>>> <andriy.tryshnivskyy@opensynergy.com> wrote: >>>> Now it's good with format, but you have missed the commit message. >>> >>> Actually commit massage contains a header only (no body message), but >>> I can add body message too. >>> Thanks! >>> >>>> >>>>> Signed-off-by: Andriy Tryshnivskyy >>>>> <andriy.tryshnivskyy@opensynergy.com> >>>> ... >>>> >>>>> +static void iio_test_iio_format_value_integer_64(struct kunit *test) >>>>> +{ >>>>> + char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL); >>>> Shouldn't this be checked against NULL? >>> >>> Good question. Truly speaking I've made new test similar to other. And >>> no other tests has a check for NULL. >>> >> The other tests not having it is my fault. There should be a >> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf) under the allocation. >> > Understood. Then If you wouldn't mind I will add assert to other tests > too. Perfect, thanks!
diff --git a/drivers/iio/test/iio-test-format.c b/drivers/iio/test/iio-test-format.c index f1e951eddb43..f07945c2cf28 100644 --- a/drivers/iio/test/iio-test-format.c +++ b/drivers/iio/test/iio-test-format.c @@ -182,12 +182,63 @@ static void iio_test_iio_format_value_multiple(struct kunit *test) IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "1 -2 3 -4 5 \n"); } +static void iio_test_iio_format_value_integer_64(struct kunit *test) +{ + char *buf = kunit_kmalloc(test, PAGE_SIZE, GFP_KERNEL); + s64 value; + int values[2]; + int ret; + + value = 24; + values[0] = lower_32_bits(value); + values[1] = upper_32_bits(value); + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "24\n"); + + value = -24; + values[0] = lower_32_bits(value); + values[1] = upper_32_bits(value); + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-24\n"); + + value = 0; + values[0] = lower_32_bits(value); + values[1] = upper_32_bits(value); + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "0\n"); + + value = 4294967295; + values[0] = lower_32_bits(value); + values[1] = upper_32_bits(value); + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "4294967295\n"); + + value = -4294967295; + values[0] = lower_32_bits(value); + values[1] = upper_32_bits(value); + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-4294967295\n"); + + value = LLONG_MAX; + values[0] = lower_32_bits(value); + values[1] = upper_32_bits(value); + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "9223372036854775807\n"); + + value = LLONG_MIN; + values[0] = lower_32_bits(value); + values[1] = upper_32_bits(value); + ret = iio_format_value(buf, IIO_VAL_INT_64, 2, values); + IIO_TEST_FORMAT_EXPECT_EQ(test, buf, ret, "-9223372036854775808\n"); +} + static struct kunit_case iio_format_test_cases[] = { KUNIT_CASE(iio_test_iio_format_value_integer), KUNIT_CASE(iio_test_iio_format_value_fixedpoint), KUNIT_CASE(iio_test_iio_format_value_fractional), KUNIT_CASE(iio_test_iio_format_value_fractional_log2), KUNIT_CASE(iio_test_iio_format_value_multiple), + KUNIT_CASE(iio_test_iio_format_value_integer_64), {} };
Signed-off-by: Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com> --- drivers/iio/test/iio-test-format.c | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)