Module: xenomai-gch Branch: next Commit: 87f395189801796921a2443abae117f673a237b0 URL: http://git.xenomai.org/?p=xenomai-gch.git;a=commit;h=87f395189801796921a2443abae117f673a237b0
Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org> Date: Sun Nov 1 19:14:40 2015 +0100 testsuite/smokey: add RTnet raw packets test --- configure.ac | 1 + testsuite/smokey/Makefile.am | 1 + testsuite/smokey/net_common/setup.c | 7 +- testsuite/smokey/net_packet_raw/Makefile.am | 10 +++ testsuite/smokey/net_packet_raw/packet_raw.c | 122 ++++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 5364b4f..29aa454 100644 --- a/configure.ac +++ b/configure.ac @@ -902,6 +902,7 @@ AC_CONFIG_FILES([ \ testsuite/smokey/fpu-stress/Makefile \ testsuite/smokey/net_udp/Makefile \ testsuite/smokey/net_packet_dgram/Makefile \ + testsuite/smokey/net_packet_raw/Makefile \ testsuite/smokey/net_common/Makefile \ testsuite/clocktest/Makefile \ testsuite/xeno-test/Makefile \ diff --git a/testsuite/smokey/Makefile.am b/testsuite/smokey/Makefile.am index 0139349..174b393 100644 --- a/testsuite/smokey/Makefile.am +++ b/testsuite/smokey/Makefile.am @@ -12,6 +12,7 @@ COBALT_SUBDIRS = \ iddp \ leaks \ net_packet_dgram\ + net_packet_raw \ net_udp \ net_common \ posix-clock \ diff --git a/testsuite/smokey/net_common/setup.c b/testsuite/smokey/net_common/setup.c index 5e83621..ea3dace 100644 --- a/testsuite/smokey/net_common/setup.c +++ b/testsuite/smokey/net_common/setup.c @@ -251,16 +251,11 @@ static int find_peer(const char *intf, void *vpeer) for(;;) { err = fscanf(f, "%s\t%s\t%s\t%s\n", hash, dest, mac, dev); - if (err == 0) { + if (err == EOF) { smokey_warning("No peer found\n"); err = -ENOENT; goto err; } - if (err < 0) { - err = -errno; - smokey_warning("fscanf: %s", strerror(-err)); - goto err; - } if (err < 4) { smokey_warning("Error parsing" " /proc/rtnet/ipv4/host_route\n"); diff --git a/testsuite/smokey/net_packet_raw/Makefile.am b/testsuite/smokey/net_packet_raw/Makefile.am new file mode 100644 index 0000000..6a6372a --- /dev/null +++ b/testsuite/smokey/net_packet_raw/Makefile.am @@ -0,0 +1,10 @@ +noinst_LIBRARIES = libnet_packet_raw.a + +libnet_packet_raw_a_SOURCES = \ + packet_raw.c + +libnet_packet_raw_a_CPPFLAGS = \ + @XENO_USER_CFLAGS@ \ + -I$(srcdir)/../net_common \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/kernel/drivers/net/stack/include diff --git a/testsuite/smokey/net_packet_raw/packet_raw.c b/testsuite/smokey/net_packet_raw/packet_raw.c new file mode 100644 index 0000000..a7302ca --- /dev/null +++ b/testsuite/smokey/net_packet_raw/packet_raw.c @@ -0,0 +1,122 @@ +/* + * RTnet AF_PACKET test + * + * Copyright (C) 2015 Gilles Chanteperdrix <g...@xenomai.org> + * + * SPDX-License-Identifier: MIT + */ + +#include <unistd.h> +#include <net/if.h> +#include <arpa/inet.h> +#include <net/ethernet.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <netpacket/packet.h> + +#include <sys/cobalt.h> +#include <smokey/smokey.h> +#include "smokey_net.h" + +smokey_test_plugin(net_packet_raw, + SMOKEY_ARGLIST( + SMOKEY_STRING(rtnet_driver), + SMOKEY_STRING(rtnet_interface), + SMOKEY_INT(rtnet_rate), + SMOKEY_INT(rtnet_duration), + ), + "Check RTnet driver, using raw packets, measuring round trip time\n" + "\tand packet losses,\n" + "\tthe rtnet_driver parameter allows choosing the network driver\n" + "\tthe rtnet_interface parameter allows choosing the network interface\n" + "\tthe rtnet_rate parameter allows choosing the packet rate\n" + "\tthe rtnet_duration parameter allows choosing the test duration\n" + "\tA server on the network must run the smokey_rtnet_server program." +); + +struct raw_packet_client { + struct smokey_net_client base; + struct ethhdr header; +}; + +static int +packet_raw_create_socket(struct smokey_net_client *bclient) +{ + struct raw_packet_client *client = (struct raw_packet_client *)bclient; + struct ifreq ifr; + int err, sock; + + sock = smokey_check_errno( + __RT(socket(PF_PACKET, SOCK_RAW, htons(ETH_P_802_EX1 + 1)))); + if (sock < 0) + return sock; + + memcpy(client->header.h_dest, bclient->ll_peer.sll_addr, 6); + ifr.ifr_ifindex = bclient->ll_peer.sll_ifindex; + err = smokey_check_errno( + __RT(ioctl(sock, SIOCGIFNAME, &ifr))); + if (err < 0) + goto err; + err = smokey_check_errno( + __RT(ioctl(sock, SIOCGIFHWADDR, &ifr))); + if (err < 0) + goto err; + memcpy(client->header.h_source, ifr.ifr_hwaddr.sa_data, 6); + client->header.h_proto = htons(ETH_P_802_EX1); + + return sock; + + err: + __RT(close(sock)); + return err; +} + +static int +packet_raw_prepare(struct smokey_net_client *bclient, + void *buf, size_t len, const struct smokey_net_payload *payload) +{ + struct raw_packet_client *client = (struct raw_packet_client *)bclient; + + if (len < sizeof(client->header) + sizeof(*payload)) + return -EINVAL; + + len = sizeof(client->header) + sizeof(*payload); + memcpy(buf, &client->header, sizeof(client->header)); + memcpy(buf + sizeof(client->header), payload, sizeof(*payload)); + return len; +} + +static int +packet_raw_extract(struct smokey_net_client *bclient, + struct smokey_net_payload *payload, const void *buf, size_t len) +{ + struct raw_packet_client *client = (struct raw_packet_client *)bclient; + + if (len < sizeof(client->header) + sizeof(*payload)) + return -EINVAL; + + len = sizeof(client->header) + sizeof(*payload); + memcpy(payload, buf + sizeof(client->header), sizeof(*payload)); + return len; +} + +static int +run_net_packet_raw(struct smokey_test *t, int argc, char *const argv[]) +{ + struct raw_packet_client client = { + .base = { + .name = "raw packets", + .option = _CC_COBALT_NET_AF_PACKET, + .create_socket = &packet_raw_create_socket, + .prepare = &packet_raw_prepare, + .extract = &packet_raw_extract, + }, + }; + struct smokey_net_client *bclient = &client.base; + + memset(&bclient->ll_peer, '\0', sizeof(bclient->ll_peer)); + bclient->ll_peer.sll_family = AF_PACKET; + bclient->peer_len = sizeof(bclient->ll_peer); + + return smokey_net_client_run(t, bclient, argc, argv); +} _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://xenomai.org/mailman/listinfo/xenomai-git