diff options
author | Steve Vinoski <[email protected]> | 2009-11-27 12:37:13 -0500 |
---|---|---|
committer | Steve Vinoski <[email protected]> | 2009-12-01 21:31:30 -0500 |
commit | 88b530ea24977081020feb2123124063e58dfc12 (patch) | |
tree | 3e1fa8301f22328d0b1cf70edc585bfca5fd8729 /lib/stdlib/test/gen_fsm_SUITE.erl | |
parent | 2a9b7a1c7816812dd637933a8fbf61bed6742785 (diff) | |
download | otp-88b530ea24977081020feb2123124063e58dfc12.tar.gz otp-88b530ea24977081020feb2123124063e58dfc12.tar.bz2 otp-88b530ea24977081020feb2123124063e58dfc12.zip |
Teach sys:get_status/1,2 to call Mod:format_status/2
Restore the ability for gen_server and gen_fsm callback
modules to format their own state for display under the
sys:get_status/1,2 calls.
This ability is extremely useful for new behavior modules
based on gen_server or gen_fsm, so that they can display
their status in a more meaningful way than just dumping
the state record. It is also generally useful for applications
wanting to display their gen_server or gen_fsm callback module
state in something other than the default manner.
Also document the previously undocumented the
gen_server:format_status/2 and gen_fsm:format_status/2 optional
callback functions that, if exported by the callback module, are
invoked when sys:get_status/1,2 are called.
Add unit tests to ensure that format_status/2 functions exported
from a gen_fsm callback module and a gen_server callback module
are called when sys:get_status/1,2 are called.
Diffstat (limited to 'lib/stdlib/test/gen_fsm_SUITE.erl')
-rw-r--r-- | lib/stdlib/test/gen_fsm_SUITE.erl | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/stdlib/test/gen_fsm_SUITE.erl b/lib/stdlib/test/gen_fsm_SUITE.erl index 62f8b2f9dd..23c1d9a193 100644 --- a/lib/stdlib/test/gen_fsm_SUITE.erl +++ b/lib/stdlib/test/gen_fsm_SUITE.erl @@ -30,7 +30,7 @@ -export([shutdown/1]). --export([sys/1, sys1/1]). +-export([sys/1, sys1/1, call_format_status/1]). -export([hibernate/1,hiber_idle/3,hiber_wakeup/3,hiber_idle/2,hiber_wakeup/2]). @@ -42,7 +42,7 @@ % The gen_fsm behaviour -export([init/1, handle_event/3, handle_sync_event/4, terminate/3, - handle_info/3]). + handle_info/3, format_status/2]). -export([idle/2, idle/3, timeout/2, wfor_conf/2, wfor_conf/3, @@ -305,7 +305,7 @@ shutdown(Config) when is_list(Config) -> ok. -sys(suite) -> [sys1]. +sys(suite) -> [sys1, call_format_status]. sys1(Config) when is_list(Config) -> ?line {ok, Pid} = @@ -317,6 +317,13 @@ sys1(Config) when is_list(Config) -> ?line sys:resume(Pid), ?line stop_it(Pid). +call_format_status(Config) when is_list(Config) -> + ?line {ok, Pid} = gen_fsm:start(gen_fsm_SUITE, [], []), + ?line Status = sys:get_status(Pid), + ?line {status, Pid, _Mod, [_PDict, running, _Parent, _, Data]} = Status, + ?line [format_status_called | _] = lists:reverse(Data), + ?line stop_it(Pid). + %% Hibernation hibernate(suite) -> []; @@ -836,3 +843,6 @@ handle_sync_event(stop_shutdown_reason, _From, _State, Data) -> {stop, {shutdown,reason}, {shutdown,reason}, Data}; handle_sync_event({get, _Pid}, _From, State, Data) -> {reply, {state, State, Data}, State, Data}. + +format_status(_Opt, [_Pdict, _StateData]) -> + [format_status_called]. |