[PATCH] tests: extend for decoding of udev_monitor_netlink_header

Dmitry V. Levin ldv at altlinux.org
Fri Mar 9 21:36:45 UTC 2018


On Wed, Mar 07, 2018 at 11:44:50PM +0530, Harsha Sharma wrote:
> * tests/netlink_kobject_uevent.c: Add test_nlmsg_type_udev.
> ---
>  tests/netlink_kobject_uevent.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/tests/netlink_kobject_uevent.c b/tests/netlink_kobject_uevent.c
> index cacab5fd..2853f02b 100644
> --- a/tests/netlink_kobject_uevent.c
> +++ b/tests/netlink_kobject_uevent.c
> @@ -30,6 +30,25 @@
>  #include <stdio.h>
>  #include <sys/socket.h>
>  #include "netlink.h"
> +#include "netlink_kobject_uevent.h"
> +
> +static void
> +test_nlmsg_type_udev(const int fd)
> +{
> +	long ret;
> +	struct udev_monitor_netlink_header uh = {
> +		.prefix = "libudev",
> +		.header_size = sizeof(uh),
> +	};
> +
> +	ret = sendto(fd, &uh, sizeof(uh), MSG_DONTWAIT, NULL, 0);
> +	printf("sendto(%d, {{prefix=\"%s\", magic=htonl(0)"
> +	", header_size=%u, properties_off=0, properties_len=0"
> +	", filter_subsystem_hash=htonl(0), filter_devtype_hash=htonl(0)"
> +	", filter_tag_bloom_hi=htonl(0), filter_tag_bloom_lo=htonl(0)}}"
> +	", %u, MSG_DONTWAIT, NULL, 0) = %s\n", fd, uh.prefix, uh.header_size,
> +	 (unsigned) sizeof(uh), sprintrc(ret));
> +}

This is a move in the right direction.  I'd recommend initializing
udev_monitor_netlink_header with different non-zero values for better
quality of the test coverage.

As you can see at
https://codecov.io/gh/strace/strace/src/a34a39cf60b54503f37c94225f947adefff6b441/netlink_kobject_uevent.c
some code paths of decode_netlink_kobject_uevent are not covered by this
test.  This include prefix mismatch and the length exceeding the size of
structure.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20180310/e95d1d5a/attachment.bin>


More information about the Strace-devel mailing list