From 874ff62cc30c3c51a6a0d3ea9fe8723d53a26cdd Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Thu, 12 Jan 2023 19:37:41 +0000 Subject: [PATCH] Add stat and fstat tests --- tests/fstat1.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/fstat2.c | 38 ++++++++++++++++++++++++++++++++++ tests/stat1.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ tests/stat2.c | 35 +++++++++++++++++++++++++++++++ 4 files changed, 182 insertions(+) create mode 100644 tests/fstat1.c create mode 100644 tests/fstat2.c create mode 100644 tests/stat1.c create mode 100644 tests/stat2.c diff --git a/tests/fstat1.c b/tests/fstat1.c new file mode 100644 index 0000000..d8d86ef --- /dev/null +++ b/tests/fstat1.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +#include +#include + +char *testcase_description = "Separate file fstat"; + +#define template "/tmp/willitscale.XXXXXX" +static char (*tmpfiles)[sizeof(template)]; +static unsigned long local_nr_tasks; + +void testcase_prepare(unsigned long nr_tasks) +{ + int i; + tmpfiles = (char(*)[sizeof(template)])malloc(sizeof(template) * nr_tasks); + assert(tmpfiles); + + for (i = 0; i < nr_tasks; i++) { + strcpy(tmpfiles[i], template); + char *tmpfile = tmpfiles[i]; + int fd = mkstemp(tmpfile); + + assert(fd >= 0); + close(fd); + } + + local_nr_tasks = nr_tasks; +} + +void testcase(unsigned long long *iterations, unsigned long nr) +{ + char *tmpfile = tmpfiles[nr]; + struct stat sb; + int fd = open(tmpfile, O_RDONLY); + + assert(fd>= 0); + + while (1) { + int error = fstat(fd, &sb); + assert(error == 0); + + (*iterations)++; + } +} + +void testcase_cleanup(void) +{ + int i; + for (i = 0; i < local_nr_tasks; i++) { + unlink(tmpfiles[i]); + } + free(tmpfiles); +} diff --git a/tests/fstat2.c b/tests/fstat2.c new file mode 100644 index 0000000..28203e7 --- /dev/null +++ b/tests/fstat2.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include +#include + +static char tmpfile[] = "/tmp/willitscale.XXXXXX"; + +char *testcase_description = "Same file fstat"; + +void testcase_prepare(unsigned long nr_tasks) +{ + int fd = mkstemp(tmpfile); + + assert(fd >= 0); + close(fd); +} + +void testcase(unsigned long long *iterations, unsigned long nr) +{ + struct stat sb; + int fd = open(tmpfile, O_RDONLY); + + assert(fd>= 0); + + while (1) { + int error = fstat(fd, &sb); + assert(error == 0); + + (*iterations)++; + } +} + +void testcase_cleanup(void) +{ + unlink(tmpfile); +} diff --git a/tests/stat1.c b/tests/stat1.c new file mode 100644 index 0000000..2038d06 --- /dev/null +++ b/tests/stat1.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include +#include +#include + +char *testcase_description = "Separate file stat"; + +#define template "/tmp/willitscale.XXXXXX" +static char (*tmpfiles)[sizeof(template)]; +static unsigned long local_nr_tasks; + +void testcase_prepare(unsigned long nr_tasks) +{ + int i; + tmpfiles = (char(*)[sizeof(template)])malloc(sizeof(template) * nr_tasks); + assert(tmpfiles); + + for (i = 0; i < nr_tasks; i++) { + strcpy(tmpfiles[i], template); + char *tmpfile = tmpfiles[i]; + int fd = mkstemp(tmpfile); + + assert(fd >= 0); + close(fd); + } + + local_nr_tasks = nr_tasks; +} + +void testcase(unsigned long long *iterations, unsigned long nr) +{ + char *tmpfile = tmpfiles[nr]; + struct stat sb; + + while (1) { + int error = stat(tmpfile, &sb); + assert(error == 0); + + (*iterations)++; + } +} + +void testcase_cleanup(void) +{ + int i; + for (i = 0; i < local_nr_tasks; i++) { + unlink(tmpfiles[i]); + } + free(tmpfiles); +} diff --git a/tests/stat2.c b/tests/stat2.c new file mode 100644 index 0000000..0391a12 --- /dev/null +++ b/tests/stat2.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include + +static char tmpfile[] = "/tmp/willitscale.XXXXXX"; + +char *testcase_description = "Same file stat"; + +void testcase_prepare(unsigned long nr_tasks) +{ + int fd = mkstemp(tmpfile); + + assert(fd >= 0); + close(fd); +} + +void testcase(unsigned long long *iterations, unsigned long nr) +{ + struct stat sb; + + while (1) { + int error = stat(tmpfile, &sb); + assert(error == 0); + + (*iterations)++; + } +} + +void testcase_cleanup(void) +{ + unlink(tmpfile); +}