Commit b0786167 authored by Christopher Alfeld's avatar Christopher Alfeld

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).
parent 921a976b
......@@ -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> - 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 <db> <testdir> [<pid> <eid> <num>]
init <db> [<pid> <eid> <num>]
test <testdir>
single <testdir> <tests>
finish [<db> <pid> <eid>]
finish
tbtest [-leavedb] [-path <path>] <db> <testdir>
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
......
......@@ -22,7 +22,7 @@
# init <db> [<pid> <eid> <num>] - Initiatlize.
# test <testdir> - Run tests
# single <testdir> <tests> - Run only <tests>
# finish [<db> <pid> <eid>] - Finish run.
# finish - Finish run
# <num> is "X <type> ...", 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> - 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 <db> <testdir> [<pid> <eid> <num>]\n";
print STDERR " init <db> [<pid> <eid> <num>]\n";
print STDERR " test <testdir>\n";
print STDERR " single <testdir> <tests>\n";
print STDERR " finish [<db> <pid> <eid>]\n";
print STDERR " finish\n";
print STDERR "<num>: Must be even lengthed list of <number> <type>.\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(" ",<STATE>);
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";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment