Some initial work for a test suite.

git-svn-id: http://repo.ham.fi/svn/aprsc/trunk@215 3ce903b1-3385-4e86-93cd-f9a4a239f7ac
This commit is contained in:
Heikki Hannikainen 2008-03-22 10:36:43 +00:00
parent 80a20cbfdf
commit 6ce9dfa388
4 changed files with 270 additions and 0 deletions

13
tests/Makefile Normal file
View File

@ -0,0 +1,13 @@
# Makefile for running the test suite
TEST_FILES = t/*.t
TEST_VERBOSE = 0
INST_LIB = .
INST_ARCHLIB = .
PERL=/usr/bin/perl
test:
PERL_DL_NONLAZY=1 $(PERL) "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE), '$(INST_LIB)', '$(INST_ARCHLIB)')" $(TEST_FILES)

117
tests/cfg-aprsc/basic Normal file
View File

@ -0,0 +1,117 @@
#
# USE RCS !!!
# $Id$
#
# Configuration for aprsc, an APRS-IS server for core servers
MyCall NOCALL
MyEmail email@example.com
MyAdmin "My Name, MYCALL"
MyHostname aprsc-1.example.com
### Directories #########
# Data directory (for database files)
RunDir data
# Log directory
LogDir logs
### Intervals #########
# Interval specification format examples:
# 600 (600 seconds), 5m, 2h, 1h30m, 1d3h15m24s, etc...
# Statistics logging
StatsInterval 1m
# How often to scan the caches for old entries
ExpiryInterval 30s
# How long to cache last position of each station
LastPositionCache 48h
# How long to cache duplicate filter entries (practically all packets)
DupeFilterCache 30s
# When no data is received from an upstream server in N seconds, switch to
# another server
UpstreamTimeout 10s
# When no data is received from a downstream server in N seconds, disconnect
ClientTimeout 48h
### TCP listener ##########
# Listen <socketname> <porttype> tcp <address to bind> <port>
# socketname: any name you wish to show up in logs and statistics
# porttype: one of:
# fullfeed - everything, after dupe filtering
# dupefeed - everything that comes in - with dupes!
# msgonly - messages only
# userfilter - user-specified filters
#
# Feed controls are partially implemented with system specific filters.
# Area-filters would be similar (like all of North America with a/// filters)
#
# Note: areas are not very precise definitions...
#
####### --- Feeds with no CWOP
Listen "Full feed, no CWOP" fullfeed tcp 0.0.0.0 20152 t/*
Listen "Full feed with duplicates, no CWOP" dupefeed tcp ::1 20160 t/*
Listen "Usa only feed, no CWOP" fullfeed tcp 0.0.0.0 20154 -t/c a/90/-180/24/-30 a/25/-160/15/-150
Listen "Europe only feed, no CWOP" fullfeed tcp 0.0.0.0 20155 -t/c a/90/-30/30/60
Listen "Stations within 350 km or your location" fullfeed tcp 0.0.0.0 20156 -t/c m/350
Listen "Stations within 100 km or your location" fullfeed tcp 0.0.0.0 20157 -t/c m/100
Listen "Stations within 1000 km or your location" fullfeed tcp 0.0.0.0 20158 -t/c m/1000
Listen "Stations within 3000 km or your location" fullfeed tcp 0.0.0.0 20159 -t/c m/3000
Listen "Regional East Coast US Only Feed" fullfeed tcp 0.0.0.0 24579 -t/c a/90/-85/24/-30
####### --- Feeds with CWOP
#
# Note: service on port 23 _requires_ this program to run as _root_
#
Listen "Full feed with CWOP" fullfeed tcp 0.0.0.0 23 t/c*
Listen "Messages only" messageonly tcp 0.0.0.0 1314 t/m
Listen "Full feed with CWOP" fullfeed tcp 0.0.0.0 10152 t/c*
Listen "Full feed with CWOP and duplicates" dupefeed tcp ::1 10160 t/c*
Listen "User-specified filters" userfilter tcp 0.0.0.0 14580
Listen "Usa only feed, with CWOP" fullfeed tcp 0.0.0.0 10154 a/90/-180/24/-30 a/25/-160/15/-150
Listen "Europe only feed, with CWOP" fullfeed tcp 0.0.0.0 10155 a/90/-30/30/60
Listen "Stations within 350 km or your location with CWOP" fullfeed tcp 0.0.0.0 10156 m/350
Listen "Stations within 100 km or your location with CWOP" fullfeed tcp 0.0.0.0 10157 m/100
Listen "Stations within 1000 km or your location with CWOP" fullfeed tcp 0.0.0.0 10158 m/1000
Listen "Stations within 3000 km or your location with CWOP" fullfeed tcp 0.0.0.0 10159 m/3000
Listen "Regional 750 km @ Brady, Tx" fullfeed tcp 0.0.0.0 14578 r/31/-99/750
Listen "Regional central USA: 49N 107W x 25N 86W" fullfeed tcp 0.0.0.0 14579 a/49/-107/25/-86
#Uplink "Uplink" rw tcp finland.aprs2.net 10152
Uplink "Uplink" ro tcp finland.aprs2.net 10152
#Listen "uplinksim" uplinksim tcp 127.0.0.1 10190
### Internals ############
# The number of worker threads to run - set this to the number of
# CPU cores you have. On a single-processor, single-core system, set this
# to 1. On a server with two processors or a new dual-core single-CPU system,
# set to 2. On a system with two dual-core processors, set to 4.
##
## Or set to about 1 per each 50 client connections, minimum 2..
## The smaller set there is for poll(2) to transfer data from and
## to the kernel, the less work each system call must do - search
## for your balance, too much threads has its own penalties.
##
WorkerThreads 20
# When running this server as super-user, the server can (in many systems)
# increase several resource limits, and do other things that less privileged
# server can not do.
#
# The FileLimit is resource limit on how many simultaneous connections and
# some other internal resources the system can use at the same time.
# If the server is not being run as super-user, this setting has no effect.
#
FileLimit 10000

128
tests/runproduct.pm Normal file
View File

@ -0,0 +1,128 @@
package runproduct;
=head1 NAME
runproduct - Runs and stops either aprsc or javaprssrvr with a selected
configuration, hiding the application-specific details from the test.
=cut
use 5.006;
use strict;
use warnings;
use IPC::Open3;
use POSIX ":sys_wait_h";
use Data::Dumper;
my %products = (
'aprsc' => {
'binary' => '../src/aprsc',
'stdargs' => '',
'cfgfileargs' => '-c',
'cfgdir' => 'cfg-aprsc'
},
'javap' => {
'binary' => '/usr/bin/java',
'stdargs' => '-server -cp ../../../javaprssrvr/javAPRSSrvr.jar javAPRSSrvr',
'cfgfileargs' => '',
'cfgdir' => 'cfg-javap'
}
);
my $prod;
my $prod_name = 'aprsc';
my $pid;
my($stdin, $stdout, $stderr);
sub init()
{
$prod_name = $ENV{'TEST_PRODUCT'} if (defined $ENV{'TEST_PRODUCT'});
if (!defined $products{$prod_name}) {
warn "No such product: " . $prod_name . "\n";
return undef;
}
$prod = $products{$prod_name};
return 1;
}
sub readout()
{
if (defined $stderr) {
}
if (defined $stdout) {
}
}
sub start($)
{
my($config) = @_;
if (defined $pid) {
return "Product already running.";
}
my $cfgfile = $prod->{'cfgdir'} . '/' . $config;
if (! -f $cfgfile) {
return "No such configuration file: $cfgfile";
}
my $cmdline = $prod->{'binary'} . ' ' . $prod->{'stdargs'} . ' '
. $prod->{'cfgfileargs'} . ' ' . $cfgfile;
warn "Product command line: $cmdline\n";
$pid = open3($stdin, $stdout, $stderr, $cmdline);
if (!defined $pid) {
return "Failed to run product: $!";
}
# let it start...
sleep(1);
my $kid = waitpid($pid, WNOHANG);
if ($kid) {
my $retval = $?;
my $signal = $retval & 127;
$retval = $retval >> 8;
readout();
discard();
return "Product quit after startup, signal $signal retcode $retval.";
}
return 1;
}
sub discard()
{
close($stdin) if (defined $stdin);
close($stdout) if (defined $stdout);
close($stderr) if (defined $stderr);
undef $pid;
}
sub stop()
{
if (!defined $pid) {
return "Product not running.";
}
my $hits = kill("TERM", $pid);
if ($hits < 1) {
return "Product is not running.";
discard();
return undef;
}
discard();
return 1;
}
1;

12
tests/t/00startstop.t Normal file
View File

@ -0,0 +1,12 @@
# Simple test to start and stop the product.
use Test;
BEGIN { plan tests => 4 };
use runproduct;
ok(1); # If we made it this far, we're ok.
ok(runproduct::init(), 1, "Failed to initialize product runner");
ok(runproduct::start("basic"), 1, "Failed to start product");
ok(runproduct::stop(), 1, "Failed to stop product");