From 8092a7aff9e2fd7dfbb008ee85623c3f8816bf36 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Fri, 18 Jun 2010 23:48:18 +0200 Subject: [PATCH] Start of automated test suite Run make test in tests directory --- build/aquosa/tests/Makefile | 14 +++ build/aquosa/tests/Makefile.omk | 9 ++ build/aquosa/tests/Makefile.test | 12 +++ build/aquosa/tests/negotiation.cc | 101 ++++++++++++++++++ build/aquosa/tests/t0001-negotiation.sh | 16 +++ build/aquosa/tests/wvtest.sh | 136 ++++++++++++++++++++++++ build/aquosa/tests/wvtestrun | 1 + 7 files changed, 289 insertions(+) create mode 100644 build/aquosa/tests/Makefile create mode 100644 build/aquosa/tests/Makefile.omk create mode 100644 build/aquosa/tests/Makefile.test create mode 100644 build/aquosa/tests/negotiation.cc create mode 100755 build/aquosa/tests/t0001-negotiation.sh create mode 100755 build/aquosa/tests/wvtest.sh create mode 120000 build/aquosa/tests/wvtestrun diff --git a/build/aquosa/tests/Makefile b/build/aquosa/tests/Makefile new file mode 100644 index 00000000..b22a3576 --- /dev/null +++ b/build/aquosa/tests/Makefile @@ -0,0 +1,14 @@ +# Generic directory or leaf node makefile for OCERA make framework + +ifndef MAKERULES_DIR +MAKERULES_DIR := $(shell ( old_pwd="" ; while [ ! -e Makefile.rules ] ; do if [ "$$old_pwd" = `pwd` ] ; then exit 1 ; else old_pwd=`pwd` ; cd -L .. 2>/dev/null ; fi ; done ; pwd ) ) +endif + +ifeq ($(MAKERULES_DIR),) +all : default +.DEFAULT:: + @echo -e "\nThe Makefile.rules has not been found in this or partent directory\n" +else +include $(MAKERULES_DIR)/Makefile.rules +endif + diff --git a/build/aquosa/tests/Makefile.omk b/build/aquosa/tests/Makefile.omk new file mode 100644 index 00000000..4d4f7b6c --- /dev/null +++ b/build/aquosa/tests/Makefile.omk @@ -0,0 +1,9 @@ +CFLAGS += -DWVTEST_CONFIGURED + +test: + $(MAKE) -f Makefile.test + +lib_LOADLIBES = wvtest frsh + +test_PROGRAMS += negotiation.wv +negotiation.wv_SOURCES = negotiation.cc diff --git a/build/aquosa/tests/Makefile.test b/build/aquosa/tests/Makefile.test new file mode 100644 index 00000000..fb20c3e6 --- /dev/null +++ b/build/aquosa/tests/Makefile.test @@ -0,0 +1,12 @@ + +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) + +all: + ./wvtestrun $(MAKE) -f Makefile.test test + +test: $(T) + +.PHONY: $(T) +$(T): + bash $@ + diff --git a/build/aquosa/tests/negotiation.cc b/build/aquosa/tests/negotiation.cc new file mode 100644 index 00000000..f4cc5bfd --- /dev/null +++ b/build/aquosa/tests/negotiation.cc @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include +#include + +#define N 3 + +int b[N] = { 10, 20, 30 }; + +// TODO: Allow specifying loglevel in evironment + +// static struct option long_opts[] = { +// { "loglevel", 1, 0, 'l' }, +// { 0, 0, 0, 0} +// }; + +// static void +// usage(void) +// { +// printf("usage: negotiation [ options ]\n"); +// printf(" -l, --loglevel |=,...\n"); +// } + + +WVTEST_MAIN("basic negotiation") +{ + int ret; + frsh_contract_t contract[N]; + frsh_vres_id_t vres[N]; + frsh_rel_time_t budget, period, deadline; + int i; +// char opt; + +// while ((opt = getopt_long(argc, argv, "l:", &long_opts[0], NULL)) != EOF) { +// switch (opt) { +// case 'l': + ul_log_domain_arg2levels("forb_proto_inet=6"); +// break; +// case 'h': +// /\*default:*\/ +// usage(); +// exit(opt == 'h' ? 0 : 1); +// } +// } + + ret = WVFRSH(frsh_init()); + if (ret) exit(1); + + /* Negotiate N contracts */ + for (i=0; i&2 + if [ "$CODE" -ne 0 ]; then + exit $CODE + else + return 0 + fi +} + + +WVPASS() +{ + TEXT="$*" + + _wvfind_caller + if "$@"; then + _wvcheck 0 "$TEXT" + return 0 + else + _wvcheck 1 "$TEXT" + # NOTREACHED + return 1 + fi +} + + +WVFAIL() +{ + TEXT="$*" + + _wvfind_caller + if "$@"; then + _wvcheck 1 "NOT($TEXT)" + # NOTREACHED + return 1 + else + _wvcheck 0 "NOT($TEXT)" + return 0 + fi +} + + +_wvgetrv() +{ + ( "$@" >&2 ) + echo -n $? +} + + +WVPASSEQ() +{ + _wvfind_caller + _wvcheck $(_wvgetrv [ "$#" -eq 2 ]) "exactly 2 arguments" + echo "Comparing:" >&2 + echo "$1" >&2 + echo "--" >&2 + echo "$2" >&2 + _wvcheck $(_wvgetrv [ "$1" = "$2" ]) "'$1' = '$2'" +} + + +WVPASSNE() +{ + _wvfind_caller + _wvcheck $(_wvgetrv [ "$#" -eq 2 ]) "exactly 2 arguments" + echo "Comparing:" >&2 + echo "$1" >&2 + echo "--" >&2 + echo "$2" >&2 + _wvcheck $(_wvgetrv [ "$1" != "$2" ]) "'$1' != '$2'" +} + + +WVPASSRC() +{ + RC=$? + _wvfind_caller + _wvcheck $(_wvgetrv [ $RC -eq 0 ]) "return code($RC) == 0" +} + + +WVFAILRC() +{ + RC=$? + _wvfind_caller + _wvcheck $(_wvgetrv [ $RC -ne 0 ]) "return code($RC) != 0" +} + + +WVSTART() +{ + echo >&2 + _wvfind_caller + echo "Testing \"$*\" in $WVCALLER_FILE:" >&2 +} + +PATH=$PATH:../_compiled/bin:../_compiled/bin-tests diff --git a/build/aquosa/tests/wvtestrun b/build/aquosa/tests/wvtestrun new file mode 120000 index 00000000..50e8b95d --- /dev/null +++ b/build/aquosa/tests/wvtestrun @@ -0,0 +1 @@ +../../../src/wvtest/wvtestrun \ No newline at end of file -- 2.39.2