aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/test
diff options
context:
space:
mode:
authorZandra Hird <[email protected]>2015-03-20 14:55:01 +0100
committerZandra Hird <[email protected]>2015-03-20 14:55:18 +0100
commitb4a9bc73058e9d934143d41e766722f3e3b3d758 (patch)
tree56c1a53aa08842f42b148b3f627a48c3e1e2247e /erts/emulator/test
parentc0b559c6a0cf6fa9ff7215df59a71b7fa054ed85 (diff)
parent6f9c07ae2694a2dc1f721fd10af22b8813d15bc1 (diff)
downloadotp-b4a9bc73058e9d934143d41e766722f3e3b3d758.tar.gz
otp-b4a9bc73058e9d934143d41e766722f3e3b3d758.tar.bz2
otp-b4a9bc73058e9d934143d41e766722f3e3b3d758.zip
Merge branch 'nox/fix-port_info-race' into maint
* nox/fix-port_info-race: Fix a race condition when calling port_info/1 OTP-12587
Diffstat (limited to 'erts/emulator/test')
-rw-r--r--erts/emulator/test/port_bif_SUITE.erl27
1 files changed, 25 insertions, 2 deletions
diff --git a/erts/emulator/test/port_bif_SUITE.erl b/erts/emulator/test/port_bif_SUITE.erl
index f439867e9c..0c5b09d45a 100644
--- a/erts/emulator/test/port_bif_SUITE.erl
+++ b/erts/emulator/test/port_bif_SUITE.erl
@@ -24,7 +24,7 @@
init_per_group/2,end_per_group/2, command/1,
command_e_1/1, command_e_2/1, command_e_3/1, command_e_4/1,
port_info1/1, port_info2/1,
- port_info_os_pid/1,
+ port_info_os_pid/1, port_info_race/1,
connect/1, control/1, echo_to_busy/1]).
-export([do_command_e_1/1, do_command_e_2/1, do_command_e_4/1]).
@@ -42,7 +42,8 @@ all() ->
groups() ->
[{command_e, [],
[command_e_1, command_e_2, command_e_3, command_e_4]},
- {port_info, [], [port_info1, port_info2, port_info_os_pid]}].
+ {port_info, [],
+ [port_info1, port_info2, port_info_os_pid, port_info_race]}].
init_per_suite(Config) ->
Config.
@@ -254,6 +255,28 @@ do_port_info_os_pid() ->
true = erlang:port_close(P),
ok.
+port_info_race(Config) when is_list(Config) ->
+ DataDir = ?config(data_dir, Config),
+ Program = filename:join(DataDir, "port_test"),
+ Top = self(),
+ P1 = open_port({spawn,Program}, [{packet,1}]),
+ P2 = open_port({spawn,Program}, [{packet,1}]),
+ Info1 = erlang:port_info(P1),
+ Info2 = erlang:port_info(P2),
+ F = fun Loop(Port, _, 0) ->
+ Top ! {ok,Port};
+ Loop(Port, Info, N) ->
+ Info = erlang:port_info(Port),
+ Loop(Port, Info, N - 1)
+ end,
+ spawn_link(fun () -> F(P1, Info1, 1000) end),
+ spawn_link(fun () -> F(P2, Info2, 1000) end),
+ receive {ok,P1} -> ok end,
+ receive {ok,P2} -> ok end,
+ true = erlang:port_close(P1),
+ true = erlang:port_close(P2),
+ ok.
+
output_test(_, _, Input, Output) when Output > 16#1fffffff ->
io:format("~p bytes received\n", [Input]);
output_test(P, Bin, Input0, Output0) ->