diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5eb645909c480fd7dbd6d76b3bb593a3d04ad06e --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/swmodd +/*.xml +/*.log +/result +*.swp +*.swo +*.gcda +*.gcno +*.gcov diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..4a4ebf8f9ee63aa4e28165be2aff856dbe84a804 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,31 @@ +include: + - project: 'iopsys/gitlab-ci-pipeline' + file: '/static-code-analysis.yml' + +stages: + - static_code_analysis + - api_test + +variables: + DEBUG: 'TRUE' + SOURCE_FOLDER: "src" + +run_api_test: + stage: api_test + image: iopsys/code-analysis:latest + allow_failure: true + script: + - "./gitlab-ci/install-dependencies.sh" + - "./gitlab-ci/setup.sh" + - "./gitlab-ci/functional-api-test.sh" + + artifacts: + when: always + reports: + junit: ./report/tap.xml + paths: + - timestamp.log + - api-test-coverage.xml + - memory-report.xml + - api-result.log + diff --git a/Makefile b/Makefile index b37a04c3f7842ed5579a46572cf6c73f40aa8cf9..6f01f0e407e782bd1b2f32e05bce6c4be1e9433e 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,16 @@ -PROG = swmodd -OBJS = swmod.o swmod_host.o swmod_opkg.o swmod_uci.o tools.o +all: + make -C src all -PROG_CFLAGS = $(CFLAGS) -fstrict-aliasing -Wall -PROG_LDFLAGS = $(LDFLAGS) -luci -lubus -lubox -ljson-c -lblobmsg_json -luuid - -ifeq ($(SWMOD_LXC),yes) -OBJS += swmod_lxc.o -PROG_CFLAGS += -DSWMOD_LXC -PROG_LDFLAGS += -llxc -endif - -%.o: %.c - $(CC) $(PROG_CFLAGS) $(FPIC) -c -o $@ $< - -all: ${PROG} - -${PROG}: $(OBJS) - $(CC) $(PROG_CFLAGS) -o $@ $^ $(PROG_LDFLAGS) +swmodd: + make -C src swmodd clean: - rm -f *.o $(PROG) + make -C src clean + -rm -f swmodd + -find -name '*.gcda' -exec rm {} -fv \; + -find -name '*.gcno' -exec rm {} -fv \; + -find -name '*.gcov' -exec rm {} -fv \; + -rm -f *.log *.xml + -rm -rf report + +.PHONY: all swmodd clean diff --git a/gitlab-ci/functional-api-test.sh b/gitlab-ci/functional-api-test.sh new file mode 100755 index 0000000000000000000000000000000000000000..52bb4fbfa3465b37648d520a9eca20810a122796 --- /dev/null +++ b/gitlab-ci/functional-api-test.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +echo "$0 preparation script" +pwd + +source ./gitlab-ci/shared.sh + +trap cleanup EXIT +trap cleanup SIGINT + +date +%s > timestamp.log +# clean and make +make clean +make +check_ret $? + +supervisorctl status all +supervisorctl update +supervisorctl restart all +exec_cmd ubus -t 10 wait_for usp.raw usp +supervisorctl status all + +exec_cmd ubus wait_for swmodule + +ubus call swmodule environment + +supervisorctl status all +supervisorctl stop all +supervisorctl status + +#report part +gcovr -r . --xml -o ./api-test-coverage.xml +gcovr -r . +exec_cmd tap-junit --input ./api-result.log --output report + +check_memory_leak memory-report.xml + +echo "Functional ubus API test :: PASS" diff --git a/gitlab-ci/install-dependencies.sh b/gitlab-ci/install-dependencies.sh new file mode 100755 index 0000000000000000000000000000000000000000..1c13de3087336fbaaee66224976f6e211bb81076 --- /dev/null +++ b/gitlab-ci/install-dependencies.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "install dependencies for unit-test script" +pwd + +source ./gitlab-ci/shared.sh + +echo "Installing required packages" +exec_cmd apt update +exec_cmd apt install -y uuid-dev lxc-dev lxc + +echo "Installing uspd" +cd /opt/dev +[ -d uspd ] && rm -fr uspd +exec_cmd git clone https://dev.iopsys.eu/iopsys/uspd.git +cd uspd +#exec_cmd git checkout origin/transaction_id +exec_cmd ./gitlab-ci/install-dependencies.sh +exec_cmd ./gitlab-ci/setup.sh +exec_cmd make +exec_cmd cp uspd /usr/sbin/uspd + + diff --git a/gitlab-ci/iopsys-supervisord.conf b/gitlab-ci/iopsys-supervisord.conf new file mode 100644 index 0000000000000000000000000000000000000000..2237cb1603a02b667ac93741af83419497070c71 --- /dev/null +++ b/gitlab-ci/iopsys-supervisord.conf @@ -0,0 +1,25 @@ +[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:uspd] +autorestart=false +startretries=0 +priority=3 +command=/bin/bash -c "/usr/sbin/uspd" + + +[program:swmodd] +autorestart=false +startretries=0 +priority=4 +command=/bin/bash -c "/usr/bin/valgrind --xml=yes --xml-file=/builds/iopsys/swmodd/memory-report.xml --leak-check=full --show-reachable=yes --show-leak-kinds=all --errors-for-leak-kinds=all --error-exitcode=1 --track-origins=yes /builds/iopsys/swmodd/swmodd" + diff --git a/gitlab-ci/setup.sh b/gitlab-ci/setup.sh new file mode 100755 index 0000000000000000000000000000000000000000..7d5a0a066ce18a34f5f0b878eff40a01291bd9d6 --- /dev/null +++ b/gitlab-ci/setup.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +echo "preparation script" + +pwd +#cp -r ./test/files/* / +cp ./gitlab-ci/iopsys-supervisord.conf /etc/supervisor/conf.d/ + diff --git a/gitlab-ci/shared.sh b/gitlab-ci/shared.sh new file mode 100644 index 0000000000000000000000000000000000000000..bb62efae0bcb5a4d65e1e7fdbc5991c8ad3a4f63 --- /dev/null +++ b/gitlab-ci/shared.sh @@ -0,0 +1,60 @@ +#!/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 check_memory_leak() +{ + memory_log=${1} + + if [ ! -f ${memory_log} ]; then + echo "Memory log ${memory_log} not present for validation" + exit 1; + fi + + echo "Checking memory leaks..." + grep -q "UninitCondition" ${memory_log} + error_on_zero $? + + grep -q "Leak_DefinitelyLost" ${memory_log} + error_on_zero $? + + grep -q "Leak_PossiblyLost" ${memory_log} + error_on_zero $? + + grep -q "Leak_StillReachable" ${memory_log} + error_on_zero $? +} diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..90b783642a35716eaad74bfcb2fd286852485a97 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,27 @@ +ifeq ($(CP),) +CP := cp -f +endif + +PROG = swmodd +OBJS = swmod.o swmod_host.o swmod_opkg.o swmod_uci.o tools.o + +PROG_CFLAGS = $(CFLAGS) -fstrict-aliasing -Wall +PROG_LDFLAGS = $(LDFLAGS) -luci -lubus -lubox -ljson-c -lblobmsg_json -luuid + +ifeq ($(SWMOD_LXC),yes) +OBJS += swmod_lxc.o +PROG_CFLAGS += -DSWMOD_LXC +PROG_LDFLAGS += -llxc +endif + +%.o: %.c + $(CC) $(PROG_CFLAGS) $(FPIC) -c -o $@ $< + +all: ${PROG} + +${PROG}: $(OBJS) + $(CC) $(PROG_CFLAGS) -o $@ $^ $(PROG_LDFLAGS) + $(CP) ${PROG} ../${PROG} + +clean: + rm -f *.o $(PROG) diff --git a/swmod.c b/src/swmod.c similarity index 100% rename from swmod.c rename to src/swmod.c diff --git a/swmod.h b/src/swmod.h similarity index 100% rename from swmod.h rename to src/swmod.h diff --git a/swmod_host.c b/src/swmod_host.c similarity index 100% rename from swmod_host.c rename to src/swmod_host.c diff --git a/swmod_host.h b/src/swmod_host.h similarity index 100% rename from swmod_host.h rename to src/swmod_host.h diff --git a/swmod_lxc.c b/src/swmod_lxc.c similarity index 100% rename from swmod_lxc.c rename to src/swmod_lxc.c diff --git a/swmod_lxc.h b/src/swmod_lxc.h similarity index 100% rename from swmod_lxc.h rename to src/swmod_lxc.h diff --git a/swmod_opkg.c b/src/swmod_opkg.c similarity index 100% rename from swmod_opkg.c rename to src/swmod_opkg.c diff --git a/swmod_opkg.h b/src/swmod_opkg.h similarity index 100% rename from swmod_opkg.h rename to src/swmod_opkg.h diff --git a/swmod_uci.c b/src/swmod_uci.c similarity index 100% rename from swmod_uci.c rename to src/swmod_uci.c diff --git a/swmod_uci.h b/src/swmod_uci.h similarity index 100% rename from swmod_uci.h rename to src/swmod_uci.h diff --git a/tools.c b/src/tools.c similarity index 100% rename from tools.c rename to src/tools.c diff --git a/tools.h b/src/tools.h similarity index 100% rename from tools.h rename to src/tools.h