From 8ff68249905b367b4b7179aa4c600511bfec5b87 Mon Sep 17 00:00:00 2001 From: Kjell Winblad Date: Wed, 29 May 2019 10:50:24 +0200 Subject: Fix the test case cpu_sup_SUITE:util_values The message signaling that the spinning processes had stopped was previously sent too early. --- lib/os_mon/test/cpu_sup_SUITE.erl | 47 ++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/os_mon/test/cpu_sup_SUITE.erl b/lib/os_mon/test/cpu_sup_SUITE.erl index 3a8346ac44..7a8065c591 100644 --- a/lib/os_mon/test/cpu_sup_SUITE.erl +++ b/lib/os_mon/test/cpu_sup_SUITE.erl @@ -155,45 +155,56 @@ tiny_diff(A, B) -> -define(SPIN_TIME, 1000). +spinner(Parent) -> + receive + stop -> Parent ! stopped + after 0 -> spinner(Parent) + end. + %% Test utilization values util_values(Config) when is_list(Config) -> - + NrOfProcessors = + case erlang:system_info(logical_processors_available) of + unknown -> 2; + X -> X + end, Tester = self(), Ref = make_ref(), - Loop = fun (L) -> L(L) end, Spinner = fun () -> - NrOfProcesses = 100, - Loopers = [spawn_link(fun () -> Loop(Loop) end) - || _ <- lists:seq(1,NrOfProcesses)], + Spinner = self(), + NrOfProcesses = NrOfProcessors, + Loopers = + [spawn_link(fun () -> spinner(Spinner) end) + || _ <- lists:seq(1,NrOfProcesses)], receive after ?SPIN_TIME -> ok end, - [(fun () -> - unlink(Looper), - exit(Looper, kill), - Tester ! Ref - end)() - || Looper <- Loopers] - + [begin + Looper ! stop, + receive stopped -> ok end + end + || Looper <- Loopers], + Tester ! Ref end, + Spin = fun () -> + spawn_link(Spinner), + receive Ref -> ok end + end, cpu_sup:util(), receive after ?SPIN_TIME -> ok end, LowUtil0 = cpu_sup:util(), - NrOfProcessors = erlang:system_info(logical_processors_available), case LowUtil0 of - U when U > ((100.0 / NrOfProcessors) * 0.5) -> + U when U > ((100.0 / NrOfProcessors) * 0.33) -> %% 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, + Spin(), HighUtil1 = cpu_sup:util(), receive after ?SPIN_TIME -> ok end, LowUtil1 = cpu_sup:util(), - spawn_link(Spinner), - receive Ref -> ok end, + Spin(), HighUtil2 = cpu_sup:util(), receive after ?SPIN_TIME -> ok end, -- cgit v1.2.3