]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/commitdiff
Start of automated test suite
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 18 Jun 2010 21:48:18 +0000 (23:48 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 18 Jun 2010 21:48:18 +0000 (23:48 +0200)
Run make test in tests directory

build/aquosa/tests/Makefile [new file with mode: 0644]
build/aquosa/tests/Makefile.omk [new file with mode: 0644]
build/aquosa/tests/Makefile.test [new file with mode: 0644]
build/aquosa/tests/negotiation.cc [new file with mode: 0644]
build/aquosa/tests/t0001-negotiation.sh [new file with mode: 0755]
build/aquosa/tests/wvtest.sh [new file with mode: 0755]
build/aquosa/tests/wvtestrun [new symlink]

diff --git a/build/aquosa/tests/Makefile b/build/aquosa/tests/Makefile
new file mode 100644 (file)
index 0000000..b22a357
--- /dev/null
@@ -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 (file)
index 0000000..4d4f7b6
--- /dev/null
@@ -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 (file)
index 0000000..fb20c3e
--- /dev/null
@@ -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 (file)
index 0000000..f4cc5bf
--- /dev/null
@@ -0,0 +1,101 @@
+#include <frsh.h>
+#include <error.h>
+#include <res_dummy.h>
+#include <getopt.h>
+#include <ul_logreg.h>
+#include <wvtest.h>
+
+#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 <number>|<domain>=<number>,...\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<N; i++) {
+               ret = WVFRSH(frsh_contract_init(&contract[i]));
+               if (ret) exit(1);
+
+               ret = WVFRSH(frsh_contract_set_resource_and_label(
+                       &contract[i],
+                       DUMMY_RESOURCE_TYPE, DUMMY_RESOURCE_ID,
+                       NULL));
+               if (ret) exit(1);
+
+               budget = fosa_msec_to_rel_time(b[i]);
+               period = fosa_msec_to_rel_time(100);
+               deadline = fosa_msec_to_rel_time(50);
+               ret = WVFRSH(frsh_contract_set_basic_params(&contract[i],
+                                                           &budget,
+                                                           &period,
+                                                           FRSH_WT_BOUNDED,
+                                                           FRSH_CT_REGULAR));
+               if (ret) exit(1);
+               
+               ret = WVFRSH(frsh_contract_set_timing_reqs(&contract[i],
+                                                          false, &deadline));
+               if (ret) exit(1);
+               
+               ret = WVFRSH(frsh_contract_negotiate(&contract[i], &vres[i]));
+               if (ret) exit(1);
+       }
+       for (i=0; i<2 /*N*/; i++) {
+               // FIXME: There is a bug on the test - the 3rd renegotiation fails
+               budget = fosa_msec_to_rel_time(2*b[i]);
+               period = fosa_msec_to_rel_time(110);
+               ret = WVFRSH(frsh_contract_set_basic_params(&contract[i],
+                                                           &budget,
+                                                           &period,
+                                                           FRSH_WT_BOUNDED,
+                                                           FRSH_CT_REGULAR));
+               if (ret) exit(1);
+
+               ret = WVFRSH(frsh_contract_renegotiate_sync(&contract[i], vres[i]));
+               if (ret) exit(1);
+       }
+
+       /* Cancel N contracts */
+       for (i=0; i<N; i++) {
+               ret = WVFRSH(frsh_contract_cancel(vres[i]));
+               if (ret) exit(1);
+       }
+
+       frsh_destroy();
+}
diff --git a/build/aquosa/tests/t0001-negotiation.sh b/build/aquosa/tests/t0001-negotiation.sh
new file mode 100755 (executable)
index 0000000..2977840
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+. ./wvtest.sh
+
+WVSTART Setup
+set -e
+fcb & FCB=$!
+sleep 1
+frm_dummy & FRM=$!
+sleep 1
+negotiation.wv
+
+WVSTART Kill
+WVPASS kill $FCB
+WVPASS kill $FRM
+
diff --git a/build/aquosa/tests/wvtest.sh b/build/aquosa/tests/wvtest.sh
new file mode 100755 (executable)
index 0000000..2a40068
--- /dev/null
@@ -0,0 +1,136 @@
+#
+# Include this file in your shell script by using:
+#         #!/bin/sh
+#         . ./wvtest.sh
+#
+
+# we don't quote $TEXT in case it contains newlines; newlines
+# aren't allowed in test output.  However, we set -f so that
+# at least shell glob characters aren't processed.
+_wvtextclean()
+{
+       ( set -f; echo $* )
+}
+
+
+if [ -n "$BASH_VERSION" ]; then
+       _wvfind_caller()
+       {
+               LVL=$1
+               WVCALLER_FILE=${BASH_SOURCE[2]}
+               WVCALLER_LINE=${BASH_LINENO[1]}
+       }
+else
+       _wvfind_caller()
+       {
+               LVL=$1
+               WVCALLER_FILE="unknown"
+               WVCALLER_LINE=0
+       }
+fi
+
+
+_wvcheck()
+{
+       CODE="$1"
+       TEXT=$(_wvtextclean "$2")
+       OK=ok
+       if [ "$CODE" -ne 0 ]; then
+               OK=FAILED
+       fi
+       echo "! $WVCALLER_FILE:$WVCALLER_LINE  $TEXT  $OK" >&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 (symlink)
index 0000000..50e8b95
--- /dev/null
@@ -0,0 +1 @@
+../../../src/wvtest/wvtestrun
\ No newline at end of file