1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2011-2016. All Rights Reserved.
5%%
6%% Licensed under the Apache License, Version 2.0 (the "License");
7%% you may not use this file except in compliance with the License.
8%% You may obtain a copy of the License at
9%%
10%%     http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing, software
13%% distributed under the License is distributed on an "AS IS" BASIS,
14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15%% See the License for the specific language governing permissions and
16%% limitations under the License.
17%%
18%% %CopyrightEnd%
19%%
20-module(beam_disasm_SUITE).
21
22-include_lib("common_test/include/ct.hrl").
23
24-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
25	 init_per_group/2,end_per_group/2]).
26
27-export([stripped/1]).
28
29suite() -> [{ct_hooks,[ts_install_cth]}].
30
31all() ->
32    [stripped].
33
34groups() ->
35    [].
36
37init_per_suite(Config) ->
38    Config.
39
40end_per_suite(_Config) ->
41    ok.
42
43init_per_group(_GroupName, Config) ->
44    Config.
45
46end_per_group(_GroupName, Config) ->
47    Config.
48
49%% Check that stripped beam files can be disassembled.
50stripped(Config) when is_list(Config) ->
51    PrivDir = proplists:get_value(priv_dir, Config),
52    SrcName = filename:join(PrivDir, "tmp.erl"),
53    BeamName = filename:join(PrivDir, "tmp.beam"),
54    Prog = <<"-module(tmp).\n-export([tmp/0]).\ntmp()->ok.\n">>,
55    ok = file:write_file(SrcName, Prog),
56    {ok, tmp} =
57	compile:file(SrcName, [{outdir, PrivDir}]),
58    {beam_file, tmp, _, Attr, CompileInfo, [_|_]} =
59	beam_disasm:file(BeamName),
60    true = is_list(Attr),
61    true = is_list(CompileInfo),
62    {ok, {tmp, _}} = beam_lib:strip(BeamName),
63    {beam_file, tmp, _, [], [], [_|_]} =
64	beam_disasm:file(BeamName),
65    ok.
66