[PATCH v2 2/2] tests: check decoding of ifinfomsg netlink attributes
JingPiao Chen
chenjingpiao at gmail.com
Sun Aug 20 08:07:44 UTC 2017
On Sun, Aug 20, 2017 at 01:35:58AM +0300, Dmitry V. Levin wrote:
> On Sat, Aug 19, 2017 at 09:50:11AM +0800, JingPiao Chen wrote:
> > * gen_tests.in (nlattr_ifinfomsg): Replace netlink_sock_diag.test
> > with netlink_sock_diag-v.sh, using verbose to check decoding of array.
> > * tests/nlattr_ifinfomsg.c: Include <stddef.h>, <arpa/inet.h>,
> > <linux/if_link.h> and <linux/netdevice.h>.
> > (SET_IFI_TYPE, IFLA_PHYS_PORT_ID, IFLA_LINK_NETNSID): New macros.
> > (init_ifinfomsg): Set ifinfomsg.ifi_type field.
> > (print_ifinfomsg): Print ifinfomsg.ifi_type field use %s format.
> > (main): Check decoding of IFLA_LINK_NETNSID, IFLA_STATS,
> > IFLA_MAP, IFLA_STATS64, IFLA_PHYS_PORT_ID and IFLA_ADDRESS.
> > ---
[...]
> > +
> > + static const uint8_t id[] = { 0xcd, 0xef };
> > + TEST_NLATTR(fd, nlh0, hdrlen,
> > + init_ifinfomsg, print_ifinfomsg,
> > + IFLA_PHYS_PORT_ID, sizeof(id), id, sizeof(id),
> > + printf("[%u, %u]", id[0], id[1]));
> > +
> > + static uint8_t bigid[33];
>
> Please use DEFAULT_STRLEN.
>
> > + memcpy(bigid, pattern, sizeof(bigid));
> > + TEST_NLATTR(fd, nlh0, hdrlen,
> > + init_ifinfomsg, print_ifinfomsg,
> > + IFLA_PHYS_PORT_ID, sizeof(bigid), bigid, sizeof(bigid),
> > + size_t i;
> > + for (i = 0; i < 32; ++i) {
>
> Likewise.
I do not think it should use DEFAULT_STRLEN.
Here 33 = MAX_PHYS_ITEM_ID_LEN + 1.
I add a comment like in print_item_id:
/* MAX_PHYS_ITEM_ID_LEN = 32 */
--
JingPiao Chen
More information about the Strace-devel
mailing list