diff --git a/base-foc/run/env b/base-foc/run/env index f1671a55f..8d00a7e7f 100644 --- a/base-foc/run/env +++ b/base-foc/run/env @@ -71,6 +71,17 @@ proc fiasco_external { } { return 1 } +## +# Reset the target system via the Fiasco.OC kernel debugger +# +proc reset { {spawn_id_arg -1} } { + global spawn_id + if { $spawn_id_arg == -1 } { + set spawn_id_arg $spawn_id + } + send -i $spawn_id_arg "\033^^" +} + ################################## ## Test framework API functions ## ################################## diff --git a/libports/run/network_test.inc b/libports/run/network_test.inc new file mode 100644 index 000000000..9366fbe75 --- /dev/null +++ b/libports/run/network_test.inc @@ -0,0 +1,205 @@ +# +# \brief Test ping +# \author Josef Soentgen +# \date 2013-01-06 +# + +# +# Client parameters +# +set packet_payload_size 24 +set packet_count 1000000 + +# +# Build +# + +set build_components { + core init + drivers/pci drivers/timer drivers/nic + test/lwip/pingpong/server +} + +lappend_if $use_nic_bridge build_components server/nic_bridge + +lappend_if [expr [have_spec omap4] || [have_spec exynos5]] build_components drivers/usb + +build $build_components + +create_boot_directory + +# +# Generate config +# + +set config { + + + + + + + + + + + + + + + + + + + + + } + +append_if $use_nic_bridge config { + + + + + } +append_if [expr $use_nic_bridge && ([have_spec omap4] || [have_spec exynos5])] config { + } +append_if [expr $use_nic_bridge && (![have_spec omap4] && ![have_spec exynos5])] config { + } +append_if $use_nic_bridge config { + + + + } + +append config " + " +append config { + + + + + } +append_if $use_nic_bridge config { + } +append config { + + + } + +append_if [expr [have_spec omap4] || [have_spec exynos5]] config { + + + + + + + + + + } + +append_if [expr ![have_spec omap4] && ![have_spec exynos5]] config { + + + + } + +append_if [have_spec pci] config { + + + + } + +append config { + +} + +install_config $config + +# +# Boot modules +# + +# generic modules +set boot_modules { + core init timer + ld.lib.so libc.lib.so lwip.lib.so libc_log.lib.so +} + +lappend_if $use_nic_bridge boot_modules nic_bridge + +lappend boot_modules $test_server_name + +# platform-specific modules +lappend_if [have_spec pci] boot_modules pci_drv +lappend_if [expr [have_spec omap4] || [have_spec exynos5]] boot_modules usb_drv +lappend_if [expr ![have_spec omap4] && ![have_spec exynos5]] boot_modules nic_drv + +build_boot_image $boot_modules + +# establish serial connection with the server system +spawn picocom -b 115200 /dev/ttyUSB0 +set server_spawn_id $spawn_id +set timeout -1 +expect -i $server_spawn_id "Terminal ready" + +# reset the server system (if Fiasco.OC is already running) +reset $server_spawn_id + +# get IP address from server +expect { + -i $server_spawn_id + -re "got IP address (.*)\033.*\n" { set ip_addr $expect_out(1,string) } +} +puts "got server IP address: $ip_addr" + +# wait until the server is ready +expect -i $server_spawn_id "wait...*\n" + +# build the client +set pingpong_dir $genode_dir/libports/src/test/lwip/pingpong +exec g++ -o bin/network_test_client \ + $pingpong_dir/client/main.cc \ + $pingpong_dir/pingpong.cc \ + -I $pingpong_dir + +# start the client +spawn bin/network_test_client \ + -serverip $ip_addr \ + -startsize $packet_payload_size \ + -endsize $packet_payload_size \ + -count $packet_count + +# wait until the client is connected to the server +expect -i $server_spawn_id "client \[1|3\] connected..." + +# start counting the execution time +set time_start [clock milliseconds] + +# wait until the server received all packets +expect { + -i $server_spawn_id + -re "received .*\n" { } +} + +# stop counting the execution time +set time_end [clock milliseconds] + +set milliseconds [expr $time_end - $time_start] +set payload_total [expr $packet_count * $packet_payload_size] +set payload_bytes_per_second [expr $payload_total * 1000 / $milliseconds ] + +set test_result "$milliseconds ms ($payload_bytes_per_second payload bytes per second)" + +puts "\nTest succeeded in $test_result." + +# disconnect from server system +send -i $server_spawn_id "\x01\x18" ;# Ctrl-A Ctrl-X +expect { + -i $server_spawn_id + "Thanks for using picocom" +} + +exec rm -f bin/network_test_client + +# vi: set ft=tcl : diff --git a/libports/run/network_test.run b/libports/run/network_test.run new file mode 100644 index 000000000..71ffba1a4 --- /dev/null +++ b/libports/run/network_test.run @@ -0,0 +1,18 @@ +source ${genode_dir}/libports/run/network_test_lwip.run +set test_result_lwip $test_result + +source ${genode_dir}/libports/run/network_test_lwip_nic_bridge.run +set test_result_lwip_nic_bridge $test_result + +source ${genode_dir}/libports/run/network_test_libc_lwip.run +set test_result_libc_lwip $test_result + +source ${genode_dir}/libports/run/network_test_libc_lwip_nic_bridge.run +set test_result_libc_lwip_nic_bridge $test_result + +puts "\nTest results:\n" +puts "lwip: $test_result_lwip" +puts "lwip_nic_bridge: $test_result_lwip_nic_bridge" +puts "libc_lwip: $test_result_libc_lwip" +puts "libc_lwip_nic_bridge: $test_result_libc_lwip_nic_bridge" +puts "" diff --git a/libports/run/network_test_libc_lwip.run b/libports/run/network_test_libc_lwip.run new file mode 100644 index 000000000..98d0603cc --- /dev/null +++ b/libports/run/network_test_libc_lwip.run @@ -0,0 +1,4 @@ +set use_nic_bridge 0 +set test_server_name "test-ping_server_libc_lwip" + +source ${genode_dir}/libports/run/network_test.inc diff --git a/libports/run/network_test_libc_lwip_nic_bridge.run b/libports/run/network_test_libc_lwip_nic_bridge.run new file mode 100644 index 000000000..94897e2f5 --- /dev/null +++ b/libports/run/network_test_libc_lwip_nic_bridge.run @@ -0,0 +1,4 @@ +set use_nic_bridge 1 +set test_server_name "test-ping_server_libc_lwip" + +source ${genode_dir}/libports/run/network_test.inc diff --git a/libports/run/network_test_lwip.run b/libports/run/network_test_lwip.run new file mode 100644 index 000000000..bcce7ad31 --- /dev/null +++ b/libports/run/network_test_lwip.run @@ -0,0 +1,4 @@ +set use_nic_bridge 0 +set test_server_name "test-ping_server_lwip" + +source ${genode_dir}/libports/run/network_test.inc diff --git a/libports/run/network_test_lwip_nic_bridge.run b/libports/run/network_test_lwip_nic_bridge.run new file mode 100644 index 000000000..86c9c8027 --- /dev/null +++ b/libports/run/network_test_lwip_nic_bridge.run @@ -0,0 +1,4 @@ +set use_nic_bridge 1 +set test_server_name "test-ping_server_lwip" + +source ${genode_dir}/libports/run/network_test.inc diff --git a/libports/run/test-ping_client.run b/libports/run/test-ping_client.run index ae3f711eb..727707c13 100644 --- a/libports/run/test-ping_client.run +++ b/libports/run/test-ping_client.run @@ -14,7 +14,7 @@ set build_components { test/lwip/pingpong/client } -lappend_if [have_spec omap4] build_components drivers/usb +lappend_if [expr [have_spec omap4] || [have_spec exynos5]] build_components drivers/usb build $build_components @@ -45,15 +45,9 @@ set config { - - - - - - } -append_if [have_spec omap4] config { +append_if [expr [have_spec omap4] || [have_spec exynos5]] config { @@ -64,7 +58,7 @@ append_if [have_spec omap4] config { } -append_if [expr ![have_spec omap4]] config { +append_if [expr ![have_spec omap4] && ![have_spec exynos5]] config { @@ -72,10 +66,40 @@ append_if [expr ![have_spec omap4]] config { append_if [have_spec pci] config { - + } +# establish serial connection with the server system +spawn picocom -b 115200 /dev/ttyUSB0 +set server_spawn_id $spawn_id +set timeout -1 +expect -i $server_spawn_id "Terminal ready" + +# get IP address from server +expect { + -i $server_spawn_id + -re "got IP address (.*)\033.*\n" { set ip_addr $expect_out(1,string) } +} +puts "got server IP address: $ip_addr" + +append config { + + + + + + + + + + + } +append config " + + + " + append config { } @@ -89,8 +113,8 @@ install_config $config # generic modules set boot_modules { core init timer - ld.lib.so libc.lib.so lwip.lib.so - test-ping_client + ld.lib.so libc.lib.so libc_log.lib.so lwip_nic_dhcp.lib.so lwip.lib.so + test-ping_client_libc_lwip } # platform-specific modules @@ -112,6 +136,22 @@ append_if [have_spec lan9118] qemu_args " -net nic,model=lan9118 " append qemu_args " -net user " -run_genode_until forever +expect -i $server_spawn_id "wait..." + +run_genode_until {Sucessfully connected to server.} 60 + +expect -i $server_spawn_id "client 3 connected..." + +set time_start [clock milliseconds] + +set timeout -1 +expect { + -i $server_spawn_id + -re "received .*\n" { } +} + +set time_end [clock milliseconds] + +puts "\nTest succeeded in [expr $time_end - $time_start] milliseconds." # vi: set ft=tcl : diff --git a/libports/run/test-ping_server.run b/libports/run/test-ping_server.run index df71ada43..ff60584c6 100644 --- a/libports/run/test-ping_server.run +++ b/libports/run/test-ping_server.run @@ -14,7 +14,7 @@ set build_components { test/lwip/pingpong/server } -lappend_if [have_spec omap4] build_components drivers/usb +lappend_if [expr [have_spec omap4] || [have_spec exynos5]] build_components drivers/usb build $build_components @@ -46,14 +46,14 @@ set config { - + - + } -append_if [have_spec omap4] config { +append_if [expr [have_spec omap4] || [have_spec exynos5]] config { @@ -64,7 +64,7 @@ append_if [have_spec omap4] config { } -append_if [expr ![have_spec omap4]] config { +append_if [expr ![have_spec omap4] && ![have_spec exynos5]] config { @@ -72,7 +72,7 @@ append_if [expr ![have_spec omap4]] config { append_if [have_spec pci] config { - + } @@ -89,14 +89,14 @@ install_config $config # generic modules set boot_modules { core init timer - ld.lib.so libc.lib.so lwip.lib.so - test-ping_server + ld.lib.so libc.lib.so lwip.lib.so libc_log.lib.so + test-ping_server_libc_lwip } # platform-specific modules lappend_if [have_spec pci] boot_modules pci_drv -lappend_if [have_spec omap4] boot_modules usb_drv -lappend_if [expr ![have_spec omap4]] boot_modules nic_drv +lappend_if [expr [have_spec omap4] || [have_spec exynos5]] boot_modules usb_drv +lappend_if [expr ![have_spec omap4] && ![have_spec exynos5]] boot_modules nic_drv build_boot_image $boot_modules diff --git a/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk b/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk new file mode 100644 index 000000000..ae012f9c7 --- /dev/null +++ b/libports/src/test/lwip/pingpong/client/libc_lwip/target.mk @@ -0,0 +1,8 @@ +TARGET = test-ping_client_libc_lwip +LIBS = base libc libc_lwip lwip libc_lwip_nic_dhcp libc_log config_args +SRC_CC = main.cc pingpong.cc + +CC_OPT_main += -fpermissive + +vpath main.cc $(PRG_DIR)/.. +vpath pingpong.cc $(PRG_DIR)/../.. diff --git a/libports/src/test/lwip/pingpong/client/lwip/target.mk b/libports/src/test/lwip/pingpong/client/lwip/target.mk new file mode 100644 index 000000000..f8a53cbaa --- /dev/null +++ b/libports/src/test/lwip/pingpong/client/lwip/target.mk @@ -0,0 +1,10 @@ +TARGET = test-ping_client_lwip +LIBS = base libc lwip libc_log config_args +SRC_CC = main.cc pingpong.cc + +CC_OPT_main += -fpermissive + +INC_DIR += $(REP_DIR)/src/lib/lwip/include + +vpath main.cc $(PRG_DIR)/.. +vpath pingpong.cc $(PRG_DIR)/../.. diff --git a/libports/src/test/lwip/pingpong/client/main.cc b/libports/src/test/lwip/pingpong/client/main.cc index bab82c5bc..9bead67d3 100644 --- a/libports/src/test/lwip/pingpong/client/main.cc +++ b/libports/src/test/lwip/pingpong/client/main.cc @@ -12,20 +12,8 @@ * under the terms of the GNU General Public License version 2. */ -/* Genode includes */ -#include -#include -#include - -#include - /* libc includes */ -#include -#include -#include -#include -#include -#include +#include #include "../pingpong.h" @@ -37,30 +25,30 @@ dial(const char *addr) int s; struct sockaddr_in in_addr; - PLOG("Create new socket..."); + printf("Create new socket...\n"); s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) { - PERR("Could not create socket!"); + printf("ERROR: Could not create socket!\n"); return -1; } - PLOG("Connect to server %s:%d...", addr, Sport); + printf("Connect to server %s:%d...\n", addr, Sport); in_addr.sin_port = htons(Sport); in_addr.sin_family = AF_INET; in_addr.sin_addr.s_addr = inet_addr(addr); if (connect(s, (struct sockaddr *)&in_addr, sizeof (in_addr)) == -1) { - PERR("Could not connect to server!"); + printf("ERROR: Could not connect to server!\n"); close(s); return -1; } - PLOG("Sucessful connected to server."); + printf("Sucessfully connected to server.\n"); return s; } int -sendping(const char *addr, size_t dsize) +sendping(const char *addr, size_t dsize, int count) { Packet p; int s; @@ -75,24 +63,24 @@ sendping(const char *addr, size_t dsize) p.h.dsize = dsize; p.d = (char *)malloc(p.h.dsize); if (p.d == NULL) { - PERR("Out of memory!"); + printf("ERROR: Out of memory!\n"); return -1; } - PINF("Try to send %d packets...", Numpackets); - for (i = 0; i < Numpackets; i++) { + printf("Trying to send %d packets...\n", count); + for (i = 0; i < count; i++) { forgepacket(&p, i + 1); n = sendpacket(s, &p); if (n <= 0) break; if (n != (sizeof (Packetheader) + p.h.dsize)) { - PERR("size mismatch: %ld != %lu", n, sizeof (Packetheader) + p.h.dsize); + printf("ERROR: size mismatch: %ld != %lu\n", n, sizeof (Packetheader) + p.h.dsize); break; } if (verbose) - PINF("%lu %ld", p.h.id, n); + printf("%u %ld\n", p.h.id, n); } close(s); @@ -100,15 +88,15 @@ sendping(const char *addr, size_t dsize) switch (n) { case 0: - PERR("Disconnect, sent packets: %lu", i); + printf("Disconnect, sent packets: %lu\n", i); return 0; break; case -1: - PERR("Error, sent packets: %lu", i); + printf("Error, sent packets: %lu\n", i); return 1; break; default: - PINF("Sucessful, sent packets: %lu", i); + printf("Sucessful, sent packets: %lu\n", i); return 0; break; } @@ -120,21 +108,18 @@ sendping(const char *addr, size_t dsize) int main(int argc, char *argv[]) { - char serverip[16]; + char serverip[16] = "0.0.0.0"; unsigned int i; unsigned int startsize, endsize; - - /* DHCP */ - if (lwip_nic_init(0, 0, 0)) { - PERR("We got no IP address!"); - return 1; - } + unsigned int count; /* default settings */ startsize = 1; endsize = 32768; + count = 1024; verbose = 0; +#if 0 Genode::Xml_node argv_node = Genode::config()->xml_node().sub_node("argv"); try { argv_node.attribute("serverip" ).value(serverip, sizeof(serverip)); @@ -142,14 +127,26 @@ main(int argc, char *argv[]) argv_node.attribute("endsize").value( &endsize ); argv_node.attribute("verbose").value( &verbose ); } catch(...) { } +#endif + + for (int i = 1; i < argc; i += 2) { + if (strcmp(argv[i], "-serverip") == 0) + strncpy(serverip, argv[i+1], sizeof(serverip)); + else if (strcmp(argv[i], "-startsize") == 0) + startsize = atoi(argv[i+1]); + else if (strcmp(argv[i], "-endsize") == 0) + endsize = atoi(argv[i+1]); + else if (strcmp(argv[i], "-count") == 0) + count = atoi(argv[i+1]); + } if ((endsize + sizeof (Packetheader)) > Databuf) { - PERR("endsize is greater than the servers' data buffer"); + printf("ERROR: endsize is greater than the servers' data buffer\n"); return 1; } for (i = startsize; i <= endsize; i <<= 1) - sendping(serverip, i); + sendping(serverip, i, count); return 0; } diff --git a/libports/src/test/lwip/pingpong/client/target.mk b/libports/src/test/lwip/pingpong/client/target.mk deleted file mode 100644 index 466331b17..000000000 --- a/libports/src/test/lwip/pingpong/client/target.mk +++ /dev/null @@ -1,7 +0,0 @@ -TARGET = test-ping_client -LIBS = cxx env libc libc_lwip lwip -SRC_CC = main.cc ../pingpong.cc - -CC_OPT_main += -fpermissive - -INC_DIR += $(REP_DIR)/src/lib/lwip/include diff --git a/libports/src/test/lwip/pingpong/pingpong.cc b/libports/src/test/lwip/pingpong/pingpong.cc index 49311526f..def6120d6 100644 --- a/libports/src/test/lwip/pingpong/pingpong.cc +++ b/libports/src/test/lwip/pingpong/pingpong.cc @@ -12,13 +12,8 @@ * under the terms of the GNU General Public License version 2. */ -/* Genode includes */ -#include - /* libc includes */ -#include -#include -#include +#include #include "pingpong.h" @@ -36,7 +31,7 @@ checkpacket(size_t n, Packet *p) { /* check size of received packet */ if (n != (sizeof (Packetheader) + p->h.dsize)) { - PERR("packetsize mismatch!"); + printf("ERROR: packetsize mismatch!\n"); return -1; } @@ -44,13 +39,13 @@ checkpacket(size_t n, Packet *p) /* check packet type */ if (p->h.type != Tping) { - PERR("wrong packet type!"); + printf("ERROR: wrong packet type!\n"); return -1; } /* check payload */ if (p->d[p->h.dsize - 1] != (p->h.id % 128)) { - PERR("packet payload corrupt, expected: %d got: %d", (p->h.id % 128), + printf("ERROR: packet payload corrupt, expected: %d got: %d\n", (p->h.id % 128), p->d[p->h.dsize - 1]); return -1; } @@ -72,11 +67,11 @@ sendpacket(int s, Packet *p) sent = send(s, b + nh, sizeof (Packetheader) - nh, 0); switch (sent) { case -1: - PERR("send(Packetheader) == -1"); + printf("ERROR: send(Packetheader) == -1\n"); return nh; break; case 0: - PERR("send(Packetheader) == 0, connection closed"); + printf("ERROR: send(Packetheader) == 0, connection closed\n"); return nh; break; default: @@ -92,11 +87,11 @@ sendpacket(int s, Packet *p) sent = send(s, b + nd, dsize - nd, 0); switch (sent) { case -1: - PERR("send(data) == -1"); + printf("ERROR: send(data) == -1\n"); return nd; break; case 0: - PERR("send(data) == 0, connection closed"); + printf("ERROR: send(data) == 0, connection closed\n"); return nd; break; default: @@ -121,12 +116,12 @@ recvpacket(int s, Packet *p, char *dbuf, size_t ldbuf) r = recv(s, b + nh, sizeof (Packetheader) - nh, 0); switch (r) { case -1: - PERR("recv(Packetheader) == -1"); + printf("ERROR: recv(Packetheader) == -1\n"); return nh; break; case 0: /* disconnect */ - PERR("recv(Packetheader) == 0, connection closed"); + //printf("ERROR: recv(Packetheader) == 0, connection closed\n"); return nh; break; default: @@ -136,7 +131,7 @@ recvpacket(int s, Packet *p, char *dbuf, size_t ldbuf) } if (p->h.dsize > ldbuf) { - PERR("packet payload is too large for dbuf!"); + printf("ERROR: packet payload is too large for dbuf!\n"); return -1; } @@ -147,12 +142,12 @@ recvpacket(int s, Packet *p, char *dbuf, size_t ldbuf) r = recv(s, dbuf + nd, dsize - nd, 0); switch (r) { case -1: - PERR("recv(data) == -1"); + printf("ERROR: recv(data) == -1\n"); return nh + nd; break; case 0: /* disconnect */ - PERR("recv(data) == 0, connection closed"); + printf("ERROR: recv(data) == 0, connection closed\n"); return nh + nd; break; default: diff --git a/libports/src/test/lwip/pingpong/pingpong.h b/libports/src/test/lwip/pingpong/pingpong.h index 708aa3ee7..b0e06edaf 100644 --- a/libports/src/test/lwip/pingpong/pingpong.h +++ b/libports/src/test/lwip/pingpong/pingpong.h @@ -15,6 +15,32 @@ #ifndef _PINGPONG_H_ #define _PINGPONG_H_ +/* libc includes */ +#include + +#ifdef LWIP_NATIVE +#include +#define accept(a,b,c) lwip_accept(a,b,c) +#define bind(a,b,c) lwip_bind(a,b,c) +#define close(s) lwip_close(s) +#define connect(a,b,c) lwip_connect(a,b,c) +#define listen(a,b) lwip_listen(a,b) +#define recv(a,b,c,d) lwip_recv(a,b,c,d) +#define select(a,b,c,d,e) lwip_select(a,b,c,d,e) +#define send(a,b,c,d) lwip_send(a,b,c,d) +#define socket(a,b,c) lwip_socket(a,b,c) +#else +/* libc includes */ +#include +#include +#include +#include +#include +#include +#include +#include +#endif + enum { Databuf = 1024 * 1024, // data buffer for server Numpackets = 1024, diff --git a/libports/src/test/lwip/pingpong/server/libc_lwip/target.mk b/libports/src/test/lwip/pingpong/server/libc_lwip/target.mk new file mode 100644 index 000000000..e0bd9f5a1 --- /dev/null +++ b/libports/src/test/lwip/pingpong/server/libc_lwip/target.mk @@ -0,0 +1,8 @@ +TARGET = test-ping_server_libc_lwip +LIBS = base libc libc_lwip_nic_dhcp libc_lwip lwip libc_log config_args +SRC_CC = main.cc pingpong.cc + +CC_OPT_main += -fpermissive + +vpath main.cc $(PRG_DIR)/.. +vpath pingpong.cc $(PRG_DIR)/../.. diff --git a/libports/src/test/lwip/pingpong/server/lwip/target.mk b/libports/src/test/lwip/pingpong/server/lwip/target.mk new file mode 100644 index 000000000..61524b6d8 --- /dev/null +++ b/libports/src/test/lwip/pingpong/server/lwip/target.mk @@ -0,0 +1,12 @@ +TARGET = test-ping_server_lwip +LIBS = base libc lwip libc_log config_args +SRC_CC = main.cc pingpong.cc + +CC_OPT += -DLWIP_NATIVE + +CC_OPT_main += -fpermissive + +INC_DIR += $(REP_DIR)/src/lib/lwip/include + +vpath main.cc $(PRG_DIR)/.. +vpath pingpong.cc $(PRG_DIR)/../.. diff --git a/libports/src/test/lwip/pingpong/server/main.cc b/libports/src/test/lwip/pingpong/server/main.cc index 072b13911..3a49a9423 100644 --- a/libports/src/test/lwip/pingpong/server/main.cc +++ b/libports/src/test/lwip/pingpong/server/main.cc @@ -12,20 +12,12 @@ * under the terms of the GNU General Public License version 2. */ -/* Genode includes */ -#include -#include -#include - -#include - /* libc includes */ -#include -#include -#include -#include -#include -#include +#include + +#ifdef LWIP_NATIVE +#include +#endif #include "../pingpong.h" @@ -37,19 +29,19 @@ announce(const char *addr) int s; struct sockaddr_in in_addr; - PLOG("Create new socket..."); + printf("Create new socket...\n"); s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s == -1) { - PERR("Could not create socket!"); + printf("ERROR: Could not create socket!\n"); return -1; } - PLOG("Bind socket to %d", Sport); + printf("Bind socket to %d\n", Sport); in_addr.sin_port = htons(Sport); in_addr.sin_family = AF_INET; in_addr.sin_addr.s_addr = inet_addr(addr); if ( bind(s, (struct sockaddr *)&in_addr, sizeof (in_addr)) == -1) { - PERR("Could not bind!"); + printf("ERROR: Could not bind!\n"); close(s); return -1; } @@ -69,9 +61,9 @@ recvping(const char *addr) if (s == -1) return -1; - PLOG("Listen on %s:%d...", addr, Sport); + printf("Listen on %s:%d...\n", addr, Sport); if (listen(s, 5) == -1) { - PERR("Could not listen!"); + printf("ERROR: Could not listen!\n"); close(s); return -1; } @@ -80,19 +72,20 @@ recvping(const char *addr) Packet p; int act; size_t packets; + ssize_t packet_size = 0; ssize_t n; - PINF("wait..."); + printf("wait...\n"); c = accept(s, &caddr, &lcaddr); if (c == -1) { - PERR("Invalid socket from accept()!"); + printf("ERROR: Invalid socket from accept()!\n"); continue; } - PLOG("client %d connected...", c); + printf("client %d connected...\n", c); p.d = (char *)malloc(Databuf); if (p.d == NULL) { - PERR("Out of memeory!"); + printf("ERROR: Out of memeory!\n"); close(c); break; } @@ -100,14 +93,22 @@ recvping(const char *addr) /* receive packets from client */ act = 1; packets = 0; while (act) { + + fd_set rfds; + FD_ZERO(&rfds); + FD_SET(c, &rfds); + + if (select(c + 1, &rfds, NULL, NULL, NULL) == -1) + printf("ERROR: select() == -1\n"); + n = recvpacket(c, &p, p.d, Databuf); switch (n) { case -1: /* error */ - PERR("recvpacket() == -1"); + printf("ERROR: recvpacket() == -1\n"); case 0: /* disconnect */ - PERR("disconnect"); + //printf("ERROR: disconnect\n"); close(c); act = 0; break; @@ -115,14 +116,17 @@ recvping(const char *addr) /* check if packet is vaid */ if (checkpacket(n, &p)) { act = 0; + } else { + packets++; + packet_size = n; } break; } if (verbose) - PINF("%u %d", p.h.id, n); + printf("%u %d\n", p.h.id, n); } - PINF("received packets: %u", packets); + printf("received %u packets of size %u\n", packets, packet_size); free(p.d); } @@ -135,16 +139,20 @@ recvping(const char *addr) int main(int argc, char *argv[]) { - char listenip[16]; + char listenip[16] = "0.0.0.0"; +#ifdef LWIP_NATIVE + lwip_tcpip_init(); /* DHCP */ if (lwip_nic_init(0, 0, 0)) { - PERR("We got no IP address!"); + printf("ERROR: We got no IP address!\n"); return 1; } +#endif verbose = 0; +#if 0 Genode::Xml_node argv_node = Genode::config()->xml_node().sub_node("argv"); try { argv_node.attribute("listenip" ).value(listenip, sizeof(listenip)); @@ -153,6 +161,7 @@ main(int argc, char *argv[]) PERR("listenip was not specified!"); return 1; } +#endif recvping(listenip); diff --git a/libports/src/test/lwip/pingpong/server/target.mk b/libports/src/test/lwip/pingpong/server/target.mk deleted file mode 100644 index 97b11e46c..000000000 --- a/libports/src/test/lwip/pingpong/server/target.mk +++ /dev/null @@ -1,7 +0,0 @@ -TARGET = test-ping_server -LIBS = cxx env libc libc_lwip lwip -SRC_CC = main.cc ../pingpong.cc - -CC_OPT_main += -fpermissive - -INC_DIR += $(REP_DIR)/src/lib/lwip/include