From f5250b136c50e6b98f0aad2c4e13a6efd5c817b6 Mon Sep 17 00:00:00 2001 From: Olof Hagsand Date: Mon, 6 Mar 2017 19:40:39 +0100 Subject: [PATCH] test --- test/clixon | 23 +++++++++++++++++++---- test/lib.sh | 22 ++++++++++++++++++++++ test/test2.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100755 test/test2.sh diff --git a/test/clixon b/test/clixon index 749d754c..9c38654a 100755 --- a/test/clixon +++ b/test/clixon @@ -10,17 +10,32 @@ err(){ } # cd to working dir -cd /tmp +cd /var/tmp if [ $# -ne 0 ]; then err "usage: $0" 0 fi +rm -rf cligen rm -rf clixon +git clone https://github.com/olofhagsand/cligen.git +if [ $? -ne 0 ]; then + err "git clone cligen" 1 +fi +cd cligen +CFLAGS=-Werror ./configure +if [ $? -ne 0 ]; then + err "configure" 2 +fi +make +if [ $? -ne 0 ]; then + err "make" 3 +fi +cd .. git clone https://github.com/clicon/clixon.git if [ $? -ne 0 ]; then - err "git clone" 1 + err "git clone clixon" 1 fi cd clixon -CFLAGS=-Werror ./configure +CFLAGS=-Werror ./configure --with-cligen=../cligen if [ $? -ne 0 ]; then err "configure" 2 fi @@ -54,5 +69,5 @@ if [ $errcode -ne 0 ]; then err "test" $errcode fi cd ../.. -rm -rf clixon +rm -rf clixon cligen logger "CLIXON: tests OK" diff --git a/test/lib.sh b/test/lib.sh index 8a1a8129..99040a00 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -30,6 +30,7 @@ expectfn(){ if [ -z "$ret" -a -z "$expect" ]; then return fi + # grep extended grep match=`echo "$ret" | grep -Eo "$expect"` # echo "ret:$ret" # echo "expect:$expect" @@ -39,3 +40,24 @@ expectfn(){ fi } +# clicon_cli tester. First arg is command and second is expected outcome +expecteof(){ + cmd=$1 + input=$2 + expect=$3 + +# Do while read stuff +ret=$($cmd<]]>]]>" "]]>]]>" + +new "netconf lock" +expecteof "clixon_netconf -qf $clixon_cf" "]]>]]>" "]]>]]>" + +new "Kill backend" +# Check if still alive +pid=`pgrep clixon_backend` +if [ -z "$pid" ]; then + err "backend already dead" +fi +# kill backend +sudo clixon_backend -zf $clixon_cf +if [ $? -ne 0 ]; then + err "kill backend" +fi +