Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(coverage): Add simple coverage #2067

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,10 @@ nimbus-build-system.paths
*.sqlite3-wal

/examples/nodejs/build/

# Coverage
coverage_html_report/
*.info

# Wildcard
*.ignore.*
52 changes: 52 additions & 0 deletions scripts/run_cov.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 1 addition & 7 deletions tests/all_tests_common.nim
Original file line number Diff line number Diff line change
@@ -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
5 changes: 1 addition & 4 deletions tests/all_tests_wakunode2.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
## Wakunode2

import
./wakunode2/test_app,
./wakunode2/test_validators

import ./wakunode2/test_all
7 changes: 7 additions & 0 deletions tests/common/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import
./test_base64_codec,
./test_confutils_envvar,
./test_enr_builder,
./test_envvar_serialization,
./test_protobuf_validation,
./test_sqlite_migrations
6 changes: 6 additions & 0 deletions tests/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{.used.}

import
./all_tests_common,
./all_tests_waku,
./all_tests_wakunode2
13 changes: 13 additions & 0 deletions tests/waku_archive/test_all.nim
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/waku_core/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{.used.}

import
./test_message_digest,
./test_namespaced_topics,
./test_peers,
./test_published_address,
./test_sharding,
./test_time
6 changes: 6 additions & 0 deletions tests/waku_filter_v2/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{.used.}

import
./test_waku_client,
./test_waku_filter_protocol,
./test_waku_filter
5 changes: 5 additions & 0 deletions tests/waku_relay/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{.used.}

import
./test_waku_relay,
./test_wakunode_relay
7 changes: 7 additions & 0 deletions tests/waku_rln_relay/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{.used.}

import
./test_rln_group_manager_onchain,
./test_rln_group_manager_static,
./test_waku_rln_relay,
./test_wakunode_rln_relay
7 changes: 7 additions & 0 deletions tests/waku_store/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{.used.}

import
./test_resume,
./test_rpc_codec,
./test_waku_store,
./test_wakunode_store
5 changes: 5 additions & 0 deletions tests/wakunode2/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{.used.}

import
./test_app,
./test_validators
8 changes: 8 additions & 0 deletions tests/wakunode_jsonrpc/test_all.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{.used.}

import
./test_jsonrpc_admin,
./test_jsonrpc_debug,
./test_jsonrpc_filter,
./test_jsonrpc_relay,
./test_jsonrpc_store
12 changes: 12 additions & 0 deletions tests/wakunode_rest/test_all.nim
Original file line number Diff line number Diff line change
@@ -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
Loading