From: Stanislav Fomichev <stfomichev@gmail.com>
To: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
Cc: "davem@davemloft.net" <davem@davemloft.net>,
Liam Howlett <liam.howlett@oracle.com>,
"edumazet@google.com" <edumazet@google.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"mingo@redhat.com" <mingo@redhat.com>,
"peterz@infradead.org" <peterz@infradead.org>,
"juri.lelli@redhat.com" <juri.lelli@redhat.com>,
"vincent.guittot@linaro.org" <vincent.guittot@linaro.org>,
"dietmar.eggemann@arm.com" <dietmar.eggemann@arm.com>,
"rostedt@goodmis.org" <rostedt@goodmis.org>,
"bsegall@google.com" <bsegall@google.com>,
"mgorman@suse.de" <mgorman@suse.de>,
"vschneid@redhat.com" <vschneid@redhat.com>,
"jiri@resnulli.us" <jiri@resnulli.us>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"shuah@kernel.org" <shuah@kernel.org>,
"linux-kselftest@vger.kernel.org"
<linux-kselftest@vger.kernel.org>, Pei Li <peili.io@oracle.com>
Subject: Re: [PATCH net-next v5 2/3] connector/cn_proc: Kunit tests for threads hash table
Date: Fri, 18 Oct 2024 07:30:53 -0700 [thread overview]
Message-ID: <ZxJxHaodJu1Wcgcb@mini-arch> (raw)
In-Reply-To: <B227B573-F9DF-4063-9A20-787504091DCB@oracle.com>
On 10/18, Anjali Kulkarni wrote:
>
>
> > On Oct 17, 2024, at 5:55 PM, Stanislav Fomichev <stfomichev@gmail.com> wrote:
> >
> > On 10/18, Anjali Kulkarni wrote:
> >>
> >>
> >>> On Oct 17, 2024, at 5:13 PM, Stanislav Fomichev <stfomichev@gmail.com> wrote:
> >>>
> >>> On 10/17, Anjali Kulkarni wrote:
> >>>> Kunit tests to test hash table add, delete, duplicate add and delete.
> >>>> Add following configs and compile kernel code:
> >>>>
> >>>> CONFIG_CONNECTOR=y
> >>>> CONFIG_PROC_EVENTS=y
> >>>> CONFIG_NET=y
> >>>> CONFIG_KUNIT=m
> >>>> CONFIG_CN_HASH_KUNIT_TEST=m
> >>>>
> >>>> To run kunit tests:
> >>>> sudo modprobe cn_hash_test
> >>>>
> >>>> Output of kunit tests and hash table contents are displayed in
> >>>> /var/log/messages (at KERN_DEBUG level).
> >>>>
> >>>> Signed-off-by: Anjali Kulkarni <anjali.k.kulkarni@oracle.com>
> >>>> ---
> >>>> drivers/connector/cn_hash.c | 40 ++++++++
> >>>> drivers/connector/connector.c | 12 +++
> >>>> include/linux/connector.h | 4 +
> >>>> lib/Kconfig.debug | 17 ++++
> >>>> lib/Makefile | 1 +
> >>>> lib/cn_hash_test.c | 167 ++++++++++++++++++++++++++++++++++
> >>>> lib/cn_hash_test.h | 10 ++
> >>>> 7 files changed, 251 insertions(+)
> >>>> create mode 100644 lib/cn_hash_test.c
> >>>> create mode 100644 lib/cn_hash_test.h
> >>>>
> >>>> diff --git a/drivers/connector/cn_hash.c b/drivers/connector/cn_hash.c
> >>>> index a079e9bcea6d..40099b5908ac 100644
> >>>> --- a/drivers/connector/cn_hash.c
> >>>> +++ b/drivers/connector/cn_hash.c
> >>>> @@ -170,6 +170,46 @@ int cn_hash_get_exval(struct cn_hash_dev *hdev, pid_t pid)
> >>>> return -EINVAL;
> >>>> }
> >>>>
> >>>> +int cn_hash_display_hlist(struct cn_hash_dev *hdev, pid_t pid, int max_len,
> >>>> + int *hkey, int *key_display)
> >>>> +{
> >>>> + struct uexit_pid_hnode *hnode;
> >>>> + int key, count = 0;
> >>>> +
> >>>> + mutex_lock(&hdev->uexit_hash_lock);
> >>>> + key = hash_min(pid, HASH_BITS(hdev->uexit_pid_htable));
> >>>> + pr_debug("Bucket: %d\n", key);
> >>>> +
> >>>> + hlist_for_each_entry(hnode,
> >>>> + &hdev->uexit_pid_htable[key],
> >>>> + uexit_pid_hlist) {
> >>>> + if (key_display[key] != 1) {
> >>>> + if (hnode->uexit_pid_hlist.next == NULL)
> >>>> + pr_debug("pid %d ", hnode->pid);
> >>>> + else
> >>>> + pr_debug("pid %d --> ", hnode->pid);
> >>>> + }
> >>>> + count++;
> >>>> + }
> >>>> +
> >>>> + mutex_unlock(&hdev->uexit_hash_lock);
> >>>> +
> >>>> + if ((key_display[key] != 1) && !count)
> >>>> + pr_debug("(empty)\n");
> >>>> +
> >>>> + pr_debug("\n");
> >>>> +
> >>>> + *hkey = key;
> >>>> +
> >>>> + if (count > max_len) {
> >>>> + pr_err("%d entries in hlist for key %d, expected %d\n",
> >>>> + count, key, max_len);
> >>>> + return -EINVAL;
> >>>> + }
> >>>> +
> >>>> + return 0;
> >>>> +}
> >>>> +
> >>>> bool cn_hash_table_empty(struct cn_hash_dev *hdev)
> >>>> {
> >>>> bool is_empty;
> >>>> diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
> >>>> index c1c0dcec53c0..2be2fe1adc12 100644
> >>>> --- a/drivers/connector/connector.c
> >>>> +++ b/drivers/connector/connector.c
> >>>> @@ -304,6 +304,18 @@ int cn_get_exval(pid_t pid)
> >>>> }
> >>>> EXPORT_SYMBOL_GPL(cn_get_exval);
> >>>>
> >>>> +int cn_display_hlist(pid_t pid, int max_len, int *hkey, int *key_display)
> >>>> +{
> >>>> + struct cn_dev *dev = &cdev;
> >>>> +
> >>>> + if (!cn_already_initialized)
> >>>> + return 0;
> >>>> +
> >>>> + return cn_hash_display_hlist(dev->hdev, pid, max_len,
> >>>> + hkey, key_display);
> >>>> +}
> >>>> +EXPORT_SYMBOL_GPL(cn_display_hlist);
> >>>> +
> >>>> bool cn_table_empty(void)
> >>>> {
> >>>> struct cn_dev *dev = &cdev;
> >>>> diff --git a/include/linux/connector.h b/include/linux/connector.h
> >>>> index 5384e4bb98e8..a75c3fcf182a 100644
> >>>> --- a/include/linux/connector.h
> >>>> +++ b/include/linux/connector.h
> >>>> @@ -168,4 +168,8 @@ int cn_get_exval(pid_t pid);
> >>>> bool cn_table_empty(void);
> >>>> bool cn_hash_table_empty(struct cn_hash_dev *hdev);
> >>>>
> >>>> +int cn_display_hlist(pid_t pid, int max_len, int *hkey, int *key_display);
> >>>> +int cn_hash_display_hlist(struct cn_hash_dev *hdev, pid_t pid, int max_len,
> >>>> + int *hkey, int *key_display);
> >>>> +
> >>>> #endif /* __CONNECTOR_H */
> >>>> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> >>>> index 7315f643817a..290cf0a6befa 100644
> >>>> --- a/lib/Kconfig.debug
> >>>> +++ b/lib/Kconfig.debug
> >>>> @@ -2705,6 +2705,23 @@ config HASHTABLE_KUNIT_TEST
> >>>>
> >>>> If unsure, say N.
> >>>>
> >>>> +config CN_HASH_KUNIT_TEST
> >>>> + tristate "KUnit Test for connector hashtable code" if !KUNIT_ALL_TESTS
> >>>> + depends on KUNIT
> >>>> + default KUNIT_ALL_TESTS
> >>>> + help
> >>>> + This builds the hashtable KUnit test suite.
> >>>> + It tests the basic functionality of the API defined in
> >>>> + drivers/connector/cn_hash.c.
> >>>> + CONFIG_CONNECTOR=y, CONFIG_PROC_EVENTS=y and CONFIG_NET=y needs
> >>>> + to be enabled along with CONFIG_CN_HASH_KUNIT_TEST=m and
> >>>> + CONFIG_KUNIT=m in .config file to compile and then test as a kernel
> >>>> + module with "modprobe cn_hash_test".
> >>>> + For more information on KUnit and unit tests in general please
> >>>> + refer to the KUnit documentation in Documentation/dev-tools/kunit/.
> >>>> +
> >>>> + If unsure, say N.
> >>>> +
> >>>
> >>> Looks like this needs to depend on CONFIG_CONNECTOR? Otherwise, the
> >>> existing kunit tester complains about the missing symbols (see below).
> >>> Please also hold off reposting for a couple of days to give people some
> >>> time to review.
> >>>
> >>> ERROR:root:ld: vmlinux.o: in function `cn_hash_test_dup_del':
> >>> cn_hash_test.c:(.text+0x3e9dc3): undefined reference to `cn_del_get_exval'
> >>> ld: cn_hash_test.c:(.text+0x3e9dee): undefined reference to `cn_del_get_exval'
> >>> ld: cn_hash_test.c:(.text+0x3e9e22): undefined reference to `cn_table_empty'
> >>> ld: vmlinux.o: in function `cn_display_htable':
> >>> cn_hash_test.c:(.text+0x3e9f67): undefined reference to `cn_display_hlist'
> >>> ld: vmlinux.o: in function `cn_hash_test_del_get_exval':
> >>> cn_hash_test.c:(.text+0x3ea037): undefined reference to `cn_del_get_exval'
> >>> ld: cn_hash_test.c:(.text+0x3ea088): undefined reference to `cn_table_empty'
> >>> ld: vmlinux.o: in function `cn_hash_test_dup_add':
> >>> cn_hash_test.c:(.text+0x3ea176): undefined reference to `cn_add_elem'
> >>> ld: cn_hash_test.c:(.text+0x3ea19e): undefined reference to `cn_get_exval'
> >>> ld: cn_hash_test.c:(.text+0x3ea1dc): undefined reference to `cn_add_elem'
> >>> ld: cn_hash_test.c:(.text+0x3ea205): undefined reference to `cn_get_exval'
> >>> ld: vmlinux.o: in function `cn_hash_test_del':
> >>> cn_hash_test.c:(.text+0x3ea387): undefined reference to `cn_del_get_exval'
> >>> ld: cn_hash_test.c:(.text+0x3ea3ab): undefined reference to `cn_get_exval'
> >>> ld: cn_hash_test.c:(.text+0x3ea3fd): undefined reference to `cn_table_empty'
> >>> ld: vmlinux.o: in function `cn_hash_test_add':
> >>> cn_hash_test.c:(.text+0x3ea571): undefined reference to `cn_add_elem'
> >>> ld: cn_hash_test.c:(.text+0x3ea591): undefined reference to `cn_get_exval'
> >>> make[3]: *** [../scripts/Makefile.vmlinux:34: vmlinux] Error 1
> >>> make[2]: *** [/home/kunit/testing/Makefile:1166: vmlinux] Error 2
> >>> make[1]: *** [/home/kunit/testing/Makefile:224: __sub-make] Error 2
> >>> make: *** [Makefile:224: __sub-make] Error 2
> >>
> >> Yes, I have added in the comments for CN_HASH_KUNIT_TEST, it depends on:
> >> CONFIG_CONNECTOR, CONFIG_PROC_EVENTS, CONFIG_NET. I didn’t realize
> >> I could add these to the “depends” field.
> >> So something like this: (let me know if you see any issues)
> >>
> >> tristate "KUnit Test for connector hashtable code" if !KUNIT_ALL_TESTS
> >> depends on KUNIT
> >> + depends on CONNECTOR && PROC_EVENTS
> >> + depends on NET
> >> default KUNIT_ALL_TESTS
> >>
> >> These are the configs I add to my .config file and compile it as a module and then
> >> do modprobe to test.
> >
> > [..]
> >
> >> Are you running the kunit tester with kunit.py?
> >
> > Yes, make sure all required options are picked up by
> > "./tools/testing/kunit/kunit.py run" instead of manually adding options
> > and doing modprobe.
>
> I’m unable to run kunit.py, it runs into various issues like UML, permissions, other
> errors. I talked to the kunit guys about this and we have been debugging it for a
> while but unable to fix the environment issue. But the tests work fine.
>
> What kind of VM is this being run on? Like ubuntu etc.? I will try on a different
> OS and check if kunit.py works.
It's running on fedora.
next prev parent reply other threads:[~2024-10-18 14:30 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 18:14 [PATCH net-next v5 0/3] Threads support in proc connector Anjali Kulkarni
2024-10-17 18:14 ` [PATCH net-next v5 1/3] connector/cn_proc: Add hash table for threads Anjali Kulkarni
2024-10-17 18:14 ` [PATCH net-next v5 2/3] connector/cn_proc: Kunit tests for threads hash table Anjali Kulkarni
2024-10-18 0:13 ` Stanislav Fomichev
2024-10-18 0:34 ` Anjali Kulkarni
2024-10-18 0:55 ` Stanislav Fomichev
2024-10-18 1:08 ` Anjali Kulkarni
2024-10-18 14:30 ` Stanislav Fomichev [this message]
2024-10-22 20:36 ` Anjali Kulkarni
2024-10-22 23:50 ` Stanislav Fomichev
2024-10-23 2:03 ` Anjali Kulkarni
2024-10-23 2:24 ` Anjali Kulkarni
2024-10-23 15:05 ` Stanislav Fomichev
2024-10-23 15:58 ` Anjali Kulkarni
2024-10-19 1:28 ` kernel test robot
2024-10-19 2:51 ` kernel test robot
2024-10-17 18:14 ` [PATCH net-next v5 3/3] connector/cn_proc: Selftest for threads Anjali Kulkarni
2024-10-18 10:04 ` Simon Horman
2024-10-18 15:36 ` Anjali Kulkarni
2024-10-18 9:49 ` [PATCH net-next v5 0/3] Threads support in proc connector Simon Horman
2024-10-18 15:31 ` Anjali Kulkarni
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=ZxJxHaodJu1Wcgcb@mini-arch \
--to=stfomichev@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=anjali.k.kulkarni@oracle.com \
--cc=bsegall@google.com \
--cc=davem@davemloft.net \
--cc=dietmar.eggemann@arm.com \
--cc=edumazet@google.com \
--cc=jiri@resnulli.us \
--cc=juri.lelli@redhat.com \
--cc=kuba@kernel.org \
--cc=liam.howlett@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=peili.io@oracle.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/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).