Skip to content
Permalink
Browse files
Enable code coverage for eunit + bindingtester
The EUnit coverage is on by default. The bindingtester can be enabled
by defining the COVER_ENABLED environment variable. It writes to the
same directory that EUnit does; namely "_build/test/cover/" if ERL_LIBS
is defined to point to the "test" profile for erlfdb (as it should be
for code coverage analysis). For example:

COVER_ENABLED=1 ERL_LIBS=_build/test/lib/erlfdb /usr/src/foundationdb/bindings/bindingtester/bindingtester.py erlang --test-name api --instruction-prefix api --num-ops 10000

We could try to be a little smarter here and align to rebar3's config
options, but I didn't bother with that for now.
  • Loading branch information
kocolosk committed Nov 17, 2021
1 parent 111367c commit 2f6b6484e472ee805c0eb3253ad66a2a1b5a2e29
Showing 2 changed files with 26 additions and 1 deletion.
@@ -36,3 +36,5 @@
debug_info,
verbose
]}.

{cover_enabled, true}.
@@ -1020,6 +1020,27 @@ get_dir_or_ss_mod(#{}) ->
erlfdb_directory.


maybe_cover_compile() ->
case os:getenv("COVER_ENABLED") of
Cover when Cover == false; Cover == "" ->
ok;
_ ->
cover:compile_beam_directory(code:lib_dir(erlfdb, ebin))
end.

maybe_write_coverdata(Prefix, APIVsn) ->
case os:getenv("COVER_ENABLED") of
Cover when Cover == false; Cover == "" ->
ok;
_ ->
CoverDir = filename:join(code:lib_dir(erlfdb), "../../cover/"),
Filename = io_lib:format("bindingtest-~s-~s.coverdata", [Prefix, APIVsn]),
Path = filename:join(CoverDir, Filename),
filelib:ensure_dir(Path),
cover:export(Path)
end.


main([Prefix, APIVsn]) ->
main([Prefix, APIVsn, ""]);

@@ -1028,6 +1049,8 @@ main([Prefix, APIVsn, ClusterFileStr]) ->
%% io:get_line(Prompt),
%% io:format("Running tests: ~s ~s ~s~n", [Prefix, APIVsn, ClusterFileStr]),

maybe_cover_compile(),
application:set_env(erlfdb, api_version, list_to_integer(APIVsn)),
Db = erlfdb:open(iolist_to_binary(ClusterFileStr)),
init_run_loop(Db, iolist_to_binary(Prefix)).
init_run_loop(Db, iolist_to_binary(Prefix)),
maybe_write_coverdata(Prefix, APIVsn).

0 comments on commit 2f6b648

Please sign in to comment.