Mailinglist Archive: yast-devel (177 mails)

< Previous Next >
[yast-devel] [PATCH 09/11] Move agent-dummy to new structure, drop dependency on YCP
From: Stanislav Visnovsky <visnov@xxxxxxxxxx>

This patch moves the agent to new test framework (like agent-resolver).
It also does not log using ycpdebug bug proper y2debug.
---
core/agent-dummy/src/DummyAgent.cc | 8 +-
core/agent-dummy/testsuite/Makefile.am | 22 ++++---
.../testsuite/ag_dummy.test/Makefile.am | 3 +
.../testsuite/ag_dummy.test/ag_dummy.exp | 12 +++
core/agent-dummy/testsuite/config/Makefile.am | 3 +
core/agent-dummy/testsuite/config/default.exp | 2 +
core/agent-dummy/testsuite/config/unix.exp | 5 ++
core/agent-dummy/testsuite/config/unknown.exp | 2 +
core/agent-dummy/testsuite/lib/Makefile.am | 3 +
core/agent-dummy/testsuite/lib/ag_dummy_init.exp | 76 ++++++++++++++++++++
core/agent-dummy/testsuite/rundummy.cc | 14 ++++
core/agent-dummy/testsuite/tests/Makefile.am | 3 +
core/agent-dummy/testsuite/tests/runtest.sh | 18 +++++
13 files changed, 158 insertions(+), 13 deletions(-)
create mode 100644 core/agent-dummy/testsuite/ag_dummy.test/Makefile.am
create mode 100644 core/agent-dummy/testsuite/ag_dummy.test/ag_dummy.exp
create mode 100644 core/agent-dummy/testsuite/config/Makefile.am
create mode 100644 core/agent-dummy/testsuite/config/default.exp
create mode 100644 core/agent-dummy/testsuite/config/unix.exp
create mode 100644 core/agent-dummy/testsuite/config/unknown.exp
create mode 100644 core/agent-dummy/testsuite/lib/Makefile.am
create mode 100644 core/agent-dummy/testsuite/lib/ag_dummy_init.exp
create mode 100644 core/agent-dummy/testsuite/rundummy.cc
create mode 100644 core/agent-dummy/testsuite/tests/Makefile.am
create mode 100755 core/agent-dummy/testsuite/tests/runtest.sh
delete mode 100644 core/agent-dummy/testsuite/y2ag_dummy.cc

diff --git a/core/agent-dummy/src/DummyAgent.cc
b/core/agent-dummy/src/DummyAgent.cc
index e778738..c59b0b2 100644
--- a/core/agent-dummy/src/DummyAgent.cc
+++ b/core/agent-dummy/src/DummyAgent.cc
@@ -50,7 +50,7 @@ DummyAgent::Read (const YCPPath& path, const YCPValue& arg ,
const YCPValue&)
v = checkPath(path, defaultMap, deflt);
}

