Skip to content

Commit

Permalink
Each VFS test runs in separate directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
cahirwpz committed Jul 31, 2023
1 parent 87b2fde commit 7960683
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 125 deletions.
2 changes: 2 additions & 0 deletions bin/utest/getcwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <unistd.h>

TEST_ADD(getcwd, 0) {
xchdir("/");

{
/* Working directory is set to root if not changed */
char buffer[256];
Expand Down
17 changes: 17 additions & 0 deletions bin/utest/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
Expand Down Expand Up @@ -102,6 +103,14 @@ static int running(void) {
return pending;
}

#define TMPDIR "/tmp"

char testdir[128] = TMPDIR;

static void testdir_cleanup(void) {
xrmdir(testdir);
}

static void run_test(sigset_t *mask, test_entry_t *te) {
timeval_t tv = timestamp();
const char *name = te->name;
Expand All @@ -116,6 +125,14 @@ static void run_test(sigset_t *mask, test_entry_t *te) {
setpgid(0, 0);
xsigprocmask(SIG_SETMASK, mask, NULL);

if (te->flags & TF_TMPDIR) {
snprintf(testdir, sizeof(testdir), TMPDIR "/%s.%d", te->name, getpid());
xmkdir(testdir, 0);
atexit(testdir_cleanup);
}

xchdir(testdir);

if (te->flags & TF_DEBUG)
__verbose = 1;

Expand Down
8 changes: 8 additions & 0 deletions bin/utest/utest.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef int (*test_func_t)(void);
typedef enum test_flags {
TF_DISABLED = INT32_MIN, /* test will return success without being executed */
TF_DEBUG = 1, /* display debug messages to stderr */
TF_TMPDIR = 2, /* create temp di rand run the test there */
} test_flags_t;

typedef struct test_entry {
Expand Down Expand Up @@ -90,6 +91,12 @@ pid_t wait_child_terminated(pid_t pid, int signo);
void wait_child_stopped(pid_t pid);
void wait_child_continued(pid_t pid);

/*
* VFS test related definitions
*/

extern char testdir[];

/*
* libc function wrappers that call die(...) on error
*/
Expand Down Expand Up @@ -134,6 +141,7 @@ void wait_child_continued(pid_t pid);
#define xopen(...) NOFAIL(open, int, __VA_ARGS__)
#define xpipe(...) NOFAIL_NR(pipe, __VA_ARGS__)
#define xread(...) NOFAIL(read, ssize_t, __VA_ARGS__)
#define xreadlink(...) NOFAIL(readlink, ssize_t, __VA_ARGS__)
#define xrmdir(...) NOFAIL_NR(rmdir, __VA_ARGS__)
#define xsetgroups(...) NOFAIL_NR(setgroups, __VA_ARGS__)
#define xsetresuid(...) NOFAIL_NR(setresuid, __VA_ARGS__)
Expand Down
Loading

0 comments on commit 7960683

Please sign in to comment.