@@ -27,17 +27,25 @@
#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
S_IXGRP|S_IROTH|S_IXOTH)
#define FILE_EISDIR "."
-#define FILE_EACCES "/dev/null"
+#define FILE_EACCESS "/dev/null"
#define FILE_ENOENT "/tmp/does/not/exist"
#define FILE_ENOTDIR "./tmpfile/"
-#define TEST_TMPFILE "./tmpfile"
-#define TEST_ELOOP "test_file_eloop1"
-#define TEST_ENAMETOOLONG nametoolong
-#define TEST_EROFS "mntpoint/file"
+#define FILE_TMPFILE "./tmpfile"
+#define FILE_ELOOP "test_file_eloop1"
+#define FILE_EROFS "ro_mntpoint/file"
-static char nametoolong[PATH_MAX+2];
static struct passwd *ltpuser;
+static char *file_eisdir;
+static char *file_eaccess;
+static char *file_enoent;
+static char *file_enotdir;
+static char *file_tmpfile;
+static char *file_eloop;
+static char *file_enametoolong;
+static char *file_erofs;
+static char *file_null;
+
static void setup_euid(void)
{
SAFE_SETEUID(ltpuser->pw_uid);
@@ -49,21 +57,21 @@ static void cleanup_euid(void)
}
static struct test_case {
- char *filename;
- char *exp_errval;
+ char **filename;
+ char *desc;
int exp_errno;
void (*setupfunc) ();
void (*cleanfunc) ();
} tcases[] = {
- {FILE_EISDIR, "EISDIR", EISDIR, NULL, NULL},
- {FILE_EACCES, "EACCES", EACCES, NULL, NULL},
- {FILE_ENOENT, "ENOENT", ENOENT, NULL, NULL},
- {FILE_ENOTDIR, "ENOTDIR", ENOTDIR, NULL, NULL},
- {TEST_TMPFILE, "EPERM", EPERM, setup_euid, cleanup_euid},
- {NULL, "EPERM", EPERM, setup_euid, cleanup_euid},
- {TEST_ELOOP, "ELOOP", ELOOP, NULL, NULL},
- {TEST_ENAMETOOLONG, "ENAMETOOLONG", ENAMETOOLONG, NULL, NULL},
- {TEST_EROFS, "EROFS", EROFS, NULL, NULL},
+ {&file_eisdir, FILE_EISDIR, EISDIR, NULL, NULL},
+ {&file_eaccess, FILE_EACCESS, EACCES, NULL, NULL},
+ {&file_enoent, FILE_ENOENT, ENOENT, NULL, NULL},
+ {&file_enotdir, FILE_ENOTDIR, ENOTDIR, NULL, NULL},
+ {&file_tmpfile, FILE_TMPFILE, EPERM, setup_euid, cleanup_euid},
+ {&file_null, "NULL", EPERM, setup_euid, cleanup_euid},
+ {&file_eloop, FILE_ELOOP, ELOOP, NULL, NULL},
+ {&file_enametoolong, "aaaa...", ENAMETOOLONG, NULL, NULL},
+ {&file_erofs, FILE_EROFS, EROFS, NULL, NULL},
};
static void setup(void)
@@ -76,10 +84,10 @@ static void setup(void)
ltpuser = SAFE_GETPWNAM("nobody");
- fd = SAFE_CREAT(TEST_TMPFILE, 0777);
+ fd = SAFE_CREAT(FILE_TMPFILE, 0777);
SAFE_CLOSE(fd);
- TEST(acct(TEST_TMPFILE));
+ TEST(acct(FILE_TMPFILE));
if (TST_RET == -1)
tst_brk(TBROK | TTERRNO, "acct failed unexpectedly");
@@ -89,11 +97,11 @@ static void setup(void)
tst_brk(TBROK | TTERRNO, "acct(NULL) failed");
/* ELOOP SETTING */
- SAFE_SYMLINK(TEST_ELOOP, "test_file_eloop2");
- SAFE_SYMLINK("test_file_eloop2", TEST_ELOOP);
+ SAFE_SYMLINK(FILE_ELOOP, "test_file_eloop2");
+ SAFE_SYMLINK("test_file_eloop2", FILE_ELOOP);
- /* ENAMETOOLONG SETTING */
- memset(nametoolong, 'a', PATH_MAX+1);
+ memset(file_enametoolong, 'a', PATH_MAX+1);
+ file_enametoolong[PATH_MAX+1] = 0;
}
static void verify_acct(unsigned int nr)
@@ -103,31 +111,29 @@ static void verify_acct(unsigned int nr)
if (tcase->setupfunc)
tcase->setupfunc();
- TEST(acct(tcase->filename));
+ TST_EXP_FAIL(acct(*tcase->filename), tcase->exp_errno,
+ "acct(%s)", tcase->desc);
if (tcase->cleanfunc)
tcase->cleanfunc();
-
- if (TST_RET != -1) {
- tst_res(TFAIL, "acct(%s) succeeded unexpectedly",
- tcase->filename);
- return;
- }
-
- if (TST_ERR == tcase->exp_errno) {
- tst_res(TPASS | TTERRNO, "acct() failed as expected");
- } else {
- tst_res(TFAIL | TTERRNO,
- "acct() failed, expected: %s",
- tst_strerrno(tcase->exp_errno));
- }
}
static struct tst_test test = {
.needs_root = 1,
- .mntpoint = "mntpoint",
+ .mntpoint = "ro_mntpoint",
.needs_rofs = 1,
.tcnt = ARRAY_SIZE(tcases),
.setup = setup,
.test = verify_acct,
+ .bufs = (struct tst_buffers []) {
+ {&file_eisdir, .str = FILE_EISDIR},
+ {&file_eaccess, .str = FILE_EACCESS},
+ {&file_enoent, .str = FILE_ENOENT},
+ {&file_enotdir, .str = FILE_ENOTDIR},
+ {&file_tmpfile, .str = FILE_TMPFILE},
+ {&file_eloop, .str = FILE_ELOOP},
+ {&file_enametoolong, .size = PATH_MAX+2},
+ {&file_erofs, .str = FILE_EROFS},
+ {}
+ }
};
Signed-off-by: Cyril Hrubis <chrubis@suse.cz> --- testcases/kernel/syscalls/acct/acct01.c | 84 +++++++++++++------------ 1 file changed, 45 insertions(+), 39 deletions(-)