diff options
author | Björn Gustavsson <[email protected]> | 2016-03-09 10:22:22 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-03-09 10:22:22 +0100 |
commit | b68ec56d44ff7f94289670ca0f10c8bbce927be5 (patch) | |
tree | 383357605de92f9eb9cb15bb411b3e52111ee223 /lib/stdlib/test | |
parent | 00a0a2d227be215741264030b929c1fc7b7473d5 (diff) | |
parent | 983f1346c536527b4fc9ed1d27cfb01d71392e43 (diff) | |
download | otp-b68ec56d44ff7f94289670ca0f10c8bbce927be5.tar.gz otp-b68ec56d44ff7f94289670ca0f10c8bbce927be5.tar.bz2 otp-b68ec56d44ff7f94289670ca0f10c8bbce927be5.zip |
Merge branch 'bjorn/cuddle-with-tests' into maint
* bjorn/cuddle-with-tests:
io_SUITE: Don't fail on fast computers with rough timers
Diffstat (limited to 'lib/stdlib/test')
-rw-r--r-- | lib/stdlib/test/io_SUITE.erl | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/lib/stdlib/test/io_SUITE.erl b/lib/stdlib/test/io_SUITE.erl index bb1ed2a4fc..cb96f8b575 100644 --- a/lib/stdlib/test/io_SUITE.erl +++ b/lib/stdlib/test/io_SUITE.erl @@ -2265,12 +2265,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. @@ -2278,19 +2280,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]), @@ -2298,6 +2304,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"), |