From a3fa81eafff105086cf3f0c942c5247686edac28 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Mon, 23 Sep 2013 09:08:14 +0200 Subject: Remove last remnants of "spec" --- lib/diameter/test/diameter_compiler_SUITE.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/diameter/test/diameter_compiler_SUITE.erl') diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index 81722c8dca..40d0bf7c63 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -403,7 +403,7 @@ generate(Config) -> [] = ?util:run([{?MODULE, [generate, M, Bin, N, T]} || {E,N} <- Rs, {ok, M} <- [norm(E)], - T <- [erl, hrl, spec]]). + T <- [erl, hrl, dict]]). generate(Mods, Bin, N, Mode) -> B = modify(Bin, Mods ++ [{"@name .*", "@name dict" ++ ?L(N)}]), -- cgit v1.2.3 From 742e83daafafd95b31643f9f2a702da725e1ec18 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Mon, 23 Sep 2013 14:21:41 +0200 Subject: Adapt compiler suite to diameter_make It was originally written before this interface existed. --- lib/diameter/test/diameter_compiler_SUITE.erl | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'lib/diameter/test/diameter_compiler_SUITE.erl') diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index 40d0bf7c63..66c671b52d 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -45,7 +45,7 @@ %% RE/Replacement (in the sense of re:replace/4) pairs for morphing %% base_rfc3588.dia. The key is 'ok' or the the expected error as %% returned in the first element of the error tuple returned by -%% diameter_dict_util:parse/2. +%% diameter_make:codec/2. -define(REPLACE, [{ok, "", @@ -361,10 +361,18 @@ format(Config) -> format(Mods, Bin) -> B = modify(Bin, Mods), - {ok, Dict} = diameter_dict_util:parse(B, []), - {ok, D} = diameter_dict_util:parse(diameter_dict_util:format(Dict), []), + {ok, Dict} = make(B, []), + {ok, D} = make(diameter_make:format(Dict), []), {Dict, Dict} = {Dict, D}. +make(File, Opts) -> + case diameter_make:codec(File, [return, debug | Opts]) of + {ok, [_E,_H,_F,[_Vsn|Dict]]} -> + {ok, Dict}; + {error, _} = E -> + E + end. + %% =========================================================================== %% replace/1 %% @@ -379,13 +387,10 @@ replace(Config) -> replace({E, Mods}, Bin) -> B = modify(Bin, Mods), - case {E, diameter_dict_util:parse(B, [{include, here()}]), Mods} of + case {E, make(B, [{include, here()}]), Mods} of {ok, {ok, Dict}, _} -> Dict; - {_, {error, {E,_} = T}, _} -> - S = diameter_dict_util:format_error(T), - true = nochar($", S, E), - true = nochar($', S, E), + {_, {error, S}, _} -> S end. @@ -407,7 +412,7 @@ generate(Config) -> generate(Mods, Bin, N, Mode) -> B = modify(Bin, Mods ++ [{"@name .*", "@name dict" ++ ?L(N)}]), - {ok, Dict} = diameter_dict_util:parse(B, []), + {ok, Dict} = make(B, []), File = "dict" ++ integer_to_list(N), {_, ok} = {Dict, diameter_codegen:from_dict("dict", Dict, @@ -428,9 +433,6 @@ norm({E, RE, Repl}) -> norm({_,_} = T) -> T. -nochar(Char, Str, Err) -> - Err == parse orelse not lists:member(Char, Str) orelse Str. - here() -> filename:dirname(code:which(?MODULE)). -- cgit v1.2.3 From 8e819a7960a256b6c3b7bf5856c3f81b8df9ca7e Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Wed, 25 Sep 2013 11:28:19 +0200 Subject: Simplify and extend diameter_make interface In particular, make codec/2 flexible as to what's generated, the formats (erl, hrl, parse, forms and beam) being passed in the options list and defaulting to [erl, hrl]. The 'parse' format is the internal format to which dictionaries are parsed, which can be manipulated by flatten/1 before being passed back to codec/2 or format/1. Remove the (undocumented) dict/1,2 since codec/2 now subsumes it with the 'parse' option. --- lib/diameter/test/diameter_compiler_SUITE.erl | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'lib/diameter/test/diameter_compiler_SUITE.erl') diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index 66c671b52d..943cac1446 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -366,8 +366,8 @@ format(Mods, Bin) -> {Dict, Dict} = {Dict, D}. make(File, Opts) -> - case diameter_make:codec(File, [return, debug | Opts]) of - {ok, [_E,_H,_F,[_Vsn|Dict]]} -> + case diameter_make:codec(File, [parse, hrl, return | Opts]) of + {ok, [Dict, _]} -> {ok, Dict}; {error, _} = E -> E @@ -408,20 +408,30 @@ generate(Config) -> [] = ?util:run([{?MODULE, [generate, M, Bin, N, T]} || {E,N} <- Rs, {ok, M} <- [norm(E)], - T <- [erl, hrl, dict]]). + T <- [erl, hrl, parse, forms]]). generate(Mods, Bin, N, Mode) -> B = modify(Bin, Mods ++ [{"@name .*", "@name dict" ++ ?L(N)}]), {ok, Dict} = make(B, []), File = "dict" ++ integer_to_list(N), - {_, ok} = {Dict, diameter_codegen:from_dict("dict", - Dict, - [{name, File}, - {prefix, "base"}, - debug], - Mode)}, - Mode == erl - andalso ({ok, _} = compile:file(File ++ ".erl", [return_errors])). + {_, ok} = {Dict, diameter_make:codec(Dict, + [{name, File}, + {prefix, "base"}, + Mode])}, + generate(Mode, File, Dict). + +generate(erl, File, _) -> + {ok, _} = compile:file(File ++ ".erl", [return_errors]); + +generate(forms, File, _) -> + {ok, [_]} = file:consult(File ++ ".F"); + +generate(parse, File, Dict) -> + {ok, [Dict]} = file:consult(File ++ ".D"), %% assert + {ok, [_]} = diameter_make:codec(Dict, [beam, return]); + +generate(hrl, _, _) -> + ok. %% =========================================================================== -- cgit v1.2.3 From b4b8a2130348d8828a53303d7003e24abfc692f2 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Fri, 4 Oct 2013 10:57:07 +0200 Subject: Fix diameter_make:flatten/1 To set @avp_vendor_id, @codecs and @custom_types as required for imported avps. --- lib/diameter/test/diameter_compiler_SUITE.erl | 119 ++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 7 deletions(-) (limited to 'lib/diameter/test/diameter_compiler_SUITE.erl') diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index 943cac1446..a37f52a2c5 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -31,10 +31,15 @@ %% testcases -export([format/1, format/2, replace/1, replace/2, - generate/1, generate/4]). + generate/1, generate/4, + flatten1/1, flatten1/3, + flatten2/1]). -export([dict/0]). %% fake dictionary module +%% dictionary callbacks for flatten2/1 +-export(['A1'/3, 'Unsigned32'/3]). + -define(base, "base_rfc3588.dia"). -define(util, diameter_util). -define(S, atom_to_list). @@ -335,7 +340,9 @@ suite() -> all() -> [format, replace, - generate]. + generate, + flatten1, + flatten2]. %% Error handling testcases will make an erroneous dictionary out of %% the base dictionary and check that the expected error results. @@ -361,11 +368,11 @@ format(Config) -> format(Mods, Bin) -> B = modify(Bin, Mods), - {ok, Dict} = make(B, []), - {ok, D} = make(diameter_make:format(Dict), []), + {ok, Dict} = parse(B, []), + {ok, D} = parse(diameter_make:format(Dict), []), {Dict, Dict} = {Dict, D}. -make(File, Opts) -> +parse(File, Opts) -> case diameter_make:codec(File, [parse, hrl, return | Opts]) of {ok, [Dict, _]} -> {ok, Dict}; @@ -387,7 +394,7 @@ replace(Config) -> replace({E, Mods}, Bin) -> B = modify(Bin, Mods), - case {E, make(B, [{include, here()}]), Mods} of + case {E, parse(B, [{include, here()}]), Mods} of {ok, {ok, Dict}, _} -> Dict; {_, {error, S}, _} -> @@ -412,7 +419,7 @@ generate(Config) -> generate(Mods, Bin, N, Mode) -> B = modify(Bin, Mods ++ [{"@name .*", "@name dict" ++ ?L(N)}]), - {ok, Dict} = make(B, []), + {ok, Dict} = parse(B, []), File = "dict" ++ integer_to_list(N), {_, ok} = {Dict, diameter_make:codec(Dict, [{name, File}, @@ -433,6 +440,104 @@ generate(parse, File, Dict) -> generate(hrl, _, _) -> ok. +%% =========================================================================== +%% flatten1/1 + +flatten1(_Config) -> + [Vsn | BaseD] = diameter_gen_base_rfc6733:dict(), + {ok, I} = parse("@inherits diameter_gen_base_rfc6733\n", []), + [Vsn | FlatD] = diameter_make:flatten(I), + [] = ?util:run([{?MODULE, [flatten1, K, BaseD, FlatD]} + || K <- [avp_types, grouped, enum]]). + +flatten1(Key, BaseD, FlatD) -> + Vs = orddict:fetch(Key, BaseD), + Vs = orddict:fetch(Key, FlatD). + +%% =========================================================================== +%% flatten2/1 + +flatten2(_Config) -> + Dict1 = + "@name diameter_test1\n" + "@prefix diameter_test1\n" + "@vendor 666 test\n" + "@avp_vendor_id 111 A1 A3\n" + "@avp_vendor_id 222 A4 A6\n" + "@custom_types " ++ ?S(?MODULE) ++ " A1 A4\n" + "@codecs " ++ ?S(?MODULE) ++ " A3 A6\n" + "@avp_types\n" + "A1 1001 Unsigned32 V\n" + "A2 1002 Unsigned32 V\n" + "A3 1003 Unsigned32 V\n" + "A4 1004 Unsigned32 V\n" + "A5 1005 Unsigned32 V\n" + "A6 1006 Unsigned32 V\n" + "@end ignored\n", + Dict2 = + "@name diameter_test2\n" + "@prefix diameter_test2\n" + "@vendor 777 test\n" + "@inherits diameter_test1 A1 A2 A3\n" + "@inherits diameter_gen_base_rfc6733\n" + "@avp_vendor_id 333 A1\n", + + {ok, [E1, {_,B1}]} + = diameter_make:codec(Dict1, [erl, beam, return]), + ct:pal("~s", [E1]), + {module, diameter_test1} + = code:load_binary(diameter_test1, "diameter_test1", B1), + + + {ok, [D2, E2, {_,B2}]} + = diameter_make:codec(Dict2, [parse, erl, beam, return]), + ct:pal("~s", [E2]), + {module, diameter_test2} + = code:load_binary(diameter_test2, "diameter_test2", B2), + + + Flat = lists:flatten(diameter_make:format(diameter_make:flatten(D2))), + ct:pal("~s", [Flat]), + {ok, [E3, {_,B3}]} + = diameter_make:codec(Flat, [erl, beam, return, + {name, "diameter_test3"}]), + ct:pal("~s", [E3]), + {module, diameter_test3} + = code:load_binary(diameter_test3, "diameter_test3", B3), + + {M1, M2, M3} = {diameter_test1, diameter_test2, diameter_test3}, + + [{1001, 111, M1, 'A1'}, %% @avp_vendor_id + {1002, 666, M1, 'A2'}, %% @vendor + {1003, 111, M1, 'A3'}, %% @avp_vendor_id + {1004, 222, M1, 'A4'}, %% @avp_vendor_id + {1005, 666, M1, 'A5'}, %% @vendor + {1006, 222, M1, 'A6'}, %% @avp_vendor_id + {1001, 333, M2, 'A1'}, %% M2 @avp_vendor_id + {1002, 666, M2, 'A2'}, %% M1 @vendor + {1003, 666, M2, 'A3'}, %% M1 @vendor + {1001, 333, M3, 'A1'}, %% (as for M2) + {1002, 666, M3, 'A2'}, %% " + {1003, 666, M3, 'A3'}] %% " + = [{Code, Vid, Mod, Name} + || Mod <- [M1, M2, M3], + Code <- lists:seq(1001, 1006), + Vid <- [666, 111, 222, 777, 333], + {Name, 'Unsigned32'} <- [Mod:avp_name(Code, Vid)]], + + [] = [{A,T,M,RC} || A <- ['A1', 'A3'], + T <- [encode, decode], + M <- [M2, M3], + Ref <- [make_ref()], + RC <- [M:avp(T, Ref, A)], + RC /= {T, Ref}]. + +'A1'(T, 'Unsigned32', Ref) -> + {T, Ref}. + +'Unsigned32'(T, 'A3', Ref) -> + {T, Ref}. + %% =========================================================================== modify(Bin, Mods) -> -- cgit v1.2.3 From 2eb76ba556b8775cffc94eac26b448eac70af267 Mon Sep 17 00:00:00 2001 From: Anders Svensson Date: Sun, 1 Dec 2013 14:19:27 +0100 Subject: Return compilable forms instead of beam That is, preprocessed forms that can be passed to compile:forms/1,2. --- lib/diameter/test/diameter_compiler_SUITE.erl | 33 +++++++++++++-------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'lib/diameter/test/diameter_compiler_SUITE.erl') diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index a37f52a2c5..ed369e8af3 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -435,7 +435,8 @@ generate(forms, File, _) -> generate(parse, File, Dict) -> {ok, [Dict]} = file:consult(File ++ ".D"), %% assert - {ok, [_]} = diameter_make:codec(Dict, [beam, return]); + {ok, [F]} = diameter_make:codec(Dict, [forms, return]), + {ok, _, _, _} = compile:forms(F, [return]); generate(hrl, _, _) -> ok. @@ -482,30 +483,23 @@ flatten2(_Config) -> "@inherits diameter_gen_base_rfc6733\n" "@avp_vendor_id 333 A1\n", - {ok, [E1, {_,B1}]} - = diameter_make:codec(Dict1, [erl, beam, return]), + {ok, [E1, F1]} + = diameter_make:codec(Dict1, [erl, forms, return]), ct:pal("~s", [E1]), - {module, diameter_test1} - = code:load_binary(diameter_test1, "diameter_test1", B1), + diameter_test1 = M1 = load_forms(F1), - - {ok, [D2, E2, {_,B2}]} - = diameter_make:codec(Dict2, [parse, erl, beam, return]), + {ok, [D2, E2, F2]} + = diameter_make:codec(Dict2, [parse, erl, forms, return]), ct:pal("~s", [E2]), - {module, diameter_test2} - = code:load_binary(diameter_test2, "diameter_test2", B2), - + diameter_test2 = M2 = load_forms(F2), Flat = lists:flatten(diameter_make:format(diameter_make:flatten(D2))), ct:pal("~s", [Flat]), - {ok, [E3, {_,B3}]} - = diameter_make:codec(Flat, [erl, beam, return, + {ok, [E3, F3]} + = diameter_make:codec(Flat, [erl, forms, return, {name, "diameter_test3"}]), ct:pal("~s", [E3]), - {module, diameter_test3} - = code:load_binary(diameter_test3, "diameter_test3", B3), - - {M1, M2, M3} = {diameter_test1, diameter_test2, diameter_test3}, + diameter_test3 = M3 = load_forms(F3), [{1001, 111, M1, 'A1'}, %% @avp_vendor_id {1002, 666, M1, 'A2'}, %% @vendor @@ -538,6 +532,11 @@ flatten2(_Config) -> 'Unsigned32'(T, 'A3', Ref) -> {T, Ref}. +load_forms(Forms) -> + {ok, Mod, Bin, _} = compile:forms(Forms, [return]), + {module, Mod} = code:load_binary(Mod, ?S(Mod), Bin), + Mod. + %% =========================================================================== modify(Bin, Mods) -> -- cgit v1.2.3