diff options
Diffstat (limited to 'erts/emulator/test/statistics_SUITE.erl')
-rw-r--r-- | erts/emulator/test/statistics_SUITE.erl | 75 |
1 files changed, 26 insertions, 49 deletions
diff --git a/erts/emulator/test/statistics_SUITE.erl b/erts/emulator/test/statistics_SUITE.erl index bc12821887..898908c40f 100644 --- a/erts/emulator/test/statistics_SUITE.erl +++ b/erts/emulator/test/statistics_SUITE.erl @@ -1,19 +1,19 @@ %% %% %CopyrightBegin% -%% -%% Copyright Ericsson AB 1997-2009. All Rights Reserved. -%% +%% +%% Copyright Ericsson AB 1997-2010. All Rights Reserved. +%% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in %% compliance with the License. You should have received a copy of the %% Erlang Public License along with this software. If not, it can be %% retrieved online at http://www.erlang.org/. -%% +%% %% Software distributed under the License is distributed on an "AS IS" %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See %% the License for the specific language governing rights and limitations %% under the License. -%% +%% %% %CopyrightEnd% %% @@ -25,7 +25,7 @@ init_per_testcase/2, fin_per_testcase/2, wall_clock/1, wall_clock_zero_diff/1, wall_clock_update/1, - runtime/1, runtime_zero_diff/1, runtime_zero_update/1, + runtime/1, runtime_zero_diff/1, runtime_update/1, runtime_diff/1, run_queue/1, run_queue_one/1, reductions/1, reductions_big/1, garbage_collection/1, io/1, @@ -99,8 +99,7 @@ wall_clock_update1(0) -> %%% Test statistics(runtime). -runtime(suite) -> [runtime_zero_diff, runtime_zero_update, runtime_update, - runtime_diff]. +runtime(suite) -> [runtime_zero_diff, runtime_update, runtime_diff]. runtime_zero_diff(doc) -> "Tests that the difference between the times returned from two consectuitive " @@ -117,55 +116,32 @@ runtime_zero_diff1(N) when N > 0 -> runtime_zero_diff1(0) -> ?line test_server:fail("statistics(runtime) never returned zero difference"). -runtime_zero_update(doc) -> - "Test that the time differences returned by two calls to " - "statistics(runtime) several seconds apart is zero."; -runtime_zero_update(Config) when is_list(Config) -> - case ?t:is_debug() of - false -> ?line runtime_zero_update1(6); - true -> {skip,"Unreliable in DEBUG build"} - end. - -runtime_zero_update1(N) when N > 0 -> - ?line {T1, _} = statistics(runtime), - ?line receive after 7000 -> ok end, - ?line case statistics(runtime) of - {T, Td} when Td =< 80 -> - test_server:format("ok, Runtime before: {~p, _} after: {~p, ~p}", - [T1, T, Td]), - ok; - {T, R} -> - test_server:format("nok, Runtime before: {~p, _} after: {~p, ~p}", - [T1, T, R]), - runtime_zero_update1(N-1) - end; -runtime_zero_update1(0) -> - ?line test_server:fail("statistics(runtime) never returned zero difference"). - runtime_update(doc) -> - "Test that the statistics(runtime) returns a substanstially updated difference " - "after running a process that takes all CPU power of the Erlang process " - "for a second."; + "Test that the statistics(runtime) returns a substanstially " + "updated difference after running a process that takes all CPU " + " power of the Erlang process for a second."; runtime_update(Config) when is_list(Config) -> case ?t:is_cover() of false -> ?line process_flag(priority, high), - ?line test_server:m_out_of_n(1, 10, fun runtime_update/0); + do_runtime_update(10); true -> {skip,"Cover-compiled"} end. -runtime_update() -> - ?line {T1,_} = statistics(runtime), +do_runtime_update(0) -> + {comment,"Never close enough"}; +do_runtime_update(N) -> + ?line {T1,Diff0} = statistics(runtime), ?line spawn_link(fun cpu_heavy/0), receive after 1000 -> ok end, ?line {T2,Diff} = statistics(runtime), - ?line Delta = abs(Diff-1000), - ?line test_server:format("T1 = ~p, T2 = ~p, Diff = ~p, abs(Diff-1000) = ~p", - [T1,T2,Diff,Delta]), + ?line true = is_integer(T1+T2+Diff0+Diff), + ?line test_server:format("T1 = ~p, T2 = ~p, Diff = ~p, T2-T1 = ~p", + [T1,T2,Diff,T2-T1]), ?line if - abs(Diff-1000) =:= Delta, Delta =< 100 -> - ok + T2 - T1 =:= Diff, 900 =< Diff, Diff =< 1500 -> ok; + true -> do_runtime_update(N-1) end. cpu_heavy() -> @@ -212,17 +188,18 @@ reductions(Config) when is_list(Config) -> %% 300 * 4 is more than CONTEXT_REDS (1000). Thus, there will be one or %% more context switches. - reductions(300, Reductions). + Mask = (1 bsl erlang:system_info(wordsize)*8) - 1, + reductions(300, Reductions, Mask). -reductions(N, Previous) when N > 0 -> +reductions(N, Previous, Mask) when N > 0 -> ?line {Reductions, Diff} = statistics(reductions), ?line build_some_garbage(), ?line if Reductions > 0 -> ok end, ?line if Diff >= 0 -> ok end, io:format("Previous = ~p, Reductions = ~p, Diff = ~p, DiffShouldBe = ~p", - [Previous, Reductions, Diff, Reductions-Previous]), - ?line if Reductions == Previous+Diff -> reductions(N-1, Reductions) end; -reductions(0, _) -> + [Previous, Reductions, Diff, (Reductions-Previous) band Mask]), + ?line if Reductions == ((Previous+Diff) band Mask) -> reductions(N-1, Reductions, Mask) end; +reductions(0, _, _) -> ok. build_some_garbage() -> |