[Libsysio-commit] libsysio_tests: libsysio/tests help.c helper.pm sysio_stubs.c sysio_tests.c test_c
Brought to you by:
lward
|
From: Sonja T. <so...@us...> - 2003-07-01 16:04:16
|
Update of /cvsroot/libsysio/libsysio/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv9480/libsysio/tests
Modified Files:
Tag: libsysio_tests
help.c helper.pm sysio_stubs.c sysio_tests.c test_copy.pl
test_driver.c test_driver.h test_getcwd.pl test_list.pl
test_path.pl test_stats.pl
Log Message:
Adding more tests and bug fixes
Index: help.c
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/help.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- help.c 30 May 2003 18:14:15 -0000 1.1.2.1
+++ help.c 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -5,13 +5,13 @@ void do_help() {
int i, d, count = 0;
fprintf(outfp, "libsysio test harness\n");
- fprintf(outfp, "To get help on a specific command, use help <cmd>\n");
+ fprintf(outfp, "To get help on a specific command, use HELP <cmd>\n");
fprintf(outfp, "To exit, type exit or quit\n");
- fprintf(outfp, "\nTo save the result from a function, use \"$res = command\"\n");
+ fprintf(outfp, "\nTo save the result from a function, use \"$res = CALL command\"\n");
fprintf(outfp, "To later use that res, do \"comm $res\"\n");
- fprintf(outfp, "\n\nAvailable commands are:\n\n");
+ fprintf(outfp, "\n\nAvailable commands are (always preceded by CALL):\n\n");
/* Get total number of commands */
while (cmd_list[count].cmd)
@@ -21,9 +21,10 @@ void do_help() {
if (count %4)
d++;
for (i=0; i < d; i++) {
- if (cmd_list[i+d].cmd) {
- if (cmd_list[i+2*d].cmd) {
- if (cmd_list[i+3*d].cmd)
+
+ if ( (i+d) < count ) {
+ if ( (i + 2*d) < count) {
+ if ( (i+3*d) < count)
fprintf(outfp, "%-15s %-15s %-15s %-15s\n",
cmd_list[i].cmd, cmd_list[i+d].cmd, cmd_list[i+2*d].cmd,
cmd_list[i+3*d].cmd);
@@ -45,6 +46,11 @@ void usage_setdebug()
fprintf(outfp, "setdebug [level]: Set debugging level to level\n");
}
+void usage_clear()
+{
+ fprintf(outfp, "clear buf: zero out the buffer\n");
+}
+
void usage_printline()
{
fprintf(outfp, "printline [0|1]: Turn off (0) or on (1) the printing of line number\n");
@@ -103,9 +109,13 @@ void usage_cmpbufs()
void usage_init()
{
- fprintf(outfp, "init: initilizes libsysio to default values for root directory and \n");
- fprintf(outfp, " : current directory. Must be called before any other libsysio calls\n");
- fprintf(outfp, " : Returns 0 on success, -1 on failure\n");
+ fprintf(outfp, "init <driver> <path> <flags>: Without any arguments, initilizes libsysio\n");
+ fprintf(outfp, " : to default values for root directory and\n");
+ fprintf(outfp, " : current directory. Accepts optional\n");
+ fprintf(outfp, " : arguments for the root driver, the mount\n");
+ fprintf(outfp, " : path, and the mount flags. Must be called\n");
+ fprintf(outfp, " : before any other libsysio calls. Returns\n");
+ fprintf(outfp," : 0 on success, -1 on failure\n");
}
void usage_list()
Index: helper.pm
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/helper.pm,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- helper.pm 30 May 2003 18:14:15 -0000 1.1.2.1
+++ helper.pm 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -21,7 +21,14 @@ sub print_and_exit
# Clean up
my $cmdstr = 'FREE $buf';
$cmdstr = $cmdstr."\n";
- send_cmd($cmdfh, $outfh, "FREE", $cmdstr);
+
+ print $cmdfh $cmdstr;
+
+ my $res = <$outfh>;
+ chop($res);
+ if ($res ne "0000 ") {
+ print STDOUT "ERROR! Failed to free buf (code $res)\n";
+ }
print $cmdfh "exit\n";
close $outfh;
@@ -70,7 +78,7 @@ sub verify_cmd
my $err = <$outfh>;
chop($err);
- print_and_exit($cmdfh, $outfh, 1, "ERROR! $cmd returned $res\n");
+ print_and_exit($cmdfh, $outfh, 1, "ERROR! $cmd returned $err\n");
}
return $res;
}
@@ -82,12 +90,41 @@ sub cmp_nums
my ($cmdfh, $outfh, $ionum, $pnum, $desc) = @_;
my $str;
+ if (!defined($ionum)) {
+ print_and_exit($cmdfh, $outfh, 1, "ERROR! ionum for $desc undefined");
+ } elsif (!defined($pnum)) {
+ print_and_exit($cmdfh, $outfh, 1, "ERROR! pnum for $desc undefined");
+ }
if ($ionum != $pnum) {
my $str = sprintf("ERROR! Sysio's number %x does not match Perl's (%x)\n",
$ionum, $pnum);
$str = sprintf("%s Numbers were %s\n", $str, $desc);
- print_and_exit(1, $str);
+ print_and_exit($cmdfh, $outfh, 1, $str);
+ }
}
+
+sub get_type
+{
+ my $mode = $_[0];
+ my $t = '?';
+
+ if (S_ISDIR($mode)) {
+ $t = 'd';
+ } elsif (S_ISCHR($mode)) {
+ $t = 'c';
+ } elsif (S_ISBLK($mode)) {
+ $t = 'b';
+ } elsif (S_ISREG($mode)) {
+ $t = 'f';
+ } elsif (S_ISFIFO($mode)) {
+ $t = 'p';
+ } elsif (S_ISLNK($mode)) {
+ $t = 'S';
+ } elsif (S_ISSOCK($mode)) {
+ $t = 's';
+ }
+
+ return $t;
}
END{}
Index: sysio_stubs.c
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/sysio_stubs.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- sysio_stubs.c 30 May 2003 18:14:15 -0000 1.1.2.1
+++ sysio_stubs.c 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -98,6 +98,7 @@ int do_fillbuff(int argc, char **argv)
DBG(2,
fprintf(outfp,
"fillbuff requires a value, a type, a size, an offset, and the target buffer\n"));
+ fprintf(stderr, "fillbuff requires 5 args, you gave %d\n", argc);
return INVALID_ARGS;
}
@@ -112,7 +113,7 @@ int do_fillbuff(int argc, char **argv)
DBG(2, fprintf(outfp, "Can't find buffer at %s\n", argv[4]));
return INVALID_VAR;
}
- buf = buflist[index]->buf+offset;
+ buf = (char *)(buflist[index]->buf)+offset;
DBG(4, fprintf(outfp, "Buffer start is at %p\n", buflist[index]));
@@ -157,6 +158,8 @@ int do_fillbuff(int argc, char **argv)
} else {
DBG(2, fprintf(outfp, "Unknown type %s. Valid types are UINT, STR, and PTR\n",
typestr));
+ fprintf(stderr, "Unknown type %s. Valid types are UINT, STR, and PTR\n",
+ typestr);
return INVALID_ARGS;
}
@@ -238,15 +241,19 @@ int do_printbuf(int argc, char **argv)
index = mobj->obj;
buf_st = buflist[index];
+ DBG(2, fprintf(outfp, "buf_st is %x:\n", buf_st));
buf = buf_st->buf;
DBG(2, fprintf(outfp, "buf %s:\n", argv[0]));
if (mobj->type == STR) {
sprintf(output, "\n%s", (char *)buf);
} else {
sprintf(output,"%s\n", output);
+ DBG(2, fprintf(outfp, "buf_st->len is %d, buf is %x\n", buf_st->len, buf));
if (argc == 1) {
for (i = 0; i < buf_st->len/4; i++)
+ DBG(2, fprintf(outfp, "%#x ", ((int *)buf)[i]));
sprintf(output, "%s%#x ", output, ((int *)buf)[i]);
+
}
for (i = 1; i < argc; i++) {
@@ -297,6 +304,28 @@ int do_mount(int argc, char **argv)
return SUCCESS;
}
+int do_clear(int argc, char **argv)
+{
+ int index;
+ struct buf_t *buf;
+
+ if (argc != 1) {
+ DBG(2, fprintf(outfp, "Invalid number of args (%d) for clear\n",
+ argc));
+ return INVALID_ARGS;
+ }
+ index = get_obj(argv[0]);
+ if (index < 0) {
+ fprintf(outfp, "Unable to locate buffer %s\n",
+ argv[0]);
+ return -1;
+ }
+ buf = buflist[index];
+ bzero(buf->buf, buf->len);
+
+ return SUCCESS;
+}
+
int do_list(int argc, char **argv)
{
char *buf;
@@ -321,12 +350,46 @@ int do_list(int argc, char **argv)
return sysio_list(*argv);
}
-int do_init(int argc, char **args)
+/*
+ * Initlizes sysio library. Will use default initlization
+ * unless arguments are given
+ */
+int do_init(int argc, char **argv)
{
- if ((argc) || (args)) {
- DBG(2, fprintf(outfp, "Expected no args for init\n"));
+ if (argc > 0) {
+ char *rdriver;
+ char *mpath;
+ int mflags, rsize, msize;
+ if (argc != 3) {
+ DBG(2, fprintf(outfp, "Invalid number of args (%d) for init\n",
+ argc));
+ return INVALID_ARGS;
+ }
+
+ rdriver = get_str(argv[0]);
+ rsize = sizeof(rdriver)+1;
+ if (rsize > 75) {
+ DBG(2, fprintf(outfp, "%s too long for root driver\n", rdriver));
+ return INVALID_ARGS;
+ }
+ bzero(root_driver, 75);
+ memcpy(root_driver, rdriver, rsize);
+
+ mpath = get_str(argv[1]);
+ msize = sizeof(mpath)+1;
+ if (msize > 250) {
+ DBG(2, fprintf(outfp, "%s too long for mount path\n", mpath));
+ return INVALID_ARGS;
+ }
+ bzero(mntpath, 250);
+ memcpy(mntpath, mpath, msize);
+
+ mflags = get_obj(argv[2]);
+ if (mflags == -1) {
+ DBG(2, fprintf(outfp, "Invalid flags argument %s\n", argv[2]));
return INVALID_ARGS;
}
+ }
DBG(5, fprintf(outfp, "In do_init\n"));
last_type = SINT;
@@ -413,8 +477,10 @@ int do_exit(int argc, char **argv)
if (argc)
DBG(3, printf("Exiting with %d from %s\n", val, argv[0]));
- fclose(outfp);
+
exit(val);
+
+ return 0;
}
int get_buffer(int argc, char **argv)
@@ -423,7 +489,7 @@ int get_buffer(int argc, char **argv)
struct buf_t *buf;
if (argc == 1) /* Just put size, not alignment */
- align = 8;
+ align = 16;
else if (argc == 2)
align = get_obj(argv[1]);
else {
@@ -444,8 +510,8 @@ int get_buffer(int argc, char **argv)
buf->buf = alloc_buff32(size, align);
buf->len = size;
buflist[next] = buf;
- DBG(3, fprintf(outfp, "Your buffer (%p) is at index %d\n",
- buf, next));
+ DBG(3, fprintf(outfp, "Your buffer (%p) (%p) is at index %d\n",
+ buf, buf->buf, next));
next++;
last_type = PTR;
@@ -498,6 +564,7 @@ int cmp_bufs(int argc, char **argv)
argv[0]);
return -1;
}
+ buf1 = buflist[index1]->buf;
index2 = get_obj(argv[1]);
if (index2 < 0) {
@@ -506,7 +573,7 @@ int cmp_bufs(int argc, char **argv)
return -1;
}
-
+ buf2 = buflist[index2]->buf;
res = strcmp(buf1, buf2);
DBG(3, fprintf(outfp, "strcmp returned %d\n", res));
@@ -550,12 +617,9 @@ int do_chown(int argc, char **argv)
int do_open(int argc, char **argv)
{
char *name = argv[0];
- int flags;
+ int flags = O_RDWR;
- if (!flags) {
- /* Default to O_RDWR */
- flags |= O_RDWR;
- } else
+ if (argc > 1)
flags = get_obj(argv[1]);
if (name[0] == '$') {
@@ -709,7 +773,6 @@ int do_fcntl(int argc, char **argv)
struct cmd_map *cmd;
int fd;
- int ret;
/*
* get_cmd translates a symbolic command into
@@ -734,7 +797,7 @@ int do_fcntl(int argc, char **argv)
last_ret_val = sysio_fcntl(fd, cmd, argv[2]);
else
last_ret_val = sysio_fcntl(fd, cmd, NULL);
- DBG(4, fprintf(outfp, "Got return value of %d\n", ret));
+ DBG(4, fprintf(outfp, "Got return value of %d\n", last_ret_val));
my_errno = errno;
last_type = SINT;
@@ -2113,17 +2176,18 @@ int do_mknod(int argc, char **argv)
int dev;
if (argc != 3) {
- fprintf(outfp, "Invalid number of args (%d) for mknod\n", argc);
+ DBG(2, fprintf(outfp, "Invalid number of args (%d) for mknod\n", argc));
return INVALID_ARGS;
}
dev = get_obj(argv[2]);
if (dev < 0) {
- fprintf(outfp, "Unable to understand %s\n", argv[2]);
+ DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2]));
return INVALID_ARGS;
}
last_type = SINT;
+
return sysio_mknod(argv[0], argv[1], (dev_t) dev);
}
Index: sysio_tests.c
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/sysio_tests.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- sysio_tests.c 30 May 2003 18:14:15 -0000 1.1.2.1
+++ sysio_tests.c 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -269,7 +269,7 @@ int sysio_chdir(char *newdir)
my_perror(newdir);
return -1;
}
-
+ /*
buf = getcwd(NULL, 0);
if (!buf) {
my_perror(newdir);
@@ -280,6 +280,7 @@ int sysio_chdir(char *newdir)
DBG(4, sprintf(output, "New dir is %s\n", buf));
free(buf);
+ */
return SUCCESS;
}
@@ -655,19 +656,19 @@ int sysio_fcntl(int fd, struct cmd_map*
void print_stat(struct stat *st)
{
DBG(3, sprintf(output, "%sstruct stat: \n", output));
- DBG(3, sprintf(output, "%s st_dev: %#10x\n", output, (unsigned int)st->st_dev));
- DBG(3, sprintf(output, "%s st_ino: %#10x\n", output, (unsigned int) st->st_ino));
- DBG(3, sprintf(output, "%s st_mode: %o\n", output, st->st_mode));
- DBG(3, sprintf(output, "%s st_nlink: %d\n", output, st->st_nlink));
- DBG(3, sprintf(output, "%s st_uid: %d\n", output, st->st_uid));
- DBG(3, sprintf(output, "%s st_gid: %d\n", output, st->st_gid));
- DBG(3, sprintf(output, "%s st_rdev: %d\n", output, (int)st->st_rdev));
- DBG(3, sprintf(output, "%s st_size: %d\n", output, (int) st->st_size));
- DBG(3, sprintf(output, "%s st_blksize: %d\n", output, (int) st->st_blksize));
- DBG(3, sprintf(output, "%s st_blocks: %d\n", output, (int) st->st_blocks));
- DBG(3, sprintf(output, "%s st_atime: %#10x\n", output, (unsigned int) st->st_atime));
- DBG(3, sprintf(output, "%s st_mtime: %#10x\n", output, (unsigned int) st->st_mtime));
- DBG(3, sprintf(output, "%s st_ctime: %#10x", output, (unsigned int) st->st_ctime));
+ DBG(3, sprintf(output, "%s st_dev: %#16x\n", output, (unsigned int)st->st_dev));
+ DBG(3, sprintf(output, "%s st_ino: %#16x\n", output, (unsigned int) st->st_ino));
+ DBG(3, sprintf(output, "%s st_mode: %#16x\n", output, st->st_mode));
+ DBG(3, sprintf(output, "%s st_nlink: %#16x\n", output, st->st_nlink));
+ DBG(3, sprintf(output, "%s st_uid: %#16x\n", output, st->st_uid));
+ DBG(3, sprintf(output, "%s st_gid: %#16x\n", output, st->st_gid));
+ DBG(3, sprintf(output, "%s st_rdev: %#16x\n", output, (int)st->st_rdev));
+ DBG(3, sprintf(output, "%s st_size: %#16x\n", output, (int) st->st_size));
+ DBG(3, sprintf(output, "%s st_blksize: %#16x\n", output, (int) st->st_blksize));
+ DBG(3, sprintf(output, "%s st_blocks: %#16x\n", output, (int) st->st_blocks));
+ DBG(3, sprintf(output, "%s st_atime: %#16x\n", output, (unsigned int) st->st_atime));
+ DBG(3, sprintf(output, "%s st_mtime: %#16x\n", output, (unsigned int) st->st_mtime));
+ DBG(3, sprintf(output, "%s st_ctime: %#16x", output, (unsigned int) st->st_ctime));
}
int sysio_fstat(int fd, void *buf)
@@ -726,11 +727,18 @@ int sysio_getdirentries(int fd, char *bu
err = getdirentries(fd, buf, nbytes, basep);
last_ret_val = err;
- DBG(4, sprintf(output, "Read %d bytes\n", err));
+ DBG(4, sprintf(output, "%sRead %d bytes\n", output, err));
dp = (struct dirent *)buf;
while (err > 0) {
- DBG(3, sprintf(output, "\t%s: ino %llu off %llu len %x type %c\n",
+ DBG(3, sprintf(output, "%s\t%s: ino %llu off %llu len %x type %c\n",
+ output,
+ dp->d_name,
+ (unsigned long long )dp->d_ino,
+ (unsigned long long )dp->d_off,
+ dp->d_reclen,
+ (char )dp->d_type));
+ DBG(3, fprintf(outfp, "\t%s: ino %x off %x len %x type %x\n",
dp->d_name,
(unsigned long long )dp->d_ino,
(unsigned long long )dp->d_off,
@@ -879,16 +887,7 @@ int sysio_mknod(char *path, char *mode_a
int err;
int mode;
-
- /* Is the new mode symbolic? */
- if (isalpha(mode_arg[0])) {
- /* Could be specifying defines */
- if (mode_arg[0] == 'S')
- mode = get_mode(mode_arg, DEFINED, 0);
- else
- mode = get_mode(mode_arg, SYMBOLIC, 0);
- } else
- mode = get_mode(mode_arg, NUMERIC, 0);
+ mode = get_obj(mode_arg);
if (mode < 0) {
DBG(2,sprintf(output, "Cant get mode from %s\n", mode_arg));
Index: test_copy.pl
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/test_copy.pl,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- test_copy.pl 30 May 2003 18:14:15 -0000 1.1.2.1
+++ test_copy.pl 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -20,11 +20,15 @@ sub usage
sub process_cmd
{
- my ($src, $dest) = @_;
+ my ($src, $dest, $is_alpha) = @_;
eval {
+ if ($is_alpha == 0) {
open2(\*OUTFILE, \*CMDFILE, "./test_driver --np");
+ } else {
+ open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 ./test_driver --np");
+ }
};
if ($@) {
@@ -39,8 +43,9 @@ sub process_cmd
my $outfh = \*OUTFILE;
my $cmdfh = \*CMDFILE;
+ if ($is_alpha == 0) {
helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
-
+ }
# Get the filesize of src
my $size = -s $src;
@@ -103,14 +108,21 @@ sub process_cmd
helper::print_and_exit($cmdfh, $outfh, 0, "copy test successful\n");
}
-if (@ARGV != 2) {
+my $currarg = 0;
+my $is_alpha = 0;
+
+if (@ARGV < 2) {
usage;
+} elsif (@ARGV > 2 ) {
+ if ($ARGV[$currarg++] eq "-alpha") {
+ $is_alpha = 1;
+ }
}
-my $src = $ARGV[0];
-my $dest = $ARGV[1];
+my $src = $ARGV[$currarg++];
+my $dest = $ARGV[$currarg];
-process_cmd($src, $dest);
+process_cmd($src, $dest, $is_alpha);
exit 0;
Index: test_driver.c
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/test_driver.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- test_driver.c 30 May 2003 18:14:15 -0000 1.1.2.1
+++ test_driver.c 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -42,6 +42,7 @@ struct cmd_t cmd_list[] = {
{"chdir", do_chdir, usage_chdir},
{"chmod", do_chmod, usage_chmod},
{"chown", do_chown, usage_chown},
+ {"clear", do_clear, usage_clear},
{"close", do_close, usage_close},
{"cmpstr", cmp_bufs, usage_cmpbufs},
{"creat", do_creat, usage_creat},
@@ -116,10 +117,22 @@ cmd_tree* build_tree(char **cmd, int *le
void * alloc_buff32(unsigned int size, int align)
{
void* buf;
-
- if (posix_memalign(&buf, align, size))
+ long buf_ptr;
+ int err;
+ /*
+ if ((err = posix_memalign(&buf, align, size)) != 0) {
+ perror("posix_memalign");
return 0;
- return buf;
+ }
+ */
+ size += align;
+ buf = malloc(size);
+ align--;
+ DBG(3, fprintf(outfp, "Buf is at %p\n", (void *)buf));
+ buf_ptr = (long)buf + ((long)buf & align);
+
+ DBG(3, fprintf(outfp, "Buf is at %p\n", (void *)buf_ptr));
+ return (void *)buf_ptr;
}
void free_buf32(void * ptr)
@@ -180,7 +193,7 @@ struct var_mapping *get_map(char *var_na
curr = &map[index];
while ((curr) && (curr->map.obj != -1) ) {
- if (strcmp(curr->map.name, var_name))
+ if ( (curr->map.name == NULL) || (strcmp(curr->map.name, var_name)) )
curr = curr->next;
else
return &curr->map;
@@ -211,7 +224,6 @@ int get_obj(char *var_name)
if (isdigit(var_name[0]))
return atoi(var_name);
-
/*
* Check for '|', indicates that one or more values are or'd
* together
@@ -226,6 +238,13 @@ int get_obj(char *var_name)
memcpy(str1, var_name, i);
memcpy(str2, (char *)&var_name[i+1], strlen(var_name)-i);
+ if (isdigit(str1[0])) {
+ if (str1[0] == '0') {
+ /* Assume octal format */
+ obj = strtol(str1, NULL, 8);
+ } else
+ obj = atoi(str1);
+ } else {
tmp_map = get_map(str1);
if (!tmp_map) {
free(str1);
@@ -233,6 +252,15 @@ int get_obj(char *var_name)
return -1;
}
obj = tmp_map->obj;
+ }
+
+ if (isdigit(str2[0])) {
+ if (str2[0] == '0') {
+ /* Assume octal format */
+ obj |= strtol(str2, NULL, 8);
+ } else
+ obj = atoi(str2);
+ } else {
tmp_map = get_map(str2);
if (!tmp_map) {
free(str1);
@@ -240,6 +268,7 @@ int get_obj(char *var_name)
return -1;
}
obj |= tmp_map->obj;
+ }
free(str1);
free(str2);
return obj;
@@ -446,10 +475,13 @@ int run_cmd(cmd_tree *cmd_arg)
char **args;
int res, i;
struct buf_t *buf;
- char *cmd = cmd_arg->val;
+ char *cmd;
struct queue_t *child;
+ if (cmd_arg == NULL)
+ return INVALID_CMD;
+ cmd = cmd_arg->val;
cmdptr = cmdstr;
child = cmd_arg->children;
if ( (!strcmp("exit", cmd)) || (!strcmp("quit", cmd)) ||
@@ -593,6 +625,33 @@ int add_args(char **cmd, int length, int
return total;
}
+void free_tree(cmd_tree* tree)
+{
+ if (!tree)
+ return;
+
+ if (tree->children) {
+ struct queue_t *child = tree->children;
+ struct queue_t *next;
+ do {
+ next = child->next;
+ if (child->cmd)
+ free_tree(child->cmd);
+ free(child->val);
+ free(child);
+ child = next;
+ } while (child);
+ }
+
+ if (tree->res_name)
+ free(tree->res_name);
+
+ if (tree->val)
+ free(tree->val);
+
+ free(tree);
+}
+
cmd_tree* build_tree(char **cmd, int *length, int total)
{
int index = 0, used_args = 0;
@@ -666,7 +725,6 @@ char *getline(char *prompt)
while (feof(infp) && (line[i] != '\n')) {
clearerr(infp);
count++;
- sleep(0.05);
fseek(infp, 0, SEEK_CUR);
}
} else {
@@ -725,6 +783,12 @@ struct var_mapping flags_map[] = {
{"S_IROTH", S_IROTH, UINT },
{"S_IWOTH", S_IWOTH, UINT },
{"S_IXOTH", S_IXOTH, UINT },
+ {"S_IFCHR", S_IFCHR, UINT },
+ {"S_IFMT", S_IFMT, UINT },
+ {"S_IFBLK", S_IFBLK, UINT },
+ {"S_IFREG", S_IFREG, UINT },
+ {"S_IFIFO", S_IFIFO, UINT },
+ {"S_IFLNK", S_IFLNK, UINT },
{ NULL, -1, SINT }
};
@@ -740,9 +804,10 @@ void init_map()
int main(int argc, char *argv[])
{
- int count, err, i;
+ int count, err, i, orig_count;
char *input, *name;
char **cmd;
+ cmd_tree *tree;
infp = stdin;
outfp = stdout;
@@ -803,7 +868,7 @@ int main(int argc, char *argv[])
bzero(output, 4096);
input = getline("> ");
cmd = malloc(MAX_COMMAND * sizeof(char *));
- count = parser(input, cmd);
+ count = orig_count = parser(input, cmd);
name = NULL;
if ((!count) || (count > MAX_COMMAND)){
fprintf(outfp, "%s: invalid command\n", input);
@@ -820,12 +885,17 @@ int main(int argc, char *argv[])
count--;
}
i++;
- err = run_cmd(build_tree(&cmd[i], &count, 0));
+ tree = build_tree(&cmd[i], &count, 0);
+ err = run_cmd(tree);
store_result((char *)(&cmd[0][1]), last_ret_val);
- } else
- err = run_cmd(build_tree(cmd, &count, 0));
+ } else {
+ tree = build_tree(cmd, &count, 0);
+ err = run_cmd(tree);
+ }
/* Print out return code and any string from command */
fprintf(outfp, "%#04x %s\n", err, output);
+ if (tree)
+ free_tree(tree);
/* fprintf(stderr, "%#04x %s\n", err, output); */
for (i=0; i < count; i++)
free(cmd[i]);
Index: test_driver.h
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/test_driver.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- test_driver.h 30 May 2003 18:14:15 -0000 1.1.2.1
+++ test_driver.h 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -153,6 +153,7 @@ extern int do_chmod(int argc, char **arg
extern int do_chown(int argc, char **args);
extern int do_open(int argc, char **args);
extern int do_close(int argc, char **args);
+extern int do_clear(int argc, char **argv);
extern int do_dup(int argc, char **args);
extern int do_dup2(int argc, char **args);
extern int do_fcntl(int argc, char **args);
@@ -236,6 +237,7 @@ extern void usage_chmod();
extern void usage_chown();
extern void usage_open();
extern void usage_close();
+extern void usage_clear();
extern void usage_mount();
extern void usage_dup();
extern void usage_dup2();
Index: test_getcwd.pl
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/test_getcwd.pl,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- test_getcwd.pl 30 May 2003 18:14:15 -0000 1.1.2.1
+++ test_getcwd.pl 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -1,12 +1,5 @@
#!/usr/bin/perl -w
-#
-# getcwd test: Tests chdir and getcwd; will first verify that getcwd returns
-# the current working directory and will then call chdir and verify
-# that getcwd reflects the new directory
-#
-#
-
use IPC::Open2;
use strict;
@@ -14,9 +7,10 @@ use helper;
sub usage
{
- print "Usage: ./test_getcwd.pl <dir> : Test getcwd by verifying that it returns the\n";
- print " : current directory and then setting the directory\n";
- print " : to dir and verifying that getcwd reflects the change\n";
+ print "Usage: ./test_getcwd.pl <dir> : Test getcwd by verifying that it \n";
+ print " : setting the directory to dir and \n";
+ print " : verifying that getcwd reflects \n";
+ print " : the change\n";
exit(-1);
}
@@ -47,10 +41,15 @@ sub check_wkdir
sub process_cmd
{
- my ($dir) = @_;
+ my ($dir, $is_alpha) = @_;
eval {
+ if ($is_alpha == 0) {
open2(\*OUTFILE, \*CMDFILE, "./test_driver --np");
+ } else {
+ open2(\*OUTFILE, \*CMDFILE,
+ "yod -batch -quiet -sz 1 ./test_driver --np");
+ }
};
if ($@) {
@@ -65,12 +64,14 @@ sub process_cmd
my $outfh = \*OUTFILE;
my $cmdfh = \*CMDFILE;
+ if ($is_alpha == 0) {
helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
# Get current working directory from environment
my $cwd = $ENV{PWD};
check_wkdir($cwd, $outfh, $cmdfh);
+ }
# Now change to dir
helper::send_cmd($cmdfh, $outfh, "chdir", "CALL chdir $dir\n");
@@ -85,12 +86,23 @@ sub process_cmd
}
-if (@ARGV != 1) {
+my $currarg = 0;
+my $is_alpha = 0;
+
+if (@ARGV < 1) {
usage;
+} elsif (@ARGV > 1) {
+ if ($ARGV[$currarg++] eq "-alpha") {
+ $is_alpha = 1;
+ }
}
-my $dir = $ARGV[0];
+my $dir = $ARGV[$currarg];
-process_cmd($dir);
+process_cmd($dir, $is_alpha);
exit 0;
+
+
+
+
Index: test_list.pl
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/test_list.pl,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- test_list.pl 30 May 2003 18:14:15 -0000 1.1.2.1
+++ test_list.pl 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -14,30 +14,36 @@ use helper;
sub usage
{
- print "Usage: ./test_list.pl [-p] <dir> \n";
- print " ./test_list.pl -m [-p] fstype:mdir dir\n";
- print " In the first form, will compare output of libsysio's getdirentries\n";
- print " with that of Perl's readdir. If no dir is given, will use the \n";
+ print "Usage: ./test_list.pl [-p|-ni] <dir> \n";
+ print " ./test_list.pl -m [-p|-alpha] fstype:mdir dir\n";
+ print " In the first form, will attempt to verify libsysio's\n";
+ print " getdirentries. If no dir is given, will use the \n";
print " current working directory\n";
print " In the second form, will mount the given mdir (of type fstype) in dir.\n";
- print " It will then compare the output of libsysio's getdirentries on the \n";
- print " filesystem with Perl's readdir on the original mdir. It will then \n";
- print " umount the directory and verify that the umount worked\n";
+ print " It will then verify the output of libsysio's getdirentries. It will \n";
+ print " then umount the directory and verify that the umount worked\n";
print " The -p option will print the directory listing\n";
+ print " The -alpha option is for alpha architecture \n";
exit(-1);
}
sub write_print
{
- my ($offset, $outfh, $cmdfh, $do_print) = @_;
+ my ($offset, $outfh, $cmdfh, $do_print, $is_alpha) = @_;
my $bytes = 0;
- my $shortoffset = $offset+8;
+ my $intsize = 8;
+ my $intcmd = "INT";
+ if ($is_alpha == 1) {
+ $intsize = 16;
+ $intcmd = "LONG"
+ }
+ my $shortoffset = $offset+$intsize;
my $charoffset = $shortoffset+2;
my $stroffset = $charoffset+1;
my $cmdstr = 'PRINT $buf '.
- "$offset 8 INT $shortoffset 2 SHORT $charoffset 1 CHAR $stroffset 1 STR\n";
+ "$offset $intsize $intcmd $shortoffset 2 SHORT $charoffset 1 CHAR $stroffset 1 STR\n";
helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);
my $res = <$outfh>;
@@ -58,7 +64,7 @@ sub write_print
sub do_print_cmds
{
- my ($numbytes, $outfh, $cmdfh, $start, $do_print) = @_;
+ my ($numbytes, $outfh, $cmdfh, $start, $do_print, $is_alpha) = @_;
my $offset = 0;
my $bytes = 0;
@@ -69,13 +75,17 @@ sub do_print_cmds
$numbytes = 8192;
}
while ($bytes < $numbytes) {
- my $len = write_print($offset, $outfh, $cmdfh, $do_print);
+ my $len = write_print($offset, $outfh, $cmdfh, $do_print, $is_alpha);
if ($len <= 0) {
# write_print saw a 0 length record, indicating end of dir
return $numfiles;
}
$numfiles++;
+ if ($is_alpha == 0) {
$len += $len%4;
+ } else {
+ $len += $len%8;
+ }
$offset += $len;
$bytes += $len;
$i++;
@@ -86,7 +96,7 @@ sub do_print_cmds
sub print_dir_cmd
{
- my ($outfh, $cmdfh, $start, $mdir, $do_print) = @_;
+ my ($outfh, $cmdfh, $start, $mdir, $do_print, $is_alpha) = @_;
my $cmdstr = "CALL getdirentries ( ".'$fd = CALL open '."$mdir O_RDONLY ) ( ";
$cmdstr .= '$buf = ALLOC 8192 ) 8192 $basep'."\n";
@@ -98,7 +108,7 @@ sub print_dir_cmd
while ($numbytes > 0) {
- do_print_cmds($numbytes, $outfh, $cmdfh, $start, $do_print);
+ do_print_cmds($numbytes, $outfh, $cmdfh, $start, $do_print, $is_alpha);
$cmdstr = "CALL getdirentries ".'$fd $buf 8192 $basep'."\n";
helper::send_cmd($cmdfh, $outfh, "getdirentries", $cmdstr);
@@ -111,12 +121,16 @@ sub print_dir_cmd
sub process_cmd
{
- my ($mdir, $tdir, $do_mount, $do_print) = @_;
+ my ($mdir, $tdir, $do_mount, $is_alpha, $do_print) = @_;
my $size = 8192;
my $done_files = 0;
eval {
+ if ($is_alpha == 1) {
+ open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 ./test_driver --np");
+ } else {
open2(\*OUTFILE, \*CMDFILE, "./test_driver --np");
+ }
};
if ($@) {
@@ -131,15 +145,17 @@ sub process_cmd
my $outfh = \*OUTFILE;
my $cmdfh = \*CMDFILE;
+ if ($is_alpha == 0) {
helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
+ }
my $start = 0;
if ($do_mount == 1) {
helper::send_cmd($cmdfh, $outfh, "mount", "CALL mount $mdir $tdir\n");
- print_dir_cmd($outfh, $cmdfh, $start, $tdir, $do_print);
+ print_dir_cmd($outfh, $cmdfh, $start, $tdir, $do_print, $is_alpha);
} else {
- print_dir_cmd($outfh, $cmdfh, $start, $mdir, $do_print);
+ print_dir_cmd($outfh, $cmdfh, $start, $mdir, $do_print, $is_alpha);
}
# Attempt to unmount and verify the contents
@@ -181,6 +197,7 @@ sub process_cmd
my @mydir;
$mydir[0] = "./";
my $do_mount = 0;
+my $is_alpha = 0;
my $do_print = 0;
my $dircnt = 0;
for (my $i = 0; $i < @ARGV; $i++)
@@ -189,6 +206,8 @@ for (my $i = 0; $i < @ARGV; $i++)
$do_print = 1;
} elsif ($ARGV[$i] eq "-m") {
$do_mount = 1;
+ } elsif ($ARGV[$i] eq "-alpha") {
+ $is_alpha = 1;
} else {
$mydir[$dircnt] = $ARGV[$i];
$dircnt++;
@@ -207,6 +226,6 @@ if ($do_mount == 1) {
($fstype, $dir) = split(/:/, $mydir[0]);
}
-process_cmd($mydir[0], $mydir[1], $do_mount, $do_print);
+process_cmd($mydir[0], $mydir[1], $do_mount, $is_alpha, $do_print);
exit 0;
Index: test_path.pl
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/test_path.pl,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- test_path.pl 30 May 2003 18:14:15 -0000 1.1.2.1
+++ test_path.pl 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -80,12 +80,17 @@ sub process_path
sub process_cmd
{
- my ($usestdin, @paths) = @_;
+ my ($usestdin, $isalpha, @paths) = @_;
my $path;
eval {
+ if ($isalpha == 0) {
open2(\*OUTFILE, \*CMDFILE, "./test_driver --np");
+ } else {
+ open2(\*OUTFILE, \*CMDFILE,
+ "yod -batch -quiet -sz 1 ./test_driver --np");
+ }
};
if ($@) {
@@ -99,7 +104,9 @@ sub process_cmd
my $outfh = \*OUTFILE;
my $cmdfh = \*CMDFILE;
+ if ($isalpha == 0) {
helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
+ }
# Allocate the stat buffer
my $cmdstr = '$buf = ALLOC ( $size = CALL sizeof stat )';
@@ -135,9 +142,18 @@ sub process_cmd
my $usestdin = 0;
+my $isalpha = 0;
+
+# The -alpha arg must be before the paths
+# (if they exist)
+if ( (@ARGV > 0) && ($ARGV[0] eq "-alpha")) {
+ $isalpha = 1;
+ pop(@ARGV);
+}
+
if (@ARGV == 0) {
$usestdin = 1;
}
-process_cmd($usestdin, @ARGV);
+process_cmd($usestdin, $isalpha, @ARGV);
Index: test_stats.pl
===================================================================
RCS file: /cvsroot/libsysio/libsysio/tests/Attic/test_stats.pl,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -w -b -B -p -r1.1.2.1 -r1.1.2.2
--- test_stats.pl 30 May 2003 18:14:15 -0000 1.1.2.1
+++ test_stats.pl 1 Jul 2003 16:04:12 -0000 1.1.2.2
@@ -8,13 +8,6 @@
#
#
-#
-# Usage ./test_stats.pl file: Verifies that the set of stat calls (stat, fstat, fstatvfs, and
-# : statvfs) return the same set of stats for file and that the calls
-# : return the same items as Perl's stat call (which would use a native
-# : library and not libsysio)
-#
-#
use IPC::Open2;
use strict;
@@ -22,11 +15,11 @@ use helper;
sub usage
{
- print "Usage ./test_stats.pl file : Verifies that the set of stat calls (stat, fstat,\n";
- print " : fstatvfs, statvfs) return the same set of stats for \n";
- print " : file and that the calls return the same items as Perl's \n";
- print " : stat call (which would use a native library and not \n";
- print " : libsysio)\n";
+ print "Usage ./test_stats.pl file : Verifies that the set of stat calls (stat, \n";
+ print " : fstat, fstatvfs, statvfs) return the same set\n";
+ print " : of stats for file and that the calls return the\n";
+ print " : same items as Perl's stat call (which would use\n";
+ print " : a native library and not libsysio)\n";
exit(-1);
}
@@ -35,13 +28,22 @@ sub usage
sub cmp_stats
{
- my ( $cmdfh, $outfh,
- $iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev,
- $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime,
- $pdev, $pino, $pmode, $pnlink, $puid, $pgid, $prdev,
- $psize, $patime, $pmtime, $pctime, $pblksize, $pblks) = @_;
+ my ( $cmdfh, $outfh, $is_alpha, @stats) = @_;
- helper::cmp_nums($cmdfh, $outfh, $iodev, $pdev, "device numbers");
+
+ my ($iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev,
+ $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime, @pstats) =
+ @stats;
+
+ if ($is_alpha == 1) {
+ ($iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev,
+ $iosize, $ioatime, $iomtime, $ioctime, $ioblks, $ioblksize, @pstats) =
+ @stats;
+ }
+ my ($pdev, $pino, $pmode, $pnlink, $puid, $pgid, $prdev,
+ $psize, $patime, $pmtime, $pctime, $pblksize, $pblks) = @pstats;
+
+# helper::cmp_nums($cmdfh, $outfh, $iodev, $pdev, "device numbers");
helper::cmp_nums($cmdfh, $outfh, $ioino, $pino, "inode numbers");
helper::cmp_nums($cmdfh, $outfh, $iomode, $pmode, "file modes");
helper::cmp_nums($cmdfh, $outfh, $ionlink, $pnlink, "number of links");
@@ -61,11 +63,16 @@ sub cmp_stats
# Perl's output
sub verify_stat
{
- my ($cmdfh, $outfh, $cmd, @stats) = @_;
+ my ($cmdfh, $outfh, $cmd, $is_alpha, @stats) = @_;
my $i=0;
+ my $cmdstr;
# Print out the stat buffer
- my $cmdstr = 'PRINT $buf 0 8 LONG 12 24 INT 44 8 LONG 52 8 INT 64 24 LONG'."\n";
+ if ($is_alpha == 0) {
+ $cmdstr = 'PRINT $buf 0 8 LONG 12 24 INT 44 8 LONG 52 8 INT 64 24 LONG'."\n";
+ } else {
+ $cmdstr = 'PRINT $buf 0 16 LONG 16 16 INT 32 8 LONG 40 4 INT 48 40 LONG'."\n";
+ }
helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);
my $res = <$outfh>;
@@ -76,16 +84,21 @@ sub verify_stat
$i++;
}
- cmp_stats($cmdfh, $outfh, @iostats, @stats);
+ cmp_stats($cmdfh, $outfh, $is_alpha, @iostats, @stats);
}
sub process_cmd
{
- my ($file) = $_[0];
+ my ($file, $is_alpha) = @_;
eval {
+ if ($is_alpha == 0) {
open2(\*OUTFILE, \*CMDFILE, "./test_driver --np");
+ } else {
+ open2(\*OUTFILE, \*CMDFILE,
+ "yod -batch -quiet -sz 1 ./test_driver --np");
+ }
};
if ($@) {
@@ -100,8 +113,9 @@ sub process_cmd
my $outfh = \*OUTFILE;
my $cmdfh = \*CMDFILE;
+ if ($is_alpha == 0) {
helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
-
+ }
# Get stats for file
my @stats = stat($file);
@@ -116,9 +130,11 @@ sub process_cmd
helper::send_cmd($cmdfh, $outfh, "stat", $cmdstr);
helper::verify_cmd($cmdfh, $outfh, "stat");
+ #if ($is_alpha == 0) {
# Now print the buffer out and verify that it matches
# what Perl has
- verify_stat($cmdfh, $outfh, "stat", @stats);
+ verify_stat($cmdfh, $outfh, "stat", $is_alpha, @stats);
+ #}
# Open the file
$cmdstr = '$fd = CALL open '."$file O_RDONLY\n";
@@ -131,7 +147,7 @@ sub process_cmd
helper::send_cmd($cmdfh, $outfh, "fstat", $cmdstr);
helper::verify_cmd($cmdfh, $outfh, "fstat");
- verify_stat($cmdfh, $outfh, "fstat", @stats);
+ verify_stat($cmdfh, $outfh, "fstat", $is_alpha, @stats);
# Test lstat
@stats = lstat($file);
@@ -140,7 +156,7 @@ sub process_cmd
helper::send_cmd($cmdfh, $outfh, "lstat", $cmdstr);
helper::verify_cmd($cmdfh, $outfh, "lstat");
- verify_stat($cmdfh, $outfh, "lstat", @stats);
+ verify_stat($cmdfh, $outfh, "lstat", $is_alpha, @stats);
# Now do statvfs functions
@@ -190,11 +206,20 @@ sub process_cmd
}
-if (@ARGV != 1) {
+
+
+my $currarg = 0;
+my $is_alpha = 0;
+if (@ARGV < 1) {
usage;
+} elsif (@ARGV > 1) {
+ if ($ARGV[$currarg++] eq "-alpha") {
+ $is_alpha = 1;
+ }
}
-my $file = $ARGV[0];
-process_cmd($file);
+my $file = $ARGV[$currarg];
+
+process_cmd($file, $is_alpha);
|