From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [RFC v2 12/16] net: picotcp: add test_picotcp command
Date: Sun, 19 Jul 2015 23:07:19 +0300 [thread overview]
Message-ID: <1437336443-8076-13-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1437336443-8076-1-git-send-email-antonynpavlov@gmail.com>
See original test_ipv4() from picotcp.git/test/unit/unit_ipv4.c.
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
net/Makefile | 2 ++
net/picotcp/Kconfig | 7 ++++
net/picotcp_test_ipv4.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 105 insertions(+)
diff --git a/net/Makefile b/net/Makefile
index 7a4597d..bfe74fb 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -10,3 +10,5 @@ obj-$(CONFIG_NET_IFUP) += ifup.o
obj-$(CONFIG_NET_PICOTCP) += picotcp/
obj-$(CONFIG_NET_PICOTCP) += picotcp.o
+
+obj-$(CONFIG_CMD_PICOTCP_TEST_IPV4) += picotcp_test_ipv4.o
diff --git a/net/picotcp/Kconfig b/net/picotcp/Kconfig
index 3882984..17b8293 100644
--- a/net/picotcp/Kconfig
+++ b/net/picotcp/Kconfig
@@ -31,4 +31,11 @@ config NET_PICO_BIGENDIAN
bool
prompt "bigendian picotcp"
+comment "Commands"
+
+config CMD_PICOTCP_TEST_IPV4
+ bool
+ depends on NET_PICO_SUPPORT_IPV4
+ prompt "test_picotcp command"
+
endif # NET_PICOTCP
diff --git a/net/picotcp_test_ipv4.c b/net/picotcp_test_ipv4.c
new file mode 100644
index 0000000..314d21c
--- /dev/null
+++ b/net/picotcp_test_ipv4.c
@@ -0,0 +1,96 @@
+#include <common.h>
+#include <command.h>
+#include <complete.h>
+
+#include <pico_stack.h>
+#include <pico_ipv4.h>
+#include <pico_dev_null.h>
+
+#define fail_if(a, msg) \
+ if (a) { \
+ printf("%s\n", msg); \
+ return; \
+ }
+
+#define fail_unless(a, msg) fail_if(!(a), msg)
+
+static void do_test_ipv4(void)
+{
+ #define IP_TST_SIZ 256
+ int i;
+
+ struct pico_device *dev[IP_TST_SIZ];
+ char devname[8];
+ struct pico_ip4 a[IP_TST_SIZ], d[IP_TST_SIZ], *source[IP_TST_SIZ], nm16, nm32, gw[IP_TST_SIZ], r[IP_TST_SIZ], ret;
+ struct pico_ipv4_link *l[IP_TST_SIZ];
+
+ char ipstr[] = "192.168.1.1";
+ struct pico_ip4 ipaddr;
+
+ struct pico_frame *f_NULL = NULL;
+ struct pico_ip4 *dst_NULL = NULL;
+
+ nm16.addr = long_be(0xFFFF0000);
+ nm32.addr = long_be(0xFFFFFFFF);
+
+ /*link_add*/
+ for (i = 0; i < IP_TST_SIZ; i++) {
+ snprintf(devname, 8, "nul%d", i);
+ dev[i] = pico_null_create(devname);
+ a[i].addr = long_be(0x0a000001 + (i << 16));
+ d[i].addr = long_be(0x0a000002 + (i << 16));
+ fail_if(pico_ipv4_link_add(dev[i], a[i], nm16) != 0, "Error adding link");
+ }
+ /*link_find + link_get + route_add*/
+ for (i = 0; i < IP_TST_SIZ; i++) {
+ gw[i].addr = long_be(0x0a0000f0 + (i << 16));
+ r[i].addr = long_be(0x0c00001 + (i << 16));
+ fail_unless(pico_ipv4_link_find(&a[i]) == dev[i], "Error finding link");
+ l[i] = pico_ipv4_link_get(&a[i]);
+ fail_if(l[i] == NULL, "Error getting link");
+ fail_if(pico_ipv4_route_add(r[i], nm32, gw[i], 1, l[i]) != 0, "Error adding route");
+ fail_if(pico_ipv4_route_add(d[i], nm32, gw[i], 1, l[i]) != 0, "Error adding route");
+ }
+ /*get_gateway + source_find*/
+ for (i = 0; i < IP_TST_SIZ; i++) {
+ ret = pico_ipv4_route_get_gateway(&r[i]);
+ fail_if(ret.addr != gw[i].addr, "Error get gateway: returned wrong route");
+ source[i] = pico_ipv4_source_find(&d[i]);
+ fail_if(source[i]->addr != a[i].addr, "Error find source: returned wrong route");
+ }
+ /*route_del + link_del*/
+ for (i = 0; i < IP_TST_SIZ; i++) {
+ fail_if(pico_ipv4_route_del(r[i], nm32, 1) != 0, "Error deleting route");
+ fail_if(pico_ipv4_link_del(dev[i], a[i]) != 0, "Error deleting link");
+ }
+ /*string_to_ipv4 + ipv4_to_string*/
+ pico_string_to_ipv4(ipstr, &(ipaddr.addr));
+ fail_if(ipaddr.addr != long_be(0xc0a80101), "Error string to ipv4");
+ memset(ipstr, 0, 12);
+ pico_ipv4_to_string(ipstr, ipaddr.addr);
+ fail_if(strncmp(ipstr, "192.168.1.1", 11) != 0, "Error ipv4 to string");
+
+ /*valid_netmask*/
+ fail_if(pico_ipv4_valid_netmask(long_be(nm32.addr)) != 32, "Error checking netmask");
+
+ /*is_unicast*/
+ fail_if((pico_ipv4_is_unicast(long_be(0xc0a80101))) != 1, "Error checking unicast");
+ fail_if((pico_ipv4_is_unicast(long_be(0xe0000001))) != 0, "Error checking unicast");
+
+ /*rebound*/
+ fail_if(pico_ipv4_rebound(f_NULL) != -1, "Error rebound frame");
+
+ /*frame_push*/
+ fail_if(pico_ipv4_frame_push(f_NULL, dst_NULL, PICO_PROTO_TCP) != -1, "Error push frame");
+}
+
+static int do_test_picotcp(int argc, char *argv[])
+{
+ do_test_ipv4();
+
+ return 0;
+}
+
+BAREBOX_CMD_START(test_picotcp)
+ .cmd = do_test_picotcp,
+BAREBOX_CMD_END
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-07-19 20:08 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-19 20:07 [RFC v2 00/16] barebox picotcp integration (2015.07.19) Antony Pavlov
2015-07-19 20:07 ` [RFC v2 01/16] net_udp_bind(): use uint16_t type for source port Antony Pavlov
2015-07-19 20:07 ` [RFC v2 02/16] fs/tftp.c: drop unused server_port variable Antony Pavlov
2015-07-19 20:07 ` [RFC v2 03/16] fs/nfs.c: use uint16_t for port numbers Antony Pavlov
2015-07-19 20:07 ` [RFC v2 04/16] fs/nfs.c: use SUNRPC_PORT remote port by default Antony Pavlov
2015-07-19 20:07 ` [RFC v2 05/16] net: change UDP handler function API Antony Pavlov
2015-07-19 20:07 ` [RFC v2 06/16] net: change net_udp_send() API Antony Pavlov
2015-07-19 20:07 ` [RFC v2 07/16] net: introduce setudppeerport() Antony Pavlov
2015-07-19 20:07 ` [RFC v2 08/16] net: import picotcp from github Antony Pavlov
2015-07-19 20:07 ` [RFC v2 09/16] picotcp: add barebox target support Antony Pavlov
2015-07-19 20:07 ` [RFC v2 10/16] picotcp: switch to Kbuild Antony Pavlov
2015-07-19 20:07 ` [RFC v2 11/16] net: add initial picotcp support Antony Pavlov
2015-07-19 20:07 ` Antony Pavlov [this message]
2015-07-19 20:07 ` [RFC v2 13/16] net: picotcp: add ifconfig command Antony Pavlov
2015-07-19 20:07 ` [RFC v2 14/16] net: picotcp: add ping command Antony Pavlov
2015-07-19 20:07 ` [RFC v2 15/16] net: picotcp: add route command Antony Pavlov
2015-07-19 20:07 ` [RFC v2 16/16] sandbox_defconfig: switch to picotcp Antony Pavlov
2015-07-20 7:10 ` [RFC v2 00/16] barebox picotcp integration (2015.07.19) Sascha Hauer
2015-07-20 9:50 ` Antony Pavlov
2015-07-20 10:06 ` Antony Pavlov
2015-07-20 10:45 ` Sascha Hauer
2015-07-20 12:16 ` Antony Pavlov
2015-07-24 4:58 ` Antony Pavlov
2015-07-24 7:19 ` Sascha Hauer
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=1437336443-8076-13-git-send-email-antonynpavlov@gmail.com \
--to=antonynpavlov@gmail.com \
--cc=barebox@lists.infradead.org \
/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