int stress_test2(){ int i; struct stat st; char buffer[64]; int len; int loc; void * f; printf("Starting stess test 2\n"); printf("appending..."); fflush(stdout); f = test_open("log.txt", O_APPEND | O_RDWR | O_CREAT, 0666); if ( f == NULL ){ perror("Failed to open file"); return -1; } test_fstat(f, &st); loc = st.st_size; strcpy(buffer, "123456789\n"); len = strlen(buffer); for(i = 0; i < 10000; i++){ if ( i % 100 == 0 ){ printf("."); fflush(stdout); } if ( test_write(f, loc, buffer, len) != len ){ perror("write failed"); break; } loc += len; } test_fstat(f, &st); printf("%d bytes\n", (int)st.st_size); test_close(f); return 0; }
int main () { /* Don't change the order of the calls. They partly depend on each other */ test_open (); test_write (); test_read (); test_lseek (); test_close (); test_stat (); test_fstat (); test_isatty (); test_system (); test_rename (); test_unlink (); test_time (); return 0; }
int main(void) { int rtn = test_fstat(); return rtn; }
int stress_test1(){ int i; int j; int ret; int len; struct stat st; char buffer[64]; int loc; void * f; i = 0; test_remove("log.txt"); printf("append test %d...", i); fflush(stdout); for(i = 0; i < 1000; i++){ if ( i % 50 == 0 ){ printf("%d...", i); fflush(stdout); } f = test_open("log.txt", O_APPEND | O_RDWR | O_CREAT, 0666); if ( f == NULL ){ perror("Failed to open file"); return -1; } test_fstat(f, &st); loc = st.st_size; strcpy(buffer, "1234567890123456789012345678901234567890123456789\n"); len = strlen(buffer); ret = test_write(f, loc, buffer, len); if ( ret != strlen(buffer) ){ printf("Ret is %d == %d\n", ret, len); } if ( ret != strlen(buffer) ){ perror("write failed"); test_close(f); break; } fstat(fileno(f), &st); test_close(f); fflush(stdout); f = test_open("log.txt", O_RDONLY, 0); if ( f == NULL ){ perror("Failed to open file"); return -1; } loc = 0; j = 0; errno = 0; while(1){ if ( test_read(f, loc, buffer, len) != len ){ break; } loc += len; if ( strcmp(buffer, "1234567890123456789012345678901234567890123456789\n") != 0 ){ printf("Bad comparison at line %d %d\n", j, (int)st.st_size); exit(1); } j++; } test_fstat(f, &st); test_close(f); } printf("passed\n"); return 0; }