Added docker-snmp-mem test
This commit is contained in:
Olof hagsand 2023-11-02 14:01:13 +01:00
parent e9c5287c36
commit 16a7fa3837
12 changed files with 39 additions and 36 deletions

View file

@ -156,15 +156,17 @@ static const map_str2str yang_snmp_types[] = {
{ NULL, NULL} /* if not found */
};
/* A function that checks that all subtypes of the union are the same
/*! A function that checks that all subtypes of the union are the same
*
* @param[in] ytype Yang resolved type (a union in this case)
* @param[out] cb Buffer where type of subtypes is written
* @retval 1 - true(All subtypes are the same)
* @retval 0 - false
* @retval 1 true(All subtypes are the same)
* @retval 0 false
*/
int
static int
is_same_subtypes_union(yang_stmt *ytype,
cbuf *cb)
char **restype)
{
int retval = 0;
yang_stmt *y_sub_type = NULL;
@ -188,34 +190,20 @@ is_same_subtypes_union(yang_stmt *ytype,
&y_resolved_type, &options,
&cvv, patterns, NULL, &fraction_digits) < 0 || ( NULL == y_resolved_type) )
break;
if( (NULL == (resolved_type_str = yang_argument_get(y_resolved_type))) )
if ((resolved_type_str = yang_argument_get(y_resolved_type)) == NULL)
break;
if( NULL == type_str || strcmp(type_str, resolved_type_str) == 0)
if (type_str == NULL || strcmp(type_str, resolved_type_str) == 0)
type_str = resolved_type_str;
else
break;
}
if (NULL == y_sub_type && NULL != type_str){
cbuf_append_str(cb, resolved_type_str);
if (y_sub_type == NULL && type_str != NULL){
*restype = resolved_type_str;
retval = 1;
}
return retval;
}
char*
yang_type_to_snmp(yang_stmt *ytype,
char* yang_type_str)
{
char* type_str = yang_type_str;
if (yang_type_str && strcmp(yang_type_str, "union") == 0){
cbuf *cb = cbuf_new();
if (is_same_subtypes_union(ytype, cb) > 0)
type_str = cbuf_get(cb);
}
char* ret = clicon_str2str(yang_snmp_types, type_str);
return (NULL == ret) ? type_str : ret;
}
/*! Translate from snmp string to int representation
*
* @note Internal snmpd, maybe find something in netsnmpd?
@ -346,6 +334,7 @@ snmp_yang_type_get(yang_stmt *ys,
int retval = -1;
yang_stmt *yrestype; /* resolved type */
char *restype; /* resolved type */
char *restype2;
char *origtype = NULL; /* original type */
yang_stmt *ypath;
yang_stmt *yref = NULL;
@ -354,8 +343,13 @@ snmp_yang_type_get(yang_stmt *ys,
if (yang_type_get(ys, &origtype, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0)
goto done;
restype = yrestype?yang_argument_get(yrestype):NULL;
restype = yang_type_to_snmp(yrestype, restype);
if (strcmp(restype, "leafref")==0){
if (restype && strcmp(restype, "union") == 0){
is_same_subtypes_union(yrestype, &restype);
}
if ((restype2 = clicon_str2str(yang_snmp_types, restype)) == NULL)
restype2 = restype;
if (strcmp(restype2, "leafref")==0){
if ((ypath = yang_find(yrestype, Y_PATH, NULL)) == NULL){
clicon_err(OE_YANG, 0, "No path in leafref");
goto done;
@ -372,7 +366,7 @@ snmp_yang_type_get(yang_stmt *ys,
}
if (yang_type_get(yref, &origtype, &yrestype, NULL, NULL, NULL, NULL, NULL) < 0)
goto done;
restype = yrestype?yang_argument_get(yrestype):NULL;
restype2 = yrestype?yang_argument_get(yrestype):NULL;
}
if (yrefp){
if (yref)
@ -387,7 +381,7 @@ snmp_yang_type_get(yang_stmt *ys,
if (yrestypep)
*yrestypep = yrestype;
if (restypep)
*restypep = restype;
*restypep = restype2;
retval = 0;
done:
if (origtype)
@ -406,7 +400,7 @@ snmp_yang_type_get(yang_stmt *ys,
* @retval 0 OK: Look in exist and value for return value
* @retval -1 Error
*
* @note This optimizatoin may not work if the unknown statements are augmented in ys.
* @note This optimization may not work if the unknown statements are augmented in ys.
* @see yang_extension_value for the generic function
*/
int
@ -1395,4 +1389,3 @@ clixon_snmp_api_oid_find(oid *oid0,
// done:
return retval;
}

View file

@ -96,6 +96,7 @@ RUN install -d /clixon/build/usr/local/bin/test
RUN install *.sh /clixon/build/usr/local/bin/test
RUN install *.exp /clixon/build/usr/local/bin/test
RUN install clixon.png /clixon/build/usr/local/bin/test
RUN install *.supp /clixon/build/usr/local/bin/test
RUN install -d /clixon/build/mibs
RUN install mibs/* /clixon/build/mibs

View file

@ -104,6 +104,7 @@ RUN install -d /clixon/build/usr/local/bin/test
RUN install *.sh /clixon/build/usr/local/bin/test
RUN install *.exp /clixon/build/usr/local/bin/test
RUN install clixon.png /clixon/build/usr/local/bin/test
RUN install *.supp /clixon/build/usr/local/bin/test
RUN install -d /clixon/build/mibs
RUN install mibs/* /clixon/build/mibs

View file

@ -102,6 +102,7 @@ RUN install -d /clixon/build/usr/local/bin/test
RUN install *.sh /clixon/build/usr/local/bin/test
RUN install *.exp /clixon/build/usr/local/bin/test
RUN install clixon.png /clixon/build/usr/local/bin/test
RUN install *.supp /clixon/build/usr/local/bin/test
RUN install -d /clixon/build/mibs
RUN install mibs/* /clixon/build/mibs

View file

@ -91,6 +91,13 @@ test: docker
./cleanup.sh ; ./start.sh # kill (ignore error) and the start it
sudo docker exec -t clixon-test bash -c 'cd /usr/local/bin/test && detail=true ./sum.sh'
# Special-purpose memory test for snmp
memsnmp: docker
./cleanup.sh ; ./start.sh # kill (ignore error) and the start it
sudo docker exec -t clixon-test bash -c 'sudo apk add --update valgrind; cd /usr/local/bin/test && pattern=test_snmp_union.sh ./mem.sh snmp'
# sudo docker exec -t clixon-test bash -c 'sudo apk add --update valgrind; cd /usr/local/bin/test && pattern=test_snmp*.sh ./mem.sh snmp'
depend:
install-include:

View file

@ -127,7 +127,7 @@ function testinit(){
sudo killall -q clixon_snmp
new "Starting clixon_snmp"
start_snmp $cfg &
start_snmp $cfg
fi
new "wait snmp"

View file

@ -123,7 +123,7 @@ function testinit(){
sudo killall -q clixon_snmp
new "Starting clixon_snmp"
start_snmp $cfg &
start_snmp $cfg
fi
new "wait snmp"

View file

@ -180,7 +180,7 @@ function testinit(){
sudo killall -q clixon_snmp
new "Starting clixon_snmp"
start_snmp $cfg &
start_snmp $cfg
fi
new "wait snmp"

View file

@ -90,7 +90,7 @@ function testinit(){
sudo killall -q clixon_snmp
new "Starting clixon_snmp"
start_snmp $cfg &
start_snmp $cfg
fi
new "wait snmp"

View file

@ -140,7 +140,7 @@ function testinit(){
sudo killall -q clixon_snmp
new "Starting clixon_snmp"
start_snmp $cfg &
start_snmp $cfg
fi
new "wait snmp"

View file

@ -106,7 +106,7 @@ function testinit(){
new "Starting clixon_snmp"
# XXX augmented objects seem to be registered twice: error: duplicate registration: MIB modules snmpSetSerialNo and AgentX subagent 52, session 0x562087a70e20, subsession 0x562087a820c0 (oid .1.3.6.1.6.3.1.1.6.1).
start_snmp $cfg &
start_snmp $cfg
fi
new "wait snmp"

View file

@ -116,7 +116,7 @@ function testinit(){
sudo killall -q clixon_snmp
new "Starting clixon_snmp"
start_snmp $cfg &
start_snmp $cfg
fi
new "wait snmp"