Skip to content

Commit

Permalink
Move example dict compilation to examples suite
Browse files Browse the repository at this point in the history
From compiler suite.
  • Loading branch information
Anders Svensson committed Mar 24, 2013
1 parent 849d61f commit dbdab43
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 52 deletions.
51 changes: 3 additions & 48 deletions lib/diameter/test/diameter_compiler_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2010-2012. All Rights Reserved.
%% Copyright Ericsson AB 2010-2013. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
Expand Down Expand Up @@ -31,8 +31,7 @@
%% testcases
-export([format/1, format/2,
replace/1, replace/2,
generate/1, generate/4,
examples/1]).
generate/1, generate/4]).

-export([dict/0]). %% fake dictionary module

Expand Down Expand Up @@ -328,14 +327,6 @@
"@codecs mymod "
"Origin-Host Origin-Realm\n&"}]}]).

%% Standard dictionaries in examples/dict.
-define(EXAMPLES, [rfc4004_mip,
rfc4005_nas,
rfc4006_cc,
rfc4072_eap,
rfc4590_digest,
rfc4740_sip]).

%% ===========================================================================

suite() ->
Expand All @@ -344,8 +335,7 @@ suite() ->
all() ->
[format,
replace,
generate,
examples].
generate].

%% Error handling testcases will make an erroneous dictionary out of
%% the base dictionary and check that the expected error results.
Expand Down Expand Up @@ -428,41 +418,6 @@ generate(Mods, Bin, N, Mode) ->
Mode == erl
andalso ({ok, _} = compile:file(File ++ ".erl", [return_errors])).

%% ===========================================================================
%% examples/1
%%
%% Compile dictionaries extracted from various standards.

examples(_Config) ->
Dir = filename:join([code:lib_dir(diameter, examples), "dict"]),
[D || D <- ?EXAMPLES, _ <- [examples(?S(D), Dir)]].

examples(Dict, Dir) ->
{Name, Pre} = make_name(Dict),
ok = diameter_make:codec(filename:join([Dir, Dict ++ ".dia"]),
[{name, Name},
{prefix, Pre},
inherits("rfc3588_base")
| opts(Dict)]),
{ok, _, _} = compile:file(Name ++ ".erl", [return]).

opts(M)
when M == "rfc4006_cc";
M == "rfc4072_eap" ->
[inherits("rfc4005_nas")];
opts("rfc4740_sip") ->
[inherits("rfc4590_digest")];
opts(_) ->
[].

inherits(File) ->
{Name, _} = make_name(File),
{inherits, File ++ "/" ++ Name}.

make_name(File) ->
{R, [$_|N]} = lists:splitwith(fun(C) -> C /= $_ end, File),
{string:join(["diameter_gen", N, R], "_"), "diameter_" ++ N}.

%% ===========================================================================

modify(Bin, Mods) ->
Expand Down
81 changes: 77 additions & 4 deletions lib/diameter/test/diameter_examples_SUITE.erl
Expand Up @@ -27,7 +27,8 @@
all/0]).

%% testcases
-export([compile/1,
-export([dict/1, dict/0,
code/1,
enslave/1,
start/1,
traffic/1,
Expand Down Expand Up @@ -57,17 +58,87 @@ suite() ->
[{timetrap, {seconds, 45}}].

all() ->
[compile,
[dict,
code,
enslave,
start,
traffic,
stop].

%% ===========================================================================
%% dict/1
%%
%% Compile example dictionaries in examples/dict.

-define(EXAMPLES, [rfc4004_mip,
rfc4005_nas,
rfc4006_cc,
rfc4072_eap,
rfc4590_digest,
rfc4740_sip]).

dict() ->
[{timetrap, {minutes, length(?EXAMPLES)}}].

dict(_Config) ->
Dir = filename:join([code:lib_dir(diameter, examples), "dict"]),
[] = [RC || D <- ?EXAMPLES,
RC <- [dict(atom_to_list(D), Dir)],
RC /= ok].

dict(Dict, Dir) ->
{Name, Pre} = make_name(Dict),
try
ok = make(filename:join([Dir, Dict ++ ".dia"]),
[{name, Name},
{prefix, Pre},
inherits("rfc3588_base")
| opts(Dict)]),
ok = compile(Name)
catch
throw: {_,_} = E ->
E
end.

make(File, Opts) ->
case diameter_make:codec(File, Opts) of
ok ->
ok;
No ->
throw({make, No})
end.

compile(Name) ->
case compile:file(Name ++ ".erl", [return]) of
{ok, _, _} ->
ok;
No ->
throw({compile, No})
end.

%% compile/1
opts(M)
when M == "rfc4006_cc";
M == "rfc4072_eap" ->
[inherits("rfc4005_nas")];
opts("rfc4740_sip") ->
[inherits("rfc4590_digest")];
opts(_) ->
[].

compile(Config) ->
inherits(File) ->
{Name, _} = make_name(File),
{inherits, File ++ "/" ++ Name}.

make_name(File) ->
{R, [$_|N]} = lists:splitwith(fun(C) -> C /= $_ end, File),
{string:join(["diameter_gen", N, R], "_"), "diameter_" ++ N}.

%% ===========================================================================
%% code/1
%%
%% Compile example code under examples/code.

code(Config) ->
Node = slave(hd(?NODES), here()),
[] = rpc:call(Node,
?MODULE,
Expand Down Expand Up @@ -129,6 +200,8 @@ find_files(Dir, RE) ->
cons(H,T) ->
[H|T].

%% ===========================================================================

%% enslave/1
%%
%% Start two nodes: one for the server, one for the client.
Expand Down

0 comments on commit dbdab43

Please sign in to comment.