From a119c96760350040e495d4c1d927ab7158a6aff7 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Thu, 12 Jan 2023 23:56:59 +0000 Subject: [PATCH] Add access tests --- tests/access1.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/access2.c | 33 +++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/access1.c create mode 100644 tests/access2.c diff --git a/tests/access1.c b/tests/access1.c new file mode 100644 index 0000000..d1ce1b9 --- /dev/null +++ b/tests/access1.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +#include + +char *testcase_description = "Separate file access"; + +#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]; + + while (1) { + int error = access(tmpfile, R_OK); + 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/access2.c b/tests/access2.c new file mode 100644 index 0000000..06daeb7 --- /dev/null +++ b/tests/access2.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include + +static char tmpfile[] = "/tmp/willitscale.XXXXXX"; + +char *testcase_description = "Same file access"; + +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) +{ + while (1) { + int error = access(tmpfile, R_OK); + assert(error == 0); + + (*iterations)++; + } +} + +void testcase_cleanup(void) +{ + unlink(tmpfile); +}