linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Javier Martinez Canillas <javierm@redhat.com>
To: Dana Elfassy <delfassy@redhat.com>,
	eballetb@redhat.com, dmitry.torokhov@gmail.com,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Dana Elfassy <dangel101@gmail.com>
Subject: Re: [PATCH] Input: tests: add test to cover all input_grab_device() function
Date: Wed, 17 May 2023 10:23:05 +0200	[thread overview]
Message-ID: <87a5y39xjq.fsf@minerva.mail-host-address-is-not-set> (raw)
In-Reply-To: <20230516162412.461066-1-dangel101@gmail.com>

Dana Elfassy <delfassy@redhat.com> writes:

Hello Dana,

Is great to see more input Kunit tests being added, thanks!

> Currently input_grab_device() isn't covered by any tests
> Thus, adding a test to cover the cases:
> 1. The device is grabbed successfully
> 2. Trying to grab a device that is already grabbed by another input
>    handle
>
> Signed-off-by: Dana Elfassy <dangel101@gmail.com>
> ---

I tested this and it worked for me:

$ ./tools/testing/kunit/kunit.py run --kunitconfig=drivers/input/tests/.kunitconfig
...
[09:36:42] Starting KUnit Kernel (1/1)...
[09:36:42] ============================================================
[09:36:43] ================= input_core (4 subtests) ==================
[09:36:43] [PASSED] input_test_polling
[09:36:43] [PASSED] input_test_timestamp
[09:36:43] [PASSED] input_test_match_device_id
[09:36:43] [PASSED] input_test_grab
[09:36:43] =================== [PASSED] input_core ====================
[09:36:43] ============================================================
[09:36:43] Testing complete. Ran 4 tests: passed: 4
[09:36:43] Elapsed time: 129.985s total, 5.005s configuring, 124.864s building, 0.062s running

>  drivers/input/tests/input_test.c | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
>
> diff --git a/drivers/input/tests/input_test.c b/drivers/input/tests/input_test.c
> index 25bbf51b5c87..cd4db365e9fa 100644
> --- a/drivers/input/tests/input_test.c
> +++ b/drivers/input/tests/input_test.c
> @@ -124,10 +124,38 @@ static void input_test_match_device_id(struct kunit *test)
>  	KUNIT_ASSERT_FALSE(test, input_match_device_id(input_dev, &id));
>  }
>  
> +
> +static void input_test_grab(struct kunit *test)
> +{
> +	struct input_dev *input_dev = test->priv;
> +	struct input_handle test_handle;
> +	struct input_handler handler;
> +	struct input_handle handle;
> +	struct input_device_id id;
> +	int res;
> +
> +	handler.name = "handler";
> +	handler.id_table = &id;
> +
> +	handle.dev = input_get_device(input_dev);
> +	handle.name = dev_name(&input_dev->dev);
> +	handle.handler = &handler;
> +	res = input_grab_device(&handle);
> +	KUNIT_ASSERT_TRUE(test, input_grab_device(&handle));
> +

I think you need to add a input_put_device(input_dev) here ?

Otherwise the reference counter won't be decremented.

> +	test_handle.dev = input_get_device(input_dev);
> +	test_handle.name = dev_name(&input_dev->dev);
> +	test_handle.handler = &handler;
> +

I think you can just reuse the handle variable that was set-up before ?

There's no need to another test_handle variable as far as I can tell.

> +	res = input_grab_device(&test_handle);
> +	KUNIT_ASSERT_EQ(test, res, -EBUSY);

And here add an input_put_device(input_dev) call too.

Other than that the patch looks good to me.

Tested-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat


      reply	other threads:[~2023-05-17  8:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-16 16:24 [PATCH] Input: tests: add test to cover all input_grab_device() function Dana Elfassy
2023-05-17  8:23 ` Javier Martinez Canillas [this message]

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=87a5y39xjq.fsf@minerva.mail-host-address-is-not-set \
    --to=javierm@redhat.com \
    --cc=dangel101@gmail.com \
    --cc=delfassy@redhat.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=eballetb@redhat.com \
    --cc=linux-input@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;
as well as URLs for NNTP newsgroup(s).