# HG changeset patch # User Paul Boddie # Date 1645139645 -3600 # Node ID ad13c46ff61060d372a86af923c3a616d19c641b # Parent ffb9d9de40978d2f5df04f246318aca79008558b Improved test diagnostic output. diff -r ffb9d9de4097 -r ad13c46ff610 tests/dstest_file_readdir_concurrent.cc --- a/tests/dstest_file_readdir_concurrent.cc Fri Feb 18 00:13:37 2022 +0100 +++ b/tests/dstest_file_readdir_concurrent.cc Fri Feb 18 00:14:05 2022 +0100 @@ -31,6 +31,26 @@ +static int count_files(const char *filename, int *found) +{ + file_t *reader = client_opendir(filename); + struct dirent *dirent; + + if (reader == NULL) + return 1; + + *found = 0; + + while ((dirent = client_readdir(reader)) != NULL) + { + free(dirent); + (*found)++; + } + + client_close(reader); + return 0; +} + int main(int argc, char *argv[]) { if (argc < 2) @@ -40,6 +60,23 @@ } char *filename = argv[1]; + int original; + + if (count_files(filename, &original)) + { + printf("Could not read from directory.\n"); + return 1; + } + + printf("Files found: %d\n", original); + + struct dirent *dirent; + int filenum_base = 1000, filenum = filenum_base; + int to_create = 100, remaining = to_create; + char buffer[strlen(filename) + strlen("/file-XXXX.txt") + 10]; + char data[256]; + int found = 0; + file_t *files[to_create]; printf("Opening %s...\n", filename); @@ -53,13 +90,6 @@ printf("Reading...\n"); - struct dirent *dirent; - int filenum = 1000, remaining = 100; - char buffer[strlen(filename) + strlen("/file-XXXX.txt") + 10]; - char data[256]; - int found = 0; - file_t *files[100]; - while ((dirent = client_readdir(reader)) != NULL) { free(dirent); @@ -69,7 +99,7 @@ if (remaining) { - sprintf(buffer, "%s/file-%d.txt", filename, filenum++); + sprintf(buffer, "%s/file-%d.txt", filename, filenum); file_t *file = client_open(buffer, O_RDWR | O_CREAT); @@ -81,14 +111,15 @@ /* Write something to each file. */ - sprintf(data, "Data in file-%d.txt", filenum - 1); + sprintf(data, "Data in file-%d.txt", filenum); client_write(file, data, strlen(data)); /* Remember the file for later. */ - files[remaining - 1] = file; + files[filenum - filenum_base] = file; remaining--; + filenum++; } } @@ -96,29 +127,19 @@ /* Re-read, counting files. */ - reader = client_opendir(filename); - - if (reader == NULL) + if (count_files(filename, &found)) { printf("Could not read from directory.\n"); return 1; } - found = 0; - - while ((dirent = client_readdir(reader)) != NULL) - { - free(dirent); - found++; - } - printf("Files found: %d\n", found); /* Remove some files. */ - for (filenum = 1000, remaining = 100; remaining > 0; remaining--) + for (filenum = 1000, remaining = to_create; remaining > 0; remaining--, filenum++) { - sprintf(buffer, "%s/file-%d.txt", filename, filenum++); + sprintf(buffer, "%s/file-%d.txt", filename, filenum); long err = client_remove(buffer); @@ -131,37 +152,55 @@ /* Re-read, counting files. */ - reader = client_opendir(filename); - - if (reader == NULL) + if (count_files(filename, &found)) { printf("Could not read from directory.\n"); return 1; } - found = 0; - - while ((dirent = client_readdir(reader)) != NULL) - { - free(dirent); - found++; - } - printf("Files found: %d\n", found); /* Read from the still-open but now removed files. */ - for (remaining = 0; remaining < 100; remaining++) + found = 0; + + for (filenum = 1000, remaining = 0; remaining < to_create; remaining++, filenum++) { - file_t *file = files[remaining]; + file_t *file = files[filenum - filenum_base]; + char read_data[256]; client_seek(file, SEEK_SET, 0); - offset_t nread = client_read(file, data, 256); + offset_t nread = client_read(file, read_data, 256); + + if (nread) + { + read_data[nread] = '\0'; + sprintf(data, "Data in file-%d.txt", filenum); + + if (!strcmp(data, read_data)) + found++; + } + } + + printf("Files still open: %d (%d)\n", found, to_create); - data[nread] = '\0'; - printf("Read: %s\n", data); + /* Close the files. */ + + for (remaining = 0; remaining < to_create; remaining++) + client_close(files[remaining]); + + printf("Closed files.\n"); + + /* Re-read, counting files. */ + + if (count_files(filename, &found)) + { + printf("Could not read from directory.\n"); + return 1; } + printf("Files found: %d (%d)\n", found, original); + return 0; } diff -r ffb9d9de4097 -r ad13c46ff610 tests/dstest_file_rename.cc --- a/tests/dstest_file_rename.cc Fri Feb 18 00:13:37 2022 +0100 +++ b/tests/dstest_file_rename.cc Fri Feb 18 00:14:05 2022 +0100 @@ -67,9 +67,9 @@ char source[strlen(filename) + strlen("/file-XXXX.txt") + 10]; char target[strlen(filename) + strlen("/file-XXXX.txt") + 10]; - int filenum; + int filenum, to_rename = 100; - for (filenum = 1; filenum < 100; filenum++) + for (filenum = 1; filenum <= to_rename; filenum++) { sprintf(source, "%s/file-%d.txt", filename, filenum); sprintf(target, "%s/renamed-%d.txt", filename, filenum); @@ -95,14 +95,21 @@ printf("Reading...\n"); + int renamed = 0; + while ((dirent = client_readdir(reader)) != NULL) { + if (!strncmp(dirent->d_name, "renamed-", 8)) + renamed++; + printf("> %s\n", dirent->d_name); free(dirent); } printf("Directory shown.\n"); + printf("Renamed files: %d (%d)\n", renamed, to_rename); + return 0; }