#!/bin/sh # # ASSIGN4.TEST # # To create a test script of your http server put this file, assign4.test, # your source file which must be called "server.c", and your compiled server # program which must be called "server", together in a directory. Then run # the command # sh assign4.test > test_script # # This test should take several minutes to run. # # When the test completes, edit the test_script output to include your # name, student id, and email address at the top; if you work in a group # be sure to include this information for all members of your group. For example, # # % sh assign4.test > test_script # % emacs test_script # add your name, email address, and id # # Your source code should be in a file named server.c. If you have more than # one file or use different file names for your source files, you will have # to either modify this script below, where it says SPECIFY SOURCE FILES HERE, # or you will have to edit the output of the test script so that it includes # all your sources. # # Be sure to check the test_script file before you turn it in. Be sure # it has your name, id, and email address; be sure it includes a copy # of all your source code, and be sure all the tests have run correctly. # RM=/bin/rm TESTDIR=assign4.test.$$ echo ========================================================================== echo echo CS 311 - Assignment 4 echo echo Name: echo Student ID: echo Email: echo echo Name: echo Student ID: echo Email: echo echo Name: echo Student ID: echo Email: echo echo date uname -a whoami echo echo ========================================================================== echo echo echo # SPECIFY SOURCE FILES HERE for file in Makefile parse.c response.h server.c server.h signals.c sockio.c do echo -------------------------------------------------------------------------- echo Source File: $file echo cat $file 2>&1 echo echo done if test -d $TESTDIR then echo Please rename or remove $TESTDIR exit 1 fi mkdir $TESTDIR 2>&1 cp server $TESTDIR 2>&1 cd $TESTDIR 2>&1 echo -------------------------------------------------------------------------- echo Building Test Program cat > client.c <<___EOF___ #include #include #include #include #include #include #include #include #include #include ssize_t writen(int fd, const void *vptr, size_t n); #define BUF_SIZE 8192 char *command_name; void main( int argc, char *argv[] ) { int client_sock; int len,n,total; char buf[BUF_SIZE]; struct sockaddr_in server_addr; struct hostent *hp; /* get command name */ command_name = argv[0]; /* check syntax */ if( argc != 4 ) { fprintf( stderr, "Usage: %s host port command\n", command_name ); exit( 1 ); } /* create an Internet domain stream socket */ if( (client_sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { fprintf( stderr, "%s: socket failed\n", command_name ); perror( NULL ); exit( 1 ); } /* set address of server */ bzero( &server_addr, sizeof( server_addr ) ); server_addr.sin_family = AF_INET; if( (server_addr.sin_addr.s_addr=inet_addr(argv[1])) == -1 ) { if( (hp=gethostbyname(argv[1])) == NULL ) { fprintf( stderr, "%s: cannot get host by name\n", command_name ); perror( NULL ); exit( 1 ); } bcopy( hp->h_addr, (char *)&server_addr.sin_addr, hp->h_length ); } server_addr.sin_port = htons( atoi(argv[2]) ); /* connect */ if( connect( client_sock, (struct sockaddr *)&server_addr, sizeof( server_addr ) ) < 0 ) { fprintf( stderr, "%s: connect failed\n", command_name ); perror( NULL ); exit( 1 ); } /* write command */ len = strlen( argv[3] ); if( writen( client_sock, argv[3], len ) != len || writen( client_sock, " HTTP/1.0\n\n", 11 ) != 11 ) { fprintf( stderr, "%s: write command failed\n", command_name ); perror( NULL ); exit( 1 ); } /* Shutdown the output, so we don't get the peer reset error */ if ((shutdown(client_sock, 1) < 0) && (errno != ENOTCONN) ) { perror("shutdown"); exit(1); } /* copy */ total = 0; while( (n=read( client_sock, buf, BUF_SIZE )) > 0 ) { if( write( STDOUT_FILENO, buf, n ) != n ) { fprintf( stderr, "%s: write failed\n", command_name ); perror( NULL ); exit( 1 ); } total += n; } if( n < 0 ) { fprintf( stderr, "%s: read failed\n", command_name ); perror( NULL ); exit( 1 ); } /* print total bytes copied */ fprintf( stderr, "%s: transfered %d bytes\n", command_name, total ); /* close */ close( client_sock ); /* ok */ exit( 0 ); } ssize_t /* Write "n" bytes to a descriptor. */ writen(int fd, const void *vptr, size_t n) { size_t nleft; ssize_t nwritten; const char *ptr; ptr = vptr; nleft = n; while (nleft > 0) { if ( (nwritten = write(fd, ptr, nleft)) <= 0) { if (errno == EINTR) nwritten = 0; /* and call write() again */ else return(-1); /* error */ } nleft -= nwritten; ptr += nwritten; } return(n); } ___EOF___ cc -o client client.c -lsocket -lnsl 2>&1 echo echo echo -------------------------------------------------------------------------- echo Creating Test Files echo cat > file1.txt <<___EOF___ This is a test text file. It is rather small. ___EOF___ chmod o+r file1.txt cat > file1.html <<___EOF___

