Add test cases for event and command exposed from json plugin

This commit is contained in:
Amin Ben Ramdhane 2021-10-29 17:38:03 +01:00
parent d895f2d4cd
commit 35143273fe
11 changed files with 228 additions and 19 deletions

View file

@ -693,6 +693,7 @@ The application should bring its JSON file under **'/etc/bbfdm/json/'** path wit
"usp"
],
"array": false,
"access": false,
"Push!": {
"type": "event",
"version": "2.13",

View file

@ -32,8 +32,6 @@ lib_LTLIBRARIES += libbbfdm.la
libbbfdm_la_SOURCES = \
../dmentry.c \
../dmdynamiclibrary.c \
../dmdynamicjson.c \
../dmdiagnostics.c \
../dmbbfcommon.c
@ -92,6 +90,16 @@ libbbfdm_la_SOURCES += \
../dmtree/tr143/diagnostics.c
endif #BBF_TR143
if BBFDM_ENABLE_DOTSO_PLUGIN
libbbfdm_la_SOURCES += \
../dmdynamiclibrary.c
endif #BBFDM_ENABLE_DOTSO_PLUGIN
if BBFDM_ENABLE_JSON_PLUGIN
libbbfdm_la_SOURCES += \
../dmdynamicjson.c
endif #BBFDM_ENABLE_JSON_PLUGIN
if BBF_VENDOR_EXTENSION
libbbfdm_la_SOURCES += \

View file

@ -12,13 +12,12 @@
#include "dmdynamicjson.h"
#include "dmentry.h"
#ifdef BBFDM_ENABLE_JSON_PLUGIN
#define json_object_get_string(x) (char *)json_object_get_string(x)
static LIST_HEAD(loaded_json_files);
static LIST_HEAD(json_list);
static LIST_HEAD(json_memhead);
static operation_args empty_cmd = {
.in = (const char**)NULL,
.out = (const char**)NULL
@ -1319,5 +1318,3 @@ int load_json_dynamic_arrays(struct dmctx *ctx)
}
return 0;
}
#endif /* BBFDM_ENABLE_JSON_PLUGIN */

View file

@ -12,8 +12,6 @@
#ifndef __DMENTRYJSON_H__
#define __DMENTRYJSON_H__
#ifdef BBFDM_ENABLE_JSON_PLUGIN
#include <libbbf_api/dmcommon.h>
#define JSON_FOLDER_PATH "/etc/bbfdm/json"
@ -21,5 +19,4 @@
int load_json_dynamic_arrays(struct dmctx *ctx);
int free_json_dynamic_arrays(DMOBJ *dm_entryobj);
#endif /* BBFDM_ENABLE_JSON_PLUGIN */
#endif //__DMENTRYJSON_H__

View file

@ -11,8 +11,6 @@
#include "dmdynamiclibrary.h"
#ifdef BBFDM_ENABLE_DOTSO_PLUGIN
LIST_HEAD(loaded_library_list);
LIST_HEAD(dynamic_operate_list);
LIST_HEAD(library_memhead);
@ -312,5 +310,3 @@ int load_library_dynamic_arrays(struct dmctx *ctx)
}
return 0;
}
#endif /* BBFDM_ENABLE_DOTSO_PLUGIN */

View file

@ -12,8 +12,6 @@
#ifndef __DMENTRYLIBRARY_H__
#define __DMENTRYLIBRARY_H__
#ifdef BBFDM_ENABLE_DOTSO_PLUGIN
#include <libbbf_api/dmcommon.h>
#define LIBRARY_FOLDER_PATH "/usr/lib/bbfdm"
@ -21,5 +19,4 @@
int load_library_dynamic_arrays(struct dmctx *ctx);
void free_library_dynamic_arrays(DMOBJ *dm_entryobj);
#endif /* BBFDM_ENABLE_DOTSO_PLUGIN */
#endif //__DMENTRYLIBRARY_H__

View file

