diff options
Diffstat (limited to 'erts')
-rw-r--r-- | erts/emulator/test/nif_SUITE.erl | 28 | ||||
-rw-r--r-- | erts/emulator/test/nif_SUITE_data/Makefile.src | 3 | ||||
-rw-r--r-- | erts/emulator/test/nif_SUITE_data/echo_drv.c | 62 |
3 files changed, 78 insertions, 15 deletions
diff --git a/erts/emulator/test/nif_SUITE.erl b/erts/emulator/test/nif_SUITE.erl index 4dcfbf35ca..a185b72341 100644 --- a/erts/emulator/test/nif_SUITE.erl +++ b/erts/emulator/test/nif_SUITE.erl @@ -1374,14 +1374,16 @@ get_length(Config) when is_list(Config) -> ensure_lib_loaded(Config) -> ensure_lib_loaded(Config, 1). ensure_lib_loaded(Config, Ver) -> + Path = ?config(data_dir, Config), case lib_version() of - undefined -> - Path = proplists:get_value(data_dir, Config), - Lib = "nif_SUITE." ++ integer_to_list(Ver), - ok = erlang:load_nif(filename:join(Path,Lib), []); - Ver when is_integer(Ver) -> - ok - end. + undefined -> + Lib = "nif_SUITE." ++ integer_to_list(Ver), + ok = erlang:load_nif(filename:join(Path,Lib), []); + Ver when is_integer(Ver) -> + ok + end, + erl_ddll:try_load(Path, echo_drv, []), + ok. make_atom(Config) when is_list(Config) -> ensure_lib_loaded(Config, 1), @@ -1957,7 +1959,7 @@ nif_is_process_alive(Config) -> nif_is_port_alive(Config) -> ensure_lib_loaded(Config), - Port = open_port({spawn,"/bin/sh -s unix:cmd"},[stderr_to_stdout,eof]), + Port = open_port({spawn,echo_drv},[eof]), true = is_port_alive_nif(Port), port_close(Port), false = is_port_alive_nif(Port). @@ -1991,13 +1993,13 @@ nif_binary_to_term(Config) -> nif_port_command(Config) -> ensure_lib_loaded(Config), - Port = open_port({spawn,"/bin/sh -s unix:cmd"},[stderr_to_stdout,eof]), - true = port_command_nif(Port, "echo hello\n"), + Port = open_port({spawn,echo_drv},[eof]), + true = port_command_nif(Port, "hello\n"), receive {Port,{data,"hello\n"}} -> ok after 1000 -> ct:fail(timeout) end, RefcBin = lists:flatten([lists:duplicate(100, "hello"),"\n"]), - true = port_command_nif(Port, iolist_to_binary(["echo ",RefcBin])), + true = port_command_nif(Port, iolist_to_binary(RefcBin)), receive {Port,{data,RefcBin}} -> ok after 1000 -> ct:fail(timeout) end, @@ -2006,14 +2008,14 @@ nif_port_command(Config) -> {'EXIT', {badarg, _}} = (catch port_command_nif(Port, [ok])), IoList = [lists:duplicate(100,<<"hello">>),"\n"], - true = port_command_nif(Port, ["echo ",IoList]), + true = port_command_nif(Port, [IoList]), FlatIoList = binary_to_list(iolist_to_binary(IoList)), receive {Port,{data,FlatIoList}} -> ok after 1000 -> ct:fail(timeout) end, port_close(Port), - {'EXIT', {badarg, _}} = (catch port_command_nif(Port, "echo hello\n")), + {'EXIT', {badarg, _}} = (catch port_command_nif(Port, "hello\n")), ok. diff --git a/erts/emulator/test/nif_SUITE_data/Makefile.src b/erts/emulator/test/nif_SUITE_data/Makefile.src index ab4ff77add..fbb8978771 100644 --- a/erts/emulator/test/nif_SUITE_data/Makefile.src +++ b/erts/emulator/test/nif_SUITE_data/Makefile.src @@ -4,8 +4,7 @@ NIF_LIBS = nif_SUITE.1@dll@ \ nif_mod.2@dll@ \ nif_mod.3@dll@ -all: $(NIF_LIBS) basic@dll@ rwlock@dll@ tsd@dll@ - +all: $(NIF_LIBS) basic@dll@ rwlock@dll@ tsd@dll@ echo_drv@dll@ @SHLIB_RULES@ diff --git a/erts/emulator/test/nif_SUITE_data/echo_drv.c b/erts/emulator/test/nif_SUITE_data/echo_drv.c new file mode 100644 index 0000000000..2b3510c641 --- /dev/null +++ b/erts/emulator/test/nif_SUITE_data/echo_drv.c @@ -0,0 +1,62 @@ +#include <stdio.h> +#include "erl_driver.h" + +static ErlDrvPort erlang_port; +static ErlDrvData echo_start(ErlDrvPort, char *); +static void from_erlang(ErlDrvData, char*, ErlDrvSizeT); +static ErlDrvSSizeT echo_call(ErlDrvData drv_data, unsigned int command, + char *buf, ErlDrvSizeT len, + char **rbuf, ErlDrvSizeT rlen, unsigned *ret_flags); +static ErlDrvEntry echo_driver_entry = { + NULL, /* Init */ + echo_start, + NULL, /* Stop */ + from_erlang, + NULL, /* Ready input */ + NULL, /* Ready output */ + "echo_drv", + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + echo_call, + NULL, + ERL_DRV_EXTENDED_MARKER, + ERL_DRV_EXTENDED_MAJOR_VERSION, + ERL_DRV_EXTENDED_MINOR_VERSION, + 0, + NULL, + NULL, + NULL +}; + +DRIVER_INIT(echo_drv) +{ + return &echo_driver_entry; +} + +static ErlDrvData +echo_start(ErlDrvPort port, char *buf) +{ + return (ErlDrvData) port; +} + +static void +from_erlang(ErlDrvData data, char *buf, ErlDrvSizeT count) +{ + driver_output((ErlDrvPort) data, buf, count); +} + +static ErlDrvSSizeT +echo_call(ErlDrvData drv_data, unsigned int command, + char *buf, ErlDrvSizeT len, char **rbuf, ErlDrvSizeT rlen, + unsigned *ret_flags) +{ + *rbuf = buf; + *ret_flags |= DRIVER_CALL_KEEP_BUFFER; + return len; +} + |