Skip to content

Commit

Permalink
Make option line_coverage work when given in the compile() attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorng committed Oct 22, 2024
1 parent bcafd64 commit 78c6bfc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/compiler/src/compile.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ abstr_passes(AbstrStatus) ->

{delay,[{iff,debug_info,?pass(save_abstract_code)}]},

{iff,line_coverage,{pass,sys_coverage}},
{delay,[{iff,line_coverage,{pass,sys_coverage}}]},

?pass(expand_records),
{iff,'dexp',{listing,"expand"}},
Expand Down
28 changes: 24 additions & 4 deletions lib/compiler/test/compile_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2318,22 +2318,42 @@ option_order(Config) ->
run(Config, Ts),
ok.

%% Make sure that the `line_coverage` option will not change
%% line numbers in exceptions.
sys_coverage(Config) ->
Mod = exceptions,
DataDir = proplists:get_value(data_dir, Config),

sys_coverage_1(DataDir),
sys_coverage_2(DataDir),

ok.

%% Make sure that the `line_coverage` option will not change line
%% numbers in exceptions.
sys_coverage_1(DataDir) ->
Mod = exceptions,
Source = filename:join(DataDir, "exceptions"),
{ok,Mod,Code} = compile:file(Source, [line_coverage,binary,report]),
{module,Mod} = code:load_binary(Mod, "", Code),

Mod:Mod(Config),
Mod:Mod(DataDir),

true = code:delete(Mod),
false = code:purge(Mod),

ok.

%% Make sure that the `line_coverage` option given in the `compile`
%% attribute in a module works.
sys_coverage_2(DataDir) ->
Mod = embedded_line_coverage,
Source = filename:join(DataDir, "embedded_line_coverage"),
{ok,Mod,Asm} = compile:file(Source, ['S',binary,report]),

{Mod,_,_,Fs,_} = Asm,
[{function,add,2,_,Is}|_] = Fs,
true = lists:keymember(executable_line, 1, Is),

ok.

%%%
%%% Utilities.
%%%
Expand Down
29 changes: 29 additions & 0 deletions lib/compiler/test/compile_SUITE_data/embedded_line_coverage.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2024. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%

-module(embedded_line_coverage).
-export([add/2]).

%% Test that using the `line_coverage` option works when given in a
%% module.
-compile([line_coverage]).

add(A, B) ->
A + B.

0 comments on commit 78c6bfc

Please sign in to comment.