From 5da747ff564cdcfeff90c5f5cfcfac03bc48332b Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Fri, 6 Jul 2007 14:32:44 +0000 Subject: Import DOM library. This is mainly stub functions atm (and is missing a number of key interfaces). svn path=/trunk/dom/; revision=3384 --- test/INDEX | 4 ++ test/Makefile | 60 ++++++++++++++++++++++ test/testrunner.pl | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 test/INDEX create mode 100644 test/Makefile create mode 100644 test/testrunner.pl (limited to 'test') diff --git a/test/INDEX b/test/INDEX new file mode 100644 index 0000000..a1b7297 --- /dev/null +++ b/test/INDEX @@ -0,0 +1,4 @@ +# Index for libdom testcases +# +# Test Description DataDir + diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..d9bb137 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,60 @@ +# Makefile for Hubbub testcases +# +# Toolchain is exported by top-level makefile +# +# Top-level makefile also exports the following variables: +# +# COMPONENT Name of component +# EXPORT Absolute path of export directory +# TOP Absolute path of source tree root +# +# The top-level makefile requires the following targets to exist: +# +# clean Clean source tree +# debug Create a debug binary +# distclean Fully clean source tree, back to pristine condition +# export Export distributable components to ${EXPORT} +# release Create a release binary +# setup Perform any setup required prior to compilation +# test Execute any test cases + +# Extend toolchain settings +CFLAGS += -I${TOP}/src/ -I$(CURDIR) + +# Release output +RELEASE = + +# Debug output +DEBUG = + +# Objects +OBJS = + +.PHONY: clean debug export release setup test + +# Targets +release: + +debug: + +clean: +ifneq (${OBJS}, ) + -@${RM} ${RMFLAGS} $(addsuffix ${EXEEXT}, $(OBJS)) +endif + +distclean: + -@${RM} ${RMFLAGS} log + +setup: + +export: + +test: $(OBJS) + @${PERL} testrunner.pl ${EXEEXT} + +# Pattern rules +%: %.c + @${ECHO} ${ECHOFLAGS} "==> $<" + @${CC} -c -g ${CFLAGS} -o $@.o $< + @${LD} -g -o $@ $@.o ${LDFLAGS} -ldom-debug + @${RM} ${RMFLAGS} $@.o diff --git a/test/testrunner.pl b/test/testrunner.pl new file mode 100644 index 0000000..00c54e7 --- /dev/null +++ b/test/testrunner.pl @@ -0,0 +1,147 @@ +#!/bin/perl +# +# Testcase runner for libhubbub +# +# Usage: testrunner +# +# Operates upon INDEX files described in the README. +# Locates and executes testcases, feeding data files to programs +# as appropriate. +# Logs testcase output to file. +# Aborts test sequence on detection of error. +# + +use warnings; +use strict; +use File::Spec; +use IPC::Open3; + +# Get EXE extension (if any) +my $exeext = ""; +$exeext = shift @ARGV if (@ARGV > 0); + +# Open log file and /dev/null +open(LOG, ">log") or die "Failed opening test log"; +open(NULL, "+<", File::Spec->devnull) or die "Failed opening /dev/null"; + +# Open testcase index +open(TINDEX, ") { + next if ($line =~ /^(#.*)?$/); + + # Found one; decompose + (my $test, my $desc, my $data) = split /\t+/, $line; + + # Strip whitespace + $test =~ s/^\s+|\s+$//g; + $desc =~ s/^\s+|\s+$//g; + $data =~ s/^\s+|\s+$//g if ($data); + + # Append EXE extension to binary name + $test = $test . $exeext; + + print "Test: $desc\n"; + + my $pid; + + if ($data) { + # Testcase has external data files + + # Open datafile index + open(DINDEX, "<./data/$data/INDEX") or + die "Failed opening ./data/$data/INDEX"; + + # Parse datafile index, looking for datafiles + while (my $dentry = ) { + next if ($dentry =~ /^(#.*)?$/); + + # Found one; decompose + (my $dtest, my $ddesc) = split /\t+/, $dentry; + + # Strip whitespace + $dtest =~ s/^\s+|\s+$//g; + $ddesc =~ s/^\s+|\s+$//g; + + print LOG "Running ./$test ./data/Aliases " . + "./data/$data/$dtest\n"; + + # Make message fit on an 80 column terminal + my $msg = " ==> $test [$data/$dtest]"; + $msg = $msg . "." x (80 - length($msg) - 8); + + print $msg; + + # Run testcase + $pid = open3("&&NULL", + "./$test", "./data/Aliases", + "./data/$data/$dtest"); + + my $last; + + # Marshal testcase output to log file + while (my $output = ) { + print LOG " $output"; + $last = $output; + } + + # Wait for child to finish + waitpid($pid, 0); + + print substr($last, 0, 4) . "\n"; + + # Bail, noisily, on failure + if (substr($last, 0, 4) eq "FAIL") { + print "\n\nFailure detected: " . + "consult log file\n\n\n"; + + exit(1); + } + } + + close(DINDEX); + } else { + # Testcase has no external data files + print LOG "Running ./$test ./data/Aliases\n"; + + # Make message fit on an 80 column terminal + my $msg = " ==> $test"; + $msg = $msg . "." x (80 - length($msg) - 8); + + print $msg; + + # Run testcase + $pid = open3("&NULL", + "./$test", "./data/Aliases"); + + my $last; + + # Marshal testcase output to log file + while (my $output = ) { + print LOG " $output"; + $last = $output; + } + + # Wait for child to finish + waitpid($pid, 0); + + print substr($last, 0, 4) . "\n"; + + # Bail, noisily, on failure + if (substr($last, 0, 4) eq "FAIL") { + print "\n\nFailure detected: " . + "consult log file\n\n\n"; + + exit(1); + } + } + + print "\n"; +} + +# Clean up +close(TINDEX); + +close(NULL); +close(LOG); -- cgit v1.2.3