aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/test/compile_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compiler/test/compile_SUITE.erl')
-rw-r--r--lib/compiler/test/compile_SUITE.erl122
1 files changed, 104 insertions, 18 deletions
diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index 11a62ce753..f647a4030d 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2016. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2017. 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.
@@ -31,11 +31,12 @@
file_1/1, forms_2/1, module_mismatch/1, big_file/1, outdir/1,
binary/1, makedep/1, cond_and_ifdef/1, listings/1, listings_big/1,
other_output/1, kernel_listing/1, encrypted_abstr/1,
- strict_record/1, utf8_atoms/1, extra_chunks/1,
- cover/1, env/1, core/1,
+ strict_record/1, utf8_atoms/1, utf8_functions/1, extra_chunks/1,
+ cover/1, env/1, core_pp/1,
core_roundtrip/1, asm/1, optimized_guards/1,
sys_pre_attributes/1, dialyzer/1,
- warnings/1, pre_load_check/1, env_compiler_options/1
+ warnings/1, pre_load_check/1, env_compiler_options/1,
+ bc_options/1
]).
suite() -> [{ct_hooks,[ts_install_cth]}].
@@ -49,10 +50,10 @@ all() ->
[app_test, appup_test, file_1, forms_2, module_mismatch, big_file, outdir,
binary, makedep, cond_and_ifdef, listings, listings_big,
other_output, kernel_listing, encrypted_abstr,
- strict_record, utf8_atoms, extra_chunks,
- cover, env, core, core_roundtrip, asm, optimized_guards,
+ strict_record, utf8_atoms, utf8_functions, extra_chunks,
+ cover, env, core_pp, core_roundtrip, asm, optimized_guards,
sys_pre_attributes, dialyzer, warnings, pre_load_check,
- env_compiler_options, custom_debug_info].
+ env_compiler_options, custom_debug_info, bc_options].
groups() ->
[].
@@ -162,6 +163,24 @@ forms_2(Config) when is_list(Config) ->
ok
end,
+ {ok,simple,Core} = compile:forms(SimpleCode, [to_core0,binary]),
+ forms_compile_and_load(Core, [from_core]),
+ forms_compile_and_load(Core, [from_core,native]),
+
+ {ok,simple,Asm} = compile:forms(SimpleCode, [to_asm,binary]),
+ forms_compile_and_load(Asm, [from_asm]),
+ forms_compile_and_load(Asm, [from_asm,native]),
+
+ {ok,simple,Beam} = compile:forms(SimpleCode, []),
+ forms_compile_and_load(Beam, [from_beam]),
+ forms_compile_and_load(Beam, [from_beam,native]),
+
+ %% Cover the error handling code.
+ error = compile:forms(bad_core, [from_core,report]),
+ error = compile:forms(bad_asm, [from_asm,report]),
+ error = compile:forms(<<"bad_beam">>, [from_beam,report]),
+ error = compile:forms(<<"bad_beam">>, [from_beam,native,report]),
+
ok.
@@ -179,6 +198,14 @@ forms_load_code(Mod, Src, Bin) ->
SourceOption.
+forms_compile_and_load(Code, Opts) ->
+ Mod = simple,
+ {ok,Mod,Bin} = compile:forms(Code, Opts),
+ {module,Mod} = code:load_binary(Mod, "ignore", Bin),
+ _ = Mod:module_info(),
+ true = code:delete(simple),
+ false = code:purge(simple),
+ ok.
module_mismatch(Config) when is_list(Config) ->
DataDir = proplists:get_value(data_dir, Config),
@@ -344,6 +371,7 @@ do_file_listings(DataDir, PrivDir, [File|Files]) ->
do_listing(Simple, TargetDir, dinline, ".inline"),
do_listing(Simple, TargetDir, dcore, ".core"),
do_listing(Simple, TargetDir, dcopt, ".copt"),
+ do_listing(Simple, TargetDir, dcbsm, ".core_bsm"),
do_listing(Simple, TargetDir, dsetel, ".dsetel"),
do_listing(Simple, TargetDir, dkern, ".kernel"),
do_listing(Simple, TargetDir, dlife, ".life"),
@@ -603,7 +631,7 @@ install_crypto_key(Key) ->
%% Miscellanous tests, mainly to get better coverage.
debug_info(erlang_v1, Module, ok, _Opts) ->
{ok, [Module]};
-debug_info(erlang_v1, Module, error, _Opts) ->
+debug_info(erlang_v1, _Module, error, _Opts) ->
{error, unknown_format}.
custom_debug_info(Config) when is_list(Config) ->
@@ -727,6 +755,23 @@ utf8_atoms(Config) when is_list(Config) ->
NoUtf8AtomForms = [{attribute,Anno,module,no_utf8_atom}|Forms],
error = compile:forms(NoUtf8AtomForms, [binary, r19]).
+utf8_functions(Config) when is_list(Config) ->
+ Anno = erl_anno:new(1),
+ Atom = binary_to_atom(<<"こんにちは"/utf8>>, utf8),
+ Forms = [{attribute,Anno,compile,[export_all]},
+ {function,Anno,Atom,0,[{clause,Anno,[],[],[{atom,Anno,world}]}]}],
+
+ Utf8FunctionForms = [{attribute,Anno,module,utf8_function}|Forms],
+ {ok,utf8_function,Utf8FunctionBin} =
+ compile:forms(Utf8FunctionForms, [binary]),
+ {ok,{utf8_function,[{atoms,_}]}} =
+ beam_lib:chunks(Utf8FunctionBin, [atoms]),
+ code:load_binary(utf8_function, "compile_SUITE", Utf8FunctionBin),
+ world = utf8_function:Atom(),
+
+ NoUtf8FunctionForms = [{attribute,Anno,module,no_utf8_function}|Forms],
+ error = compile:forms(NoUtf8FunctionForms, [binary, r19]).
+
extra_chunks(Config) when is_list(Config) ->
Anno = erl_anno:new(1),
Forms = [{attribute,Anno,module,extra_chunks}],
@@ -777,9 +822,9 @@ env_1(Simple, Target) ->
%% Test pretty-printing in Core Erlang format and then try to
%% compile the generated Core Erlang files.
-core(Config) when is_list(Config) ->
+core_pp(Config) when is_list(Config) ->
PrivDir = proplists:get_value(priv_dir, Config),
- Outdir = filename:join(PrivDir, "core"),
+ Outdir = filename:join(PrivDir, atom_to_list(?FUNCTION_NAME)),
ok = file:make_dir(Outdir),
TestBeams = get_unique_beam_files(),
@@ -787,11 +832,11 @@ core(Config) when is_list(Config) ->
{raw_abstract_v1,Abstr}}]}} =
beam_lib:chunks(Beam, [abstract_code]),
{Mod,Abstr} end || Beam <- TestBeams],
- test_lib:p_run(fun(F) -> do_core(F, Outdir) end, Abstr).
+ test_lib:p_run(fun(F) -> do_core_pp(F, Outdir) end, Abstr).
-do_core({M,A}, Outdir) ->
+do_core_pp({M,A}, Outdir) ->
try
- do_core_1(M, A, Outdir)
+ do_core_pp_1(M, A, Outdir)
catch
throw:{error,Error} ->
io:format("*** compilation failure '~p' for module ~s\n",
@@ -803,7 +848,7 @@ do_core({M,A}, Outdir) ->
error
end.
-do_core_1(M, A, Outdir) ->
+do_core_pp_1(M, A, Outdir) ->
{ok,M,Core0} = compile:forms(A, [to_core]),
CoreFile = filename:join(Outdir, atom_to_list(M)++".core"),
CorePP = core_pp:format(Core0),
@@ -817,7 +862,7 @@ do_core_1(M, A, Outdir) ->
ok = file:delete(CoreFile),
%% Compile as usual (including optimizations).
- compile_forms(Core, [clint,from_core,binary]),
+ compile_forms(M, Core, [clint,from_core,binary]),
%% Don't optimize to test that we are not dependent
%% on the Core Erlang optmimization passes.
@@ -826,13 +871,13 @@ do_core_1(M, A, Outdir) ->
%% records; if sys_core_fold was run it would fix
%% that; if sys_core_fold was not run v3_kernel would
%% crash.)
- compile_forms(Core, [clint,from_core,no_copt,binary]),
+ compile_forms(M, Core, [clint,from_core,no_copt,binary]),
ok.
-compile_forms(Forms, Opts) ->
+compile_forms(Mod, Forms, Opts) ->
case compile:forms(Forms, [report_errors|Opts]) of
- {ok,[],_} -> ok;
+ {ok,Mod,_} -> ok;
Other -> throw({error,Other})
end.
@@ -1347,6 +1392,47 @@ env_compiler_options(_Config) ->
end,
lists:foreach(F, Cases).
+%% Test options for compatibility with previous major versions of OTP.
+
+bc_options(Config) ->
+ DataDir = proplists:get_value(data_dir, Config),
+
+ 101 = highest_opcode(DataDir, small_float, [no_line_info]),
+
+ 103 = highest_opcode(DataDir, big,
+ [no_record_opt,no_line_info,no_stack_trimming]),
+
+ 125 = highest_opcode(DataDir, small_float, [no_line_info,no_float_opt]),
+
+ 132 = highest_opcode(DataDir, small,
+ [no_record_opt,no_float_opt,no_line_info]),
+
+ 136 = highest_opcode(DataDir, big, [no_record_opt,no_line_info]),
+
+ 153 = highest_opcode(DataDir, big, [no_record_opt]),
+ 153 = highest_opcode(DataDir, big, [r16]),
+ 153 = highest_opcode(DataDir, big, [r17]),
+ 153 = highest_opcode(DataDir, big, [r18]),
+ 153 = highest_opcode(DataDir, big, [r19]),
+ 153 = highest_opcode(DataDir, small_float, [r16]),
+ 153 = highest_opcode(DataDir, small_float, []),
+
+ 158 = highest_opcode(DataDir, small_maps, [r17]),
+ 158 = highest_opcode(DataDir, small_maps, [r18]),
+ 158 = highest_opcode(DataDir, small_maps, [r19]),
+ 158 = highest_opcode(DataDir, small_maps, []),
+
+ 159 = highest_opcode(DataDir, big, []),
+
+ ok.
+
+highest_opcode(DataDir, Mod, Opt) ->
+ Src = filename:join(DataDir, atom_to_list(Mod)++".erl"),
+ {ok,Mod,Beam} = compile:file(Src, [binary|Opt]),
+ {ok,{Mod,[{"Code",Code}]}} = beam_lib:chunks(Beam, ["Code"]),
+ <<16:32,0:32,HighestOpcode:32,_/binary>> = Code,
+ HighestOpcode.
+
%%%
%%% Utilities.
%%%