From 1ac5086c6a52a008a71d702f64e58a4ea49fc95d Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 4 Dec 2023 09:29:02 +0100 Subject: [PATCH] Tests: updated cli fuzz, vagrant, valgrind --- Makefile.in | 2 +- test/fuzz/cli/runfuzz.sh | 142 +++++++++++++++++++++++++++++++++++++-- test/lib.sh | 3 +- test/test_client.sh | 9 ++- test/vagrant/vagrant.sh | 1 + 5 files changed, 150 insertions(+), 7 deletions(-) diff --git a/Makefile.in b/Makefile.in index 123bfbcb..f1a379d6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -59,7 +59,7 @@ SUBDIRS2 = apps etc yang # without include lib for circular dependency SUBDIRS= $(SUBDIRS1) $(SUBDIRS2) .PHONY: doc example install-example clean-example all clean depend $(SUBDIRS) \ - install loc TAGS .config.status docker test checkroot mrproper \ + install loc TAGS config.status docker test checkroot mrproper \ checkinstall warnroot all: $(SUBDIRS2) warnroot diff --git a/test/fuzz/cli/runfuzz.sh b/test/fuzz/cli/runfuzz.sh index 60968e8f..f770aaf1 100755 --- a/test/fuzz/cli/runfuzz.sh +++ b/test/fuzz/cli/runfuzz.sh @@ -9,10 +9,14 @@ fi APPNAME=example cfg=conf.xml +CFD=conf.d +test -d $CFD || mkdir -p $CFD +test -d clispec || mkdir -p clispec cat < $cfg $cfg + $CFD *:* /usr/local/share/clixon clixon-example @@ -20,22 +24,152 @@ cat < $cfg /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME init - /usr/local/lib/$APPNAME/clispec + clispec /usr/local/lib/$APPNAME/cli $APPNAME 0 0 + +EOF + +cat < $CFD/autocli.xml + false include $APPNAME enable - $APPNAME + clixon-example EOF +cat < clispec/example.cli +# Clixon example specification +CLICON_MODE="example"; +CLICON_PROMPT="%U@%H %W> "; +CLICON_PLUGIN="example_cli"; + +# Autocli syntax tree operations +edit @datamodelmode, cli_auto_edit("basemodel"); +up, cli_auto_up("basemodel"); +top, cli_auto_top("basemodel"); +set @datamodel, cli_auto_set(); +merge @datamodel, cli_auto_merge(); +create @datamodel, cli_auto_create(); +delete("Delete a configuration item") { + @datamodel, cli_auto_del(); + all("Delete whole candidate configuration"), delete_all("candidate"); +} +validate("Validate changes"), cli_validate(); +commit("Commit the changes"), cli_commit(); { + [persist-id("Specify the 'persist' value of a previous confirmed-commit") ("The 'persist' value of the persistent confirmed-commit")], cli_commit(); { + ("Cancel an ongoing confirmed-commit"), cli_commit(); + ("Require a confirming commit") { + [persist("Make this confirmed-commit persistent") ("The value that must be provided as 'persist-id' in the confirming-commit or cancel-commit")] + [("The rollback timeout in seconds")], cli_commit(); + } + } +} +quit("Quit"), cli_quit(); + +debug("Debugging parts of the system"){ + cli("Set cli debug") ("Set debug level (0..n)"), cli_debug_cli(); + backend("Set backend debug") ("Set debug level (0..n)"), cli_debug_backend(); + restconf("Set restconf debug") ("Set debug level (0..n)"), cli_debug_restconf(); +} + +copy("Copy and create a new object") { + running("Copy from running db") startup("Copy to startup config"), db_copy("running", "startup"); + interface("Copy interface"){ + (|("name of interface to copy from")) to("Copy to interface") ("Name of interface to copy to"), cli_copy_config("candidate","//interface[%s='%s']","urn:ietf:params:xml:ns:yang:ietf-interfaces","name","name","toname"); + } +} +discard("Discard edits (rollback 0)"), discard_changes(); + +show("Show a particular state of the system"){ + auto("Show expand x"){ + xml @datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all"); + text @datamodelshow, cli_show_auto("candidate", "text", true, false, "report-all"); + json @datamodelshow, cli_show_auto("candidate", "json", true, false, "report-all"); + netconf @datamodelshow, cli_show_auto("candidate", "netconf", true, false, "report-all"); + cli @datamodelshow, cli_show_auto("candidate", "cli", true, false, "report-all", "set "); + } + xpath("Show configuration") ("XPATH expression") + [("Namespace")], show_conf_xpath("candidate"); + version("Show version"), cli_show_version("candidate", "text", "/"); + options("Show clixon options"), cli_show_options(); + compare("Compare candidate and running databases"), compare_dbs("running", "candidate", "xml");{ + xml("Show comparison in xml"), compare_dbs("running", "candidate", "xml"); + text("Show comparison in text"), compare_dbs("running", "candidate", "text"); + } + pagination("Show list pagination") xpath("Show configuration") ("XPATH expression"){ + xml, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "xml", "10"); + cli, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "cli", "10"); + text, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "text", "10"); + json, cli_pagination("use xpath var", "es", "http://example.com/ns/example-social", "json", "10"); + } + configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false);{ + xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false);{ + default("With-default mode"){ + report-all, cli_show_auto_mode("candidate", "xml", true, false, "report-all"); + trim, cli_show_auto_mode("candidate", "xml", true, false, "trim"); + explicit, cli_show_auto_mode("candidate", "xml", true, false, "explicit"); + report-all-tagged, cli_show_auto_mode("candidate", "xml", true, false, "report-all-tagged"); + report-all-tagged-default, cli_show_auto_mode("candidate", "xml", true, false, "report-all-tagged-default"); + report-all-tagged-strip, cli_show_auto_mode("candidate", "xml", true, false, "report-all-tagged-strip"); + } + } + cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "explicit", "set "); + netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", true, false); + text("Show configuration as text"), cli_show_auto_mode("candidate", "text", true, false); + json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", true, false); + + } + state("Show configuration and state"), cli_show_auto_mode("running", "text", true, true); { + xml("Show configuration and state as XML"), cli_show_auto_mode("running", "xml", true, true);{ + default("With-default mode"){ + report-all, cli_show_auto_mode("running", "xml", true, true, "report-all"); + trim, cli_show_auto_mode("running", "xml", true, true, "trim"); + explicit, cli_show_auto_mode("running", "xml", true, true, "explicit"); + report-all-tagged, cli_show_auto_mode("running", "xml", true, true, "report-all-tagged"); + report-all-tagged-default, cli_show_auto_mode("running", "xml", true, true, "report-all-tagged-default"); + report-all-tagged-strip, cli_show_auto_mode("running", "xml", true, true, "report-all-tagged-strip"); + } + } + } + yang("Show yang specs"), show_yang(); { + clixon-example("Show clixon-example yang spec"), show_yang("clixon-example"); + } + statistics("Show statistics"), cli_show_statistics();{ + brief, cli_show_statistics(); + modules, cli_show_statistics("modules"); + } +} +load("Load configuration from XML file") ("Filename (local filename)"),load_config_file("filename", "replace");{ + replace("Replace candidate with file contents"), load_config_file("filename", "replace");{ + cli("Replace candidate with file containing CLI commands"), load_config_file("filename", "replace", "cli"); + xml("Replace candidate with file containing XML"), load_config_file("filename", "replace", "xml"); + json("Replace candidate with file containing JSON"), load_config_file("filename", "replace", "json"); + text("Replace candidate with file containing TEXT"), load_config_file("filename", "replace", "text"); + } + merge("Merge file with existent candidate"), load_config_file("filename", "merge");{ + cli("Merge candidate with file containing CLI commands"), load_config_file("filename", "merge", "cli"); + xml("Merge candidate with file containing XML"), load_config_file("filename", "merge", "xml"); + json("Merge candidate with file containing JSON"), load_config_file("filename", "merge", "json"); + text("Merge candidate with file containing TEXT"), load_config_file("filename", "merge", "text"); + } +} +example("This is a comment") ("Just a random number"), mycallback("myarg"); +rpc("example rpc") ("routing instance"), example_client_rpc(""); +notify("Get notifications from backend"), cli_notify("EXAMPLE", "1", "text"); +no("Negate") notify("Get notifications from backend"), cli_notify("EXAMPLE", "0", "xml"); +lock,cli_lock("candidate"); +unlock,cli_unlock("candidate"); +restart , cli_restart_plugin(); +EOF + # Kill previous sudo clixon_backend -z -f $cfg -s init @@ -44,7 +178,7 @@ sudo clixon_backend -f $cfg -s init MEGS=500 # memory limit for child process (50 MB) -# remove input and input dirs +# remove input and input dirs XXX #test ! -d input || rm -rf input test ! -d output || rm -rf output @@ -53,4 +187,4 @@ test ! -d output || rm -rf output test -d output || mkdir output # Run script -afl-fuzz -i input -o output -m $MEGS -- clixon_cli -f $cfg +afl-fuzz -i input -o output -m $MEGS -- /usr/local/bin/clixon_cli -f $cfg diff --git a/test/lib.sh b/test/lib.sh index 616c7837..0a5d5222 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -201,7 +201,8 @@ BUSER=clicon : ${_ALREADY_HERE:=0} if [ -n "$CLICON_GROUP" ] && [ $_ALREADY_HERE -eq 0 ]; then - # Extra test for some archs, ie ubuntu 18 that have problems with this + # Extra test for some archs, eg ubuntu 18 that have problems with: + # Sorry, user is not allowed to execute as :clicon on sudo -g ${CLICON_GROUP} $clixon_netconf 2> /dev/null if [ $? -eq 0 ]; then clixon_cli="sudo -g ${CLICON_GROUP} $clixon_cli" diff --git a/test/test_client.sh b/test/test_client.sh index 8b6e317d..9f3c6757 100755 --- a/test/test_client.sh +++ b/test/test_client.sh @@ -165,7 +165,14 @@ new "Check entries" expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/clixon-client:table -H 'Accept: application/yang-data+xml')" 0 "HTTP/$HVER 200" "$XML" new "Run $app" -expectpart "$(sudo -g ${CLICON_GROUP} $app)" 0 '^42$' +# Extra test for some archs, eg ubuntu 18 that have problems with: +# Sorry, user is not allowed to execute as :clicon on +sudo -g ${CLICON_GROUP} $clixon_netconf 2> /dev/null +if [ $? -eq 0 ]; then + expectpart "$(sudo -g ${CLICON_GROUP} $app)" 0 '^42$' +else + expectpart "$($app)" 0 '^42$' +fi if [ $RC -ne 0 ]; then new "Kill restconf daemon" diff --git a/test/vagrant/vagrant.sh b/test/vagrant/vagrant.sh index 8bd1fedf..8584e60a 100755 --- a/test/vagrant/vagrant.sh +++ b/test/vagrant/vagrant.sh @@ -271,6 +271,7 @@ case ${with_restconf} in . ./nginx.sh $dir $idfile $port $wwwuser ;; native) + $sshcmd sudo pkill nginx | true ;; esac