@ -964,6 +964,21 @@ static void test_api_bbfdm_valid_library_operate(void **state)
}
}
static void test_api_bbfdm_valid_json_operate(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *n;
int fault = 0;
fault = dm_entry_param_method(ctx, CMD_USP_OPERATE, "Device.X_IOPSYS_EU_TEST.1.Status()", NULL, NULL);
assert_int_equal(fault, CMD_SUCCESS);
list_for_each_entry(n, &ctx->list_parameter, list) {
assert_string_not_equal(n->data, "Success");
assert_string_equal(n->type, "xsd:string");
}
}
static void test_api_bbfdm_valid_library_event(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -1007,7 +1022,47 @@ static void test_api_bbfdm_valid_library_event(void **state)
idx++;
}
assert_int_equal(idx, 2);
assert_int_equal(idx, 4);
}
static void test_api_bbfdm_valid_json_event(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *n;
int fault = 0, idx = 0;
fault = dm_entry_param_method(ctx, CMD_USP_LIST_EVENT, NULL, NULL, NULL);
assert_int_equal(fault, 0);
list_for_each_entry(n, &ctx->list_parameter, list) {
if (strcmp(n->name, "Device.X_IOPSYS_EU_TEST.1.Periodic!") == 0) {
assert_string_equal(n->type, "xsd:event");
assert_null(n->data);
}
if (strcmp(n->name, "Device.X_IOPSYS_EU_TEST.1.Push!") == 0) {
assert_string_equal(n->type, "xsd:event");
event_args *args = (event_args *)n->data;
assert_non_null(args);
const char **event_param = args->param;
assert_non_null(event_param);
for (int i = 0; event_param[i] != NULL; i++) {
switch (i) {
case 0:
assert_string_equal(event_param[i], "Data");
break;
case 1:
assert_string_equal(event_param[i], "Status");
break;
}
}
}
idx++;
}
assert_int_equal(idx, 4);
}
int main(void)
@ -1028,9 +1083,11 @@ int main(void)
// Operate method test cases
cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_standard_operate, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_library_operate, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_json_operate, setup, teardown_commit),
// Event method test cases
cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_library_event, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_valid_json_event, setup, teardown_commit),
};
return cmocka_run_group_tests(tests, NULL, group_teardown);

View file

@ -663,6 +663,75 @@
}
}
]
},
"Push!": {
"type": "event",
"version": "2.13",
"protocols": [
"usp"
],
"Data": {
"type": "string",
"read": true,
"write": true,
"version": "2.10",
"protocols": [
"usp"
]
},
"Status": {
"type": "string",
"read": true,
"write": true,
"version": "2.12",
"protocols": [
"usp"
]
}
},
"Periodic!": {
"type": "event",
"version": "2.13",
"protocols": [
"usp"
]
},
"Status()": {
"type": "command",
"async": true,
"version" : "2.12",
"protocols": [
"usp"
],
"input": {
"Option" : {
"type" : "string",
"read" : "true",
"write" : "true",
"protocol" : [
"usp"
]
}
},
"output": {
"Result" : {
"type" : "string",
"read" : "true",
"write" : "false",
"protocol" : [
"usp"
]
}
},
"mapping": [
{
"type" : "ubus",
"ubus" : {
"object" : "test",
"method" : "status"
}
}
]
}
}
}

View file

@ -0,0 +1,3 @@
{
"Result": "Success"
}

View file

@ -0,0 +1,17 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
case "$1" in
list)
echo '{ "status" : {} }'
;;
call)
case "$2" in
status)
cat /tmp/test_status.data
;;
esac
;;
esac

View file

@ -149,6 +149,64 @@ param_schema = {
]
}
event_schema = {
"definitions": {
"type_t": {
"type": "string",
"enum": [
"event"
]
},
"protocols_t": {
"type": "string",
"enum": [
"usp"
]
}
},
"type" : "object",
"properties" : {
"type" : {"$ref": "#/definitions/type_t"},
"version" : {"type": "string"},
"protocols" : {"type" : "array", "items" : {"$ref": "#/definitions/protocols_t"}}
},
"required": [
"type",
"version",
"protocols"
]
}
command_schema = {
"definitions": {
"type_t": {
"type": "string",
"enum": [
"command"
]
},
"protocols_t": {
"type": "string",
"enum": [
"usp"
]
}
},
"type" : "object",
"properties" : {
"type" : {"$ref": "#/definitions/type_t"},
"async" : {"type" : "boolean"},
"protocols" : {"type" : "array", "items" : {"$ref": "#/definitions/protocols_t"}},
"input" : {"type" : "object"},
"output" : {"type" : "object"}
},
"required": [
"type",
"async",
"protocols"
]
}
def print_validate_json_usage():
print("Usage: " + sys.argv[0] + " <dm json file>")
print("Examples:")
@ -163,10 +221,19 @@ def parse_value( key , value ):
print(key + " is not a valid path")
exit(1)
validate(instance = value, schema = obj_schema if key.endswith('.') else param_schema)
if key.endswith('.'):
__schema = obj_schema
elif key.endswith('!'):
__schema = event_schema
elif key.endswith('()'):
__schema = command_schema
else:
__schema = param_schema
validate(instance = value, schema = __schema)
for k, v in value.items():
if not k.endswith('()') and not k.endswith('!') and k != "list" and k != "mapping" and isinstance(v, dict):
if k != "list" and k != "mapping" and k != "input" and k != "output" and isinstance(v, dict):
parse_value(k, v)
### main ###