[PATCH RFC] tests: check decoding of libudev netlink header

Harsha Sharma harshasharmaiitr at gmail.com
Sat Mar 3 10:49:16 UTC 2018


On Mon, Feb 26, 2018 at 7:28 AM, Dmitry V. Levin <ldv at altlinux.org> wrote:
> On Sun, Feb 18, 2018 at 10:09:07AM +0530, Harsha Sharma wrote:
>> On Sun, Feb 18, 2018 at 9:08 AM, Chen Jingpiao <chenjingpiao at gmail.com> wrote:
>> > On 02/16 02:19, Harsha Sharma wrote:
>> >> * tests/netlink_kobject_uevent_libudev.c: New file.
>> >> * tests/gen_tests.in (netlink_kobject_uevent_libudev): New entry.
>> >> * tests/pure_executables.list: Add netlink_kobject_uevent_libudev.
>> >> * tests/.gitignore: Likewise.
>
> Sorry for delay with review, see my comments below.
>
>> >>
>> >> Signed-off-by: Harsha Sharma <harshasharmaiitr at gmail.com>
>> >> ---
>> >>  tests/.gitignore                       |  1 +
>> >>  tests/gen_tests.in                     |  1 +
>> >>  tests/netlink_kobject_uevent_libudev.c | 88 ++++++++++++++++++++++++++++++++++
>> >>  tests/pure_executables.list            |  1 +
>> >>  4 files changed, 91 insertions(+)
>> >>  create mode 100644 tests/netlink_kobject_uevent_libudev.c
>> >>
>> >> diff --git a/tests/.gitignore b/tests/.gitignore
>> >> index 2541ec24..623b98f8 100644
>> >> --- a/tests/.gitignore
>> >> +++ b/tests/.gitignore
>> >> @@ -215,6 +215,7 @@ netlink_crypto
>> >>  netlink_generic
>> >>  netlink_inet_diag
>> >>  netlink_kobject_uevent
>> >> +netlink_kobject_uevent_libudev
>> >>  netlink_netfilter
>> >>  netlink_netlink_diag
>> >>  netlink_protocol
>> >> diff --git a/tests/gen_tests.in b/tests/gen_tests.in
>> >> index 18f36408..263479a5 100644
>> >> --- a/tests/gen_tests.in
>> >> +++ b/tests/gen_tests.in
>> >> @@ -199,6 +199,7 @@ netlink_audit     +netlink_sock_diag.test
>> >>  netlink_crypto       +netlink_sock_diag.test
>> >>  netlink_generic      +netlink_sock_diag.test
>> >>  netlink_kobject_uevent       +netlink_sock_diag.test
>> >> +netlink_kobject_uevent_libudev  +netlink_sock_diag.test
>> >>  netlink_netfilter    +netlink_sock_diag.test
>> >>  netlink_protocol     -e trace=sendto
>> >>  netlink_route        +netlink_sock_diag.test
>> >> diff --git a/tests/netlink_kobject_uevent_libudev.c b/tests/netlink_kobject_uevent_libudev.c
>> >> new file mode 100644
>> >> index 00000000..8f0b2bfa
>> >> --- /dev/null
>> >> +++ b/tests/netlink_kobject_uevent_libudev.c
>> >> @@ -0,0 +1,88 @@
>> >> +/*
>> >> + * Copyright (c) 2017 JingPiao Chen <chenjingpiao at gmail.com>
>> >> + * Copyright (c) 2017 The strace developers.
>> >> + * All rights reserved.
>> >> + *
>> >> + * Redistribution and use in source and binary forms, with or without
>> >> + * modification, are permitted provided that the following conditions
>> >> + * are met:
>> >> + * 1. Redistributions of source code must retain the above copyright
>> >> + *    notice, this list of conditions and the following disclaimer.
>> >> + * 2. Redistributions in binary form must reproduce the above copyright
>> >> + *    notice, this list of conditions and the following disclaimer in the
>> >> + *    documentation and/or other materials provided with the distribution.
>> >> + * 3. The name of the author may not be used to endorse or promote products
>> >> + *    derived from this software without specific prior written permission.
>> >> + *
>> >> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
>> >> + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
>> >> + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
>> >> + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
>> >> + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
>> >> + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
>> >> + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
>> >> + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
>> >> + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
>> >> + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>> >> + */
>> >> +
>> >> +#include "tests.h"
>> >> +#include <stdio.h>
>> >> +#include <string.h>
>> >> +#include <sys/socket.h>
>> >> +#include "netlink.h"
>> >> +#include "netlink_kobject_uevent.h"
>> >> +#include <sys/types.h>
>> >> +#include <unistd.h>
>> >> +#include <arpa/inet.h>
>> >> +#include <fcntl.h>
>> >> +
>> >> +int
>> >> +main(void)
>> >> +{
>> >> +     skip_if_unavailable("/proc/self/fd/");
>> >> +
>> >> +     int fd, ret;
>> >> +     struct sockaddr_nl nls;
>> >> +     struct udev_monitor_netlink_header uh;
>> >> +
>> >> +     memset(&nls, 0, sizeof(nls));
>> >> +     nls.nl_family = AF_NETLINK;
>> >> +     nls.nl_pid = getpid();
>> >> +     nls.nl_groups = -1;
>> >> +
>> >> +     fd = socket(AF_NETLINK, (SOCK_DGRAM | SOCK_CLOEXEC),
>> >> +                 NETLINK_KOBJECT_UEVENT);
>> >> +     if (fd < 0)
>> >> +             perror_msg_and_skip("socket AF_NETLINK");
>> >> +
>> >> +     ret = bind(fd, (struct sockaddr *) &nls, sizeof(nls));
>> >> +     if (ret)
>> >> +             perror_msg_and_skip("bind AF_NETLINK");
>> >
>> > Replace with create_nl_socket().
>>
>> I need to set nls.nl_pid = getpid();
>> and nls.nl_groups = -1; to recieve from kernel broadcast so using
>> create_nl_socket in place of this doesn't work.
>>
>> >> +
>> >> +     printf("Waiting for events now...\n");
>> >
>> > Why print this message?
>>
>> This is a RFC patch so to clear what's happening I left this.
>>
>> >> +     while (1) {
>> >> +             int r = recv(fd, &uh, sizeof(uh), MSG_ERRQUEUE);
>> >> +             if (r <= 0)
>> >> +                     perror_msg_and_skip("recv");
>> >> +             if (!strcmp(uh.prefix, "libudev"))
>> >> +                     printf("recvfrom(%i, {{prefix=\"%s\""
>> >> +                            ", magic=htonl(%#x), header_size=%u"
>> >> +                            ", properties_off=%u, properties_len=%u"
>> >> +                            ", filter_subsystem_hash=htonl(%#x)"
>> >> +                            ", filter_devtype_hash=htonl(%#x)"
>> >> +                            ", filter_tag_bloom_hi=htonl(%#x)"
>> >> +                            ", filter_tag_bloom_lo=htonl(%#x)}}, %li"
>> >> +                            ", MSG_ERRQUEUE, NULL, NULL)\n",
>> >> +                            fd, uh.prefix, ntohl(uh.magic), uh.header_size,
>> >> +                            uh.properties_off, uh.properties_len,
>> >> +                            ntohl(uh.filter_subsystem_hash),
>> >> +                            ntohl(uh.filter_devtype_hash),
>> >> +                            ntohl(uh.filter_tag_bloom_hi),
>> >> +                            ntohl(uh.filter_tag_bloom_lo), sizeof(uh));
>> >> +     }
>> >
>> > I do not understand how this work. travis-ci is fail.
>>
>> This actually waits for kernel uevents and prints decoding of
>> udev_monitor_netlink_header.
>> On strace -e trace=network ./tests/netlink_kobject_uvent_libudev, it
>> shows decoding of libudev header along with printf output which is
>> exactly same.
>>
>> > netlink_kobject_uevent_libudev.gen.test source netlink_sock_diag.test,
>> > which only trace sendto syscall.
>>
>> strace -e trace=sendto udevadm monitor > /dev/null shows no output.
>> NETLINK_KOBJECT_UEVENT protocol is used to receive kernel messages to
>> userspace so sendto syscall is never used in this process. So make
>> check for this test is supposed to fail.
>
> Sorry but "make check" is an instrument of regression testing,
> it is supposed to succeed.

It succeds if it recieves any kernel message, for e.g for any device connection.
But yes, you are right,  it does not make sense for regression testing.

> As you could have noticed, all other tests of netlink protocol decoders
> do not wait for kernel messages, unlike normal netlink users.
>
> Instead, they generate these messages themselves to let strace decode
> them.
>
> I think it's quite logical if this test used the same method.

Sorry, I didn't get you, other netlink  protocol tests traces sendto
syscall which is not the case here.
Thanks for your time.

Regards,
Harsha Sharma

>
> --
> ldv
>
> --
> Strace-devel mailing list
> Strace-devel at lists.strace.io
> https://lists.strace.io/mailman/listinfo/strace-devel
>


More information about the Strace-devel mailing list