From b07861673d94d6e8dfe32a716e62fa0c5e9bd347 Mon Sep 17 00:00:00 2001 From: Christopher Alfeld Date: Fri, 6 Jul 2001 19:35:43 +0000 Subject: [PATCH] Changed things to now use a state file to keep track of state for interactive sessions. This simplies arguments and prevents the bad case where a full init is followed by a non-full finish. It also allows users to share test trees. The database is set up under the username of whatever user ran init, but any user which permissions can run tests (previously this would break because it would look for the test DB under the incorrect username). --- testsuite/README | 27 ++++++++++++++++++++----- testsuite/tbtest | 52 ++++++++++++++++++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 18 deletions(-) diff --git a/testsuite/README b/testsuite/README index cd67c3cd9..7119ce2f6 100644 --- a/testsuite/README +++ b/testsuite/README @@ -42,6 +42,7 @@ The test directory holds the following files: clean.txt Dump of clean test DB. dbdump.txt Dump of real database. defs Defs file used for configure. + state Used internally for proper cleanup. * - Appears only in frontend (default) mode. ** - Appears only in full mode. @@ -92,6 +93,23 @@ of commands, check for fail cases, and inspect data base state for correctness. To create such tests read the "Test Format" section below. +Using the Test Tree +------------------- + +It is often useful to be able to do manual testing using the test +tree. This can easily be done. By running + tbtest -leavedb init tbdb +you will setup the test tree and test database, leaving the DB +intact. You can now run all your commands from the install tree to do +manual testing just as the tests do. + +The experiment 'test' under project 'testbed' exists in the test DB +and should be used for all testing. + +The following command, when run from the test directory, will set up +your path correctly: + +setenv PATH "/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/site/bin:.:`pwd`/install/bin:`pwd`/install/sbin" Program Reference ----------------- @@ -131,13 +149,13 @@ Options: -leavedb - Do not drop the test database on exit. -path - Path to directory to store test files. -frontend - Run in frontend mode. - -full - Run in full mode (Not yet implemented). + -full - Run in full mode. Mode: run [ ] init [ ] test single - finish [ ] + finish tbtest [-leavedb] [-path ] Notes: @@ -145,9 +163,8 @@ Notes: The arguments in [] for the modes are necessary with -full and should not be present otherwise. -IMPORTANT: If running with -full you must have -full on all modes. -Doing a -full init and then a finish without -full will cause -problems. +You need only use -full on init to set the type for any other +subsequent commands. Generally tbtest is invoked in 'run' mode that does everything. For an more interactive approach a you can invoke 'tbtest init ...' and diff --git a/testsuite/tbtest b/testsuite/tbtest index 338ba9122..c22e6d66e 100755 --- a/testsuite/tbtest +++ b/testsuite/tbtest @@ -22,7 +22,7 @@ # init [ ] - Initiatlize. # test - Run tests # single - Run only -# finish [ ] - Finish run. +# finish - Finish run # is "X ...", for example "10 pc 16 shark" use DBI; @@ -67,13 +67,13 @@ sub show_help { print STDERR " -leavedb - Do not drop the test database on exit.\n"; print STDERR " -path - Path to directory to store test files.\n"; print STDERR " -frontend - Run in frontend mode.\n"; - print STDERR " -full - Run in full mode (Not yet implemented).\n"; + print STDERR " -full - Run in full mode.\n"; print STDERR "Mode:\n"; print STDERR " run [ ]\n"; print STDERR " init [ ]\n"; print STDERR " test \n"; print STDERR " single \n"; - print STDERR " finish [ ]\n"; + print STDERR " finish\n"; print STDERR ": Must be even lengthed list of .\n"; print STDERR " Ex: \"4 pc 16 shark\"\n"; print STDERR "Examples:\n"; @@ -103,6 +103,10 @@ while (($#ARGV > -1) && ($mode eq "")) { } chdir $path; +$user=`whoami`; +chop $user; +$logfile = "test.log"; +$statefile = "state"; if ($mode eq "run") { if ($type eq "frontend") { @@ -127,17 +131,24 @@ if ($mode eq "run") { if ($#ARGV <= 0) {show_help;} ($testdir,@tests) = @ARGV; } elsif ($mode eq "finish") { - if ($type eq "frontend") { - if ($#ARGV != -1) {show_help;} - } else { - if ($#ARGV != 2) {show_help;} - ($TBDB,$pid,$eid) = @ARGV; - } + if ($#ARGV != -1) {show_help;} } else { print STDERR "Unknown mode: $mode\n"; show_help; } +if (($mode ne "run") && ($mode ne "init")) { + # Read state + open(STATE,$statefile) || do { + print STDERR "Could not find state file ($statefile).\n"; + print STDERR " Run in init mode first.\n"; + exit(1); + }; + ($type,$TBDB,$user,$pid,$eid) = split(" ",); + close(STATE); +} + + if (($mode eq "run") || ($mode eq "test") || ($mode eq "single")) { if (! ($testdir =~ m|^/|)) { $testdir = "$basedir/tests/$testdir"; @@ -151,10 +162,7 @@ if (($type eq "full") && (($mode eq "init") || ($mode eq "run"))) { } } -$user=`whoami`; -chop $user; $testdb = "tbdb_$user"; -$logfile = "test.log"; # Test counts $pass = 0; @@ -226,13 +234,22 @@ sub step_init { prints "Type: $type\n"; prints "\n"; prints "Beginning test run. " . ctime(time); - + # Initialize DB $dbh = DBI->connect("DBI:mysql:database=$TBDB;host=localhost") || die "Could not connect to DB.\n"; # Having made sure we can, we now disconnect so as not to harm DB. $dbh->disconnect; + # Write state + open(STATE,"> $statefile"); + if ($type eq "full") { + print STATE "$type $TBDB $user $pid $eid\n"; + } else { + print STATE "$type $TBDB $user\n"; + } + close(STATE); + # Reserve nodes if ($type eq "full") { prints "Reserving nodes.\n"; @@ -603,6 +620,15 @@ sub step_cleanup { $pass++; } } + prints " Clearing state "; + system("rm -f $statefile"); + if (($? >> 8) != 0) { + prints "FAIL\n"; + $fail++; + } else { + prints "PASS\n"; + $pass++; + } prints "End test run. " . ctime(time); prints "END CLEANUP\n"; } -- 2.22.0