From 7d0b245174181605754820fd5ee39b4f8ecc283e Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 19 May 2020 22:26:29 +0200 Subject: [PATCH] Adapt to CLIgen 4.6 API changes --- apps/cli/cli_common.c | 2 +- apps/cli/cli_generate.c | 2 +- apps/cli/cli_main.c | 8 ++++++-- apps/cli/cli_plugin.c | 35 ++++++++++++++++++++++++----------- apps/cli/cli_plugin.h | 10 +++++----- test/README.md | 11 +++++++++-- test/mem.sh | 2 ++ 7 files changed, 48 insertions(+), 22 deletions(-) diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index 9119e939..6a691e79 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -1306,5 +1306,5 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv) parse_tree *pt; pt = cligen_tree_active_get(ch); - return cligen_help(stdout, *pt); + return cligen_help(stdout, pt); } diff --git a/apps/cli/cli_generate.c b/apps/cli/cli_generate.c index 5f8c8515..0e7224c1 100644 --- a/apps/cli/cli_generate.c +++ b/apps/cli/cli_generate.c @@ -955,7 +955,7 @@ yang2cli(clicon_handle h, handle=NULL for global namespace, this means expand callbacks must be in CLICON namespace, not in a cli frontend plugin. */ - if (cligen_expandv_str2fn(*ptnew, (expandv_str2fn_t*)clixon_str2fn, NULL) < 0) + if (cligen_expandv_str2fn(ptnew, (expandv_str2fn_t*)clixon_str2fn, NULL) < 0) goto done; retval = 0; diff --git a/apps/cli/cli_main.c b/apps/cli/cli_main.c index 5a1a0af4..b0f597e6 100644 --- a/apps/cli/cli_main.c +++ b/apps/cli/cli_main.c @@ -544,12 +544,16 @@ main(int argc, char **argv) * . */ if (clicon_cli_genmodel(h)){ - parse_tree pt = {0,}; /* cli parse tree */ + parse_tree *pt = NULL; /* cli parse tree */ char *treeref; + if ((pt = pt_new()) == NULL){ + clicon_err(OE_UNIX, errno, "pt_new"); + goto done; + } treeref = clicon_cli_model_treename(h); /* Create cli command tree from dbspec */ - if (yang2cli(h, yspec, clicon_cli_genmodel_type(h), printgen, &pt) < 0) + if (yang2cli(h, yspec, clicon_cli_genmodel_type(h), printgen, pt) < 0) goto done; cligen_tree_add(cli_cligen(h), treeref, pt); } diff --git a/apps/cli/cli_plugin.c b/apps/cli/cli_plugin.c index c3d81d27..5d8a7df1 100644 --- a/apps/cli/cli_plugin.c +++ b/apps/cli/cli_plugin.c @@ -95,12 +95,16 @@ syntax_mode_find(cli_syntax_t *stx, return NULL; if ((m = malloc(sizeof(cli_syntaxmode_t))) == NULL) { - perror("malloc"); + clicon_err(OE_UNIX, errno, "malloc"); return NULL; } memset(m, 0, sizeof(*m)); strncpy(m->csm_name, mode, sizeof(m->csm_name)-1); strncpy(m->csm_prompt, CLI_DEFAULT_PROMPT, sizeof(m->csm_prompt)-1); + if ((m->csm_pt = pt_new()) == NULL){ + clicon_err(OE_UNIX, errno, "pt_new"); + return NULL; + } INSQ(m, stx->stx_modes); stx->stx_nmodes++; @@ -126,14 +130,14 @@ static int syntax_append(clicon_handle h, cli_syntax_t *stx, const char *name, - parse_tree pt) + parse_tree *pt) { cli_syntaxmode_t *m; if ((m = syntax_mode_find(stx, name, 1)) == NULL) return -1; - if (cligen_parsetree_merge(&m->csm_pt, NULL, pt) < 0) + if (cligen_parsetree_merge(m->csm_pt, NULL, pt) < 0) return -1; return 0; @@ -154,8 +158,9 @@ cli_syntax_unload(clicon_handle h) while (stx->stx_nmodes > 0) { m = stx->stx_modes; DELQ(m, stx->stx_modes, cli_syntaxmode_t *); - if (m) + if (m){ free(m); + } stx->stx_nmodes--; } return 0; @@ -214,7 +219,7 @@ clixon_str2fn(char *name, * @param[in] h Clixon handle * @param[in] filename Name of file where syntax is specified (in syntax-group dir) * @param[in] dir Name of dir, or NULL - * @param[out] allpt Universal CLIgen parse tree: apply to all modes + * @param[out] ptall Universal CLIgen parse tree: apply to all modes */ static int cli_load_syntax_file(clicon_handle h, @@ -224,7 +229,7 @@ cli_load_syntax_file(clicon_handle h, { void *handle = NULL; /* Handle to plugin .so module */ char *mode = NULL; /* Name of syntax mode to append new syntax */ - parse_tree pt = {0,}; + parse_tree *pt = NULL; int retval = -1; FILE *f; char filepath[MAXPATHLEN]; @@ -235,6 +240,10 @@ cli_load_syntax_file(clicon_handle h, char *plgnam; clixon_plugin *cp; + if ((pt = pt_new()) == NULL){ + clicon_err(OE_UNIX, errno, "pt_new"); + goto done; + } if (dir) snprintf(filepath, MAXPATHLEN-1, "%s/%s", dir, filename); else @@ -250,7 +259,7 @@ cli_load_syntax_file(clicon_handle h, } /* Assuming this plugin is first in queue */ - if (cli_parse_file(h, f, filepath, &pt, cvv) < 0){ + if (cli_parse_file(h, f, filepath, pt, cvv) < 0){ clicon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath); fclose(f); goto done; @@ -352,11 +361,15 @@ cli_syntax_load(clicon_handle h) cligen_susp_cb_t *fns = NULL; cligen_interrupt_cb_t *fni = NULL; clixon_plugin *cp; - parse_tree ptall = {0,}; /* Universal CLIgen parse tree all modes */ + parse_tree *ptall = NULL; /* Universal CLIgen parse tree all modes */ /* Syntax already loaded. XXX should we re-load?? */ if ((stx = cli_syntax(h)) != NULL) return 0; + if ((ptall = pt_new()) == NULL){ + clicon_err(OE_UNIX, errno, "pt_new"); + goto done; + } /* Format plugin directory path */ clispec_dir = clicon_clispec_dir(h); @@ -373,7 +386,7 @@ cli_syntax_load(clicon_handle h) /* Load single specific clispec file */ if (clispec_file){ - if (cli_load_syntax_file(h, clispec_file, NULL, &ptall) < 0) + if (cli_load_syntax_file(h, clispec_file, NULL, ptall) < 0) goto done; } /* Load all clispec .cli files in directory */ @@ -385,7 +398,7 @@ cli_syntax_load(clicon_handle h) for (i = 0; i < ndp; i++) { clicon_debug(1, "DEBUG: Loading syntax '%.*s'", (int)strlen(dp[i].d_name)-4, dp[i].d_name); - if (cli_load_syntax_file(h, dp[i].d_name, clispec_dir, &ptall) < 0) + if (cli_load_syntax_file(h, dp[i].d_name, clispec_dir, ptall) < 0) goto done; } } @@ -401,7 +414,7 @@ cli_syntax_load(clicon_handle h) */ m = stx->stx_modes; do { - if (cligen_parsetree_merge(&m->csm_pt, NULL, ptall) < 0) + if (cligen_parsetree_merge(m->csm_pt, NULL, ptall) < 0) return -1; if (gen_parse_tree(h, m) != 0) goto done; diff --git a/apps/cli/cli_plugin.h b/apps/cli/cli_plugin.h index d911cc4f..7c2c7656 100644 --- a/apps/cli/cli_plugin.h +++ b/apps/cli/cli_plugin.h @@ -47,11 +47,11 @@ typedef void (clicon_callback_t)(clicon_handle h); /* List of syntax modes */ typedef struct { - qelem_t csm_qelem; /* List header */ - char csm_name[256]; /* Syntax mode name */ - char csm_prompt[CLI_PROMPT_LEN]; /* Prompt for mode */ - int csm_nsyntax; /* Num syntax specs registered by plugin */ - parse_tree csm_pt; /* CLIgen parse tree */ + qelem_t csm_qelem; /* List header */ + char csm_name[256]; /* Syntax mode name */ + char csm_prompt[CLI_PROMPT_LEN]; /* Prompt for mode */ + int csm_nsyntax; /* Num syntax specs registered by plugin */ + parse_tree *csm_pt; /* CLIgen parse tree */ } cli_syntaxmode_t; /* Plugin group object. Just a single object, not list. part of cli_handle */ diff --git a/test/README.md b/test/README.md index 0830fd74..0f5bfac2 100644 --- a/test/README.md +++ b/test/README.md @@ -58,8 +58,15 @@ Run all tests but continue after errors and only print a summary test output ide ## Memory leak test The `mem.sh` runs memory checks using valgrind. Start it with no arguments to test all components (backend, restconf, cli, netconf), or specify which components to run: ``` - mem.sh # All components - mem.sh restconf backend # Only backend and cli + mem.sh 2>&1 | tee mylog # All components + mem.sh restconf backend # Only backend and cli +``` + +## Run pattern of tests + +The above scripts work with the `pattern` variable to limit the scope of which tests run, eg: +``` + pattern="test_c*.sh" mem.sh ``` ## Performance plots diff --git a/test/mem.sh b/test/mem.sh index 0798998b..51631574 100755 --- a/test/mem.sh +++ b/test/mem.sh @@ -102,3 +102,5 @@ for cmd1 in $cmds; do memonce $cmd1 println "Mem test $cmd1 done" done + +unset pattern