Adapt to CLIgen 4.6 API changes
This commit is contained in:
parent
48dfc1201f
commit
7d0b245174
7 changed files with 48 additions and 22 deletions
|
|
@ -1306,5 +1306,5 @@ cli_help(clicon_handle h, cvec *vars, cvec *argv)
|
||||||
parse_tree *pt;
|
parse_tree *pt;
|
||||||
|
|
||||||
pt = cligen_tree_active_get(ch);
|
pt = cligen_tree_active_get(ch);
|
||||||
return cligen_help(stdout, *pt);
|
return cligen_help(stdout, pt);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -955,7 +955,7 @@ yang2cli(clicon_handle h,
|
||||||
handle=NULL for global namespace, this means expand callbacks must be in
|
handle=NULL for global namespace, this means expand callbacks must be in
|
||||||
CLICON namespace, not in a cli frontend plugin.
|
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;
|
goto done;
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
|
||||||
|
|
@ -544,12 +544,16 @@ main(int argc, char **argv)
|
||||||
* <module>.
|
* <module>.
|
||||||
*/
|
*/
|
||||||
if (clicon_cli_genmodel(h)){
|
if (clicon_cli_genmodel(h)){
|
||||||
parse_tree pt = {0,}; /* cli parse tree */
|
parse_tree *pt = NULL; /* cli parse tree */
|
||||||
char *treeref;
|
char *treeref;
|
||||||
|
|
||||||
|
if ((pt = pt_new()) == NULL){
|
||||||
|
clicon_err(OE_UNIX, errno, "pt_new");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
treeref = clicon_cli_model_treename(h);
|
treeref = clicon_cli_model_treename(h);
|
||||||
/* Create cli command tree from dbspec */
|
/* 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;
|
goto done;
|
||||||
cligen_tree_add(cli_cligen(h), treeref, pt);
|
cligen_tree_add(cli_cligen(h), treeref, pt);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,12 +95,16 @@ syntax_mode_find(cli_syntax_t *stx,
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if ((m = malloc(sizeof(cli_syntaxmode_t))) == NULL) {
|
if ((m = malloc(sizeof(cli_syntaxmode_t))) == NULL) {
|
||||||
perror("malloc");
|
clicon_err(OE_UNIX, errno, "malloc");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(m, 0, sizeof(*m));
|
memset(m, 0, sizeof(*m));
|
||||||
strncpy(m->csm_name, mode, sizeof(m->csm_name)-1);
|
strncpy(m->csm_name, mode, sizeof(m->csm_name)-1);
|
||||||
strncpy(m->csm_prompt, CLI_DEFAULT_PROMPT, sizeof(m->csm_prompt)-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);
|
INSQ(m, stx->stx_modes);
|
||||||
stx->stx_nmodes++;
|
stx->stx_nmodes++;
|
||||||
|
|
||||||
|
|
@ -126,14 +130,14 @@ static int
|
||||||
syntax_append(clicon_handle h,
|
syntax_append(clicon_handle h,
|
||||||
cli_syntax_t *stx,
|
cli_syntax_t *stx,
|
||||||
const char *name,
|
const char *name,
|
||||||
parse_tree pt)
|
parse_tree *pt)
|
||||||
{
|
{
|
||||||
cli_syntaxmode_t *m;
|
cli_syntaxmode_t *m;
|
||||||
|
|
||||||
if ((m = syntax_mode_find(stx, name, 1)) == NULL)
|
if ((m = syntax_mode_find(stx, name, 1)) == NULL)
|
||||||
return -1;
|
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 -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -154,8 +158,9 @@ cli_syntax_unload(clicon_handle h)
|
||||||
while (stx->stx_nmodes > 0) {
|
while (stx->stx_nmodes > 0) {
|
||||||
m = stx->stx_modes;
|
m = stx->stx_modes;
|
||||||
DELQ(m, stx->stx_modes, cli_syntaxmode_t *);
|
DELQ(m, stx->stx_modes, cli_syntaxmode_t *);
|
||||||
if (m)
|
if (m){
|
||||||
free(m);
|
free(m);
|
||||||
|
}
|
||||||
stx->stx_nmodes--;
|
stx->stx_nmodes--;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -214,7 +219,7 @@ clixon_str2fn(char *name,
|
||||||
* @param[in] h Clixon handle
|
* @param[in] h Clixon handle
|
||||||
* @param[in] filename Name of file where syntax is specified (in syntax-group dir)
|
* @param[in] filename Name of file where syntax is specified (in syntax-group dir)
|
||||||
* @param[in] dir Name of dir, or NULL
|
* @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
|
static int
|
||||||
cli_load_syntax_file(clicon_handle h,
|
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 */
|
void *handle = NULL; /* Handle to plugin .so module */
|
||||||
char *mode = NULL; /* Name of syntax mode to append new syntax */
|
char *mode = NULL; /* Name of syntax mode to append new syntax */
|
||||||
parse_tree pt = {0,};
|
parse_tree *pt = NULL;
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char filepath[MAXPATHLEN];
|
char filepath[MAXPATHLEN];
|
||||||
|
|
@ -235,6 +240,10 @@ cli_load_syntax_file(clicon_handle h,
|
||||||
char *plgnam;
|
char *plgnam;
|
||||||
clixon_plugin *cp;
|
clixon_plugin *cp;
|
||||||
|
|
||||||
|
if ((pt = pt_new()) == NULL){
|
||||||
|
clicon_err(OE_UNIX, errno, "pt_new");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
if (dir)
|
if (dir)
|
||||||
snprintf(filepath, MAXPATHLEN-1, "%s/%s", dir, filename);
|
snprintf(filepath, MAXPATHLEN-1, "%s/%s", dir, filename);
|
||||||
else
|
else
|
||||||
|
|
@ -250,7 +259,7 @@ cli_load_syntax_file(clicon_handle h,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assuming this plugin is first in queue */
|
/* 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);
|
clicon_err(OE_PLUGIN, 0, "failed to parse cli file %s", filepath);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -352,11 +361,15 @@ cli_syntax_load(clicon_handle h)
|
||||||
cligen_susp_cb_t *fns = NULL;
|
cligen_susp_cb_t *fns = NULL;
|
||||||
cligen_interrupt_cb_t *fni = NULL;
|
cligen_interrupt_cb_t *fni = NULL;
|
||||||
clixon_plugin *cp;
|
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?? */
|
/* Syntax already loaded. XXX should we re-load?? */
|
||||||
if ((stx = cli_syntax(h)) != NULL)
|
if ((stx = cli_syntax(h)) != NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
if ((ptall = pt_new()) == NULL){
|
||||||
|
clicon_err(OE_UNIX, errno, "pt_new");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
/* Format plugin directory path */
|
/* Format plugin directory path */
|
||||||
clispec_dir = clicon_clispec_dir(h);
|
clispec_dir = clicon_clispec_dir(h);
|
||||||
|
|
@ -373,7 +386,7 @@ cli_syntax_load(clicon_handle h)
|
||||||
|
|
||||||
/* Load single specific clispec file */
|
/* Load single specific clispec file */
|
||||||
if (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;
|
goto done;
|
||||||
}
|
}
|
||||||
/* Load all clispec .cli files in directory */
|
/* Load all clispec .cli files in directory */
|
||||||
|
|
@ -385,7 +398,7 @@ cli_syntax_load(clicon_handle h)
|
||||||
for (i = 0; i < ndp; i++) {
|
for (i = 0; i < ndp; i++) {
|
||||||
clicon_debug(1, "DEBUG: Loading syntax '%.*s'",
|
clicon_debug(1, "DEBUG: Loading syntax '%.*s'",
|
||||||
(int)strlen(dp[i].d_name)-4, dp[i].d_name);
|
(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;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -401,7 +414,7 @@ cli_syntax_load(clicon_handle h)
|
||||||
*/
|
*/
|
||||||
m = stx->stx_modes;
|
m = stx->stx_modes;
|
||||||
do {
|
do {
|
||||||
if (cligen_parsetree_merge(&m->csm_pt, NULL, ptall) < 0)
|
if (cligen_parsetree_merge(m->csm_pt, NULL, ptall) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (gen_parse_tree(h, m) != 0)
|
if (gen_parse_tree(h, m) != 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,11 @@ typedef void (clicon_callback_t)(clicon_handle h);
|
||||||
|
|
||||||
/* List of syntax modes */
|
/* List of syntax modes */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
qelem_t csm_qelem; /* List header */
|
qelem_t csm_qelem; /* List header */
|
||||||
char csm_name[256]; /* Syntax mode name */
|
char csm_name[256]; /* Syntax mode name */
|
||||||
char csm_prompt[CLI_PROMPT_LEN]; /* Prompt for mode */
|
char csm_prompt[CLI_PROMPT_LEN]; /* Prompt for mode */
|
||||||
int csm_nsyntax; /* Num syntax specs registered by plugin */
|
int csm_nsyntax; /* Num syntax specs registered by plugin */
|
||||||
parse_tree csm_pt; /* CLIgen parse tree */
|
parse_tree *csm_pt; /* CLIgen parse tree */
|
||||||
} cli_syntaxmode_t;
|
} cli_syntaxmode_t;
|
||||||
|
|
||||||
/* Plugin group object. Just a single object, not list. part of cli_handle */
|
/* Plugin group object. Just a single object, not list. part of cli_handle */
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,15 @@ Run all tests but continue after errors and only print a summary test output ide
|
||||||
## Memory leak test
|
## 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:
|
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 2>&1 | tee mylog # All components
|
||||||
mem.sh restconf backend # Only backend and cli
|
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
|
## Performance plots
|
||||||
|
|
|
||||||
|
|
@ -102,3 +102,5 @@ for cmd1 in $cmds; do
|
||||||
memonce $cmd1
|
memonce $cmd1
|
||||||
println "Mem test $cmd1 done"
|
println "Mem test $cmd1 done"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
unset pattern
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue