From 6ec79f11513982c1e93495c6ee35ea3ccfb56035 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Mon, 27 Jan 2020 19:49:01 +0100 Subject: erts: Fix bug in erlang:list_to_ref/1 for external refs --- erts/emulator/test/list_bif_SUITE.erl | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'erts/emulator/test/list_bif_SUITE.erl') diff --git a/erts/emulator/test/list_bif_SUITE.erl b/erts/emulator/test/list_bif_SUITE.erl index f95251943d..b35ba0ff77 100644 --- a/erts/emulator/test/list_bif_SUITE.erl +++ b/erts/emulator/test/list_bif_SUITE.erl @@ -23,6 +23,7 @@ -export([all/0, suite/0]). -export([hd_test/1,tl_test/1,t_length/1,t_list_to_pid/1, + t_list_to_ref/1, t_list_to_ext_pidportref/1, t_list_to_port/1,t_list_to_float/1,t_list_to_integer/1]). @@ -33,6 +34,7 @@ suite() -> all() -> [hd_test, tl_test, t_length, t_list_to_pid, t_list_to_port, + t_list_to_ref, t_list_to_ext_pidportref, t_list_to_float, t_list_to_integer]. %% Tests list_to_integer and string:to_integer @@ -126,6 +128,57 @@ t_list_to_port(Config) when is_list(Config) -> end, ok. +t_list_to_ref(Config) when is_list(Config) -> + Ref = make_ref(), + RefStr = ref_to_list(Ref), + Ref = list_to_ref(RefStr), + case catch list_to_ref(id("Incorrect list")) of + {'EXIT', {badarg, _}} -> + ok; + Res -> + ct:fail("list_to_ref/1 with incorrect arg succeeded.~n" + "Result: ~p", [Res]) + end, + ok. + +%% Test list_to_pid/port/ref for external pids/ports/refs. +t_list_to_ext_pidportref(Config) when is_list(Config) -> + {ok, Node} = slave:start(net_adm:localhost(), t_list_to_ext_pidportref), + Pid = rpc:call(Node, erlang, self, []), + Port = hd(rpc:call(Node, erlang, ports, [])), + Ref = rpc:call(Node, erlang, make_ref, []), + + PidStr = pid_to_list(Pid), + PortStr = port_to_list(Port), + RefStr = ref_to_list(Ref), + + Pid2 = list_to_pid(PidStr), + Port2 = list_to_port(PortStr), + Ref2 = list_to_ref(RefStr), + + %% No, the local roundtrips of externals does not work + %% as 'creation' is missing in the string formats and we don't know + %% the 'creation' of the connected node. + false = (Pid =:= Pid2), + false = (Pid == Pid2), + false = (Port =:= Port2), + false = (Port == Port2), + false = (Ref =:= Ref2), + false = (Ref == Ref2), + + %% But it works when sent back to matching node name, as 0-creations + %% will be converted to the local node creation. + true = rpc:call(Node, erlang, '=:=', [Pid, Pid2]), + true = rpc:call(Node, erlang, '==', [Pid, Pid2]), + true = rpc:call(Node, erlang, '=:=', [Port, Port2]), + true = rpc:call(Node, erlang, '==', [Port, Port2]), + true = rpc:call(Node, erlang, '=:=', [Ref, Ref2]), + true = rpc:call(Node, erlang, '==', [Ref, Ref2]), + + slave:stop(Node), + ok. + + %% Test list_to_float/1 with correct and incorrect arguments. t_list_to_float(Config) when is_list(Config) -> -- cgit v1.2.1