diff --git a/.gitignore b/.gitignore index 469e90e52c..bba92fab8c 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,10 @@ nimbus-build-system.paths *.sqlite3-wal /examples/nodejs/build/ + +# Coverage +coverage_html_report/ +*.info + +# Wildcard +*.ignore.* diff --git a/scripts/run_cov.sh b/scripts/run_cov.sh new file mode 100755 index 0000000000..0c496c7142 --- /dev/null +++ b/scripts/run_cov.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +# Check if env.sh has been loaded, or if this file is being ran from it. +# Using NIMC as a proxy for this, as it's defined in the nimbus-build-system's env.sh. +if [ -z "$NIMC" ] +then + echo "[ERROR] This tool can only be ran from the Nimbus environment. Either:" + echo "- Source env.sh 'source /path/to/env.sh', and then run the script directly '/path/to/scripts/run_cov.sh'." + echo "- Run this script as a parameter to env.sh '/path/to/env.sh /path/to/scripts/run_cov.sh'." + exit 1 +fi + +# Check for lcov tool +which lcov 1>/dev/null 2>&1 +if [ $? != 0 ] +then + echo "[ERROR] You need to have lcov installed in order to generate the test coverage report." + exit 2 +fi + +SCRIPT_PATH=$(dirname "$(realpath -s "$0")") +REPO_ROOT=$(dirname $SCRIPT_PATH) +generated_not_to_break_here="$REPO_ROOT/generated_not_to_break_here" + +if [ -f $generated_not_to_break_here ] +then + echo "The file '$generated_not_to_break_here' already exists. Do you want to continue? (y/n)" + read -r response + if [ "$response" != "y" ] + then + exit 3 + fi +fi + +output_directory="$REPO_ROOT/coverage_html_report" +base_filepath="$REPO_ROOT/tests/test_all" +nim_filepath=$base_filepath.nim +info_filepath=$base_filepath.info + +# Workaround a nim bug. See https://github.com/nim-lang/Nim/issues/12376 +touch $generated_not_to_break_here + +# Generate the coverage report +nim --debugger:native --passC:--coverage --passL:--coverage --passL:librln_v0.3.4.a --passL:-lm c $nim_filepath +lcov --base-directory . --directory . --zerocounters -q +$base_filepath +lcov --base-directory . --directory . --include "*/waku/**" --include "*/apps/**" --exclude "*/vendor/**" -c -o $info_filepath +genhtml -o $output_directory $info_filepath + +# Cleanup +rm -rf $info_filepath $base_filepath nimcache +rm $generated_not_to_break_here diff --git a/tests/all_tests_common.nim b/tests/all_tests_common.nim index e2e50a852c..1bbfd2c10b 100644 --- a/tests/all_tests_common.nim +++ b/tests/all_tests_common.nim @@ -1,9 +1,3 @@ {.used.} -# Waku common test suite -import - ./common/test_envvar_serialization, - ./common/test_confutils_envvar, - ./common/test_protobuf_validation, - ./common/test_enr_builder, - ./common/test_sqlite_migrations +import ./common/test_all diff --git a/tests/all_tests_wakunode2.nim b/tests/all_tests_wakunode2.nim index cedc5087b2..cfde01da01 100644 --- a/tests/all_tests_wakunode2.nim +++ b/tests/all_tests_wakunode2.nim @@ -1,6 +1,3 @@ ## Wakunode2 -import - ./wakunode2/test_app, - ./wakunode2/test_validators - +import ./wakunode2/test_all diff --git a/tests/common/test_all.nim b/tests/common/test_all.nim new file mode 100644 index 0000000000..d1573c5894 --- /dev/null +++ b/tests/common/test_all.nim @@ -0,0 +1,7 @@ +import + ./test_base64_codec, + ./test_confutils_envvar, + ./test_enr_builder, + ./test_envvar_serialization, + ./test_protobuf_validation, + ./test_sqlite_migrations diff --git a/tests/test_all.nim b/tests/test_all.nim new file mode 100644 index 0000000000..2138adc3be --- /dev/null +++ b/tests/test_all.nim @@ -0,0 +1,6 @@ +{.used.} + +import + ./all_tests_common, + ./all_tests_waku, + ./all_tests_wakunode2 diff --git a/tests/waku_archive/test_all.nim b/tests/waku_archive/test_all.nim new file mode 100644 index 0000000000..9d45d99a1b --- /dev/null +++ b/tests/waku_archive/test_all.nim @@ -0,0 +1,13 @@ +{.used.} + +import + ./test_driver_postgres_query, + ./test_driver_postgres, + ./test_driver_queue_index, + ./test_driver_queue_pagination, + ./test_driver_queue_query, + ./test_driver_queue, + ./test_driver_sqlite_query, + ./test_driver_sqlite, + ./test_retention_policy, + ./test_waku_archive diff --git a/tests/waku_core/test_all.nim b/tests/waku_core/test_all.nim new file mode 100644 index 0000000000..bd24a0bbec --- /dev/null +++ b/tests/waku_core/test_all.nim @@ -0,0 +1,9 @@ +{.used.} + +import + ./test_message_digest, + ./test_namespaced_topics, + ./test_peers, + ./test_published_address, + ./test_sharding, + ./test_time diff --git a/tests/waku_filter_v2/test_all.nim b/tests/waku_filter_v2/test_all.nim new file mode 100644 index 0000000000..b3856d1b7e --- /dev/null +++ b/tests/waku_filter_v2/test_all.nim @@ -0,0 +1,6 @@ +{.used.} + +import + ./test_waku_client, + ./test_waku_filter_protocol, + ./test_waku_filter diff --git a/tests/waku_relay/test_all.nim b/tests/waku_relay/test_all.nim new file mode 100644 index 0000000000..9131aeb5ee --- /dev/null +++ b/tests/waku_relay/test_all.nim @@ -0,0 +1,5 @@ +{.used.} + +import + ./test_waku_relay, + ./test_wakunode_relay diff --git a/tests/waku_rln_relay/test_all.nim b/tests/waku_rln_relay/test_all.nim new file mode 100644 index 0000000000..5d0c806d08 --- /dev/null +++ b/tests/waku_rln_relay/test_all.nim @@ -0,0 +1,7 @@ +{.used.} + +import + ./test_rln_group_manager_onchain, + ./test_rln_group_manager_static, + ./test_waku_rln_relay, + ./test_wakunode_rln_relay diff --git a/tests/waku_store/test_all.nim b/tests/waku_store/test_all.nim new file mode 100644 index 0000000000..e74805c392 --- /dev/null +++ b/tests/waku_store/test_all.nim @@ -0,0 +1,7 @@ +{.used.} + +import + ./test_resume, + ./test_rpc_codec, + ./test_waku_store, + ./test_wakunode_store diff --git a/tests/wakunode2/test_all.nim b/tests/wakunode2/test_all.nim new file mode 100644 index 0000000000..911c6a81d7 --- /dev/null +++ b/tests/wakunode2/test_all.nim @@ -0,0 +1,5 @@ +{.used.} + +import + ./test_app, + ./test_validators diff --git a/tests/wakunode_jsonrpc/test_all.nim b/tests/wakunode_jsonrpc/test_all.nim new file mode 100644 index 0000000000..17ac8b2a5a --- /dev/null +++ b/tests/wakunode_jsonrpc/test_all.nim @@ -0,0 +1,8 @@ +{.used.} + +import + ./test_jsonrpc_admin, + ./test_jsonrpc_debug, + ./test_jsonrpc_filter, + ./test_jsonrpc_relay, + ./test_jsonrpc_store diff --git a/tests/wakunode_rest/test_all.nim b/tests/wakunode_rest/test_all.nim new file mode 100644 index 0000000000..5c568820aa --- /dev/null +++ b/tests/wakunode_rest/test_all.nim @@ -0,0 +1,12 @@ +{.used.} + +import + ./test_rest_debug_serdes, + ./test_rest_debug, + ./test_rest_filter, + ./test_rest_health, + ./test_rest_legacy_filter, + ./test_rest_relay_serdes, + ./test_rest_relay, + ./test_rest_serdes, + ./test_rest_store