From 815c47e169b380b6e5dd957df6313cd05c773be6 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Wed, 26 Jan 2022 23:24:16 +0100 Subject: [PATCH] test: call logger apis directly --- .gitignore | 1 + apps/emqx/test/emqx_bpapi_static_checks.erl | 39 ++++++++++----------- apps/emqx/test/emqx_static_checks.erl | 15 ++++---- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 1e8075ee8..28178b1f0 100644 --- a/.gitignore +++ b/.gitignore @@ -62,3 +62,4 @@ erlang_ls.config .envrc # elixir mix.lock +apps/emqx/test/emqx_static_checks_data/ diff --git a/apps/emqx/test/emqx_bpapi_static_checks.erl b/apps/emqx/test/emqx_bpapi_static_checks.erl index 5acd69b6a..3b2d8b2ba 100644 --- a/apps/emqx/test/emqx_bpapi_static_checks.erl +++ b/apps/emqx/test/emqx_bpapi_static_checks.erl @@ -18,8 +18,6 @@ -export([run/0, dump/1, dump/0, check_compat/1, versions_file/0]). --include_lib("emqx/include/logger.hrl"). - %% Using an undocumented API here :( -include_lib("dialyzer/src/dialyzer.hrl"). @@ -75,14 +73,14 @@ run() -> Dumps = filelib:wildcard(dumps_dir() ++ "/*.bpapi"), case Dumps of [] -> - ?ERROR("No BPAPI dumps are found in ~s, abort", [dumps_dir()]), + logger:error("No BPAPI dumps are found in ~s, abort", [dumps_dir()]), false; _ -> - ?NOTICE("Running API compatibility checks for ~p", [Dumps]), + logger:notice("Running API compatibility checks for ~p", [Dumps]), check_compat(Dumps) end; false -> - ?CRITICAL("Backplane API violations found on the current branch."), + logger:critical("Backplane API violations found on the current branch.", []), false end. @@ -116,12 +114,12 @@ check_api_immutability(#{release := Rel1, api := APIs1}, #{release := Rel2, api ok; undefined -> setnok(), - ?ERROR("API ~p v~p was removed in release ~p without being deprecated.", - [API, Version, Rel2]); + logger:error("API ~p v~p was removed in release ~p without being deprecated.", + [API, Version, Rel2]); _Val -> setnok(), - ?ERROR("API ~p v~p was changed between ~p and ~p. Backplane API should be immutable.", - [API, Version, Rel1, Rel2]) + logger:error("API ~p v~p was changed between ~p and ~p. Backplane API should be immutable.", + [API, Version, Rel1, Rel2]) end end, APIs1), @@ -145,7 +143,8 @@ typecheck_apis( #{release := CallerRelease, api := CallerAPIs, signatures := Cal ok; TypeErrors -> setnok(), - [?ERROR("Incompatible RPC call: " + [logger:error( + "Incompatible RPC call: " "type of the parameter ~p of RPC call ~s on release ~p " "is not a subtype of the target function ~s on release ~p.~n" "Caller type: ~s~nCallee type: ~s~n", @@ -211,21 +210,21 @@ dump(Opts) -> erase(bpapi_ok). prepare(#{reldir := RelDir, plt := PLT}) -> - ?INFO("Starting xref...", []), + logger:info("Starting xref...", []), xref:start(?XREF), filelib:wildcard(RelDir ++ "/*/ebin/") =:= [] andalso error("No applications found in the release directory. Wrong directory?"), xref:set_default(?XREF, [{warnings, false}]), xref:add_release(?XREF, RelDir), %% Now to the dialyzer stuff: - ?INFO("Loading PLT...", []), + logger:info("Loading PLT...", []), dialyzer_plt:from_file(PLT). find_remote_calls(_Opts) -> Query = "XC | (A - [" ?IGNORED_APPS "]:App - [" ?IGNORED_MODULES "]:Mod - [" ?EXEMPTIONS "]) || (([" ?RPC_MODULES "] : Mod + [" ?RPC_FUNCTIONS "]) - [" ?IGNORED_RPC_CALLS "])", {ok, Calls} = xref:q(?XREF, Query), - ?INFO("Calls to RPC modules ~p", [Calls]), + logger:info("Calls to RPC modules ~p", [Calls]), {Callers, _Callees} = lists:unzip(Calls), Callers. @@ -235,10 +234,9 @@ warn_nonbpapi_rpcs([]) -> warn_nonbpapi_rpcs(L) -> setnok(), lists:foreach(fun({M, F, A}) -> - ?ERROR("~p:~p/~p does a remote call outside of a dedicated " - "backplane API module. " - "It may break during rolling cluster upgrade", - [M, F, A]) + logger:error("~p:~p/~p does a remote call outside of a dedicated " + "backplane API module. " + "It may break during rolling cluster upgrade", [M, F, A]) end, L). @@ -258,7 +256,7 @@ dump_api(Term = #{api := _, signatures := _, release := Release}) -> -spec dump_versions(api_dump()) -> ok. dump_versions(APIs) -> Filename = versions_file(), - ?NOTICE("Dumping API versions to ~p", [Filename]), + logger:notice("Dumping API versions to ~p", [Filename]), ok = filelib:ensure_dir(Filename), {ok, FD} = file:open(Filename, [write]), lists:foreach(fun(API) -> @@ -308,8 +306,9 @@ enrich({From0, To0}, {Acc0, PLT}) -> {Acc, PLT}; {{value, _}, none} -> setnok(), - ?CRITICAL("Backplane API function ~s calls a missing remote function ~s", - [format_call(From0), format_call(To0)]), + logger:critical( + "Backplane API function ~s calls a missing remote function ~s", + [format_call(From0), format_call(To0)]), error(missing_target) end. diff --git a/apps/emqx/test/emqx_static_checks.erl b/apps/emqx/test/emqx_static_checks.erl index 2259d33ac..3cf4d5eb5 100644 --- a/apps/emqx/test/emqx_static_checks.erl +++ b/apps/emqx/test/emqx_static_checks.erl @@ -19,7 +19,6 @@ -compile(export_all). -compile(nowarn_export_all). --include_lib("emqx/include/logger.hrl"). -include_lib("common_test/include/ct.hrl"). -include_lib("stdlib/include/assert.hrl"). @@ -29,8 +28,9 @@ init_per_suite(Config) -> Config. end_per_suite(_Config) -> - ?NOTICE("If this test suite failed, and you are unsure why, read this:~n" - "https://github.com/emqx/emqx/blob/master/apps/emqx/src/bpapi/README.md", []). + logger:notice( + "If this test suite failed, and you are unsure why, read this:~n" + "https://github.com/emqx/emqx/blob/master/apps/emqx/src/bpapi/README.md", []). t_run_check(_) -> try @@ -39,13 +39,14 @@ t_run_check(_) -> {ok, NewData} = file:consult(emqx_bpapi_static_checks:versions_file()), OldData =:= NewData orelse begin - ?CRITICAL("BPAPI versions were changed, but not committed to the repo.\n" - "Run 'make && make static_checks' and then add the changed " - "'bpapi.versions' files to the commit.", []), + logger:critical( + "BPAPI versions were changed, but not committed to the repo.\n" + "Run 'make && make static_checks' and then add the changed " + "'bpapi.versions' files to the commit."), error(version_mismatch) end catch EC:Err:Stack -> - ?CRITICAL("Test suite failed: ~p:~p~nStack:~p", [EC, Err, Stack]), + logger:critical("Test suite failed: ~p:~p~nStack:~p", [EC, Err, Stack]), error(tc_failed) end.