tests: fixes to accomodate growing OPEN_MAX and a logic error

This commit is contained in:
Ben Gras 2010-07-13 12:38:58 +00:00
parent 60549b67be
commit 835232d504
2 changed files with 77 additions and 45 deletions

View file

@ -13,6 +13,7 @@
#include <utime.h>
#include <stdio.h>
#include <limits.h>
#include <assert.h>
#define NOCRASH 1 /* test11(), 2nd pipe */
#define PDPNOHANG 1 /* test03(), write_standards() */
@ -62,18 +63,15 @@
int errct;
char *file[];
char *fnames[];
char *dir[];
/* "decl.c", created by Rene Montsma and Menno Wilcke */
/* Used in open_alot, close_alot */
char *file[20] = {"f0", "f1", "f2", "f3", "f4", "f5", "f6",
"f7", "f8", "f9", "f10", "f11", "f12", "f13",
"f14", "f15", "f16", "f17", "f18", "f19"}, *fnames[8] = {"---", "--x", "-w-", "-wx", "r--",
"r-x", "rw-", "rwx"}, *dir[8] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x",
"drw-", "drwx"};
char *filenames[MAXOPEN];
#define MODES 8
char *mode_fnames[MODES] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"},
*mode_dir[MODES] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", "drw-", "drwx"};
/* Needed for easy creating and deleting of directories */
/* "test.c", created by Rene Montsma and Menno Wilcke */
@ -120,7 +118,15 @@ int argc;
char *argv[];
{
char buffer[PATH_MAX + 1];
int n, mask;
int n, mask, i;
/* Create filenames for MAXOPEN files, the *filenames[] array. */
for(i = 0; i < MAXOPEN; i++) {
if(asprintf(&filenames[i], "file%d", i) == -1) {
fprintf(stderr, "asprintf failed\n");
return 1;
}
}
sync();
if (geteuid() == 0 || getuid() == 0) {
@ -130,8 +136,18 @@ char *argv[];
exit(1);
}
system("rm -rf DIR_17; mkdir DIR_17");
chdir("DIR_17");
#define DIR "DIR17"
system("rm -rf " DIR);
if(mkdir(DIR, 0755) != 0) {
perror("mkdir");
return 1;
}
if(chdir(DIR) < 0) {
perror("chdir");
return 1;
}
mask = (argc == 2 ? atoi(argv[1]) : 0xFFFF);
@ -219,17 +235,16 @@ void test02()
mode = 0;
/* Create twenty files, check filedes */
for (n = 0; n < MAXOPEN; n++) {
if (creat(file[n], mode) != FF + n)
err(13, CREAT, file[n]);
if (creat(filenames[n], mode) != FF + n)
err(13, CREAT, filenames[n]);
else {
if (get_mode(file[n]) != mode)
if (get_mode(filenames[n]) != mode)
err(7, CREAT, "mode set while creating many files");
/* Change mode of file to standard mode, we want to *
* use a lot (20) of files to be opened later, see *
* open_alot(), close_alot(). */
if (chmod(file[n], 0700) != OK) err(5, CHMOD, file[n]);
if (chmod(filenames[n], 0700) != OK) err(5, CHMOD, filenames[n]);
}
mode = (mode + 0100) % 01000;
}
@ -452,7 +467,7 @@ void test10()
int n, n1;
char a[ARSIZE], b[ARSIZE], *f, *lf;
f = "file10";
f = "anotherfile10";
lf = "linkfile10";
if ((n = creat(f, 0702)) != FF) /* no other open files */
@ -874,9 +889,9 @@ void make_and_fill_dirs()
{
int mode, i;
for (i = 0; i < 8; i++) {
mkdir(dir[i], 0700);
chown(dir[i], USER_ID, GROUP_ID);
for (i = 0; i < MODES; i++) {
mkdir(mode_dir[i], 0700);
chown(mode_dir[i], USER_ID, GROUP_ID);
}
setuid(USER_ID);
setgid(GROUP_ID);
@ -902,10 +917,12 @@ int mode;
err(5, CHDIR, "to dirname (put_f_in_dir)");
else {
/* Creat the file */
if ((nr = creat(fnames[mode], mode * 0100)) < 0)
err(13, CREAT, fnames[mode]);
else
try_close(nr, fnames[mode]);
assert(mode >= 0 && mode < MODES);
if ((nr = creat(mode_fnames[mode], mode * 0100)) < 0)
err(13, CREAT, mode_fnames[mode]);
else {
try_close(nr, mode_fnames[mode]);
}
if (chdir("..") != OK)
err(5, CHDIR, "to previous dir (put_f_in_dir)");
@ -1065,7 +1082,7 @@ int open_alot()
int i;
for (i = 0; i < MAXOPEN; i++)
if (open(file[i], R) == FAIL) break;
if (open(filenames[i], R) == FAIL) break;
if (i == 0) err(5, "open_alot", "at all");
return(i);
} /* open_alot */
@ -1096,13 +1113,17 @@ void clean_up_the_mess()
char dirname[6];
/* First remove 'a lot' files */
for (i = 0; i < MAXOPEN; i++) try_unlink(file[i]);
for (i = 0; i < MAXOPEN; i++) {
try_unlink(filenames[i]);
}
/* Unlink the files in dir 'drwx' */
if (chdir("drwx") != OK)
err(5, CHDIR, "to 'drwx'");
else {
for (i = 0; i < 8; i++) try_unlink(fnames[i]);
for (i = 0; i < MODES; i++) {
try_unlink(mode_fnames[i]);
}
if (chdir("..") != OK) err(5, CHDIR, "to '..'");
}
@ -1115,9 +1136,9 @@ void clean_up_the_mess()
try_unlink("drw-/rwx");
/* Unlink dirs */
for (i = 0; i < 8; i++) {
for (i = 0; i < MODES; i++) {
strcpy(dirname, "d");
strcat(dirname, fnames[i]);
strcat(dirname, mode_fnames[i]);
/* 'dirname' contains the directoryname */
rmdir(dirname);
@ -1138,8 +1159,8 @@ int sw; /* if switch == 8, give all different
else
mode = sw;
for (i = 0; i < 8; i++) {
chmod(dir[i], 040000 + mode * 0100);
for (i = 0; i < MODES; i++) {
chmod(mode_dir[i], 040000 + mode * 0100);
if (sw == 8) mode++;
}
}

View file

@ -66,18 +66,13 @@
int errct;
char *file[];
char *fnames[];
char *dir[];
/* "decl.c", created by Rene Montsma and Menno Wilcke */
/* Used in open_alot, close_alot */
char *file[20] = {"f0", "f1", "f2", "f3", "f4", "f5", "f6",
"f7", "f8", "f9", "f10", "f11", "f12", "f13",
"f14", "f15", "f16", "f17", "f18", "f19"}, *fnames[8] = {"---", "--x", "-w-", "-wx", "r--",
"r-x", "rw-", "rwx"}, *dir[8] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x",
"drw-", "drwx"};
char *file[MAXOPEN];
char *fnames[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"},
*dir[8] = {"d---", "d--x", "d-w-", "d-wx", "dr--", "dr-x", "drw-", "drwx"};
/* Needed for easy creating and deleting of directories */
/* "test.c", created by Rene Montsma and Menno Wilcke */
@ -130,7 +125,15 @@ _PROTOTYPE(void quit, (void));
int main(int argc, char **argv)
{
char buffer[PATH_MAX + 1];
int n;
int n, i;
/* Create filenames for MAXOPEN files, the *file[] array. */
for(i = 0; i < MAXOPEN; i++) {
if(asprintf(&file[i], "file%d", i) == -1) {
fprintf(stderr, "asprintf failed\n");
return 1;
}
}
if (geteuid() == 0 || getuid() == 0) {
realpath(argv[0], buffer);
@ -139,8 +142,16 @@ int main(int argc, char **argv)
exit(1);
}
system("rm -rf DIR_18; mkdir DIR_18");
chdir("DIR_18");
#define DIR "DIR18"
system("rm -rf " DIR);
if(mkdir(DIR, 0755) != 0) {
perror("mkdir");
return 1;
}
if(chdir(DIR) != 0) {
perror("chdir");
return 1;
}
if (fork()) {
printf("Test 18 ");
@ -645,7 +656,7 @@ void test05()
check(OPEN, ENOENT);
/* Dir is not searchable */
if (n = open("drw-/rwx", R) != FAIL)
if ((n = open("drw-/rwx", R)) != FAIL)
err(11, OPEN, "open in an non-searchabledir");
else
check(OPEN, EACCES);