forked from esl/ejabberd_tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_common_test.erl
73 lines (65 loc) · 2.41 KB
/
run_common_test.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-module(run_common_test).
-export([ct/0, ct_cover/0, cover_summary/0]).
-define(CT_DIR, filename:join([".", "tests"])).
-define(CT_REPORT, filename:join([".", "ct_report"])).
-define(CT_CONFIG, "test.config").
-define(EJABBERD_NODE, 'ejabberd@localhost').
ct() ->
Result = ct:run_test([{config, [?CT_CONFIG]},
{dir, ?CT_DIR},
{logdir, ?CT_REPORT}]),
case Result of
{error, Reason} ->
throw({ct_error, Reason});
_ ->
ok
end,
init:stop(0).
ct_cover() ->
prepare(),
ct:run_test([
{config, [?CT_CONFIG]},
{dir, ?CT_DIR},
{logdir, ?CT_REPORT}
]),
analyze(),
{MS,S,_} = now(),
FileName = lists:flatten(io_lib:format("run_~b~b.coverdata",[MS,S])),
io:format("export current cover ~p~n", [cover_call(export, [FileName])]),
io:format("test finished~n"),
init:stop(0).
cover_summary() ->
prepare(),
Files = rpc:call(?EJABBERD_NODE, filelib, wildcard, ["*.coverdata"]),
lists:foreach(fun(F) ->
io:format("import ~p cover ~p~n", [F, cover_call(import, [F])])
end,
Files),
analyze(),
io:format("summary completed~n"),
init:stop(0).
prepare() ->
%%rpc:call(?EJABBERD_NODE, application, stop, [ejabberd]),
cover_call(start),
Compiled = cover_call(compile_beam_directory,["lib/ejabberd-2.1.8/ebin"]),
%%io:format("start ~p~n", [rpc:call(?EJABBERD_NODE, application, start, [ejabberd, permanent])]),
io:format("Compiled modules ~p~n", [Compiled]).
%%timer:sleep(10000).
analyze() ->
Modules = cover_call(modules),
rpc:call(?EJABBERD_NODE, file, make_dir, ["coverage"]),
{ok, File} = file:open("cover_summary.txt", write),
Fun = fun(Module) ->
FileName = lists:flatten(io_lib:format("~s.COVER.html",[Module])),
FilePath = filename:join(["coverage", FileName]),
cover_call(analyse_to_file, [Module, FilePath, [html]]),
{ok, {Module, {C, NC}}} = cover_call(analyse, [Module, module]),
io:fwrite(File, "~s;~b;~b;~s\n", [Module, C, NC, FilePath])
end,
io:format("coverage analyzing~n"),
lists:foreach(Fun, Modules),
file:close(File).
cover_call(Function) ->
cover_call(Function, []).
cover_call(Function, Args) ->
rpc:call(?EJABBERD_NODE, cover, Function, Args).