diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/cls.c | 188 | ||||
-rw-r--r-- | test/test-writev.c | 26 | ||||
-rw-r--r-- | test/time-sem.c | 194 | ||||
-rw-r--r-- | test/zb.c | 86 |
4 files changed, 247 insertions, 247 deletions
diff --git a/test/cls.c b/test/cls.c index f2b0192929..1311a88512 100644 --- a/test/cls.c +++ b/test/cls.c @@ -35,32 +35,32 @@ static int checkmask(const char *data, const char *mask) int i, ch, d; for (i = 0; mask[i] != '\0' && mask[i] != '*'; i++) { - ch = mask[i]; - d = data[i]; - if (ch == '@') { - if (!isupper(d)) - return 0; - } - else if (ch == '$') { - if (!islower(d)) - return 0; - } - else if (ch == '#') { - if (!isdigit(d)) - return 0; - } - else if (ch == '&') { - if (!isxdigit(d)) - return 0; - } - else if (ch != d) - return 0; + ch = mask[i]; + d = data[i]; + if (ch == '@') { + if (!isupper(d)) + return 0; + } + else if (ch == '$') { + if (!islower(d)) + return 0; + } + else if (ch == '#') { + if (!isdigit(d)) + return 0; + } + else if (ch == '&') { + if (!isxdigit(d)) + return 0; + } + else if (ch != d) + return 0; } if (mask[i] == '*') - return 1; + return 1; else - return (data[i] == '\0'); + return (data[i] == '\0'); } /* @@ -72,19 +72,19 @@ static int hex2sec(const char *x) unsigned int j; for (i = 0, j = 0; i < 8; i++) { - ch = x[i]; - j <<= 4; - if (isdigit(ch)) - j |= ch - '0'; - else if (isupper(ch)) - j |= ch - ('A' - 10); - else - j |= ch - ('a' - 10); + ch = x[i]; + j <<= 4; + if (isdigit(ch)) + j |= ch - '0'; + else if (isupper(ch)) + j |= ch - ('A' - 10); + else + j |= ch - ('a' - 10); } if (j == 0xffffffff) - return -1; /* so that it works with 8-byte ints */ + return -1; /* so that it works with 8-byte ints */ else - return j; + return j; } int main(int argc, char **argv) @@ -103,78 +103,78 @@ int main(int argc, char **argv) const char time_format[] = "%e %b %Y %R"; if (argc != 2) { - printf("Usage: cls directory\n"); - exit(0); + printf("Usage: cls directory\n"); + exit(0); } d = opendir(argv[1]); if (d == NULL) { - perror("opendir"); - exit(1); + perror("opendir"); + exit(1); } for (;;) { - e = readdir(d); - if (e == NULL) - break; - s = e->d_name; - if (s[0] == '.' || s[0] == '#') - continue; - sprintf(path, "%s/%s", argv[1], s); - fp = fopen(path, "r"); - if (fp == NULL) { - perror("fopen"); - continue; - } - if (fgets(line, 1034, fp) == NULL) { - perror("fgets"); - fclose(fp); - continue; - } - if (!checkmask(line, "&&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&&\n")) { - fprintf(stderr, "Bad cache file\n"); - fclose(fp); - continue; - } - date = hex2sec(line); - lmod = hex2sec(line + 9); - expire = hex2sec(line + 18); - ver = hex2sec(line + 27); - len = hex2sec(line + 35); - if (fgets(line, 1034, fp) == NULL) { - perror("fgets"); - fclose(fp); - continue; - } - fclose(fp); - i = strlen(line); - if (strncmp(line, "X-URL: ", 7) != 0 || line[i - 1] != '\n') { - fprintf(stderr, "Bad cache file\n"); - continue; - } - line[i - 1] = '\0'; - if (date != -1) { - ts = *gmtime(&date); - strftime(sdate, 30, time_format, &ts); - } - else - strcpy(sdate, "-"); + e = readdir(d); + if (e == NULL) + break; + s = e->d_name; + if (s[0] == '.' || s[0] == '#') + continue; + sprintf(path, "%s/%s", argv[1], s); + fp = fopen(path, "r"); + if (fp == NULL) { + perror("fopen"); + continue; + } + if (fgets(line, 1034, fp) == NULL) { + perror("fgets"); + fclose(fp); + continue; + } + if (!checkmask(line, "&&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&& &&&&&&&&\n")) { + fprintf(stderr, "Bad cache file\n"); + fclose(fp); + continue; + } + date = hex2sec(line); + lmod = hex2sec(line + 9); + expire = hex2sec(line + 18); + ver = hex2sec(line + 27); + len = hex2sec(line + 35); + if (fgets(line, 1034, fp) == NULL) { + perror("fgets"); + fclose(fp); + continue; + } + fclose(fp); + i = strlen(line); + if (strncmp(line, "X-URL: ", 7) != 0 || line[i - 1] != '\n') { + fprintf(stderr, "Bad cache file\n"); + continue; + } + line[i - 1] = '\0'; + if (date != -1) { + ts = *gmtime(&date); + strftime(sdate, 30, time_format, &ts); + } + else + strcpy(sdate, "-"); - if (lmod != -1) { - ts = *gmtime(&lmod); - strftime(slmod, 30, time_format, &ts); - } - else - strcpy(slmod, "-"); + if (lmod != -1) { + ts = *gmtime(&lmod); + strftime(slmod, 30, time_format, &ts); + } + else + strcpy(slmod, "-"); - if (expire != -1) { - ts = *gmtime(&expire); - strftime(sexpire, 30, time_format, &ts); - } - else - strcpy(sexpire, "-"); + if (expire != -1) { + ts = *gmtime(&expire); + strftime(sexpire, 30, time_format, &ts); + } + else + strcpy(sexpire, "-"); - printf("%s: %d; %s %s %s\n", line + 7, ver, sdate, slmod, sexpire); + printf("%s: %d; %s %s %s\n", line + 7, ver, sdate, slmod, sexpire); } closedir(d); diff --git a/test/test-writev.c b/test/test-writev.c index 072689a3c5..4740738f45 100644 --- a/test/test-writev.c +++ b/test/test-writev.c @@ -57,36 +57,36 @@ void main( int argc, char **argv ) if( argc != 3 ) { usage: - fprintf( stderr, "usage: test-writev a.b.c.d port#\n" ); - exit( 1 ); + fprintf( stderr, "usage: test-writev a.b.c.d port#\n" ); + exit( 1 ); } server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = inet_addr( argv[1] ); if( server_addr.sin_addr.s_addr == INADDR_NONE ) { - fprintf( stderr, "bogus address\n" ); - goto usage; + fprintf( stderr, "bogus address\n" ); + goto usage; } server_addr.sin_port = htons( atoi( argv[2] ) ); s = socket( AF_INET, SOCK_STREAM, 0 ); if( s < 0 ) { - perror("socket"); - exit(1); + perror("socket"); + exit(1); } if( connect( s, (struct sockaddr *)&server_addr, sizeof( server_addr ) ) - != 0 ) { - perror("connect"); - exit(1); + != 0 ) { + perror("connect"); + exit(1); } if( setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&just_say_no, - sizeof(just_say_no)) != 0 ) { - perror( "TCP_NODELAY" ); - exit(1); + sizeof(just_say_no)) != 0 ) { + perror( "TCP_NODELAY" ); + exit(1); } /* now build up a two part writev and write it out */ for( i = 0; i < sizeof( buf ); ++i ) { - buf[i] = 'x'; + buf[i] = 'x'; } vector[0].iov_base = buf; vector[0].iov_len = sizeof(buf); diff --git a/test/time-sem.c b/test/time-sem.c index 6f6e5da556..792caec638 100644 --- a/test/time-sem.c +++ b/test/time-sem.c @@ -23,16 +23,16 @@ to be used: - NFS filesystems absolutely suck for fcntl() and flock() - uslock absolutely sucks on single-processor IRIX boxes, but - absolutely rocks on multi-processor boxes. The converse - is true for fcntl. sysvsem seems a moderate balance. + absolutely rocks on multi-processor boxes. The converse + is true for fcntl. sysvsem seems a moderate balance. - Under Solaris you can't have too many processes use SEM_UNDO, there - might be a tuneable somewhere that increases the limit from 29. - We're not sure what the tunable is, so there's a define - NO_SEM_UNDO which can be used to simulate us trapping/blocking - signals to be able to properly release the semaphore on a clean - child death. You'll also need to define NEED_UNION_SEMUN - under solaris. + might be a tuneable somewhere that increases the limit from 29. + We're not sure what the tunable is, so there's a define + NO_SEM_UNDO which can be used to simulate us trapping/blocking + signals to be able to properly release the semaphore on a clean + child death. You'll also need to define NEED_UNION_SEMUN + under solaris. You'll need to define USE_SHMGET_SCOREBOARD if anonymous shared mmap() doesn't work on your system (i.e. linux). @@ -101,9 +101,9 @@ accept_mutex_init(void) fcntl_fd = open("test-lock-thing", O_CREAT | O_WRONLY | O_EXCL, 0644); if (fcntl_fd == -1) { - perror ("open"); - fprintf (stderr, "Cannot open lock file: %s\n", "test-lock-thing"); - exit (1); + perror ("open"); + fprintf (stderr, "Cannot open lock file: %s\n", "test-lock-thing"); + exit (1); } unlink("test-lock-thing"); } @@ -113,11 +113,11 @@ void accept_mutex_on(void) int ret; while ((ret = fcntl(fcntl_fd, F_SETLKW, &lock_it)) < 0 && errno == EINTR) - continue; + continue; if (ret < 0) { - perror ("fcntl lock_it"); - exit(1); + perror ("fcntl lock_it"); + exit(1); } } @@ -125,8 +125,8 @@ void accept_mutex_off(void) { if (fcntl (fcntl_fd, F_SETLKW, &unlock_it) < 0) { - perror ("fcntl unlock_it"); - exit(1); + perror ("fcntl unlock_it"); + exit(1); } } @@ -149,9 +149,9 @@ void accept_mutex_init(void) flock_fd = open(FNAME, O_CREAT | O_WRONLY | O_EXCL, 0644); if (flock_fd == -1) { - perror ("open"); - fprintf (stderr, "Cannot open lock file: %s\n", "test-lock-thing"); - exit (1); + perror ("open"); + fprintf (stderr, "Cannot open lock file: %s\n", "test-lock-thing"); + exit (1); } } @@ -159,8 +159,8 @@ void accept_mutex_child_init(void) { flock_fd = open(FNAME, O_WRONLY, 0600); if (flock_fd == -1) { - perror("open"); - exit(1); + perror("open"); + exit(1); } } @@ -174,11 +174,11 @@ void accept_mutex_on(void) int ret; while ((ret = flock(flock_fd, LOCK_EX)) < 0 && errno == EINTR) - continue; + continue; if (ret < 0) { - perror ("flock(LOCK_EX)"); - exit(1); + perror ("flock(LOCK_EX)"); + exit(1); } } @@ -186,8 +186,8 @@ void accept_mutex_off(void) { if (flock (flock_fd, LOCK_UN) < 0) { - perror ("flock(LOCK_UN)"); - exit(1); + perror ("flock(LOCK_UN)"); + exit(1); } } @@ -211,9 +211,9 @@ void accept_mutex_init(void) #ifdef NEED_UNION_SEMUN /* believe it or not, you need to define this under solaris */ union semun { - int val; - struct semid_ds *buf; - ushort *array; + int val; + struct semid_ds *buf; + ushort *array; }; #endif @@ -243,8 +243,8 @@ void accept_mutex_on() #ifdef NO_SEM_UNDO if (sigprocmask(SIG_BLOCK, &accept_block_mask, &accept_previous_mask)) { - perror("sigprocmask(SIG_BLOCK)"); - exit (1); + perror("sigprocmask(SIG_BLOCK)"); + exit (1); } op.sem_flg = 0; #else @@ -253,8 +253,8 @@ void accept_mutex_on() op.sem_num = 0; op.sem_op = -1; if (semop(sem_id, &op, 1) < 0) { - perror ("accept_mutex_on"); - exit (1); + perror ("accept_mutex_on"); + exit (1); } } @@ -270,13 +270,13 @@ void accept_mutex_off() op.sem_flg = SEM_UNDO; #endif if (semop(sem_id, &op, 1) < 0) { - perror ("accept_mutex_off"); + perror ("accept_mutex_off"); exit (1); } #ifdef NO_SEM_UNDO if (sigprocmask(SIG_SETMASK, &accept_previous_mask, NULL)) { - perror("sigprocmask(SIG_SETMASK)"); - exit (1); + perror("sigprocmask(SIG_SETMASK)"); + exit (1); } #endif } @@ -304,27 +304,27 @@ void accept_mutex_init(void) fd = open ("/dev/zero", O_RDWR); if (fd == -1) { - perror ("open(/dev/zero)"); - exit (1); + perror ("open(/dev/zero)"); + exit (1); } mutex = (pthread_mutex_t *)mmap ((caddr_t)0, sizeof (*mutex), - PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (mutex == (void *)(caddr_t)-1) { - perror ("mmap"); - exit (1); + perror ("mmap"); + exit (1); } close (fd); if (pthread_mutexattr_init(&mattr)) { - perror ("pthread_mutexattr_init"); - exit (1); + perror ("pthread_mutexattr_init"); + exit (1); } if (pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED)) { - perror ("pthread_mutexattr_setpshared"); - exit (1); + perror ("pthread_mutexattr_setpshared"); + exit (1); } if (pthread_mutex_init(mutex, &mattr)) { - perror ("pthread_mutex_init"); - exit (1); + perror ("pthread_mutex_init"); + exit (1); } sigfillset(&accept_block_mask); sigdelset(&accept_block_mask, SIGHUP); @@ -335,24 +335,24 @@ void accept_mutex_init(void) void accept_mutex_on() { if (sigprocmask(SIG_BLOCK, &accept_block_mask, &accept_previous_mask)) { - perror("sigprocmask(SIG_BLOCK)"); - exit (1); + perror("sigprocmask(SIG_BLOCK)"); + exit (1); } if (pthread_mutex_lock (mutex)) { - perror ("pthread_mutex_lock"); - exit (1); + perror ("pthread_mutex_lock"); + exit (1); } } void accept_mutex_off() { if (pthread_mutex_unlock (mutex)) { - perror ("pthread_mutex_unlock"); - exit (1); + perror ("pthread_mutex_unlock"); + exit (1); } if (sigprocmask(SIG_SETMASK, &accept_previous_mask, NULL)) { - perror("sigprocmask(SIG_SETMASK)"); - exit (1); + perror("sigprocmask(SIG_SETMASK)"); + exit (1); } } @@ -423,10 +423,10 @@ static void *get_shared_mem(apr_size_t size) /* allocate shared memory for the shared_counter */ result = (unsigned long *)mmap ((caddr_t)0, size, - PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); + PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); if (result == (void *)(caddr_t)-1) { - perror ("mmap"); - exit (1); + perror ("mmap"); + exit (1); } return result; } @@ -448,8 +448,8 @@ static void *get_shared_mem(apr_size_t size) #endif if ((shmid = shmget(shmkey, size, IPC_CREAT | SHM_R | SHM_W)) == -1) { - perror("shmget"); - exit(1); + perror("shmget"); + exit(1); } #ifdef MOVEBREAK @@ -463,29 +463,29 @@ static void *get_shared_mem(apr_size_t size) * attach the segment and then move break back down. Ugly */ if ((obrk = sbrk(MOVEBREAK)) == (char *) -1) { - perror("sbrk"); + perror("sbrk"); } #endif #define BADSHMAT ((void *)(-1)) if ((result = shmat(shmid, 0, 0)) == BADSHMAT) { - perror("shmat"); + perror("shmat"); } /* * We must avoid leaving segments in the kernel's * (small) tables. */ if (shmctl(shmid, IPC_RMID, NULL) != 0) { - perror("shmctl(IPC_RMID)"); + perror("shmctl(IPC_RMID)"); } if (result == BADSHMAT) /* now bailout */ - exit(1); + exit(1); #ifdef MOVEBREAK if (obrk == (char *) -1) - return; /* nothing else to do */ + return; /* nothing else to do */ if (sbrk(-(MOVEBREAK)) == (char *) -1) { - perror("sbrk 2"); + perror("sbrk 2"); } #endif return result; @@ -513,8 +513,8 @@ void main (int argc, char **argv) unsigned long *shared_counter; if (argc != 3) { - fprintf (stderr, "Usage: time-sem num-child num iter\n"); - exit (1); + fprintf (stderr, "Usage: time-sem num-child num iter\n"); + exit (1); } num_child = atoi (argv[1]); @@ -532,54 +532,54 @@ void main (int argc, char **argv) accept_mutex_on (); for (i = 0; i < num_child; ++i) { - pid = fork(); - if (pid == 0) { - /* child, do our thing */ - accept_mutex_child_init(); - for (i = 0; i < num_iter; ++i) { - unsigned long tmp; - - accept_mutex_on (); - tmp = *shared_counter; - YIELD; - *shared_counter = tmp + 1; - accept_mutex_off (); - } - exit (0); - } else if (pid == -1) { - perror ("fork"); - exit (1); - } + pid = fork(); + if (pid == 0) { + /* child, do our thing */ + accept_mutex_child_init(); + for (i = 0; i < num_iter; ++i) { + unsigned long tmp; + + accept_mutex_on (); + tmp = *shared_counter; + YIELD; + *shared_counter = tmp + 1; + accept_mutex_off (); + } + exit (0); + } else if (pid == -1) { + perror ("fork"); + exit (1); + } } /* a quick test to see that nothing is screwed up */ if (*shared_counter != 0) { - puts ("WTF! shared_counter != 0 before the children have been started!"); - exit (1); + puts ("WTF! shared_counter != 0 before the children have been started!"); + exit (1); } gettimeofday (&first, NULL); /* launch children into action */ accept_mutex_off (); for (i = 0; i < num_child; ++i) { - if (wait(NULL) == -1) { - perror ("wait"); - } + if (wait(NULL) == -1) { + perror ("wait"); + } } gettimeofday (&last, NULL); if (*shared_counter != num_child * num_iter) { - printf ("WTF! shared_counter != num_child * num_iter!\n" - "shared_counter = %lu\nnum_child = %d\nnum_iter=%d\n", - *shared_counter, - num_child, num_iter); + printf ("WTF! shared_counter != num_child * num_iter!\n" + "shared_counter = %lu\nnum_child = %d\nnum_iter=%d\n", + *shared_counter, + num_child, num_iter); } last.tv_sec -= first.tv_sec; ms = last.tv_usec - first.tv_usec; if (ms < 0) { - --last.tv_sec; - ms += 1000000; + --last.tv_sec; + ms += 1000000; } last.tv_usec = ms; printf ("%8lu.%06lu\n", last.tv_sec, last.tv_usec); @@ -1,6 +1,6 @@ /* ZeusBench V1.01 - =============== + =============== This program is Copyright (C) Zeus Technology Limited 1996. @@ -196,11 +196,11 @@ void output_results() printf("Document Length: %d\n", doclen); printf("Concurency Level: %d\n", concurrency); printf("Time taken for tests: %d.%03d seconds\n", - timetaken/1000, timetaken%1000); + timetaken/1000, timetaken%1000); printf("Complete requests: %d\n", done); printf("Failed requests: %d\n", bad); if(bad) printf(" (Connect: %d, Length: %d, Exceptions: %d)\n", - err_conn, err_length, err_except); + err_conn, err_length, err_except); if(keepalive) printf("Keep-Alive requests: %d\n", doneka); printf("Bytes transferred: %d\n", totalread); printf("HTML transferred: %d\n", totalbread); @@ -209,7 +209,7 @@ void output_results() if(timetaken) { printf("Requests per seconds: %.2f\n", 1000*(float)(done)/timetaken); printf("Transfer rate: %.2f kb/s\n", - (float)(totalread)/timetaken); + (float)(totalread)/timetaken); } { @@ -266,8 +266,8 @@ void start_connect(struct connection *c) close(c->fd); err_conn++; if(bad++>10) { - printf("\nTest aborted after 10 failures\n\n"); - exit(1); + printf("\nTest aborted after 10 failures\n\n"); + exit(1); } start_connect(c); } @@ -352,44 +352,44 @@ void read_connection(struct connection *c) if(!s) { /* read rest next time */ if(space) - return; + return; else { - /* header is in invalid or too big - close connection */ - close(c->fd); - if(bad++>10) { - printf("\nTest aborted after 10 failures\n\n"); - exit(1); - } - FD_CLR(c->fd, &writebits); - start_connect(c); + /* header is in invalid or too big - close connection */ + close(c->fd); + if(bad++>10) { + printf("\nTest aborted after 10 failures\n\n"); + exit(1); + } + FD_CLR(c->fd, &writebits); + start_connect(c); } } else { /* have full header */ if(!good) { - /* this is first time, extract some interesting info */ - char *p, *q; - p = strstr(c->cbuff, "Server:"); - q = server_name; - if(p) { p+=8; while(*p>32) *q++ = *p++; } - *q = 0; + /* this is first time, extract some interesting info */ + char *p, *q; + p = strstr(c->cbuff, "Server:"); + q = server_name; + if(p) { p+=8; while(*p>32) *q++ = *p++; } + *q = 0; } - + c->gotheader = 1; *s = 0; /* terminate at end of header */ if(keepalive && - (strstr(c->cbuff, "Keep-Alive") - || strstr(c->cbuff, "keep-alive"))) /* for benefit of MSIIS */ - { - char *cl; - cl = strstr(c->cbuff, "Content-Length:"); - /* for cacky servers like NCSA which break the spec and send a - lower case 'l' */ - if(!cl) cl = strstr(c->cbuff, "Content-length:"); - if(cl) { - c->keepalive=1; - c->length = atoi(cl+16); - } + (strstr(c->cbuff, "Keep-Alive") + || strstr(c->cbuff, "keep-alive"))) /* for benefit of MSIIS */ + { + char *cl; + cl = strstr(c->cbuff, "Content-Length:"); + /* for cacky servers like NCSA which break the spec and send a + lower case 'l' */ + if(!cl) cl = strstr(c->cbuff, "Content-length:"); + if(cl) { + c->keepalive=1; + c->length = atoi(cl+16); + } } c->bread += c->cbx - (s+l-c->cbuff) + r-tocopy; totalbread += c->bread; @@ -454,8 +454,8 @@ int test() /* setup request */ sprintf(request,"GET %s HTTP/1.0\r\nUser-Agent: ZeusBench/1.0\r\n" - "%sHost: %s\r\nAccept: */*\r\n\r\n", file, - keepalive?"Connection: Keep-Alive\r\n":"", machine ); + "%sHost: %s\r\nAccept: */*\r\n\r\n", file, + keepalive?"Connection: Keep-Alive\r\n":"", machine ); reqlen = strlen(request); @@ -491,10 +491,10 @@ int test() for(i=0; i<concurrency; i++) { int s = con[i].fd; if(FD_ISSET(s, &sel_except)) { - bad++; - err_except++; - start_connect(&con[i]); - continue; + bad++; + err_except++; + start_connect(&con[i]); + continue; } if(FD_ISSET(s, &sel_read)) read_connection(&con[i]); if(FD_ISSET(s, &sel_write)) write_request(&con[i]); @@ -511,7 +511,7 @@ int test() void usage(char *progname) { printf("\nZeusBench v1.0\n\n"); printf("Usage: %s <machine> <file> [-k] [-n requests | -t timelimit (sec)]" - "\n\t\t[-c concurrency] [-p port] \n",progname); + "\n\t\t[-c concurrency] [-p port] \n",progname); printf("Filename should start with a '/' e.g. /index.html\n\n"); exit(EINVAL); } @@ -534,8 +534,8 @@ int main(int argc, char **argv) { case 'n': requests = atoi(optarg); if(!requests) { - printf("Invalid number of requests\n"); - exit(1); + printf("Invalid number of requests\n"); + exit(1); } break; case 'k': |