Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access tests #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions tests/access1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>
#include <string.h>

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);
}
33 changes: 33 additions & 0 deletions tests/access2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <assert.h>

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);
}