t_api.pl revision 15a44745412679c30a6d022733925af70a38b715
#
# Copyright (C) 1999, 2000 Internet Software Consortium.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# $Id: t_api.pl,v 1.5 2000/07/27 09:38:32 tale Exp $
require "getopts.pl";
#
# a minimalistic test api in perl compatable with the C api
# used for the bind 9 regression tests
#
sub t_info {
package t_api;
printf("I:${format}%s", @rest);
}
sub t_result {
package t_api;
local($result) = @_;
$T_inresult = 1;
printf("R:$result\n");
}
sub t_assert {
package t_api;
}
sub t_getenv {
package t_api;
local($name) = @_;
}
package t_api;
$| = 1;
sub t_on_abort {
$T_aborted = 1;
&t_info("got abort\n");
die;
}
sub t_on_alarm {
$T_timedout = 1;
&t_info("got alarm\n");
die;
}
sub t_on_int {
$T_terminated = 1;
&t_info("got int\n");
die;
}
# initialize the test environment
sub t_initconf {
local($cfile) = @_;
if ((-f $cfile) && (-s _)) {
open(XXX, "< $cfile");
while (<XXX>) {
next if (/^\#/);
next unless (/=/);
chop;
}
close(XXX);
}
}
# dump the configuration to the journal
sub t_dumpconf {
&main't_info("%s\t%s\n", $name, $T_env{$name});
}
}
# run a test
sub doTestN {
package main;
local($testnumber) = @_;
local($status);
if (defined($T_testlist[$testnumber])) {
$t_api'T_inresult = 0;
$t_api'T_aborted = 0;
$t_api'T_timedout = 0;
$t_api'T_terminated = 0;
$t_api'T_unresolved = 0;
alarm($t_api'T_timeout);
alarm(0);
if (! defined($status)) {
&t_result("UNRESOLVED");
}
elsif (! $t_api'T_inresult) {
&t_result("NORESULT");
}
}
else {
&t_result("UNTESTED");
}
}
$T_usage = "Usage:
x : don't execute tests in a subproc (n/a)
";
# get command line args
# if -u, print usage and exit
if (defined($main'opt_u)) {
print $T_usage;
exit(0);
}
# implement -h and -t after we add test descriptions to T_testlist ZZZ
if (defined($main'opt_h)) {
print "the -h option is not implemented\n";
exit(0);
}
if (defined($main'opt_t)) {
print "the -t option is not implemented\n";
exit(0);
}
#
# silently ignore the -x option
# this exists in the C version of the api
# to facilitate exception debugging with gdb
# and is not meaningful here
#
$T_configfile = "t_config";
$T_debug = 0;
$T_timeout = 10;
$T_testnum = -1;
# print the start line
chop $date;
($cmd = $0) =~ s/\.\///g;
printf("S:$cmd:$date\n");
# initialize the test environment
&t_dumpconf() if ($T_debug);
# establish working directory if requested
# run the tests
if ($T_testnum == -1) {
# run all tests
$T_ntests = $#main'T_testlist + 1;
}
}
else {
# otherwise run the specified test
}
# print the end line
chop $date;
printf("E:$cmd:$date\n");
1;