Commit 89c2cf2e authored by Pierre DAVID's avatar Pierre DAVID

Preliminary version of test framework.

parent ab376d11
...@@ -187,3 +187,17 @@ Metrology server ...@@ -187,3 +187,17 @@ Metrology server
.../crontab.metro .../crontab.metro
NMWSDIR/ NMWSDIR/
.../gengraph .../gengraph
Test system
-----------
SBINDIR/
.../netmagis-test
NMLIBDIR/
.../tests/
.../sc-*.test
NMVARDIR/
.../tests/
.../sc-*-*.out
.../sc-*-*.err
...@@ -69,6 +69,7 @@ usage: ...@@ -69,6 +69,7 @@ usage:
@echo " install-topo" @echo " install-topo"
@echo " install-metro" @echo " install-metro"
@echo " install-netmagis.org" @echo " install-netmagis.org"
@echo " install-devtools"
@echo " distrib" @echo " distrib"
@echo " freebsd-ports" @echo " freebsd-ports"
@echo " debian-packages" @echo " debian-packages"
...@@ -119,6 +120,9 @@ install-metro: ...@@ -119,6 +120,9 @@ install-metro:
install-netmagis.org: build-www install-netmagis.org: build-www
cd doc/netmagis.org ; make $(DIRS) SUBST="$(SUBST)" TCLSH=$(TCLSH) install cd doc/netmagis.org ; make $(DIRS) SUBST="$(SUBST)" TCLSH=$(TCLSH) install
install-devtools:
cd devtools ; make $(DIRS) SUBST="$(SUBST)" TCLSH=$(TCLSH) install
distrib: clean distrib: clean
rm -rf /tmp/netmagis-$(VERSION) rm -rf /tmp/netmagis-$(VERSION)
mkdir /tmp/netmagis-$(VERSION) mkdir /tmp/netmagis-$(VERSION)
......
NINSTALL = ../ninstall
build:
@echo ">>> Making build in `pwd`"
install:
@echo ">>> Making install in `pwd`"
cd tests ; make $(DIRS) install
clean:
This directory provides automated tests in order to check correct
behaviour of a Netmagis installation.
NINSTALL = ../../ninstall
PROG = netmagis-test
FILES = cgi
TESTS = *.test
install:
@echo ">>> Making install in `pwd`"
mkdir -p $(DESTDIR)$(SBINDIR)
mkdir -p $(DESTDIR)$(NMLIBDIR)/tests
mkdir -p $(DESTDIR)$(NMVARDIR)/tests
$(NINSTALL) -m 0755 -e "s|%NMLIBDIR%|$(NMLIBDIR)|" \
-e "s|%NMVARDIR%|$(NMVARDIR)|" \
-e "s|%NMCGIDIR%|$(NMCGIDIR)|" \
$(SUBST) $(PROG) $(DESTDIR)$(SBINDIR)
$(NINSTALL) -m 0755 $(SUBST) $(FILES) $(DESTDIR)$(NMLIBDIR)/tests
$(NINSTALL) -m 0644 -e "s|%NMLIBDIR%|$(NMLIBDIR)|" \
-e "s|%NMVARDIR%|$(NMVARDIR)|" \
-e "s|%NMCGIDIR%|$(NMCGIDIR)|" \
$(SUBST) $(TESTS) $(DESTDIR)$(NMLIBDIR)/tests
clean:
#!%TCLSH%
proc post-string {str} {
regsub -all {%} $str "%25" str
regsub -all {\+} $str "%2B" str
regsub -all {\&} $str "%26" str
regsub -all "\n" $str "%0A" str
regsub -all "\r" $str "%0D" str
regsub -all {\<} $str "%3C" str
regsub -all {=} $str "%3D" str
regsub -all {\>} $str "%3E" str
regsub -all {\?} $str "%3F" str
regsub -all {"} $str "%22" str
regsub -all {"} $str "%22" str
regsub -all { } $str "%20" str
return $str
}
proc run {path login argv} {
global env
set env(REQUEST_METHOD) "GET"
set query {}
foreach kv $argv {
if {[regexp {^([^=]+)=(.*)} $kv match k v]} then {
set k [post-string $k]
set v [post-string $v]
lappend query "$k=$v"
} else {
puts stderr "Invalid argument '$kv'"
exit 1
}
}
set env(QUERY_STRING) [join $query "&"]
if {$login ne ""} then {
set env(REMOTE_USER) $login
} else {
catch {unset env(REMOTE_USER)}
}
catch {unset env(PATH_INFO)}
if {[catch {exec -ignorestderr $path} msg]} then {
puts stderr "Script '$path' failed"
puts stderr $msg
set r 1
} else {
puts stdout $msg
set r 0
}
return $r
}
set usage {usage: %1$s [-h][-l login] path var=val var=val ...}
proc usage {argv0} {
global usage
puts stderr [format $usage $argv0]
}
proc main {argv0 argv} {
set login ""
while {[llength $argv] > 0} {
set arg [lindex $argv 0]
switch -glob -- $arg {
-l {
set login [lindex $argv 1]
set argv [lreplace $argv 0 1]
}
-h {
usage $argv0
return 0
}
-* {
usage $argv0
return 1
}
default {
break
}
}
}
if {[llength $argv] == 0} then {
usage $argv0
return 1
}
set path [lindex $argv 0]
set argv [lreplace $argv 0 0]
return [run $path $login $argv]
}
return [main $argv0 $argv]
#!%TCLSH%
#
# This script runs one or more Netmagis tests
#
# Syntax:
# netmagis-test file.test ... file.test # run specified tests
# netmagis-test # run all tests
#
# Note: Netmagis instance must be installed (this is needed to provide
# correct paths and password)
#
# Output of each test is
# pref: directory and base name of test
# cmd: cmd to run
# pattern: pattern to search in stdout
# return value: 1 if run ok and pattern found in stdout
proc run-and-grep {pref cmd pattern} {
set r 0
set out "$pref.out"
set err "$pref.err"
if {[catch {exec -ignorestderr sh -c $cmd > $out 2>$err} x]} then {
#
# An error occurrend
# r contains cmd standard output with a last
# line "child process exited abnormally"
# File contains cmd standard error
#
} else {
#
# Script terminated without error
# r contains cmd standard output
# File contains cmd standard error
#
set fd [open $out "r"]
set t [read $fd]
close $fd
if {[regexp $pattern $t]} then {
set r 1
}
}
return $r
}
proc init {} {
global tabtests
catch {array unset tabtests}
set tabtests(idx) 0
}
proc load-examples {runall output} {
exec [$runall]
}
# register a test
proc test {name cmd pattern} {
global tabtests
set idx $tabtests(idx)
set tabtests($idx) [list $name $cmd $pattern]
incr tabtests(idx)
}
proc run-tests {fd} {
global tabtests
set r 0
set ntests $tabtests(idx)
for {set i 0} {$i < $ntests} {incr i} {
lassign $tabtests($i) name cmd pattern
puts -nonewline $fd "$name: "
flush $fd
set rt [run-and-grep %NMVARDIR%/tests/$name $cmd $pattern]
if {$rt} then {
puts $fd "ok"
} else {
puts $fd "fail"
set r 1
}
}
return $r
}
proc main {file} {
init
source $file
run-tests stdout
}
exit [main [lindex $argv 0]]
# install :
# - param 1 = run-all.sh location
# - param 2 = grep string
#install {ZZ} {}
test add-1 {%NMLIBDIR%/tests/cgi -l pda %NMCGIDIR%/add} {<b>Add host}
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