diff options
author | Kjell Winblad <[email protected]> | 2019-05-07 16:57:17 +0200 |
---|---|---|
committer | Kjell Winblad <[email protected]> | 2019-05-21 14:40:23 +0200 |
commit | c8cec4415b49ce3b70d760e81aaa482af20d93a2 (patch) | |
tree | d20eb037d50d1c141d9fce5890cbee4ef4ee7f79 | |
parent | a16317a001a042cbe73cb62669f69e42bf3bf974 (diff) | |
download | otp-c8cec4415b49ce3b70d760e81aaa482af20d93a2.tar.gz otp-c8cec4415b49ce3b70d760e81aaa482af20d93a2.tar.bz2 otp-c8cec4415b49ce3b70d760e81aaa482af20d93a2.zip |
Make the `cpu_sup_SUITE:util_values` test case more reliable
Previously, the `util_values` test case in the test suite
`cpu_sup_SUITE` tested the `cpu_sup:util()` by checking if a process
that spins in a loop cause the CPU utilization measured with
`cpu_sup:util()` to increase. This was unreliable on test machines
that ran other tasks at the same time. This commit tries to make the
test case more reliable by skipping the test case if it is detected
that the system is doing other work that use a lot of CPU time and
starting 100 spinning processes instead of only 1.
-rw-r--r-- | lib/os_mon/test/cpu_sup_SUITE.erl | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/lib/os_mon/test/cpu_sup_SUITE.erl b/lib/os_mon/test/cpu_sup_SUITE.erl index ba28f31f26..3a8346ac44 100644 --- a/lib/os_mon/test/cpu_sup_SUITE.erl +++ b/lib/os_mon/test/cpu_sup_SUITE.erl @@ -162,39 +162,54 @@ util_values(Config) when is_list(Config) -> Ref = make_ref(), Loop = fun (L) -> L(L) end, Spinner = fun () -> - Looper = spawn_link(fun () -> Loop(Loop) end), + NrOfProcesses = 100, + Loopers = [spawn_link(fun () -> Loop(Loop) end) + || _ <- lists:seq(1,NrOfProcesses)], receive after ?SPIN_TIME -> ok end, - unlink(Looper), - exit(Looper, kill), - Tester ! Ref - end, + [(fun () -> + unlink(Looper), + exit(Looper, kill), + Tester ! Ref + end)() + || Looper <- Loopers] + end, cpu_sup:util(), - - spawn_link(Spinner), - receive Ref -> ok end, - HighUtil1 = cpu_sup:util(), - receive after ?SPIN_TIME -> ok end, - LowUtil1 = cpu_sup:util(), + LowUtil0 = cpu_sup:util(), + NrOfProcessors = erlang:system_info(logical_processors_available), + case LowUtil0 of + U when U > ((100.0 / NrOfProcessors) * 0.5) -> + %% We cannot run this test if the system is doing other + %% work at the same time as the result will be unreliable + {skip, io_lib:format("CPU utilization was too high (~f%)", [LowUtil0])}; + _ -> + cpu_sup:util(), + spawn_link(Spinner), + receive Ref -> ok end, + HighUtil1 = cpu_sup:util(), - spawn_link(Spinner), - receive Ref -> ok end, - HighUtil2 = cpu_sup:util(), + receive after ?SPIN_TIME -> ok end, + LowUtil1 = cpu_sup:util(), - receive after ?SPIN_TIME -> ok end, - LowUtil2 = cpu_sup:util(), + spawn_link(Spinner), + receive Ref -> ok end, + HighUtil2 = cpu_sup:util(), - Utils = [{high1,HighUtil1}, {low1,LowUtil1}, - {high2,HighUtil2}, {low2,LowUtil2}], - io:format("Utils: ~p~n", [Utils]), + receive after ?SPIN_TIME -> ok end, + LowUtil2 = cpu_sup:util(), - false = LowUtil1 > HighUtil1, - false = LowUtil1 > HighUtil2, - false = LowUtil2 > HighUtil1, - false = LowUtil2 > HighUtil2, + Utils = [{high1,HighUtil1}, {low1,LowUtil1}, + {high2,HighUtil2}, {low2,LowUtil2}], + io:format("Utils: ~p~n", [Utils]), - ok. + false = LowUtil1 > HighUtil1, + false = LowUtil1 > HighUtil2, + false = LowUtil2 > HighUtil1, + false = LowUtil2 > HighUtil2, + + ok + end. % Outdated |