diff options
author | Dan Gudmundsson <[email protected]> | 2017-11-20 15:23:24 +0100 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2017-12-01 15:24:02 +0100 |
commit | d4341cd249d728174fce580bd018e1e8b402d161 (patch) | |
tree | da490e0cd419bf3413f4d55992e659e23ecbb6e7 /lib/kernel/test | |
parent | a90b3712dcec20c96eeeecbabc2672ec67c7d89a (diff) | |
download | otp-d4341cd249d728174fce580bd018e1e8b402d161.tar.gz otp-d4341cd249d728174fce580bd018e1e8b402d161.tar.bz2 otp-d4341cd249d728174fce580bd018e1e8b402d161.zip |
kernel: add a resource reference counter
System resources/functionality may need to be reference counted
to be handled correctly when used or enabled/disabled from more
than one process or application.
It is easier to handle this in erlang code than in erts, so make a
process that deals with the housekeeping.
Diffstat (limited to 'lib/kernel/test')
-rw-r--r-- | lib/kernel/test/kernel_SUITE.erl | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/lib/kernel/test/kernel_SUITE.erl b/lib/kernel/test/kernel_SUITE.erl index da56359294..7898988dbe 100644 --- a/lib/kernel/test/kernel_SUITE.erl +++ b/lib/kernel/test/kernel_SUITE.erl @@ -30,14 +30,14 @@ -export([init_per_testcase/2, end_per_testcase/2]). %% Test cases must be exported. --export([app_test/1, appup_test/1]). +-export([app_test/1, appup_test/1, refc/1]). suite() -> [{ct_hooks,[ts_install_cth]}, {timetrap,{minutes,2}}]. all() -> - [app_test, appup_test]. + [app_test, appup_test, refc]. groups() -> []. @@ -163,3 +163,68 @@ check_appup([Vsn|Vsns],Instrs,Expected) -> end; check_appup([],_,_) -> ok. + +%%% Check that refc module handles the counters as expected +refc(_Config) -> + Enable = fun(Enable) -> erlang:system_flag(scheduler_wall_time, Enable) end, + IsOn = fun() -> undefined /= erlang:statistics(scheduler_wall_time) end, + Tester = self(), + Loop = fun Loop() -> + receive + die -> normal; + {apply, Bool} -> + Res = Enable(Bool), + Tester ! {self(), Res}, + Loop() + end + end, + + %% Counter should be 0 + false = Enable(false), + + false = Enable(true), + true = Enable(true), + true = Enable(false), + true = Enable(false), + + %% Counter should be 0 + false = IsOn(), + + P1 = spawn_link(Loop), + P1 ! {apply, true}, + receive {P1, R1} -> false = R1 end, + + %% P1 has turned it on counter should be one + true = IsOn(), + true = Enable(true), + true = Enable(false), + true = IsOn(), + + P1 ! {apply, false}, + receive {P1, R2} -> true = R2 end, + false = IsOn(), + + P1 ! {apply, true}, + receive {P1, R3} -> false = R3 end, + true = IsOn(), + true = Enable(false), + + + P1 ! die, + timer:sleep(100), + false = IsOn(), + false = Enable(false), + + P2 = spawn_link(Loop), + P2 ! {apply, true}, + receive {P2, R4} -> false = R4 end, + true = IsOn(), + P2 ! {apply, true}, + receive {P2, R5} -> true = R5 end, + true = IsOn(), + + P2 ! die, + timer:sleep(100), + false = IsOn(), + + ok. |