diff --git a/.gitignore b/.gitignore index 79baa50161d5c79cfc8626408023b3b23c5a7114..4acf9e70a2b32848ebf54e34e844a40e26a0d424 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,7 @@ ieee1905d *.swp *.swo *~ +vgcore.* +*.so +timestamp.log +*.xml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ebb40a29721e1ae342478ae7e134b0febe2f33e5..4673cac8603fe8c84605e6dceec84cfc56e6c6d5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,7 @@ include: stages: - static_code_analysis + - functional_test - functional_api_test variables: @@ -11,7 +12,7 @@ variables: SOURCE_FOLDER: "libieee1905/ src/ include/" run_functional_test: - stage: functional_api_test + stage: functional_test image: iopsys/code-analysis-dev:latest allow_failure: true script: @@ -19,6 +20,21 @@ run_functional_test: - "./gitlab-ci/setup.sh" - "./gitlab-ci/functional-test.sh" + artifacts: + when: always + paths: + - functional-test-memory-report.xml + - timestamp.log + +run_functional_api_test: + stage: functional_api_test + image: iopsys/code-analysis-dev:latest + allow_failure: true + script: + - "./gitlab-ci/install-dependencies.sh" + - "./gitlab-ci/setup.sh" + - "./gitlab-ci/functional-api-test.sh" + artifacts: when: always paths: diff --git a/Makefile b/Makefile index a97e9eb07700c2023c4ad4ae3ba624d032dd8907..a6d929e5e36e0f4f7ec63d5b4fb43d0b37d9c8bb 100644 --- a/Makefile +++ b/Makefile @@ -109,6 +109,7 @@ clean: rm -f timestamp.log rm -f unit-test-coverage.xml rm -f functional-test-coverage.xml + rm -f functional-test-memory-report.xml rm -f memory-report.xml rm -f api-result.log rm -f api-test-coverage.xml diff --git a/gitlab-ci/functional-api-test.sh b/gitlab-ci/functional-api-test.sh new file mode 100755 index 0000000000000000000000000000000000000000..f8d6fc4327b018aea1b58136a0ed3e3703d21630 --- /dev/null +++ b/gitlab-ci/functional-api-test.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +echo "$0 preparation script" +pwd + +export LIB_DIR=${PWD}/lib + +echo "Cleaning ..." +make clean + +echo "Running tests now pwd ${LIB_DIR}" +#CFLAGS="${CFLAGS} -g -Wall -g -O0 -fprofile-arcs -ftest-coverage --coverage" CONFIG_IEEE1905_ALME_OVER_UBUS=y make +CONFIG_IEEE1905_ALME_OVER_UBUS=y make +ret=$? + +# installing dependent library +make install + +supervisorctl status all +supervisorctl update +supervisorctl restart all +sleep 3 +supervisorctl status all + +# run API validation +ubus-api-validator -d ./test/api/json/ > ./api-result.log +ret=$? + +supervisorctl stop all +supervisorctl status + +cp ./memory-report.xml ./api-test-memory-report.xml +tap-junit --input ./api-result.log --output report +date +%s > timestamp.log + +echo "$0 exit status ${ret}" +exit ${ret} diff --git a/gitlab-ci/functional-test.sh b/gitlab-ci/functional-test.sh index f8d6fc4327b018aea1b58136a0ed3e3703d21630..55e86aaa4e9f465076f03b4c350dd255c1ed6a56 100755 --- a/gitlab-ci/functional-test.sh +++ b/gitlab-ci/functional-test.sh @@ -15,6 +15,7 @@ ret=$? # installing dependent library make install +ldconfig supervisorctl status all supervisorctl update @@ -22,15 +23,14 @@ supervisorctl restart all sleep 3 supervisorctl status all -# run API validation -ubus-api-validator -d ./test/api/json/ > ./api-result.log +./gitlab-ci/replay_packets.sh +./gitlab-ci/verify.sh ret=$? supervisorctl stop all supervisorctl status -cp ./memory-report.xml ./api-test-memory-report.xml -tap-junit --input ./api-result.log --output report +cp memory-report.xml functional-test-memory-report.xml date +%s > timestamp.log echo "$0 exit status ${ret}" diff --git a/gitlab-ci/install-dependencies.sh b/gitlab-ci/install-dependencies.sh index d867fd1e2afdf9f8fe2861b6be6081b7ce17df5a..03370521dc702f82a1941fc01f62455cb07b280c 100755 --- a/gitlab-ci/install-dependencies.sh +++ b/gitlab-ci/install-dependencies.sh @@ -18,7 +18,7 @@ function exec_cmd() mkdir -p /opt/dev/ # install packages exec_cmd apt update -exec_cmd apt install -y iproute2 +exec_cmd apt install -y iproute2 tcpreplay # install libraries from source cd /opt/dev diff --git a/gitlab-ci/replay_packets.sh b/gitlab-ci/replay_packets.sh new file mode 100755 index 0000000000000000000000000000000000000000..64c9c6b2f5a26a43da4a7603ff3a5fb41dc1b786 --- /dev/null +++ b/gitlab-ci/replay_packets.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +pwd +PCAP_PATH="./test/pcap/" + +function replay() +{ + echo "Replaying ${1}.pcap" + tcpreplay -q --intf1=eth0 ${PCAP_PATH}/${1}.pcap >/dev/null +} + +replay topology_discover +replay autoconfig_search +replay topology_query +replay topology_discover +replay topology_query +replay topology_response +replay topology_discover +replay higher_layer_query +replay link_metric_query +replay higher_layer_response +replay link_metric_response + diff --git a/gitlab-ci/verify.sh b/gitlab-ci/verify.sh new file mode 100755 index 0000000000000000000000000000000000000000..4fbd299594fcd0e7947cdf4792cb656bbdcef37e --- /dev/null +++ b/gitlab-ci/verify.sh @@ -0,0 +1,59 @@ +#!/bin/bash +OUT_PATH=./test/output + +# output metrics used for validation in this file is aligned with pcap(s) +# used to simulate neighbor + +function verify_file() +{ + diff -q ${OUT_PATH}/${1} ${2} >/dev/null 2>&1 + + if [ "$?" -eq 0 ]; then + echo "PASS" + else + echo "Output differs" + cat ${2} + exit 1 + fi +} + +function verify_output() +{ + grep -wq "${1}" /tmp/t.log + if [ "$?" -eq 0 ]; then + echo "PASS" + else + echo "Output differs" + cat /tmp/t.log + exit 1 + fi +} + +function verify_info() +{ + echo "Verify ieee1905 info" + ubus call ieee1905.al.eth0 info >/tmp/t.log + + verify_output "\"name\": \"eth0\"," +} + +function verify_neighbors() +{ + echo "Verify ieee1905 neighbors info" + ubus call ieee1905.al.eth0 neighbors >/tmp/t.log + + verify_file neighbors.data /tmp/t.log +} + +function verify_link() +{ + echo "Verify ieee1905 link info" + ubus call ieee1905.al.eth0 link_info >/tmp/t.log + + verify_output "00:22:07:6f:70:e2" +} + +## Call tests here +verify_info +verify_neighbors +verify_link diff --git a/test/files/etc/config/ieee1905 b/test/files/etc/config/ieee1905 index 21e172263c063127b1a03c5d7b54f753304eafcf..dcedf74dc5d2f50fca23ddc672ea5ade19831b8e 100644 --- a/test/files/etc/config/ieee1905 +++ b/test/files/etc/config/ieee1905 @@ -1,7 +1,7 @@ config ieee1905 'ieee1905' option enabled '1' option debug true - option debug_level 2 + option debug_level 3 option macaddress '02:42:ac:11:00:02' option registrar 0 option cmdu_event 0 diff --git a/test/output/info.data b/test/output/info.data new file mode 100644 index 0000000000000000000000000000000000000000..1f30e331bcbe928de344a9115b14d038e8799935 --- /dev/null +++ b/test/output/info.data @@ -0,0 +1,25 @@ +{ + "name": "eth0", + "mac": "02:42:ac:11:00:02", + "interface_type": "IEEE 802.3ab", + "secured": true, + "pushbutton_status": 2, + "power_state": "On", + "neighbour_nr": 1, + "neighbors": [ + "02:42:09:42:f7:70" + ], + "ipv4_nr": 1, + "ipv4": [ + { + "type": true, + "address": "172.17.0.2", + "dhcp": "127.1.1.1" + } + ], + "ipv6_nr": 0, + "ipv6": [ + + ], + "vendor_nr": 0 +} diff --git a/test/output/link.data b/test/output/link.data new file mode 100644 index 0000000000000000000000000000000000000000..56ae27b53762d156127afefd5caebb879c46c157 --- /dev/null +++ b/test/output/link.data @@ -0,0 +1,15 @@ +{ + "links": [ + { + "ieee1905id": "00:22:07:6f:70:e2", + "interfaceid": "00:22:07:6f:70:e2", + "media_type": "IEEE 802.3ab", + "ieee802dot1bridge": false, + "mac_throughput_capacity": 10000, + "link_availability": 100, + "packet_errors_rx": 0, + "phy_rate": 10000, + "rssi": 0 + } + ] +} diff --git a/test/output/neighbors.data b/test/output/neighbors.data new file mode 100644 index 0000000000000000000000000000000000000000..bf1d09e9d589c91b72ba51270b29847a5fd17286 --- /dev/null +++ b/test/output/neighbors.data @@ -0,0 +1,6 @@ +{ + "neighbors_nr": 1, + "neighbors": [ + "00:22:07:6f:70:e2" + ] +} diff --git a/test/pcap/autoconfig_search.pcap b/test/pcap/autoconfig_search.pcap new file mode 100644 index 0000000000000000000000000000000000000000..75860be32bf78444ad310d5a07bade10e85c0cb5 Binary files /dev/null and b/test/pcap/autoconfig_search.pcap differ diff --git a/test/pcap/higher_layer_query.pcap b/test/pcap/higher_layer_query.pcap new file mode 100644 index 0000000000000000000000000000000000000000..c0a7c8d4294824ba83f221861d87313f7e037ad5 Binary files /dev/null and b/test/pcap/higher_layer_query.pcap differ diff --git a/test/pcap/higher_layer_response.pcap b/test/pcap/higher_layer_response.pcap new file mode 100644 index 0000000000000000000000000000000000000000..66984f46eff45569ba3bb363e2e26cff446527f9 Binary files /dev/null and b/test/pcap/higher_layer_response.pcap differ diff --git a/test/pcap/link_metric_query.pcap b/test/pcap/link_metric_query.pcap new file mode 100644 index 0000000000000000000000000000000000000000..1d7a8172409c4192ea2e3891b5f16a0a4723c6d5 Binary files /dev/null and b/test/pcap/link_metric_query.pcap differ diff --git a/test/pcap/link_metric_response.pcap b/test/pcap/link_metric_response.pcap new file mode 100644 index 0000000000000000000000000000000000000000..293eaad8dbdfb4ec7307243011f482dcf0f913e0 Binary files /dev/null and b/test/pcap/link_metric_response.pcap differ diff --git a/test/pcap/topology_discover.pcap b/test/pcap/topology_discover.pcap new file mode 100644 index 0000000000000000000000000000000000000000..11c0aee2d19bb090e9b22968467bc752cd6ba502 Binary files /dev/null and b/test/pcap/topology_discover.pcap differ diff --git a/test/pcap/topology_query.pcap b/test/pcap/topology_query.pcap new file mode 100644 index 0000000000000000000000000000000000000000..b12274161b472b68b627dacd62dfa121fac51f33 Binary files /dev/null and b/test/pcap/topology_query.pcap differ diff --git a/test/pcap/topology_response.pcap b/test/pcap/topology_response.pcap new file mode 100644 index 0000000000000000000000000000000000000000..ed00e206c0d0ecdc7a2dbe95e9bf5e744cba00ea Binary files /dev/null and b/test/pcap/topology_response.pcap differ