logo
Go to the homepage of the Vrije Universiteit. Go to the homepage of the department of computer science. Go to the homepage of the faculty of sciences.

<< Computer Networks Practicum: How to Test



First of all get the simple test program (simpletest.c) from the this web site. The program requires two environment variables, IP1 and IP2 that represent the IP addresses of the machines when ETH=1 and ETH=2. Make your TCP library work with simpletest. Than create new test programs, most you can base on the simple test.

Attention: Please, do not submit your implementation for testing if it does not pass this test. For getting your grade, your implementation will be tested in much more details than simply running this trivial program!

Testing is a simple process: Think of a test... predict the outcome... do the test... check the results. Sounds simple, but in practice hard!

Looking at simple test, it is easy to see it sends a small package from a parent process to a child process and back. It would be nice to have a bigger message to exchange because the TCP library will have to deal with big messages as well.

To change the simple test program in to a program that tests substantial transfers, copy the simpletest.c to bigtest.c and change the code along these lines:

  char buf[40000];
Parent Code:
  memset(buf,'1',sizeof(buf)) 
  buf[sizeof(buf)-1]='\0'
  tcp_connect()
  tcp_write(buf,sizeof(buf))
  tcp_read(buf,16)
  strcmp(buf,"foo")
  tcp_close()
Child Code:
  tcp_listen()
  tot = 0;
  while (tot<sizeof(buf)) {
    len = tcp_read(buf,sizeof(buf));
    tot += len;
  }
  tcp_write("foo",4)
  tcp_close()
Note that this is pseudo code, the real code would contain a lot of checks and printf() statements as the simple test program does. Don't forget to check the return value from tcp_read(), it might be less than zero.

Further enhancements can be made, for example the child can also send a large buffer. The size of the array 'buf' could be set to bigger sizes. The size of the array 'buf' could be set to special values, like equal to, or one more or less that the maximum TCP payload, powers of two etc. Also a test program could be constructed to test all values from 1 to 10240. Though this test would take a long time to run.

In the test set, there is a test that is often failed. It basically is the bigtest.c program where the parent code sends out a 1 byte packet first, than a 2 byte, 4 byte, 8 byte, etc. The child code reads a packet of 1024 bytes, and than 512 bytes, etc. After this, the whole process is ran backwards, using powers of two minus 1. In general sending packets of one size and receiving packets of an other, is a tough test.

Read the assignment again, carefully, and make a list of does and don't-s. For example if the assignment states that alarm and signal should be restored, copy simpletest.c to alarmtest.c and make changes along these lines:

testhand() {} /* Dummy signal handler. */
Parent Code:
  alarm(30000);
  signal(SIGALRM, testhand);
  tcp_connect(inet_aton(ip2),1234)
  tcp_write(buf,sizeof(buf))
  tcp_read(buf,16)
  tcp_close()
  al = alarm(0);
  if (al<20000)
      printf("error")
  if (signal(SIGALRM, NULL) != testhand)
      printf("error")
Child Code:
  alarm(30000);
  signal(SIGALRM, testhand);
  tcp_listen(1234,&saddr)
  while (tot<sizeof(buf))
      len = tcp_read(buf,sizeof(buf));
  tcp_write("foo",4)
  tcp_close()
  al = alarm(0);
  if (al<20000)
      printf("error")
  if (signal(SIGALRM, NULL) != testhand)
      printf("error")
Make a separate test program for each do and don't.

Make a program that tells you how long each tcp_...() function took.

Note that it is simple to change simpletest to allow testing of different (versions of) tcp_libs, just change the line

  if (fork()) {
to:
  if (eth[0]=='1') {
This way setting the ETH variable to "1" forces the testprogram to run the parent code, and setting it to "2" will get the child code run. Creating two executables from this source code, with different TCP librarys, will allow cross testing.

An other way of performing test is putting extra statements in the source code. For example:

    send_ip_package(...)
could be changed to:
    send_ip_package(...)
  #if TEST == 3
    send_ip_package(...) /* Simulate duplicate. */
  #endif
or:
  #if TEST != 4 /* Simulate packet loss in test 4. */
    send_ip_package(...)
  #endif
Simply compiling with the -DTEST=4 flag would create a lib that will simulate packet drops.

Needless to say that the above is just the beginning of real testing. Another way to test your TCP/HTTP implementation is to try to access your Web server via an (almost) standard browsers. Information is available here. There are many more ways to test code. And indeed more testing should be done.

Remember: What can go wrong will!


If you have any comments, please e-mail the maintainer of this page.
Your browser does not fully support CSS. This may result in visual artifacts.