From: adilger Date: Tue, 12 Aug 2003 16:59:47 +0000 (+0000) Subject: Add sleeping write/verification test to CVS. X-Git-Tag: v1_7_0_51~2^7~695 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=c9aac9bf939b46f378135e46ae3c400f38fef7dd;p=fs%2Flustre-release.git Add sleeping write/verification test to CVS. usage: sleeptest [basename [sleeptime]] Fixes a couple of bugs in the current test: - assumes that there is 100 bytes after offset & ~4095 (fails at iter 233) - assumes that "Line" appears in the output (fails if < 60 bytes read) --- diff --git a/lustre/tests/sleeptest.c b/lustre/tests/sleeptest.c new file mode 100644 index 0000000..d8beceb --- /dev/null +++ b/lustre/tests/sleeptest.c @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFSIZE (4096) + +#define min(a,b) ((a) < (b) ? (a) : (b)) + +int main(int argc, char *argv[]) +{ + + FILE *w_str; + int read_fd; + int rc, iter; + int line, delta, next; + int sleeptime = 0; + char *now_time; + const char ok_chars[] = "MonTueWedThuFriSatSun" + "JanFebMarAprMayJunJulAugSepOctNovDec" + "Line 0123456789 of file, written at:\n"; + + char buf_r[BUFSIZE]; + + char pathname[256] = "/mnt/lustre/linetest_"; + char *host; + + if (argc > 1) { + strncpy(pathname, argv[1], 255); + pathname[255] = '\0'; + } + + host = getenv("HOSTNAME"); + if (host) + strcat(pathname, host); + + if (argc > 2) + sleeptime = strtoul(argv[2], NULL, 0); + + if (sleeptime == 0) + sleeptime = 30; + + printf("Test file used is: %s at %ds intervals\n", pathname, sleeptime); + + w_str = fopen(pathname, "wb"); + if (w_str == NULL) { + perror("fopen"); + exit(1); + } + read_fd = open(pathname, O_RDONLY); + if (read_fd < 0) { + perror("open"); + exit(1); + } + + next = 1; + delta = 17; + iter = 1; + while (1) { + time_t now; + struct tm *t; + long offset; + + now = time((time_t *)NULL); + t = localtime(&now); + now_time = asctime(t); + + printf("iter: %d\n", iter); + + for (line=next; line<(next+delta); line++) { + rc = fprintf(w_str, "Line %8d of file, written at: %s", + line, now_time); + /* \n comes from ctime() result */ + if (rc <= 0) { + perror("fprintf"); + exit(4); + } + rc = fflush(w_str); + if (rc != 0) { + perror("fflush"); + exit(5); + } + } + next += delta; + + /* Check for corruption */ + offset = ftell(w_str); + rc = lseek(read_fd, offset & ~4095, SEEK_SET); + if (rc != (offset & ~4095)) { + perror("lseek"); + exit(7); + } + + rc = read(read_fd, buf_r, min(100, offset & 4095)); + if (rc != min(100, offset & 4095)) { + printf("rc: %d, off %lu buf: '%s'\n", rc,offset,buf_r); + exit(8); + } + buf_r[rc] = 0; + /* Chars from "C" days/months, and above Line */ + if (strspn(buf_r, ok_chars) != rc) { + printf("Corruption detected at %lu on %s", + offset & ~4095, now_time); + exit(9); + } + + sleep(sleeptime); + iter++; + } + +}