Skip to content

Commit

Permalink
bif_SUITE: Fix failing test cases when run in a git repo
Browse files Browse the repository at this point in the history
The preloaded BEAM files in `$ERL_TOP`/erts/preloaded/ebin` in
the git repo longer contains debug information. That would cause
three of the test cases to fail. Instead of failing, don't attempt
to verify BIFs residing in preloaded modules when running the tests
in a git repo.
  • Loading branch information
bjorng committed Nov 11, 2024
1 parent c24e439 commit 422622a
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions erts/emulator/test/bif_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,17 @@ shadow_comments(_Config) ->
List1 = [MFA || {M,_,_}=MFA <- List0, M =/= erlang],
List = List1 ++ ErlangList,
HasTypes = [MFA || {M,F,A}=MFA <- List,
erl_bif_types:is_known(M, F, A)],
Path = get_code_path(),
BifRel = sofs:relation(HasTypes, [{m,f,a}]),
BifModules = sofs:to_external(sofs:projection(1, BifRel)),
AbstrByModule = [extract_abstract(Mod, Path) || Mod <- BifModules],
erl_bif_types:is_known(M, F, A)],
BifModules = bif_modules(HasTypes),
AbstrByModule = [extract_abstract(Mod) || Mod <- BifModules],
Specs0 = [extract_specs(Mod, Abstr) ||
{Mod,Abstr} <- AbstrByModule],
Specs = lists:append(Specs0),
SpecFuns0 = [F || {F,_} <- Specs],
SpecFuns = sofs:relation(SpecFuns0, [{m,f,a}]),
BifRel = sofs:relation(HasTypes, [{m,f,a}]),
HasTypesAndSpecs = sofs:intersection(BifRel, SpecFuns),
Commented0 = lists:append([extract_comments(Mod, Path) ||
Commented0 = lists:append([extract_comments(Mod) ||
Mod <- BifModules]),
Commented = sofs:relation(Commented0, [{m,f,a}]),
{NoComments0,_,NoBifSpecs0} =
Expand Down Expand Up @@ -246,8 +245,8 @@ shadow_comments(_Config) ->
ct:fail(erl_bif_types)
end.

extract_comments(Mod, Path) ->
Beam = which(Mod, Path),
extract_comments(Mod) ->
Beam = which(Mod),
SrcDir = filename:join(filename:dirname(filename:dirname(Beam)), "src"),
Src = filename:join(SrcDir, atom_to_list(Mod) ++ ".erl"),
{ok,Bin} = file:read_file(Src),
Expand All @@ -267,13 +266,12 @@ specs(_) ->
List0 = erlang:system_info(snifs),

%% Ignore all operators.
List = [MFA || MFA <- List0, not is_operator(MFA)],
List1 = [MFA || MFA <- List0, not is_operator(MFA)],

%% Extract specs from the abstract code for all BIFs.
Path = get_code_path(),
BifRel = sofs:relation(List, [{m,f,a}]),
BifModules = sofs:to_external(sofs:projection(1, BifRel)),
AbstrByModule = [extract_abstract(Mod, Path) || Mod <- BifModules],
BifModules = bif_modules(List1),
List = [MFA || {M,_,_}=MFA <- List1, lists:member(M, BifModules)],
AbstrByModule = [extract_abstract(Mod) || Mod <- BifModules],
Specs0 = [extract_specs(Mod, Abstr) ||
{Mod,Abstr} <- AbstrByModule],
Specs = lists:append(Specs0),
Expand Down Expand Up @@ -312,10 +310,8 @@ make_mfa(M, {M,_,_}=MFA) -> MFA.

improper_bif_stubs(_) ->
Bifs = erlang:system_info(snifs),
Path = get_code_path(),
BifRel = sofs:relation(Bifs, [{m,f,a}]),
BifModules = sofs:to_external(sofs:projection(1, BifRel)),
AbstrByModule = [extract_abstract(Mod, Path) || Mod <- BifModules],
BifModules = bif_modules(Bifs),
AbstrByModule = [extract_abstract(Mod) || Mod <- BifModules],
Funcs0 = [extract_functions(Mod, Abstr) ||
{Mod,Abstr} <- AbstrByModule],
Funcs = lists:append(Funcs0),
Expand Down Expand Up @@ -1792,35 +1788,42 @@ busy_wait_go() ->

id(I) -> I.

%% Get code path, including the path for the erts application.
get_code_path() ->
Erts = filename:join([code:root_dir(),"erts","preloaded","ebin"]),
case filelib:is_dir(Erts) of
true->
[Erts|code:get_path()];
_ ->
code:get_path()
bif_modules(MFAs) ->
BifRel = sofs:relation(MFAs, [{m,f,a}]),
BifModules = sofs:to_external(sofs:projection(1, BifRel)),
case is_otp_installed() of
true ->
BifModules;
false ->
%% Running in an uninstalled system. The preloaded modules
%% don't contain any abstract code.
io:put_chars("** Running in an uninstalled system. Not verifying pre-loaded modules\n"
"** because they don't have debug_info chunks.\n"),
[M || M <- BifModules, code:which(M) =/= preloaded]
end.

which(Mod, Path) ->
which_1(atom_to_list(Mod) ++ ".beam", Path).
is_otp_installed() ->
LibDir = code:lib_dir(),
ErtsDir = code:lib_dir(erts),
lists:prefix(LibDir, ErtsDir).

which_1(Base, [D|Ds]) ->
Path = filename:join(D, Base),
case filelib:is_regular(Path) of
true -> Path;
false -> which_1(Base, Ds)
end.
print_mfa({M,F,A}) ->
io:format("~p:~p/~p", [M,F,A]).

extract_abstract(Mod, Path) ->
Beam = which(Mod, Path),
which(Mod) ->
case code:which(Mod) of
preloaded ->
filename:join([code:lib_dir(erts), "ebin", atom_to_list(Mod) ++ ".beam"]);
Beam when is_list(Beam) ->
Beam
end.

extract_abstract(Mod) ->
Beam = which(Mod),
{ok,{Mod,[{abstract_code,{raw_abstract_v1,Abstr}}]}} =
beam_lib:chunks(Beam, [abstract_code]),
{Mod,Abstr}.


tok_loop() ->
tok_loop(hej).

Expand Down

0 comments on commit 422622a

Please sign in to comment.