From e1b94d94d237f7a83ec43a48760159c78be1b412 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 7 Dec 2020 09:56:07 +0100 Subject: [PATCH] * Ensure all fopen check for NULL (not -1) * Improve test-perf cycles --- apps/backend/backend_startup.c | 2 +- apps/cli/cli_common.c | 2 +- example/main/example_backend.c | 4 ++-- lib/src/clixon_datastore_read.c | 2 +- lib/src/clixon_options.c | 2 +- lib/src/clixon_xml_changelog.c | 2 +- lib/src/clixon_xml_io.c | 3 ++- test/test_copy_config.sh | 4 ++-- test/test_perf_cli.sh | 2 +- test/test_perf_mem.sh | 2 +- test/test_perf_netconf.sh | 2 +- test/test_perf_restconf.sh | 2 +- test/test_perf_startup.sh | 2 +- test/test_perf_state.sh | 2 +- test/test_perf_state_only.sh | 2 +- util/clixon_util_datastore.c | 2 +- util/clixon_util_path.c | 2 +- util/clixon_util_socket.c | 2 +- util/clixon_util_xml.c | 4 ++-- util/clixon_util_xpath.c | 2 +- 20 files changed, 24 insertions(+), 23 deletions(-) diff --git a/apps/backend/backend_startup.c b/apps/backend/backend_startup.c index e347e158..59203fc7 100644 --- a/apps/backend/backend_startup.c +++ b/apps/backend/backend_startup.c @@ -173,7 +173,7 @@ load_extraxml(clicon_handle h, if (filename == NULL) return 1; - if ((fp = fopen(filename, "r")) < 0){ + if ((fp = fopen(filename, "r")) == NULL){ clicon_err(OE_UNIX, errno, "open(%s)", filename); goto done; } diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index f95cdd73..40ea7d98 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -811,7 +811,7 @@ load_config_file(clicon_handle h, goto done; } /* Open and parse local file into xml */ - if ((fp = fopen(filename, "r")) < 0){ + if ((fp = fopen(filename, "r")) == NULL){ clicon_err(OE_UNIX, errno, "open(%s)", filename); goto done; } diff --git a/example/main/example_backend.c b/example/main/example_backend.c index b7a21ffd..c6a979f9 100644 --- a/example/main/example_backend.c +++ b/example/main/example_backend.c @@ -402,7 +402,7 @@ example_statedata(clicon_handle h, } else{ cxobj *x1; - if ((fp = fopen(_state_file, "r")) < 0){ + if ((fp = fopen(_state_file, "r")) == NULL){ clicon_err(OE_UNIX, errno, "open(%s)", _state_file); goto done; } @@ -984,7 +984,7 @@ example_daemon(clicon_handle h) /* Read state file (or should this be in init/start?) */ if (_state && _state_file && _state_file_init){ yspec = clicon_dbspec_yang(h); - if ((fp = fopen(_state_file, "r")) < 0){ + if ((fp = fopen(_state_file, "r")) == NULL){ clicon_err(OE_UNIX, errno, "open(%s)", _state_file); goto done; } diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index 9273db5a..144a9fee 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -453,7 +453,7 @@ xmldb_readfile(clicon_handle h, goto done; } /* Parse file into internal XML tree from different formats */ - if ((fp = fopen(dbfile, "r")) < 0) { + if ((fp = fopen(dbfile, "r")) == NULL) { clicon_err(OE_UNIX, errno, "open(%s)", dbfile); goto done; } diff --git a/lib/src/clixon_options.c b/lib/src/clixon_options.c index 62729dba..c1b2f15d 100644 --- a/lib/src/clixon_options.c +++ b/lib/src/clixon_options.c @@ -211,7 +211,7 @@ parse_configfile_one(const char *filename, cbuf *cbret = NULL; int ret; - if ((fp = fopen(filename, "r")) < 0){ + if ((fp = fopen(filename, "r")) == NULL){ clicon_err(OE_UNIX, errno, "open configure file: %s", filename); return -1; } diff --git a/lib/src/clixon_xml_changelog.c b/lib/src/clixon_xml_changelog.c index 6ac20eab..9bcce257 100644 --- a/lib/src/clixon_xml_changelog.c +++ b/lib/src/clixon_xml_changelog.c @@ -445,7 +445,7 @@ clixon_xml_changelog_init(clicon_handle h) yspec = clicon_dbspec_yang(h); if ((filename = clicon_option_str(h, "CLICON_XML_CHANGELOG_FILE")) != NULL){ - if ((fp = fopen(filename, "r")) < 0){ + if ((fp = fopen(filename, "r")) == NULL){ clicon_err(OE_UNIX, errno, "fopen(%s)", filename); goto done; } diff --git a/lib/src/clixon_xml_io.c b/lib/src/clixon_xml_io.c index 2fef4436..203c51a1 100644 --- a/lib/src/clixon_xml_io.c +++ b/lib/src/clixon_xml_io.c @@ -582,7 +582,8 @@ FSM(char *tag, * cxobj *xt = NULL; * cxobj *xerr = NULL; * FILE *f; - * f = fopen(filename, "r"); + * if ((f = fopen(filename, "r")) == NULL) + * err; * if ((ret = clixon_xml_parse_file(f, YB_MODULE, yspec, "", &xt, &xerr)) < 0) * err; * xml_free(xt); diff --git a/test/test_copy_config.sh b/test/test_copy_config.sh index 4697f0ba..cc9149d7 100755 --- a/test/test_copy_config.sh +++ b/test/test_copy_config.sh @@ -168,10 +168,10 @@ fi # restconf copy new "restconf copy-config smoketest, json" -expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" http://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '{"ietf-netconf:input": {"target": {"startup": [null]},"source": {"running": [null]}}}')" 0 'HTTP/1.1 204 No Content' +expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" $RCPROTO://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '{"ietf-netconf:input": {"target": {"startup": [null]},"source": {"running": [null]}}}')" 0 'HTTP/1.1 204 No Content' new "restconf copy-config smoketest, xml" -expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" http://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '')" 0 'HTTP/1.1 204 No Content' +expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" $RCPROTO://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '')" 0 'HTTP/1.1 204 No Content' # Here running is empty new "Check running empty" diff --git a/test/test_perf_cli.sh b/test/test_perf_cli.sh index abcbb08b..779e48b9 100755 --- a/test/test_perf_cli.sh +++ b/test/test_perf_cli.sh @@ -10,7 +10,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi : ${format:=xml} # Number of list/leaf-list entries in file -: ${perfnr:=10000} +: ${perfnr:=20000} # Number of requests made get/put : ${perfreq:=10} diff --git a/test/test_perf_mem.sh b/test/test_perf_mem.sh index 4c5f9ee4..568fda1c 100755 --- a/test/test_perf_mem.sh +++ b/test/test_perf_mem.sh @@ -14,7 +14,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi clixon_util_xpath=clixon_util_xpath # Number of list/leaf-list entries in file -: ${perfnr:=1000} # 10000 causes timeout in valgrind test +: ${perfnr:=2000} # 10000 causes timeout in valgrind test APPNAME=example diff --git a/test/test_perf_netconf.sh b/test/test_perf_netconf.sh index 441ecc4b..41ac4e3e 100755 --- a/test/test_perf_netconf.sh +++ b/test/test_perf_netconf.sh @@ -11,7 +11,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi : ${format:=xml} # Number of list/leaf-list entries in file -: ${perfnr:=10000} +: ${perfnr:=20000} # Number of requests made get/put : ${perfreq:=10} diff --git a/test/test_perf_restconf.sh b/test/test_perf_restconf.sh index 0835d20b..bd60f02c 100755 --- a/test/test_perf_restconf.sh +++ b/test/test_perf_restconf.sh @@ -11,7 +11,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi : ${format:=xml} # Number of list/leaf-list entries in file -: ${perfnr:=10000} +: ${perfnr:=20000} # Number of requests made get/put : ${perfreq:=10} diff --git a/test/test_perf_startup.sh b/test/test_perf_startup.sh index 1da4f27e..33f55a94 100755 --- a/test/test_perf_startup.sh +++ b/test/test_perf_startup.sh @@ -7,7 +7,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Number of list/leaf-list entries in file -: ${perfnr:=10000} +: ${perfnr:=20000} APPNAME=example diff --git a/test/test_perf_state.sh b/test/test_perf_state.sh index 1586317e..8fce648d 100755 --- a/test/test_perf_state.sh +++ b/test/test_perf_state.sh @@ -13,7 +13,7 @@ fin=$dir/fin : ${format:=xml} # Number of list/leaf-list entries in file (cant be less than 2) -: ${perfnr:=1000} +: ${perfnr:=20000} # Number of requests made get/put : ${perfreq:=10} diff --git a/test/test_perf_state_only.sh b/test/test_perf_state_only.sh index c3123448..2f010a78 100755 --- a/test/test_perf_state_only.sh +++ b/test/test_perf_state_only.sh @@ -13,7 +13,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi : ${format:=xml} # Number of list/leaf-list entries in file (cant be less than 2) -: ${perfnr:=1000} +: ${perfnr:=20000} # Number of requests made get/put : ${perfreq:=10} diff --git a/util/clixon_util_datastore.c b/util/clixon_util_datastore.c index daea215b..ecea9e8e 100644 --- a/util/clixon_util_datastore.c +++ b/util/clixon_util_datastore.c @@ -251,7 +251,7 @@ main(int argc, char **argv) } if (argc == 2){ FILE *fp; - if ((fp = fopen(xmlfilename, "r")) < 0){ + if ((fp = fopen(xmlfilename, "r")) == NULL){ clicon_err(OE_UNIX, errno, "fopen(%s)", xmlfilename); goto done; } diff --git a/util/clixon_util_path.c b/util/clixon_util_path.c index d42ebad9..63e979c8 100644 --- a/util/clixon_util_path.c +++ b/util/clixon_util_path.c @@ -135,7 +135,7 @@ main(int argc, break; case 'f': /* XML file */ filename = optarg; - if ((fp = fopen(filename, "r")) < 0){ + if ((fp = fopen(filename, "r")) == NULL){ clicon_err(OE_UNIX, errno, "fopen(%s)", optarg); goto done; } diff --git a/util/clixon_util_socket.c b/util/clixon_util_socket.c index 8c737962..4fa3aa3d 100644 --- a/util/clixon_util_socket.c +++ b/util/clixon_util_socket.c @@ -138,7 +138,7 @@ main(int argc, usage(argv[0]); } if (input_filename){ - if ((fp = fopen(input_filename, "r")) < 0){ + if ((fp = fopen(input_filename, "r")) == NULL){ clicon_err(OE_YANG, errno, "open(%s)", input_filename); goto done; } diff --git a/util/clixon_util_xml.c b/util/clixon_util_xml.c index 79af8021..100afd95 100644 --- a/util/clixon_util_xml.c +++ b/util/clixon_util_xml.c @@ -263,7 +263,7 @@ main(int argc, * Always validated */ if (top_input_filename){ - if ((tfp = fopen(top_input_filename, "r")) < 0){ + if ((tfp = fopen(top_input_filename, "r")) == NULL){ clicon_err(OE_YANG, errno, "fopen(%s)", top_input_filename); goto done; } @@ -288,7 +288,7 @@ main(int argc, xt = xbot; } if (input_filename){ - if ((fp = fopen(input_filename, "r")) < 0){ + if ((fp = fopen(input_filename, "r")) == NULL){ clicon_err(OE_YANG, errno, "open(%s)", input_filename); goto done; } diff --git a/util/clixon_util_xpath.c b/util/clixon_util_xpath.c index 943912b3..01b88c5e 100644 --- a/util/clixon_util_xpath.c +++ b/util/clixon_util_xpath.c @@ -168,7 +168,7 @@ main(int argc, break; case 'f': /* XML file */ filename = optarg; - if ((fp = fopen(filename, "r")) < 0){ + if ((fp = fopen(filename, "r")) == NULL){ clicon_err(OE_UNIX, errno, "open(%s)", argv[1]); goto done; }