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 stat and fstat tests #35

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 56 additions & 0 deletions tests/fstat1.c
@@ -0,0 +1,56 @@
#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 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);
}
38 changes: 38 additions & 0 deletions tests/fstat2.c
@@ -0,0 +1,38 @@
#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 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);
}
53 changes: 53 additions & 0 deletions tests/stat1.c
@@ -0,0 +1,53 @@
#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 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);
}
35 changes: 35 additions & 0 deletions tests/stat2.c
@@ -0,0 +1,35 @@
#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 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);
}