- ycpdebug("%sRead %s", DUMMY_LOG_STRING,
+ y2debug("%sRead %s", DUMMY_LOG_STRING,
(path->toString() + (arg.isNull()?"":(" "+arg->toString())) +
(v.isNull()?"":(" "+v->toString())) ).c_str());

@@ -78,7 +78,7 @@ DummyAgent::Write (const YCPPath& path, const YCPValue& value,
v = checkPath(path, defaultMap, deflt);
}

- ycpdebug("%sWrite %s", DUMMY_LOG_STRING,
+ y2debug("%sWrite %s", DUMMY_LOG_STRING,
(path->toString() + " " + value->toString() +
(arg.isNull()?"":(" "+arg->toString())) +
(v.isNull()?"":(" "+v->toString())) ).c_str());
@@ -107,7 +107,7 @@ DummyAgent::Execute (const YCPPath& path, const YCPValue&
value,
v = checkPath(path, defaultMap, deflt);
}

- ycpdebug("%sExecute %s", DUMMY_LOG_STRING,
+ y2debug("%sExecute %s", DUMMY_LOG_STRING,
(path->toString() + " " + value->toString() +
(arg.isNull()?"":(" "+arg->toString())) +
(v.isNull()?"":(" "+v->toString())) ).c_str());
@@ -136,7 +136,7 @@ YCPList DummyAgent::Dir(const YCPPath& path)
}
}

- ycpdebug("%sDir %s: %s", DUMMY_LOG_STRING,
+ y2debug("%sDir %s: %s", DUMMY_LOG_STRING,
path->toString().c_str(), l->toString ().c_str ());

return l;
diff --git a/core/agent-dummy/testsuite/Makefile.am
b/core/agent-dummy/testsuite/Makefile.am
index 9a4d0a4..6d6bb74 100644
--- a/core/agent-dummy/testsuite/Makefile.am
+++ b/core/agent-dummy/testsuite/Makefile.am
@@ -1,19 +1,23 @@
-#
# Makefile.am for core/agent-dummy/testsuite
-#
+
+SUBDIRS = config lib ag_dummy.test tests

AM_CXXFLAGS = -DY2LOG=\"agent-dummy\"

+PACKAGE = ag_dummy
AUTOMAKE_OPTIONS = dejagnu

-INCLUDES = \
- ${Y2UTIL_CFLAGS}
+INCLUDES = ${AGENT_INCLUDES}

-noinst_PROGRAMS = y2ag_dummy
+noinst_PROGRAMS = rundummy

-y2ag_dummy_SOURCES = y2ag_dummy.cc
-y2ag_dummy_LDADD = ${AGENT_LIBADD}
-y2ag_dummy_LDFLAGS = \
- -Xlinker --whole-archive \
+rundummy_SOURCES = rundummy.cc
+rundummy_LDADD = ${AGENT_LIBADD}
+rundummy_LDFLAGS = \
+ -Xlinker --whole-archive \
../src/libpy2ag_dummy.la \
-Xlinker --no-whole-archive
+
+clean-local:
+ rm -f tmp.err.* tmp.out.* site.exp *.log *.sum *.bak
+
diff --git a/core/agent-dummy/testsuite/ag_dummy.test/Makefile.am
b/core/agent-dummy/testsuite/ag_dummy.test/Makefile.am
new file mode 100644
index 0000000..be14737
--- /dev/null
+++ b/core/agent-dummy/testsuite/ag_dummy.test/Makefile.am
@@ -0,0 +1,3 @@
+# Makefile.am for core/agent-resolver/testsuite/ag_dummy.test
+
+EXTRA_DIST = ag_dummy.exp
diff --git a/core/agent-dummy/testsuite/ag_dummy.test/ag_dummy.exp
b/core/agent-dummy/testsuite/ag_dummy.test/ag_dummy.exp
new file mode 100644
index 0000000..af44db5
--- /dev/null
+++ b/core/agent-dummy/testsuite/ag_dummy.test/ag_dummy.exp
@@ -0,0 +1,12 @@
+#
+# ag_rcconfig.exp
+# 'main' file for all ag_rcconfig tests
+#
+
+# get all files matching tests/*.ycp
+
+set filenames [lsort [glob $srcdir/tests/*.ycp]]
+
+# foreach file, call ycp-run (from testsuite/lib)
+
+foreach file $filenames { ycp-run $file }
diff --git a/core/agent-dummy/testsuite/config/Makefile.am
b/core/agent-dummy/testsuite/config/Makefile.am
new file mode 100644
index 0000000..8a4c15c
--- /dev/null
+++ b/core/agent-dummy/testsuite/config/Makefile.am
@@ -0,0 +1,3 @@
+# Makefile.am for core/agent-resolver/testsuite/config
+
+EXTRA_DIST = default.exp unix.exp unknown.exp
diff --git a/core/agent-dummy/testsuite/config/default.exp
b/core/agent-dummy/testsuite/config/default.exp
new file mode 100644
index 0000000..fe1e08a
--- /dev/null
+++ b/core/agent-dummy/testsuite/config/default.exp
@@ -0,0 +1,2 @@
+# default.exp -- empty
+
diff --git a/core/agent-dummy/testsuite/config/unix.exp
b/core/agent-dummy/testsuite/config/unix.exp
new file mode 100644
index 0000000..956160e
--- /dev/null
+++ b/core/agent-dummy/testsuite/config/unix.exp
@@ -0,0 +1,5 @@
+load_lib "ag_dummy_init.exp"
+
+proc ag_dummy_exit {} {}
+proc ag_dummy_version {} {}
+
diff --git a/core/agent-dummy/testsuite/config/unknown.exp
b/core/agent-dummy/testsuite/config/unknown.exp
new file mode 100644
index 0000000..fe48c2f
--- /dev/null
+++ b/core/agent-dummy/testsuite/config/unknown.exp
@@ -0,0 +1,2 @@
+perror "No setup for current configuration"
+exit 1
diff --git a/core/agent-dummy/testsuite/lib/Makefile.am
b/core/agent-dummy/testsuite/lib/Makefile.am
new file mode 100644
index 0000000..da7c1ba
--- /dev/null
+++ b/core/agent-dummy/testsuite/lib/Makefile.am
@@ -0,0 +1,3 @@
+# Makefile.am for core/agent-dummy/testsuite/lib
+
+EXTRA_DIST = ag_dummy_init.exp
diff --git a/core/agent-dummy/testsuite/lib/ag_dummy_init.exp
b/core/agent-dummy/testsuite/lib/ag_dummy_init.exp
new file mode 100644
index 0000000..5740bfe
--- /dev/null
+++ b/core/agent-dummy/testsuite/lib/ag_dummy_init.exp
@@ -0,0 +1,76 @@
+#
+# run a ycp file
+#
+proc ycp-run { src } {
+
+ set path [split $src "/"]
+ set filename [lindex $path [expr [llength $path]-1]]
+
+ # extract basename and check extension
+
+ set fname [split $filename "."]
+
+ if {[llength $fname] < 2} {
+ fail "Bad filename syntax '$src'"
+ return -1
+ }
+ if {[lindex $fname [expr [llength $fname]-1]] != "ycp"} {
+ fail "Not .ycp extension '$src'"
+ return -1
+ }
+
+ # setup filenames
+
+ # $src is the name of the original testfile with absolute path
+ # tests/$filename is the name of the original testfile with relative path,
+ # relative to the testsuite directory
+ set test_input "tests/$filename"
+
+ set base_name [lindex $fname 0]
+
+ set stdout_name "tests/$base_name.out"
+ set stderr_name "tests/$base_name.err"
+ set log_name "tests/$base_name.log"
+ set tmpout_name "tmp.out.$base_name"
+ set tmperr_name "tmp.err.$base_name"
+ set tmplog_name "tmp.log.$base_name"
+
+ puts "Running $base_name..."
+
+ # run the test
+
+ set result ""
+ set oops [catch { set result [exec "tests/runtest.sh" "$test_input"
"$tmpout_name" "$tmperr_name" ] } catched]
+
+ if {$oops != 0} {
+ fail "test case failed for $base_name: $catched"
+ return -1
+ }
+
+ # check return code from runycp
+
+ if {$result != ""} {
+ warning "Compilation of $base_name results in '$result'"
+ return -1
+ }
+
+ # check stderr
+
+ if {[diff $stderr_name "tmp.err.$base_name"] != 1} {
+ fail "Wrong stderr for $base_name"
+ return -1
+ }
+
+ # check stdout
+
+ if {[diff $stdout_name "tmp.out.$base_name"] != 1} {
+ fail "Wrong stdout for $base_name"
+ return -1
+ }
+
+ # ok, all is fine
+
+ pass $base_name
+
+ return 0
+}
diff --git a/core/agent-dummy/testsuite/rundummy.cc
b/core/agent-dummy/testsuite/rundummy.cc
new file mode 100644
index 0000000..801b12e
--- /dev/null
+++ b/core/agent-dummy/testsuite/rundummy.cc
@@ -0,0 +1,14 @@
+/*
+ * Author: Arvin Schnell <arvin@xxxxxxx>
+ */
+
+#include <scr/run_agent.h>
+
+#include "../src/DummyAgent.h"
+
+
+int
+main (int argc, char *argv[])
+{
+ run_agent <DummyAgent> (argc, argv, true);
+}
diff --git a/core/agent-dummy/testsuite/tests/Makefile.am
b/core/agent-dummy/testsuite/tests/Makefile.am
new file mode 100644
index 0000000..fca63e0
--- /dev/null
+++ b/core/agent-dummy/testsuite/tests/Makefile.am
@@ -0,0 +1,3 @@
+# Makefile.am for core/agent-dummy/testsuite/tests
+
+EXTRA_DIST = *.ycp *.in *.out *.err runtest.sh
diff --git a/core/agent-dummy/testsuite/tests/runtest.sh
b/core/agent-dummy/testsuite/tests/runtest.sh
new file mode 100755
index 0000000..a4a5177
--- /dev/null
+++ b/core/agent-dummy/testsuite/tests/runtest.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+unset Y2DEBUG
+unset Y2DEBUGALL
+unset Y2DEBUGGER
+
+IN_FILE=${1%.*}".in"
+rm -f "$IN_FILE.test" 2>/dev/null
+cp $IN_FILE "$IN_FILE.test" 2>/dev/null
+
+SCR_FILE=${1%.*}".scr"
+rm -f "$SCR_FILE" 2>/dev/null
+echo -e ".\n\n\`ag_resolver(\n \`ResolverAgent(\"$IN_FILE.test\")\n)\n"
"$SCR_FILE"
+
+(./runresolver -l - "$1" >"$2") 2>&1 | fgrep -v " <0> " | grep -v "^$" | sed
's/^....-..-.. ..:..:.. [^)]*) //g' >$3
+
+cat "$IN_FILE.test" >>"$2" 2>/dev/null
+exit 0
diff --git a/core/agent-dummy/testsuite/y2ag_dummy.cc
b/core/agent-dummy/testsuite/y2ag_dummy.cc
deleted file mode 100644
index e69de29..0000000
--
1.7.3.2

--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
References