diff --git a/.gitignore b/.gitignore index 5c15fbc3bc53e85505511799aae33e230cbe75b2..b7939bd7d29a5901d4dc2ea62d147f1bd690fc39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ bulkdatad *.o *.so +*.gcda +*.gcno +*.log docs/index.md diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cd26647f75cf9ee0f92e35cb05c8b846edaaff88..556b6c295c84d9c7569d0c89db569d4aed19a3db 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,4 +14,20 @@ variables: stages: - static_code_analysis + - compilation_test - deploy + +run_compilation_test: + stage: compilation_test + image: ${COMMON_IMAGE} + allow_failure: false + script: + - "./gitlab-ci/install-dependencies.sh" + - "./gitlab-ci/setup.sh" + - "./gitlab-ci/compilation-test.sh" + + artifacts: + when: always + paths: + - timestamp.log + - /tmp/memory-report.xml diff --git a/docs/.pages b/docs/.pages index daec10e234eac9ff817e52821ac72b8a96c35ecb..c31edb4e605b9f0d47c7bd6ebc73e3fd455f145d 100644 --- a/docs/.pages +++ b/docs/.pages @@ -1,4 +1,4 @@ -title: "Bulkdata documentation" +title: "Bulkdata" nav: - "arch" diff --git a/docs/api/.pages b/docs/api/.pages index 929034182223e90ba299969b5f018277b0a3c530..2d670868075a4cd6312d1e1e18b8c57e787f9bff 100644 --- a/docs/api/.pages +++ b/docs/api/.pages @@ -1,4 +1,4 @@ -title: "Bulkdata API" +title: "Bulkdata" nav: - "ubus" diff --git a/docs/api/ubus/.pages b/docs/api/ubus/.pages index e2d5ae91273a09583d8cd5c10d92a22ab5b0f6c5..1acac62065d4d24127cff1acdfa58ac6ec1d7bc7 100644 --- a/docs/api/ubus/.pages +++ b/docs/api/ubus/.pages @@ -1 +1,2 @@ +title: "Bulkdata" hide: true diff --git a/docs/api/uci/.pages b/docs/api/uci/.pages index beaa06d976c8ba0e7146812efd92761e31daeccf..f2e86012b6c599b3794e5d86ce7ffd72fbc0e5b1 100644 --- a/docs/api/uci/.pages +++ b/docs/api/uci/.pages @@ -1,4 +1,4 @@ -title: "Bulkdata UCI" +title: "Bulkdata" nav: - "..." diff --git a/docs/arch/.pages b/docs/arch/.pages index e2d5ae91273a09583d8cd5c10d92a22ab5b0f6c5..1acac62065d4d24127cff1acdfa58ac6ec1d7bc7 100644 --- a/docs/arch/.pages +++ b/docs/arch/.pages @@ -1 +1,2 @@ +title: "Bulkdata" hide: true diff --git a/docs/guide/.pages b/docs/guide/.pages index 27aaee4b9bc7e1e90eb2553b4940b73fe2e2dc23..f2e86012b6c599b3794e5d86ce7ffd72fbc0e5b1 100644 --- a/docs/guide/.pages +++ b/docs/guide/.pages @@ -1,4 +1,4 @@ -title: "Bulkdata Developer Guide" +title: "Bulkdata" nav: - "..." diff --git a/gitlab-ci/compilation-test.sh b/gitlab-ci/compilation-test.sh new file mode 100755 index 0000000000000000000000000000000000000000..af3f1d3df6955771347713132b354dadea6ede17 --- /dev/null +++ b/gitlab-ci/compilation-test.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "$0 preparation script" +pwd + +source ./gitlab-ci/shared.sh + +# build package +date +%s > timestamp.log +build_bulkdata + +supervisorctl update +supervisorctl restart all +supervisorctl status all +exec_cmd ubus -t 20 wait_for bbfdm + +supervisorctl stop all +supervisorctl status + +grep -q "Leak_" /tmp/memory-report.xml +error_on_zero $? + +echo "Compilation Test :: PASS" diff --git a/gitlab-ci/install-dependencies.sh b/gitlab-ci/install-dependencies.sh new file mode 100755 index 0000000000000000000000000000000000000000..8de80eb35b98e558576aea7bd234ac56862b50f8 --- /dev/null +++ b/gitlab-ci/install-dependencies.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +echo "install dependencies for unit-test script" +pwd + +source ./gitlab-ci/shared.sh + +# install bbfdm +install_bbfdm diff --git a/gitlab-ci/iopsys-supervisord.conf b/gitlab-ci/iopsys-supervisord.conf new file mode 100644 index 0000000000000000000000000000000000000000..5ffa481b09863821fb99cb63c30e5189707b95d8 --- /dev/null +++ b/gitlab-ci/iopsys-supervisord.conf @@ -0,0 +1,24 @@ +[program:ubusd] +autorestart=false +startretries=0 +priority=1 +command=/bin/bash -c "/usr/sbin/ubusd" + +[program:rpcd] +autorestart=false +startretries=0 +priority=2 +command=/bin/bash -c "/usr/sbin/rpcd" + +[program:bbfdmd] +autorestart=false +startretries=0 +priority=3 +command=/bin/bash -c "/usr/sbin/bbfdmd" + +[program:bulkdatad] +autorestart=false +startretries=0 +priority=4 +command=/bin/bash -c "/usr/bin/valgrind --xml=yes --xml-file=/tmp/memory-report.xml --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all --error-exitcode=1 --track-origins=yes /usr/sbin/bulkdatad" + diff --git a/gitlab-ci/setup.sh b/gitlab-ci/setup.sh new file mode 100755 index 0000000000000000000000000000000000000000..5c591864975d8063e380f5faacb47afa2ca3562c --- /dev/null +++ b/gitlab-ci/setup.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "preparation script" + +mkdir -p /var/state/ +cp ./gitlab-ci/iopsys-supervisord.conf /etc/supervisor/conf.d/ +cp -rf ./test/files/* / diff --git a/gitlab-ci/shared.sh b/gitlab-ci/shared.sh new file mode 100644 index 0000000000000000000000000000000000000000..fc573ee47f290c0f706818c7528509b7f01ff8b5 --- /dev/null +++ b/gitlab-ci/shared.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +function cleanup() +{ + echo "" +} + +function check_ret() +{ + ret=$1 + if [ "$ret" -ne 0 ]; then + echo "Validation of last command failed, ret(${ret})" + exit $ret + fi + +} + +function error_on_zero() +{ + ret=$1 + if [ "$ret" -eq 0 ]; then + echo "Validation of last command failed, ret(${ret})" + exit $ret + fi + +} + +function exec_cmd() +{ + echo "executing $@" + $@ >/dev/null 2>&1 + + if [ $? -ne 0 ]; then + echo "Failed to execute $@" + exit 1 + fi +} + +function clean_stunc() +{ + make -C src clean + rm *.gcno + rm *.gcda +} + +function build_bulkdata() +{ + export CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage -D_GNU_SOURCE" + export LDFLAGS="--coverage" + make clean + make + exec_cmd ln -s ${PWD}/bulkdatad /usr/sbin/bulkdatad +} + +function install_bbfdm() +{ + [ -d "/opt/dev/bbfdm" ] && rm -rf /opt/dev/bbfdm + + if [ -n "${BBFDM_BRANCH}" ]; then + exec_cmd git clone -b ${BBFDM_BRANCH} https://dev.iopsys.eu/bbf/bbfdm.git /opt/dev/bbfdm + else + exec_cmd git clone https://dev.iopsys.eu/bbf/bbfdm.git /opt/dev/bbfdm + fi + + cd /opt/dev/bbfdm + ./gitlab-ci/install-dependencies.sh install + ./gitlab-ci/setup.sh install +} diff --git a/src/utils.c b/src/utils.c index 2462cd6d3757ed2181ed17f88773205fb22d0f01..34ce612cc89c531fc2e1869b6cdb86df115e1d6c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -17,7 +17,7 @@ #include <libubox/blobmsg_json.h> #include "utils.h" -#define USP_OBJECT_NAME "usp.raw" +#define DM_OBJECT_NAME "bbfdm" static unsigned char LogLevel = DEFAULT_LOG_LEVEL; static bool g_usp_object_available = false; @@ -199,8 +199,8 @@ static void get_value_single_cb(struct ubus_request *req, int type __attribute__ __P_MAX }; const struct blobmsg_policy p[__P_MAX] = { - { "parameter", BLOBMSG_TYPE_STRING }, - { "value", BLOBMSG_TYPE_STRING } + { "path", BLOBMSG_TYPE_STRING }, + { "data", BLOBMSG_TYPE_STRING } }; if (!msg) @@ -245,8 +245,8 @@ static void get_value_group_cb(struct ubus_request *req, int type __attribute__( __P_MAX }; const struct blobmsg_policy p[__P_MAX] = { - { "parameter", BLOBMSG_TYPE_STRING }, - { "value", BLOBMSG_TYPE_STRING }, + { "path", BLOBMSG_TYPE_STRING }, + { "data", BLOBMSG_TYPE_STRING }, { "type", BLOBMSG_TYPE_STRING } }; @@ -285,7 +285,7 @@ static int uspd_call(struct ubus_context *ctx, char *method, uint32_t id; - if (ubus_lookup_id(ctx, USP_OBJECT_NAME, &id)) + if (ubus_lookup_id(ctx, DM_OBJECT_NAME, &id)) return -1; // Invoke Ubus to get data from uspd @@ -309,7 +309,10 @@ int get_value_single(vendor_data_t *arg) blob_buf_init(&bb, 0); blobmsg_add_string(&bb, "path", arg->path); + void *table = blobmsg_open_table(&bb, "optional"); blobmsg_add_string(&bb, "proto", "cwmp"); + blobmsg_add_string(&bb, "format", "raw"); + blobmsg_close_table(&bb, table); // Invoke Ubus to get data from uspd res = uspd_call(ubus_ctx, "get", &bb, get_value_single_cb, arg); @@ -333,7 +336,10 @@ int get_value_group(vendor_data_t *arg) blob_buf_init(&bb, 0); blobmsg_add_string(&bb, "path", arg->path); + void *table = blobmsg_open_table(&bb, "optional"); blobmsg_add_string(&bb, "proto", "cwmp"); + blobmsg_add_string(&bb, "format", "raw"); + blobmsg_close_table(&bb, table); // Invoke Ubus to get data from uspd res = uspd_call(ubus_ctx, "get", &bb, get_value_group_cb, arg); @@ -717,7 +723,7 @@ static void lookup_event_cb(struct ubus_context *ctx __attribute__((unused)), return; path = blobmsg_data(attr); - if (strcmp(path, USP_OBJECT_NAME) == 0) { + if (strcmp(path, DM_OBJECT_NAME) == 0) { g_usp_object_available = true; uloop_end(); } @@ -754,7 +760,7 @@ int wait_for_usp_raw_object(void) ubus_register_event_handler(uctx, &add_event, "ubus.object.add"); // check if object already present - ret = ubus_lookup_id(uctx, USP_OBJECT_NAME, &ubus_id); + ret = ubus_lookup_id(uctx, DM_OBJECT_NAME, &ubus_id); if (ret == 0) { g_usp_object_available = true; goto end; @@ -772,7 +778,7 @@ end: ubus_free(uctx); if (g_usp_object_available == false) { - ERR("%s object not found", USP_OBJECT_NAME); + ERR("%s object not found", DM_OBJECT_NAME); return -1; } diff --git a/test/files/etc/config/bulkdata b/test/files/etc/config/bulkdata new file mode 100644 index 0000000000000000000000000000000000000000..41329ba799a3d79121f32f72d79ffe7778960b94 --- /dev/null +++ b/test/files/etc/config/bulkdata @@ -0,0 +1,17 @@ +config bulkdata 'bulkdata' + option log_level '3' + option enable '1' + +config profile 'profile_1' + option name 'test' + option protocol 'HTTP' + option reporting_interval '60' + option encoding_type 'JSON' + option http_url 'http://localhost' + option http_method 'PUT' + option enable '1' + +config profile_parameter 'profile_1_parameter_1' + option dm_parent 'profile_1' + option name 'test_data' + option reference 'Device.DeviceInfo.Uptime'