Commit 8b214a9a authored by Christopher Alfeld's avatar Christopher Alfeld

Nice utility for constructing tb_compare parts of tests. It works like this.

Say I want to check the contents of the virt_lans table.  I run my
experiment through tbprerun, and manually inspect virt_lans to make
sure it's correct.  Then I do something like:

dbdump tbdb_calfeld 'select vname,delay,bandwidth,lossrate,member from virt_lans where pid="testbed" and eid="test"'

dbdump should output something like:

@result = (
["link2","0","100","0.025","node4:2"],
["link2","0","100","0.025","node5:1"],
["link3","0","100","0.000","node6:0"],
["link3","0","100","0.000","node5:2"],
["lan2","25","100","0.000","node4:0"],
["lan2","25","100","0.000","node3:1"],
["link4","500","45","0.000","node6:1"],
["link4","500","45","0.000","node1:1"],
["lan3","50","100","0.000","node1:0"],
["lan3","50","100","0.000","node2:0"],
["lan3","50","100","0.000","node3:0"],
["link1","0","100","0.000","node4:1"],
["link1","0","100","0.000","node5:0"],
);

which I copy and paste into my test script and put immediately under
it the command:

tb_compare("select vname,delay,bandwidth,lossrate,member from virt_lans" .
	" where pid=\"testbed\" and eid=\"test",\@result);
parent 228da8b4
#!/usr/bin/perl -w
# This scripts takes a DB and a select statement and dumps the
# results of the table in a format that can easily be inserted into
# atest script for use with tb_compare.
use DBI;
if ($#ARGV != 1) {
print STDERR "Syntax: $0 <db> <query>\n";
exit(1);
}
($db,$query) = @ARGV;
$dbh = DBI->connect("DBI:mysql:database=$db;host=localhost") ||
die "Could not connect to DB.\n";
$sth = $dbh->prepare($query);
$sth->execute;
print "\@result = (\n";
while (@row = $sth->fetchrow_array) {
print "[\"" . $row[0] . "\"";
foreach $element (@row[1..$#row]) {
print ",\"$element\""
}
print "\],\n";
}
print ");\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