diff packages/net/tcpip/current/tests/ping_test.c @ 105:5a0cc6c243a9 ecos-sw-2000-06-30

Merge from eCos master repository on 2000-06-30-08:18:49-BST
author jlarmour
date Fri, 30 Jun 2000 16:27:35 +0000
parents ced4577552cd
children 84e4bde58b26
line wrap: on
line diff
--- a/packages/net/tcpip/current/tests/ping_test.c
+++ b/packages/net/tcpip/current/tests/ping_test.c
@@ -56,6 +56,37 @@
 
 #include <network.h>
 
+#include <pkgconf/system.h>
+#include <pkgconf/net.h>
+
+#include <cyg/infra/testcase.h>
+
+#ifdef CYGBLD_DEVS_ETH_DEVICE_H    // Get the device config if it exists
+#include CYGBLD_DEVS_ETH_DEVICE_H  // May provide CYGTST_DEVS_ETH_TEST_NET_REALTIME
+#endif
+
+#ifdef CYGPKG_NET_TESTS_USE_RT_TEST_HARNESS // do we use the rt test?
+# ifdef CYGTST_DEVS_ETH_TEST_NET_REALTIME // Get the test ancilla if it exists
+#  include CYGTST_DEVS_ETH_TEST_NET_REALTIME
+# endif
+#endif
+
+// Fill in the blanks if necessary
+#ifndef TNR_OFF
+# define TNR_OFF()
+#endif
+#ifndef TNR_ON
+# define TNR_ON()
+#endif
+#ifndef TNR_INIT
+# define TNR_INIT()
+#endif
+#ifndef TNR_PRINT_ACTIVITY
+# define TNR_PRINT_ACTIVITY()
+#endif
+
+
+
 #define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
 static char stack[STACK_SIZE];
 static cyg_thread thread_data;
@@ -63,18 +94,20 @@ static cyg_handle_t thread_handle;
 
 #define NUM_PINGS 16
 #define MAX_PACKET 4096
+#define MIN_PACKET   64
+#define MAX_SEND   4000
+
+#define PACKET_ADD  ((MAX_SEND - MIN_PACKET)/NUM_PINGS)
+#define nPACKET_ADD  1 
+
 static unsigned char pkt1[MAX_PACKET], pkt2[MAX_PACKET];
 
 #define UNIQUEID 0x1234
 
-extern void
-cyg_test_exit(void);
-
 void
 pexit(char *s)
 {
-    perror(s);
-    cyg_test_exit();
+    CYG_TEST_FAIL_FINISH(s);
 }
 
 // Compute INET checksum
@@ -149,7 +182,7 @@ static void
 ping_host(int s, struct sockaddr_in *host)
 {
     struct icmp *icmp = (struct icmp *)pkt1;
-    int icmp_len = 64;
+    int icmp_len = MIN_PACKET;
     int seq, ok_recv, bogus_recv;
     cyg_tick_count_t *tp;
     long *dp;
@@ -159,7 +192,8 @@ ping_host(int s, struct sockaddr_in *hos
     ok_recv = 0;
     bogus_recv = 0;
     diag_printf("PING server %s\n", inet_ntoa(host->sin_addr));
-    for (seq = 0;  seq < NUM_PINGS;  seq++) {
+    for (seq = 0;  seq < NUM_PINGS;  seq++, icmp_len += PACKET_ADD ) {
+        TNR_ON();
         // Build ICMP packet
         icmp->icmp_type = ICMP_ECHO;
         icmp->icmp_code = 0;
@@ -177,12 +211,14 @@ ping_host(int s, struct sockaddr_in *hos
         icmp->icmp_cksum = inet_cksum( (u_short *)icmp, icmp_len+8);
         // Send it off
         if (sendto(s, icmp, icmp_len+8, 0, (struct sockaddr *)host, sizeof(*host)) < 0) {
+            TNR_OFF();
             perror("sendto");
             continue;
         }
         // Wait for a response
         fromlen = sizeof(from);
         len = recvfrom(s, pkt2, sizeof(pkt2), 0, (struct sockaddr *)&from, &fromlen);
+        TNR_OFF();
         if (len < 0) {
             perror("recvfrom");
         } else {
@@ -193,6 +229,7 @@ ping_host(int s, struct sockaddr_in *hos
             }
         }
     }
+    TNR_OFF();
     diag_printf("Sent %d packets, received %d OK, %d bad\n", NUM_PINGS, ok_recv, bogus_recv);
 }
 
@@ -205,12 +242,12 @@ ping_test(struct bootp *bp)
     int s;
 
     if ((p = getprotobyname("icmp")) == (struct protoent *)0) {
-        perror("getprotobyname");
+        pexit("getprotobyname");
         return;
     }
     s = socket(AF_INET, SOCK_RAW, p->p_proto);
     if (s < 0) {
-        perror("socket");
+        pexit("socket");
         return;
     }
     tv.tv_sec = 1;
@@ -230,6 +267,7 @@ void
 net_test(cyg_addrword_t p)
 {
     diag_printf("Start PING test\n");
+    TNR_INIT();
     init_all_network_interfaces();
 #ifdef CYGHWR_NET_DRIVER_ETH0
     if (eth0_up) {
@@ -241,7 +279,8 @@ net_test(cyg_addrword_t p)
         ping_test(&eth1_bootp_data);
     }
 #endif
-    cyg_test_exit();
+    TNR_PRINT_ACTIVITY();
+    CYG_TEST_PASS_FINISH("Ping test OK");
 }
 
 void