diff --git a/c_src/quicer_nif.c b/c_src/quicer_nif.c index 5dca270d..aa0fe5fa 100644 --- a/c_src/quicer_nif.c +++ b/c_src/quicer_nif.c @@ -21,6 +21,7 @@ limitations under the License. #include "quicer_listener.h" #include "quicer_vsn.h" +#include #include #include @@ -1692,6 +1693,16 @@ make_event(ErlNifEnv *env, prop); // 4th element, event props :: any()) // } +ERL_NIF_TERM +do_malloc_trim(__unused_parm__ ErlNifEnv *env, + __unused_parm__ int argc, + __unused_parm__ const ERL_NIF_TERM argv[]) +{ + CXPLAT_FRE_ASSERT(argc == 0); + malloc_trim(0); + return ATOM_OK; +} + static ErlNifFunc nif_funcs[] = { /* | name | arity| funptr | flags| * @@ -1744,6 +1755,7 @@ static ErlNifFunc nif_funcs[] = { { "copy_stream_handle", 1, copy_stream_handle, 0}, /* for testing */ { "mock_buffer_sig", 3, mock_buffer_sig, 0}, + { "malloc_trim", 0, do_malloc_trim, 0}, #ifdef QUICER_USE_SNK { "set_snab_kc_pid", 1, set_snab_kc_pid, 0}, { "get_snab_kc_pid", 0, get_snab_kc_pid, 0}, diff --git a/src/quicer_nif.erl b/src/quicer_nif.erl index 6d35e00a..e6354de7 100644 --- a/src/quicer_nif.erl +++ b/src/quicer_nif.erl @@ -54,6 +54,9 @@ get_stream_rid/1 ]). +%% tools +-export([malloc_trim/0]). + %% For tests only -export([ open_connection/0, @@ -347,6 +350,10 @@ get_conn_rid(_Handle) -> get_stream_rid(_Handle) -> erlang:nif_error(nif_library_not_loaded). +-spec malloc_trim() -> ok. +malloc_trim() -> + erlang:nif_error(nif_library_not_loaded). + -spec controlling_process(connection_handle() | stream_handle(), pid()) -> ok | {error, closed | badarg | owner_dead | not_owner}. diff --git a/test/quicer_SUITE.erl b/test/quicer_SUITE.erl index 14c65954..2688b7b1 100644 --- a/test/quicer_SUITE.erl +++ b/test/quicer_SUITE.erl @@ -155,6 +155,9 @@ tc_peercert_server/1, tc_peercert_server_nocert/1, + %% Toolings + tc_malloc_trim/1, + %% Versions test tc_abi_version/1 %% testcase to verify env works @@ -838,10 +841,10 @@ tc_stream_controlling_process_demon(Config) -> end ), receive - {'DOWN', MonRef, process, NewOwner, {Res, Stm}} -> + {'DOWN', MonRef, process, OldOwner, {Res, Stm}} -> ct:pal("Set controlling_process res: ~p", [Res]) end, - ?assertEqual({error, owner_dead}, quicer:controlling_process(Stm, NewOwner)), + ?assertEqual({error, owner_dead}, quicer:controlling_process(Stm, OldOwner)), ok = quicer:setopt(Stm, active, true), {ok, _Len} = quicer:send(Stm, <<"owner_changed">>), receive @@ -3193,6 +3196,9 @@ tc_setopt_congestion_control_algorithm(Config) -> SPid ! done, ok. +tc_malloc_trim(_) -> + quicer_nif:malloc_trim(). + %%% ==================== %%% Internal helpers %%% ====================