diff options
author | Lukas Larsson <[email protected]> | 2015-12-10 10:59:34 +0100 |
---|---|---|
committer | Lukas Larsson <[email protected]> | 2016-03-29 14:57:10 +0200 |
commit | 348f3f2ee2d2707e30658c3600e05309ad0e72bf (patch) | |
tree | 8557d5468c3a3b68bf55ac586b9c7b322e4f3198 /erts/emulator/test | |
parent | 4a736966eba5398a22697db6ca67e1e3dd3cd0f2 (diff) | |
download | otp-348f3f2ee2d2707e30658c3600e05309ad0e72bf.tar.gz otp-348f3f2ee2d2707e30658c3600e05309ad0e72bf.tar.bz2 otp-348f3f2ee2d2707e30658c3600e05309ad0e72bf.zip |
erts: Add enif_is_process/port_alive
Diffstat (limited to 'erts/emulator/test')
-rw-r--r-- | erts/emulator/test/nif_SUITE.erl | 25 | ||||
-rw-r--r-- | erts/emulator/test/nif_SUITE_data/nif_SUITE.c | 26 |
2 files changed, 48 insertions, 3 deletions
diff --git a/erts/emulator/test/nif_SUITE.erl b/erts/emulator/test/nif_SUITE.erl index d3bf91092f..3202986ce7 100644 --- a/erts/emulator/test/nif_SUITE.erl +++ b/erts/emulator/test/nif_SUITE.erl @@ -43,7 +43,8 @@ nif_exception/1, call_nif_exception/1, nif_nan_and_inf/1, nif_atom_too_long/1, nif_monotonic_time/1, nif_time_offset/1, nif_convert_time_unit/1, - nif_now_time/1, nif_cpu_time/1, nif_unique_integer/1 + nif_now_time/1, nif_cpu_time/1, nif_unique_integer/1, + nif_is_process_alive/1, nif_is_port_alive/1 ]). -export([many_args_100/100]). @@ -75,7 +76,8 @@ all() -> nif_schedule, dirty_nif, dirty_nif_send, dirty_nif_exception, nif_exception, nif_nan_and_inf, nif_atom_too_long, nif_monotonic_time, nif_time_offset, nif_convert_time_unit, - nif_now_time, nif_cpu_time, nif_unique_integer + nif_now_time, nif_cpu_time, nif_unique_integer, + nif_is_process_alive, nif_is_port_alive ]. init_per_testcase(_Case, Config) -> @@ -1939,6 +1941,23 @@ nif_unique_integer(Config) -> true = is_integer(unique_integer_nif([])), true = is_integer(unique_integer_nif([])). +nif_is_process_alive(Config) -> + ensure_lib_loaded(Config), + + {Pid,_} = spawn_monitor(fun() -> receive ok -> nok end end), + true = is_process_alive_nif(Pid), + exit(Pid, die), + receive _ -> ok end, %% Clear monitor + false = is_process_alive_nif(Pid). + +nif_is_port_alive(Config) -> + ensure_lib_loaded(Config), + + Port = open_port({spawn,"/bin/sh -s unix:cmd"},[stderr_to_stdout,eof]), + true = is_port_alive_nif(Port), + port_close(Port), + false = is_port_alive_nif(Port). + %% The NIFs: lib_version() -> undefined. call_history() -> ?nif_stub. @@ -1997,6 +2016,8 @@ call_nif_exception(_) -> ?nif_stub. call_nif_nan_or_inf(_) -> ?nif_stub. call_nif_atom_too_long(_) -> ?nif_stub. unique_integer_nif(_) -> ?nif_stub. +is_process_alive_nif(_) -> ?nif_stub. +is_port_alive_nif(_) -> ?nif_stub. %% maps is_map_nif(_) -> ?nif_stub. diff --git a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c index 1960689590..2ce0168788 100644 --- a/erts/emulator/test/nif_SUITE_data/nif_SUITE.c +++ b/erts/emulator/test/nif_SUITE_data/nif_SUITE.c @@ -30,6 +30,7 @@ static int static_cntA; /* zero by default */ static int static_cntB = NIF_SUITE_LIB_VER * 100; static ERL_NIF_TERM atom_false; +static ERL_NIF_TERM atom_true; static ERL_NIF_TERM atom_self; static ERL_NIF_TERM atom_ok; static ERL_NIF_TERM atom_join; @@ -138,6 +139,7 @@ static int load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info) msgenv_dtor, ERL_NIF_RT_CREATE, NULL); atom_false = enif_make_atom(env,"false"); + atom_true = enif_make_atom(env,"true"); atom_self = enif_make_atom(env,"self"); atom_ok = enif_make_atom(env,"ok"); atom_join = enif_make_atom(env,"join"); @@ -2008,6 +2010,26 @@ static ERL_NIF_TERM unique_integer(ErlNifEnv* env, int argc, const ERL_NIF_TERM return enif_make_unique_integer(env, properties); } +static ERL_NIF_TERM is_process_alive(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifPid pid; + if (!enif_get_local_pid(env, argv[0], &pid)) + return enif_make_badarg(env); + if (enif_is_process_alive(env, &pid)) + return atom_true; + return atom_false; +} + +static ERL_NIF_TERM is_port_alive(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) +{ + ErlNifPort port; + if (!enif_get_local_port(env, argv[0], &port)) + return enif_make_badarg(env); + if (enif_is_port_alive(env, &port)) + return atom_true; + return atom_false; +} + static ErlNifFunc nif_funcs[] = { {"lib_version", 0, lib_version}, @@ -2083,7 +2105,9 @@ static ErlNifFunc nif_funcs[] = {"convert_time_unit", 3, convert_time_unit}, {"now_time", 0, now_time}, {"cpu_time", 0, cpu_time}, - {"unique_integer_nif", 1, unique_integer} + {"unique_integer_nif", 1, unique_integer}, + {"is_process_alive_nif", 1, is_process_alive}, + {"is_port_alive_nif", 1, is_port_alive} }; ERL_NIF_INIT(nif_SUITE,nif_funcs,load,reload,upgrade,unload) |