Improve gui-cli script to be able to run automated tests and save results.

This commit is contained in:
Ben Greear
2019-10-11 13:45:00 -07:00
parent 7ed2c713d1
commit be5e05fe38

View File

@@ -26,6 +26,10 @@ my $lfmgr_port = 3990;
# Default values for ye ole cmd-line args.
my $port = "";
my $cmd = "";
my $ttype = ""; # Test type
my $tname = "lfgui-test";
my $tconfig = ""; # test config
my $rpt_dest = "";
my $show_help = 0;
########################################################################
@@ -34,9 +38,14 @@ my $show_help = 0;
my $usage = qq($0 [--manager { hostname or address of LANforge GUI machine } ]
[--port {port name} ]
[--ttype {test instance type} ]
[--tname {test instance name} ]
[--tconfig {test configuration name, use defaults if not specified} ]
[--rpt_dest {Copy report to destination once it is complete} ]
[--cmd { command to send to the GUI } ]
Example:
lf_gui_cmd.pl --manager localhost --port 3990 --ttype TR-398 --tname mytest --tconfig comxim --rpt_dest /var/www/html/lf_reports
lf_gui_cmd.pl --manager localhost --port 3990 --cmd \"help\"
);
@@ -48,6 +57,10 @@ if (@ARGV < 2) {
GetOptions (
'help|h' => \$show_help,
'manager|mgr|m=s' => \$lfmgr_host,
'ttype=s' => \$ttype,
'tname=s' => \$tname,
'tconfig=s' => \$tconfig,
'rpt_dest=s' => \$rpt_dest,
'port=s' => \$port,
'cmd|c=s' => \$cmd,
) || die("$usage");
@@ -67,9 +80,51 @@ $t->open( Host => $lfmgr_host,
$t->waitfor("/lfgui\# /");
$t->print($cmd);
my @rslt = $t->waitfor('/lfgui\#/');
if ($cmd ne "") {
print doCmd("$cmd");
}
print join( "\n", @rslt );
if ($ttype ne "") {
doCmd("cv create '$ttype' '$tname'");
if ($tconfig ne "") {
doCmd("cv load 'tname' '$tconfig'");
}
doCmd("cv click '$tname' 'Auto Save Report'");
doCmd("cv click '$tname' 'Start'");
while (1) {
my $rslt = doCmd("cv get '$tname' 'Report Location:'");
print "Result-:$rslt:-\n";
if ($rslt =~ /^\s*Report Location:::(.*)/) {
my $loc = $1;
if ($loc eq "") {
# Wait longer
sleep(1);
}
else {
# Copy some place it can be seen easily?
if ($rpt_dest ne "") {
my $cp = "cp -ar $loc $rpt_dest";
print "Copy test results: $cp\n";
system($cp);
}
last;
}
}
}
}
exit(0);
sub doCmd {
my $cmd = shift;
print ">>>Sending:$cmd\n";
$t->print($cmd);
my @rslt = $t->waitfor('/lfgui\#/');
if ($rslt[@rslt-1] eq "lfgui\#") {
$rslt[@rslt-1] = "";
}
return join("\n", @rslt);
}