aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2016-03-07 12:57:17 +0100
committerBjörn Gustavsson <[email protected]>2016-03-07 12:57:17 +0100
commit983f1346c536527b4fc9ed1d27cfb01d71392e43 (patch)
tree174d7a7bcc01832f31c8488cca866d547bdc72b1 /lib/stdlib
parentc5ef73b4a587bf8f2e7b7b3d74fe917fdbe6153f (diff)
downloadotp-983f1346c536527b4fc9ed1d27cfb01d71392e43.tar.gz
otp-983f1346c536527b4fc9ed1d27cfb01d71392e43.tar.bz2
otp-983f1346c536527b4fc9ed1d27cfb01d71392e43.zip
io_SUITE: Don't fail on fast computers with rough timers
On a computer which is fast, but with timers with low resolution, the measured time for an empty queue could be zero, which could cause the test case to fail. Add a calibration function to scale up the amount the amount of work so that the measured time will not be lower than 50 ms.
Diffstat (limited to 'lib/stdlib')
-rw-r--r--lib/stdlib/test/io_SUITE.erl40
1 files changed, 29 insertions, 11 deletions
diff --git a/lib/stdlib/test/io_SUITE.erl b/lib/stdlib/test/io_SUITE.erl
index 0e897631ff..9507e972bc 100644
--- a/lib/stdlib/test/io_SUITE.erl
+++ b/lib/stdlib/test/io_SUITE.erl
@@ -2253,12 +2253,14 @@ io_lib_width_too_small(_Config) ->
%% Test that the time for a huge message queue is not
%% significantly slower than with an empty message queue.
io_with_huge_message_queue(Config) when is_list(Config) ->
- case test_server:is_native(gen) of
- true ->
+ case {test_server:is_native(gen),test_server:is_cover()} of
+ {true,_} ->
{skip,
"gen is native - huge message queue optimization "
"is not implemented"};
- false ->
+ {_,true} ->
+ {skip,"Running under cover"};
+ {false,false} ->
do_io_with_huge_message_queue(Config)
end.
@@ -2266,19 +2268,23 @@ do_io_with_huge_message_queue(Config) ->
PrivDir = ?privdir(Config),
File = filename:join(PrivDir, "slask"),
{ok, F1} = file:open(File, [write]),
-
- {Time,ok} = timer:tc(fun() -> writes(1000, F1) end),
+ Test = fun(Times) ->
+ {Time,ok} = timer:tc(fun() -> writes(Times, F1) end),
+ Time
+ end,
+ {Times,EmptyTime} = calibrate(100, Test),
[self() ! {msg,N} || N <- lists:seq(1, 500000)],
erlang:garbage_collect(),
- {NewTime,ok} = timer:tc(fun() -> writes(1000, F1) end),
+ FullTime = Test(Times),
file:close(F1),
- io:format("Time for empty message queue: ~p", [Time]),
- io:format("Time for huge message queue: ~p", [NewTime]),
+ file:delete(File),
+ io:format("Number of writes: ~p", [Times]),
+ io:format("Time for empty message queue: ~p", [EmptyTime]),
+ io:format("Time for huge message queue: ~p", [FullTime]),
- IsCover = test_server:is_cover(),
- case (NewTime+1) / (Time+1) of
- Q when Q < 10; IsCover ->
+ case (FullTime+1) / (EmptyTime+1) of
+ Q when Q < 10 ->
ok;
Q ->
io:format("Q = ~p", [Q]),
@@ -2286,6 +2292,18 @@ do_io_with_huge_message_queue(Config) ->
end,
ok.
+%% Make sure that the time is not too short. That could cause the
+%% test case to fail.
+calibrate(N, Test) when N =< 100000 ->
+ case Test(N) of
+ Time when Time < 50000 ->
+ calibrate(10*N, Test);
+ Time ->
+ {N,Time}
+ end;
+calibrate(N, _) ->
+ N.
+
writes(0, _) -> ok;
writes(N, F1) ->
file:write(F1, "hello\n"),