~clint-fewbar/ubuntu/precise/erlang/merge-15b

« back to all changes in this revision

Viewing changes to lib/reltool/test/rtt.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%% 
 
4
%% Copyright Ericsson AB 2010. All Rights Reserved.
 
5
%% 
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%% 
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%% 
 
17
%% %CopyrightEnd%
 
18
 
 
19
-module(rtt).
 
20
-compile(export_all).
 
21
 
 
22
%%  Modules or suites can be shortcuts, for example server expands to reltool_server_SUITE.
 
23
%%  
 
24
%%  t(Tests) run reltool testcases.
 
25
%%    Tests can be module, {module, test_case} or [module|{module,test_case}]
 
26
 
 
27
t() ->
 
28
    t(read_test_case()).
 
29
t(Test) ->
 
30
    t(Test, []).
 
31
 
 
32
t(Mod, TC) when is_atom(Mod), is_atom(TC) ->
 
33
    t({Mod,TC}, []);
 
34
t(all, Config) when is_list(Config) ->
 
35
    Fs = filelib:wildcard("reltool_*_SUITE.erl"),
 
36
    t([list_to_atom(filename:rootname(File)) || File <- Fs], Config);
 
37
t(Test,Config) when is_list(Config) ->
 
38
    Tests = resolve(Test),
 
39
    write_test_case(Test),
 
40
    Res = reltool_test_lib:run_test(Tests, Config),    
 
41
    append_test_case_info(Test, Res).
 
42
 
 
43
user() ->
 
44
    user(read_test_case()). 
 
45
user(Mod) ->
 
46
    t(Mod, [{user,step}]).
 
47
user(Mod,Tc) when is_atom(Tc) ->
 
48
    t({Mod,Tc}, [{user,step}]).
 
49
    
 
50
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
51
%% Resolves the name of test suites and test cases
 
52
%% according to the alias definitions. Single atoms
 
53
%% are assumed to be the name of a test suite. 
 
54
 
 
55
resolve(Suite0) when is_atom(Suite0) ->
 
56
    case alias(Suite0) of
 
57
        Suite when is_atom(Suite) ->
 
58
            {Suite, all};
 
59
        {Suite, Case} ->
 
60
            {Suite, Case}
 
61
    end;
 
62
resolve({Suite0, Case}) when is_atom(Suite0), is_atom(Case) ->
 
63
    case alias(Suite0) of
 
64
        Suite when is_atom(Suite) ->
 
65
            {Suite, Case};
 
66
        {Suite, Case2} ->
 
67
            {Suite, Case2}
 
68
    end;
 
69
resolve(List) when is_list(List) ->
 
70
    [resolve(Case) || Case <- List].
 
71
 
 
72
alias(Suite) when is_atom(Suite) ->
 
73
    Str = atom_to_list(Suite),
 
74
    case {Str, lists:reverse(Str)} of
 
75
        {"reltool" ++ _, "ETIUS" ++ _} ->
 
76
            Suite;
 
77
        _ -> 
 
78
            list_to_atom("reltool_" ++ Str ++ "_SUITE")
 
79
    end.
 
80
 
 
81
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
82
 
 
83
config_fname() ->
 
84
    "reltool_test_case_config".
 
85
 
 
86
%% Read default config file
 
87
read_config() ->
 
88
    Fname = config_fname(),
 
89
    reltool_test_lib:log("Consulting file ~s...~n", [Fname]),
 
90
    case file:consult(Fname) of
 
91
        {ok, Config} ->
 
92
            reltool_test_lib:log("Read config ~w~n", [Config]),
 
93
            Config;
 
94
        _Error ->
 
95
            Config = reltool_test_lib:default_config(),
 
96
            reltool_test_lib:log("<>WARNING<> Using default config: ~w~n", [Config]),
 
97
            Config
 
98
    end.
 
99
 
 
100
%% Write new default config file
 
101
write_config(Config) when is_list(Config) ->
 
102
    Fname = config_fname(),
 
103
    {ok, Fd} = file:open(Fname, write),
 
104
    write_list(Fd, Config),
 
105
    file:close(Fd).
 
106
 
 
107
write_list(Fd, [H | T]) ->
 
108
    ok = io:format(Fd, "~p.~n",[H]),
 
109
    write_list(Fd, T);
 
110
write_list(_, []) ->
 
111
    ok.
 
112
 
 
113
test_case_fname() ->
 
114
    "reltool_test_case_info".
 
115
 
 
116
%% Read name of test case
 
117
read_test_case() ->
 
118
    Fname = test_case_fname(),
 
119
    case file:open(Fname, [read]) of
 
120
        {ok, Fd} ->
 
121
            Res = io:read(Fd, []),
 
122
            file:close(Fd),
 
123
            case Res of
 
124
                {ok, TestCase} ->
 
125
                    reltool_test_lib:log("Using test case ~w from file ~s~n",
 
126
                                         [TestCase, Fname]),
 
127
                    TestCase;
 
128
                {error, _} ->
 
129
                    default_test_case(Fname)
 
130
            end;
 
131
        {error, _} ->
 
132
            default_test_case(Fname)
 
133
    end.
 
134
 
 
135
default_test_case(Fname) ->
 
136
    TestCase = all, 
 
137
    reltool_test_lib:log("<>WARNING<> Cannot read file ~s, "
 
138
                         "using default test case: ~w~n",
 
139
                         [Fname, TestCase]),
 
140
    TestCase.
 
141
 
 
142
write_test_case(TestCase) ->
 
143
    Fname = test_case_fname(),
 
144
    {ok, Fd} = file:open(Fname, write),
 
145
    ok = io:format(Fd, "~p.~n",[TestCase]),
 
146
    file:close(Fd).
 
147
 
 
148
append_test_case_info(TestCase, TestCaseInfo) ->
 
149
    Fname = test_case_fname(),
 
150
    {ok, Fd} = file:open(Fname, [read, write]),
 
151
    ok = io:format(Fd, "~p.~n",[TestCase]),
 
152
    ok = io:format(Fd, "~p.~n",[TestCaseInfo]),
 
153
    file:close(Fd),
 
154
    TestCaseInfo.