[Libsysio-commit] namespace_assembly: libsysio/tests test_all.pl test_copy.pl test_driver.c test_sta
Brought to you by:
lward
|
From: Sonja T. <so...@us...> - 2004-02-10 14:42:14
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28921 Modified Files: Tag: namespace_assembly test_all.pl test_copy.pl test_driver.c test_stats.pl Log Message: Added support for namespace assembly. Removed usage of test_stdfd.pl from test_all, instead using test_copy to perform function. Also removed test_mounts from test_all since it is covered with the namespace assembly Index: test_all.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_all.pl,v retrieving revision 1.6.2.1 retrieving revision 1.6.2.2 diff -u -w -b -B -p -r1.6.2.1 -r1.6.2.2 --- test_all.pl 28 Jan 2004 13:16:57 -0000 1.6.2.1 +++ test_all.pl 10 Feb 2004 14:38:50 -0000 1.6.2.2 @@ -35,6 +35,38 @@ my $cwd = $ENV{PWD}; # Get tests directory my $testdir = $FindBin::Bin; +my $namespace_env = "SYSIO_NAMESPACE"; +my $home = $ENV{"HOME"}; +my $auto_mount = $ENV{"SYSIO_AUTOMOUNT"}; +my $root_flags = "0"; +my $extras = ""; +if ((defined($auto_mount)) && ($auto_mount == "xyes")) { + $root_flags = "2"; + + # + # Add a /auto directory for automounted file systems. We + # craft one automount that mounts /usr/home from the native + # file system. Further automounts in the sub-mounts are not enabled. + # + $extras=" \ + {mnt, dev=\"incore:0755+0+0\",dir=\"/mnt\",fl=2} \ + {creat, ft=dir,nm=\"/mnt/home\",pm=0755,ow=0,gr=0} \ + {creat, ft=file,nm=\"/mnt/home/.mount\",pm=0600, \ + str=\"native:/usr/home\"}"; +} +$ENV{$namespace_env} = "\ + {mnt, dev=\"native:/\",dir=/,fl=$root_flags} \ + {mnt, dev=\"incore:0755+0+0\",dir=\"/dev\"} \ + {creat, ft=chr,nm=\"/dev/stdin\",pm=0400,mm=0+0} \ + {creat, ft=chr,nm=\"/dev/stdout\",pm=0200,mm=0+1} \ + {creat, ft=chr,nm=\"/dev/stderr\",pm=0200,mm=0+2} \ + {creat, ft=dir,nm=\"/dev/fd\",pm=0755,ow=0,gr=0} \ + {creat, ft=chr,nm=\"/dev/fd/0\",pm=0400,mm=0+0} \ + {creat, ft=chr,nm=\"/dev/fd/1\",pm=0200,mm=0+1} \ + {creat, ft=chr,nm=\"/dev/fd/2\",pm=0200,mm=0+2} \ + {cd, dir=\"$home\"} \ + $extras "; + my $res; if ($use_system == 1) { @@ -93,19 +125,6 @@ if ($resarr[0] ne $res) { } } -if (($alpha_arg eq "") || ($is_broke == 0)) { - # Test mount - $res = `perl $testdir/test_list.pl $alpha_arg -m native:$testdir $cwd/tmp_dir/test2`; - chop($res); - if ($res ne "list test successful") { - print "Mount test failed with message: $res\n"; - $failures++; - } else { - $success++; - print "test_mount finished successfully\n"; - } - -} # Test getcwd $res = `perl $testdir/test_getcwd.pl $alpha_arg $cwd/tmp_dir/test1`; chop($res); @@ -140,9 +159,9 @@ if ($res ne "stat test successful") { } # Test stdfd -$res = `perl $testdir/test_stdfd.pl $alpha_arg foo_dir`; +$res = `echo "foobar" | perl $testdir/test_copy.pl $alpha_arg -o /dev/stdin /dev/stdout`; chop($res); -if ($res ne "test_stdfd successful") { +if ($res ne "copy test successful") { print "stdfd test failed with message: $res\n"; $failures++; } else { @@ -174,5 +193,4 @@ if ($use_system == 1) { exit 1; } } - exit $failures; Index: test_copy.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_copy.pl,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -u -w -b -B -p -r1.3.2.1 -r1.3.2.2 --- test_copy.pl 28 Jan 2004 13:16:57 -0000 1.3.2.1 +++ test_copy.pl 10 Feb 2004 14:38:51 -0000 1.3.2.2 @@ -20,7 +20,7 @@ sub usage sub process_cmd { - my ($src, $dest, $is_alpha) = @_; + my ($src, $dest, $overwrite, $is_alpha) = @_; # Get tests directory my $testdir = $FindBin::Bin; @@ -53,6 +55,13 @@ sub process_cmd my $size = -s $src; my $bufsize; + # If reading from stdin, just read one line + my $line; + if ($src eq "/dev/stdin") { + $line = <STDIN>; + $size = length($line); + } + if ( $size > 1024) { # Arbitrary limit $bufsize = 1024; } else { @@ -63,10 +72,16 @@ sub process_cmd # Open src my $cmdstr = '$src = CALL open '."$src O_RDONLY\n"; helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); + helper::verify_cmd($cmdfh, $outfh, "open $src"); # Open dest - $cmdstr = '$dest = CALL open '."$dest O_RDWR|O_CREAT 7777\n"; + my $flags = "O_WRONLY|O_CREAT"; + if ($overwrite == 0) { + $flags .= "|O_EXCL"; + } + $cmdstr = '$dest = CALL open '."$dest $flags 0666\n"; helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); + my $destfile = helper::verify_cmd($cmdfh, $outfh, "open $dest"); # Allocate buffer $cmdstr = '$buf = ALLOC '."$bufsize\n"; @@ -75,15 +90,60 @@ sub process_cmd # Read size bytes from src and write them out to dest my $bytes = $size; while ($bytes > 0) { + + my $readb; + my $res; + if ($src eq "/dev/stdin") { + # Send "delay" option to read which will give us time to + # put something in stdin (since we can't send an eof) + my $cmdstr = "CALL read ".'$src $buf '."$bytes delay\n"; + print $cmdfh $cmdstr; + # Give time to process command + sleep 1; + + # Send line from stdin + print $cmdfh $line; + sleep 0.5; + + # Make sure read was OK + $res = <$outfh>; + chop($res); + if ($res ne "0000 ") { + helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Read failed with code $res\n"); + } + + # See how many bytes we got... + $readb = helper::verify_cmd($cmdfh, $outfh, "read"); + $readb = oct($readb); + if ($readb != $bytes) { + helper::print_and_exit($cmdfh, $outfh, 0, "Short read\n"); + } + + $cmdstr = "CALL write ".'$dest $buf '."$readb\n"; + print $cmdfh $cmdstr; + + # Suck up the stdout... + $res = <$outfh>; + chop($res); + + $res = <$outfh>; + chop($res); + $res = oct($res); + + if ($res != 0) { + helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Write failed with code $res\n"); + } + } else { $cmdstr = 'CALL read $src $buf '."$bufsize\n"; helper::send_cmd($cmdfh, $outfh, "read", $cmdstr); - my $res = helper::verify_cmd($cmdfh, $outfh, "read"); - my $readb = oct($res); + $res = helper::verify_cmd($cmdfh, $outfh, "read"); + $readb = oct($res); # Now write $readb back out to dest $cmdstr = 'CALL write $dest $buf '."$readb\n"; helper::send_cmd($cmdfh, $outfh, "write", $cmdstr); + } $res = helper::verify_cmd($cmdfh, $outfh, "write"); @@ -101,31 +161,41 @@ sub process_cmd $cmdstr = 'CALL close $dest'."\n"; helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); + if ($src ne "/dev/stdin") { my $cmpres = system("cmp -s $src $dest"); if ($cmpres != 0) { print STDOUT "ERROR! File $src differs from $dest\n"; exit 1; } - + } helper::print_and_exit($cmdfh, $outfh, 0, "copy test successful\n"); } my $currarg = 0; my $is_alpha = 0; +my $overwrite = 0; + +my $len = @ARGV-2; if (@ARGV < 2) { usage; -} elsif (@ARGV > 2 ) { - if ($ARGV[$currarg++] eq "-alpha") { +} + +my $i; +for ($i=0; $i < $len; $i++ ) { + if ($ARGV[$i] eq "-alpha") { $is_alpha = 1; } + if ($ARGV[$i] eq "-o") { + $overwrite = 1; + } } -my $src = $ARGV[$currarg++]; -my $dest = $ARGV[$currarg]; +my $src = $ARGV[$i++]; +my $dest = $ARGV[$i]; -process_cmd($src, $dest, $is_alpha); +process_cmd($src, $dest, $overwrite, $is_alpha); exit 0; Index: test_driver.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_driver.c,v retrieving revision 1.4.2.2 retrieving revision 1.4.2.3 diff -u -w -b -B -p -r1.4.2.2 -r1.4.2.3 --- test_driver.c 9 Feb 2004 13:11:19 -0000 1.4.2.2 +++ test_driver.c 10 Feb 2004 14:38:51 -0000 1.4.2.3 @@ -219,10 +219,47 @@ char *get_str(char *var_name) return var_name; } +static char* +get_or_part(char **str, int* did_alloc) +{ + char *tmp_str = *str; + int i, norm_str=0; + + if (tmp_str == NULL) + return NULL; + + if (tmp_str[0] == '|') { + tmp_str++; + norm_str=1; + } + + for (i=0; (unsigned int)i < strlen(tmp_str); i++) { + if (tmp_str[i] == '|') { + char *new_str = (char *)malloc(i+1); + memcpy(new_str, tmp_str, i); + new_str[i] = '\0'; + *did_alloc = 1; + *str = &tmp_str[i]; + return new_str; + } + } + + if (norm_str) { + *did_alloc = 0; + *str = NULL; + return tmp_str; + } + + return NULL; +} + int get_obj(char *var_name) { + char** str = &var_name; + char *str1; struct var_mapping *var_map; - int i; + int did_alloc=0; + int obj=0, got_obj=0; DBG(5, fprintf(outfp, "Getting object for %s\n", var_name)); @@ -234,53 +271,33 @@ int get_obj(char *var_name) * Check for '|', indicates that one or more values are or'd * together */ - for (i=0; (unsigned int)i < strlen(var_name); i++) { - if (var_name[i] == '|') { - char *str1 = malloc(i+1); - char *str2 = malloc(strlen(var_name)-i+1); - int obj; - struct var_mapping *tmp_map; - - memcpy(str1, var_name, i); - str1[i] = '\0'; - memcpy(str2, (char *)&var_name[i+1], strlen(var_name)-i); + while ((str1 = get_or_part(str, &did_alloc)) != NULL) { if (isdigit(str1[0])) { if (str1[0] == '0') { /* Assume octal format */ - obj = strtol(str1, NULL, 8); + obj |= strtol(str1, NULL, 8); } else - obj = atoi(str1); + obj |= atoi(str1); } else { - tmp_map = get_map(str1); - if (!tmp_map) { + var_map = get_map(str1); + if (!var_map) { + if (did_alloc) free(str1); - free(str2); return -1; } - obj = tmp_map->obj; + obj |= var_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) { + if (did_alloc) { + did_alloc = 0; free(str1); - free(str2); - return -1; } - obj |= tmp_map->obj; + got_obj++; } - free(str1); - free(str2); + + if (got_obj) return obj; - } - } var_map = get_map(var_name); if (!var_map) Index: test_stats.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_stats.pl,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -u -w -b -B -p -r1.5.2.1 -r1.5.2.2 --- test_stats.pl 28 Jan 2004 13:16:57 -0000 1.5.2.1 +++ test_stats.pl 10 Feb 2004 14:38:51 -0000 1.5.2.2 @@ -172,6 +172,7 @@ sub process_cmd verify_stat($cmdfh, $outfh, "lstat", $is_alpha, @stats); } + if (0) { # Now do statvfs functions $cmdstr = '$buf2 = ALLOC ( $size2 = CALL sizeof statvfs )'."\n"; helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); @@ -223,6 +224,7 @@ sub process_cmd helper::print_and_exit($cmdfh, $outfh, 1, $str); } } + } helper::print_and_exit($cmdfh, $outfh, 0, "stat test successful\n"); } |