File 2152-Add-some-tests-for-observer-backend.patch of Package erlang
From c967331efae085721f3a5f9859d0b4753b96a562 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20W=C4=85sowski?= <michal@erlang.org>
Date: Thu, 10 Apr 2025 11:39:26 +0200
Subject: [PATCH 2/2] Add some tests for observer backend
---
lib/runtime_tools/test/Makefile | 21 ++++++
.../test/observer_backend_SUITE.erl | 69 +++++++++++++++++++
2 files changed, 90 insertions(+)
create mode 100644 lib/runtime_tools/test/observer_backend_SUITE.erl
diff --git a/lib/runtime_tools/test/Makefile b/lib/runtime_tools/test/Makefile
index 62a8b7a2e8..4ff0d4fa66 100644
--- a/lib/runtime_tools/test/Makefile
+++ b/lib/runtime_tools/test/Makefile
@@ -1,4 +1,24 @@
#
+# %CopyrightBegin%
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Copyright Ericsson AB 1997-2025. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# %CopyrightEnd%
+#
include $(ERL_TOP)/make/target.mk
include $(ERL_TOP)/make/$(TARGET)/otp.mk
@@ -11,6 +31,7 @@ MODULES = \
dbg_SUITE \
scheduler_SUITE \
msacc_SUITE \
+ observer_backend_SUITE \
zzz_SUITE
ERL_FILES= $(MODULES:%=%.erl)
diff --git a/lib/runtime_tools/test/observer_backend_SUITE.erl b/lib/runtime_tools/test/observer_backend_SUITE.erl
new file mode 100644
index 0000000000..ebeb523639
--- /dev/null
+++ b/lib/runtime_tools/test/observer_backend_SUITE.erl
@@ -0,0 +1,69 @@
+%%
+%% %CopyrightBegin%
+%%
+%% SPDX-License-Identifier: Apache-2.0
+%%
+%% Copyright Ericsson AB 2025. All Rights Reserved.
+%%
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
+%%
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
+%%
+%% %CopyrightEnd%
+%%
+-module(observer_backend_SUITE).
+-include_lib("runtime_tools/include/observer_backend.hrl").
+
+%% Test server specific exports
+-export([all/0, suite/0]).
+
+%% Test cases
+-export([procs_info/1, etop_collect/1]).
+
+suite() ->
+ [{ct_hooks,[ts_install_cth]},
+ {timetrap, {minutes, 1}}].
+
+all() ->
+ [procs_info, etop_collect].
+
+
+procs_info(_Config) ->
+ [spawn_link(fun() -> timer:sleep(5000) end) || _ <- lists:seq(1, 20000)],
+ observer_backend:procs_info(self()),
+ 10000 = get_chunk_length(),
+ 10000 = get_chunk_length(),
+ ChunkLength = get_chunk_length(),
+ true = (ChunkLength > 0).
+
+etop_collect(_Config) ->
+ [spawn_link(fun() -> timer:sleep(5000) end) || _ <- lists:seq(1, 20000)],
+ ok = observer_backend:etop_collect(self()),
+ EtopLength = get_etop_length(),
+ true = (EtopLength > 20000).
+
+get_chunk_length() ->
+ Self = self(),
+ receive
+ {procs_info, Self, ProcInfo} ->
+ length(ProcInfo)
+ after 0 ->
+ ct:fail("Did not receive message in time.")
+ end.
+
+get_etop_length() ->
+ Self = self(),
+ receive
+ {Self, #etop_info{n_procs = NProcs}} ->
+ NProcs
+ after 0 ->
+ ct:fail("Did not receive message in time.")
+ end.
--
2.43.0