diff options
author | Anders Svensson <anders@erlang.org> | 2022-03-18 16:05:09 +0100 |
---|---|---|
committer | Anders Svensson <anders@erlang.org> | 2022-03-18 16:05:09 +0100 |
commit | c4d2c952fec0c4ab4ac7ff34c1a153e740fac9a6 (patch) | |
tree | 231bec4ed282a7baef23d03566888db61ff939b3 /lib/diameter/test | |
parent | 7544b927b95951747a6082530b249ade9f212673 (diff) | |
parent | 4daaa84cf99f26647ffa66f100c788eae533897d (diff) | |
download | erlang-c4d2c952fec0c4ab4ac7ff34c1a153e740fac9a6.tar.gz |
Merge branch 'anders/diameter/test/OTP-16752'
* anders/diameter/test/OTP-16752:
Ensure testsuites only write to temporary directory
Diffstat (limited to 'lib/diameter/test')
-rw-r--r-- | lib/diameter/test/diameter_app_SUITE.erl | 2 | ||||
-rw-r--r-- | lib/diameter/test/diameter_codec_SUITE.erl | 29 | ||||
-rw-r--r-- | lib/diameter/test/diameter_compiler_SUITE.erl | 61 | ||||
-rw-r--r-- | lib/diameter/test/diameter_examples_SUITE.erl | 69 | ||||
-rw-r--r-- | lib/diameter/test/diameter_tls_SUITE.erl | 2 | ||||
-rw-r--r-- | lib/diameter/test/diameter_util.erl | 2 |
6 files changed, 98 insertions, 67 deletions
diff --git a/lib/diameter/test/diameter_app_SUITE.erl b/lib/diameter/test/diameter_app_SUITE.erl index 561d4283a2..adcc7114a1 100644 --- a/lib/diameter/test/diameter_app_SUITE.erl +++ b/lib/diameter/test/diameter_app_SUITE.erl @@ -76,7 +76,7 @@ run() -> run(all()). run(List) -> - Tmp = ?util:mktemp(filename:join(?util:tmpdir(), "diameter_app")), + Tmp = ?util:mktemp("diameter_app"), try run([{priv_dir, Tmp}], List) after diff --git a/lib/diameter/test/diameter_codec_SUITE.erl b/lib/diameter/test/diameter_codec_SUITE.erl index ff8a031460..f92b360dab 100644 --- a/lib/diameter/test/diameter_codec_SUITE.erl +++ b/lib/diameter/test/diameter_codec_SUITE.erl @@ -97,7 +97,7 @@ run(lib) -> %% Have a separate AVP dictionary just to exercise more code. run(unknown) -> - PD = ?util:mktemp(filename:join(?util:tmpdir(), "diameter_codec")), + PD = ?util:mktemp("diameter_codec"), DD = filename:join([code:lib_dir(diameter), "test", "diameter_codec_SUITE_data"]), @@ -132,24 +132,25 @@ run(List) -> %% =========================================================================== unknown(Priv, Data) -> - ok = make(Data, "recv.dia"), - ok = make(Data, "avps.dia"), - {ok, _, _} = compile("diameter_test_avps.erl"), - ok = make(Data, "send.dia"), - {ok, _, _} = compile("diameter_test_send.erl"), - {ok, _, _} = compile("diameter_test_recv.erl"), - {ok, _, _} = compile(filename:join([Data, "diameter_test_unknown.erl"]), + ok = make(Data, "recv.dia", Priv), + ok = make(Data, "avps.dia", Priv), + {ok, _, _} = compile(Priv, "diameter_test_avps.erl"), + ok = make(Data, "send.dia", Priv), + {ok, _, _} = compile(Priv, "diameter_test_send.erl"), + {ok, _, _} = compile(Priv, "diameter_test_recv.erl"), + {ok, _, _} = compile(Priv, + filename:join([Data, "diameter_test_unknown.erl"]), [{i, Priv}]), diameter_test_unknown:run(). -make(Dir, File) -> - diameter_make:codec(filename:join([Dir, File])). +make(Dir, File, Out) -> + diameter_make:codec(filename:join(Dir, File), [{outdir, Out}]). -compile(File) -> - compile(File, []). +compile(Dir, File) -> + compile(Dir, File, []). -compile(File, Opts) -> - compile:file(File, [return | Opts]). +compile(Dir, File, Opts) -> + compile:file(filename:join(Dir, File), [return | Opts]). %% =========================================================================== diff --git a/lib/diameter/test/diameter_compiler_SUITE.erl b/lib/diameter/test/diameter_compiler_SUITE.erl index 071ab26d08..cd886d4e8e 100644 --- a/lib/diameter/test/diameter_compiler_SUITE.erl +++ b/lib/diameter/test/diameter_compiler_SUITE.erl @@ -383,31 +383,46 @@ run() -> %% run/1 -run(List) -> +run(List) + when is_list(List) -> + Tmp = ?util:mktemp("diameter_compiler"), + try + run(List, Tmp) + after + file:del_dir_r(Tmp) + end. + +%% run/2 + +run(List, Dir) + when is_list(List) -> Path = filename:join([code:lib_dir(diameter, src), "dict", ?base]), {ok, Bin} = file:read_file(Path), - ?util:run([{{?MODULE, F, [Bin]}, 180000} || F <- List]). + ?util:run([{{?MODULE, F, [{Bin, Dir}]}, 180000} || F <- List]); + +run(F, Config) -> + run([F], proplists:get_value(priv_dir, Config)). %% =========================================================================== %% format/1 %% %% Ensure that parse o format is the identity map. -format(<<_/binary>> = Bin) -> +format({<<_/binary>> = Bin, _Dir}) -> ?util:run([{?MODULE, format, [{M, Bin}]} || E <- ?REPLACE, {ok, M} <- [norm(E)]]); format({Mods, Bin}) -> B = modify(Bin, Mods), - {ok, Dict} = parse(B, []), - {ok, D} = parse(diameter_make:format(Dict), []), + {ok, Dict} = parse(B), + {ok, D} = parse(diameter_make:format(Dict)), {Dict, Dict} = {Dict, D}; -format(_Config) -> - run([format]). +format(Config) -> + run(format, Config). -parse(File, Opts) -> - case diameter_make:codec(File, [parse, hrl, return | Opts]) of +parse(File) -> + case diameter_make:codec(File, [parse, hrl, return]) of {ok, [Dict, _]} -> {ok, Dict}; {error, _} = E -> @@ -420,21 +435,21 @@ parse(File, Opts) -> %% Ensure the expected success/error when parsing a morphed common %% dictionary. -replace(<<_/binary>> = Bin) -> +replace({<<_/binary>> = Bin, _Dir}) -> ?util:run([{?MODULE, replace, [{N, Bin}]} || E <- ?REPLACE, N <- [norm(E)]]); replace({{E, Mods}, Bin}) -> B = modify(Bin, Mods), - case {E, parse(B, [{include, here()}]), Mods} of + case {E, parse(B), Mods} of {ok, {ok, Dict}, _} -> Dict; {_, {error, {E,_} = T}, _} when E /= ok -> diameter_make:format_error(T) end; -replace(_Config) -> - run([replace]). +replace(Config) -> + run(replace, Config). re({RE, Repl}, Bin) -> re:replace(Bin, RE, Repl, [multiline]). @@ -444,25 +459,26 @@ re({RE, Repl}, Bin) -> %% %% Ensure success when generating code and compiling. -generate(<<_/binary>> = Bin) -> +generate({<<_/binary>> = Bin, Dir}) -> Rs = lists:zip(?REPLACE, lists:seq(1, length(?REPLACE))), - ?util:run([{?MODULE, generate, [{M, Bin, N, T}]} + ?util:run([{?MODULE, generate, [{M, Bin, N, T, Dir}]} || {E,N} <- Rs, {ok, M} <- [norm(E)], T <- [erl, hrl, parse, forms]]); -generate({Mods, Bin, N, Mode}) -> +generate({Mods, Bin, N, Mode, Dir}) -> B = modify(Bin, Mods ++ [{"@name .*", "@name dict" ++ ?L(N)}]), - {ok, Dict} = parse(B, []), + {ok, Dict} = parse(B), File = "dict" ++ integer_to_list(N), {_, ok} = {Dict, diameter_make:codec(Dict, [{name, File}, {prefix, "base"}, + {outdir, Dir}, Mode])}, - generate(Mode, File, Dict); + generate(Mode, filename:join(Dir, File), Dict); -generate(_Config) -> - run([generate]). +generate(Config) -> + run(generate, Config). generate(erl, File, _) -> {ok, _} = compile:file(File ++ ".erl", [return_errors]); @@ -487,7 +503,7 @@ flatten1({Key, BaseD, FlatD}) -> flatten1(_) -> [Vsn | BaseD] = diameter_gen_base_rfc6733:dict(), - {ok, I} = parse("@inherits diameter_gen_base_rfc6733\n", []), + {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]]). @@ -584,8 +600,5 @@ norm({E, RE, Repl}) -> norm({_,_} = T) -> T. -here() -> - filename:dirname(code:which(?MODULE)). - dict() -> [0 | orddict:new()]. diff --git a/lib/diameter/test/diameter_examples_SUITE.erl b/lib/diameter/test/diameter_examples_SUITE.erl index e5aab1a64a..7bb39cace3 100644 --- a/lib/diameter/test/diameter_examples_SUITE.erl +++ b/lib/diameter/test/diameter_examples_SUITE.erl @@ -74,11 +74,11 @@ suite() -> all() -> [dict, code]. -dict(_Config) -> - run([dict]). +dict(Config) -> + run(dict, Config). code(Config) -> - run([{code, proplists:get_value(priv_dir, Config)}]). + run(code, Config). %% =========================================================================== @@ -89,31 +89,45 @@ run() -> %% run/1 -run(dict) -> - compile_dicts(); +run({dict, Dir}) -> + compile_dicts(Dir); %% The example code doesn't use the example dictionaries, so a %% separate testcase. -run(code) -> - run_code(?util:tmpdir()); -run({code, Tmpdir}) -> - run_code(Tmpdir); +run({code, Dir}) -> + run_code(Dir); + +run(List) + when is_list(List) -> + Tmp = ?util:mktemp("diameter_examples"), + try + run(List, Tmp) + after + file:del_dir_r(Tmp) + end. + +%% run/2 %% Eg. erl -noinput -s diameter_examples_SUITE run code -s init stop ... -run(List) -> - ?util:run([{[fun run/1, T], 60000} || T <- List]). +run(List, Dir) + when is_list(List) -> + ?util:run([{[fun run/1, {F, Dir}], 60000} || F <- List]); + +run(F, Config) -> + run([F], proplists:get_value(priv_dir, Config)). %% =========================================================================== -%% compile_dicts/0 +%% compile_dicts/1 %% %% Compile example dictionaries in examples/dict. -compile_dicts() -> +compile_dicts(Dir) -> + Out = mkdir(Dir, "dict"), Dirs = [filename:join(H ++ ["examples", "dict"]) || H <- [[code:lib_dir(diameter)], [here(), ".."]]], [] = [{F,D,RC} || {_,F} <- sort(find_files(Dirs, ".*\\.dia$")), D <- ?DICT0, - RC <- [make(F,D)], + RC <- [make(F, D, Out)], RC /= ok]. sort([{_,_} | _] = Files) -> @@ -144,11 +158,11 @@ dep([{Dict, _} | T], Rest, Acc) -> dep([], Rest, Acc) -> dep(Rest, Acc). -make(Path, Dict0) +make(Path, Dict0, Out) when is_atom(Dict0) -> - make(Path, atom_to_list(Dict0)); + make(Path, atom_to_list(Dict0), Out); -make(Path, Dict0) -> +make(Path, Dict0, Out) -> Dict = filename:rootname(filename:basename(Path)), {Mod, Pre} = make_name(Dict), {"diameter_gen_base" ++ Suf = Mod0, _} = make_name(Dict0), @@ -156,10 +170,11 @@ make(Path, Dict0) -> try ok = to_erl(Path, [{name, Name}, {prefix, Pre}, + {outdir, Out}, {inherits, "common/" ++ Mod0} | [{inherits, D ++ "/" ++ M ++ Suf} || {D,M} <- dep(Dict)]]), - ok = to_beam(Name) + ok = to_beam(filename:join(Out, Name)) catch throw: {_,_} = E -> E @@ -347,15 +362,10 @@ traffic({Prot, Ebin}) -> %% run_code/1 -run_code(Tmpdir) -> +run_code(Dir) -> true = is_alive(), %% need distribution for peer nodes - Tmp = ?util:mktemp(filename:join(Tmpdir, "diameter_examples")), - try - {ok, Ebin} = compile_code(Tmp), - [] = ?util:run([[fun traffic/1, {T, Ebin}] || T <- ?PROTS]) - after - file:del_dir_r(Tmp) - end. + {ok, Ebin} = compile_code(mkdir(Dir, "code")), + ?util:run([[fun traffic/1, {T, Ebin}] || T <- ?PROTS]). %% call/1 @@ -365,3 +375,10 @@ call(0) -> call(N) -> {ok, _} = client:call(), call(N-1). + +%% mkdir/2 + +mkdir(Top, Dir) -> + Tmp = filename:join(Top, Dir), + ok = file:make_dir(Tmp), + Tmp. diff --git a/lib/diameter/test/diameter_tls_SUITE.erl b/lib/diameter/test/diameter_tls_SUITE.erl index 4e8cde95d3..1e7f7ed50a 100644 --- a/lib/diameter/test/diameter_tls_SUITE.erl +++ b/lib/diameter/test/diameter_tls_SUITE.erl @@ -149,7 +149,7 @@ dir(Config) -> %% =========================================================================== run() -> - Tmp = ?util:mktemp(filename:join(?util:tmpdir(), "diameter_tls")), + Tmp = ?util:mktemp("diameter_tls"), try run(Tmp, true) after diff --git a/lib/diameter/test/diameter_util.erl b/lib/diameter/test/diameter_util.erl index c2eb4b4b3e..cdb6fa410f 100644 --- a/lib/diameter/test/diameter_util.erl +++ b/lib/diameter/test/diameter_util.erl @@ -208,7 +208,7 @@ tmpdir() -> mktemp(Prefix) -> Suf = integer_to_list(erlang:monotonic_time()), - Tmp = Prefix ++ "." ++ Suf, + Tmp = filename:join(tmpdir(), Prefix ++ "." ++ Suf), ok = file:make_dir(Tmp), Tmp. |