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

coverage script for pipeline and docker setup instructions #15

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ $ sudo make -C lcov-1.11/ install
lcov --directory . --capture --output-file coverage.info
lcov --list coverage.info
```
_A `cover.sh [target_percentage]` script is also provided for coverage check after `rebar3 eunit`._

## Testing
There are some eunit tests which can be executed through `rebar3 do clean, compile, eunit` (Oracle Server connect info **MUST** be supplied through `tests/connect.config` first).
Expand Down
34 changes: 34 additions & 0 deletions cover.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

target_coverage=${1:-100}

rm -f coverage.info
# capture coverage info
lcov --quiet --directory . --capture --output-file coverage.info
# header files are not covered
lcov --quiet --remove coverage.info "*/odpi/src/*.c" "*.h" --output-file coverage.info

# Sample structure of lcov --summary coverage.info
# Reading tracefile coverage.info
# Summary coverage rate:
# lines......: 13.2% (142 of 1078 lines)
# functions..: 21.1% (12 of 57 functions)
# branches...: no data found
#
# grep to find the 'lines...' line with total % (e,g, 13.2 above)
c-bik marked this conversation as resolved.
Show resolved Hide resolved
lc_summary=$(lcov --summary coverage.info 2>&1 | grep -zo "lines[.]\+: [0-9.]\+" | tr '\0' '\n')
# stip off the rest to get the number
current_coverage=$(echo $lc_summary | sed 's/lines\.*: \(.*\)/\1/')

# calculate difference to target
result=$(awk 'BEGIN { print('$current_coverage'<'$target_coverage')?"F":"P"}')
if [ "$result" = "P" ]; then
exit 0
else
lcov --list coverage.info
echo "------------------------"
echo "TARGET : $target_coverage %"
echo "CURRENT : $current_coverage %"
echo "------------------------"
exit 1
fi
10 changes: 6 additions & 4 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@

{profiles, [
{test, [
{pre_hooks,
[{"(win32)", compile, "nmake -F c_src/Makefile.win32"}
,{"(linux|darwin)", compile, "make -f c_src/Makefile test"}]
},
{pre_hooks, [
{"(win32)", compile, "nmake -F c_src/Makefile.win32"},
{"(linux|darwin)", compile, "make -f c_src/Makefile test"},
{"(linux|darwin)", eunit, "lcov --directory . --zerocounters"}
c-bik marked this conversation as resolved.
Show resolved Hide resolved
]},
{post_hooks, [{"(linux|darwin)", eunit, "bash cover.sh"}]},
{dist_node, [{setcookie, 'testcookie'}, {name, '[email protected]'}]}
]}
]}.