This is a test html file. It is rather small.

___EOF___ chmod o+r file1.html cat > file2.html <<___EOF___ Home - Computer Science - Oregon State University Computer Science - Oregon State University

We're Hiring!( Faculty, Instructor)

New Undergraduate Degree Options: Information

Admissions Information
Courses and Degree Information
People
Organizations
Research and Publications
Resources
About the Department
Index or Search



___EOF___ chmod o+r file2.html cat file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html file2.html > file3.html 2>&1 chmod o+r file3.html ls -l 2>&1 echo echo echo -------------------------------------------------------------------------- echo Computing Port echo port=`expr $$ % 10000 + 2000` echo $port echo echo echo -------------------------------------------------------------------------- echo Starting server echo ./server $port > server.out 2>&1 & serverpid=$! echo echo echo -------------------------------------------------------------------------- echo PS echo ps 2>&1 echo echo echo -------------------------------------------------------------------------- echo Small Text File echo ./client 0 $port "GET /file1.txt" 2>&1 echo echo echo -------------------------------------------------------------------------- echo Small HTML File echo ./client 0 $port "GET /file1.html" 2>&1 echo echo echo -------------------------------------------------------------------------- echo PS echo ps 2>&1 echo echo echo -------------------------------------------------------------------------- echo Bad File echo ./client 0 $port "GET /bad_file" 2>&1 echo echo echo -------------------------------------------------------------------------- echo Bad Command echo ./client 0 $port "PUT /file1.txt" 2>&1 echo echo echo -------------------------------------------------------------------------- echo PS echo ps 2>&1 echo echo echo -------------------------------------------------------------------------- echo Big HTML File echo ./client 0 $port "GET /file3.html" 2>&1 > file3.out echo echo Diff Original and Received echo -------------------------- diff file3.html file3.out 2>&1 echo echo echo -------------------------------------------------------------------------- echo 20 Simultaneous Connections echo for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 do ./client 0 $port "GET /file2.html" 2>&1 > file2.$i.out & done sleep 30 echo echo Diff Original and Received echo -------------------------- diff file2.html file2.1.out 2>&1 echo echo Comparing Received Files echo -------------------------- for i in 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 do cmp file2.1.out file2.$i.out 2>&1 done echo echo echo -------------------------------------------------------------------------- echo 50 Simultaneous Connections echo for i in 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 do ./client 0 $port "GET /file2.html" 2>&1 > file2.$i.out & done sleep 60 echo echo Diff Original and Received echo -------------------------- diff file2.html file2.21.out 2>&1 echo echo Comparing Received Files echo -------------------------- for i in 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 do cmp file2.21.out file2.$i.out 2>&1 done echo echo echo -------------------------------------------------------------------------- echo Server Output echo cat server.out 2>&1 echo echo echo -------------------------------------------------------------------------- echo Kill Server echo kill -9 $serverpid 2>&1 echo echo cd .. $RM -rf $TESTDIR