1 From d5168b8eb0d881a0a6029c0b348a739147317238 Mon Sep 17 00:00:00 2001
2 From: Marius Vlad <marius.vlad@collabora.com>
3 Date: Mon, 29 May 2023 16:30:02 +0300
4 Subject: [PATCH] libweston/weston-log: Add a iterator helper for debug scope
6 This adds three new helpers: one to iterate over all debug scopes
7 created/added and other two are for simpler getters for the scope name
10 Included with this change is also a simple test to retrieve them.
12 This is an alternative to using the debug scope list advertised when
13 using the weston-debug private extension. libweston users can use this
14 directly to know which scopes they can subscribe to, and there's no need
15 to have a client implementation for the weston-debug protocol.
17 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
19 include/libweston/weston-log.h | 10 ++++
20 libweston/weston-log.c | 63 +++++++++++++++++++++++
21 tests/iterate-debug-scopes-test.c | 84 +++++++++++++++++++++++++++++++
22 tests/meson.build | 6 +++
23 4 files changed, 163 insertions(+)
24 create mode 100644 tests/iterate-debug-scopes-test.c
26 diff --git a/include/libweston/weston-log.h b/include/libweston/weston-log.h
27 index aeb7768b..70f41675 100644
28 --- a/include/libweston/weston-log.h
29 +++ b/include/libweston/weston-log.h
30 @@ -134,6 +134,16 @@ weston_log_subscription_iterate(struct weston_log_scope *scope,
32 weston_log_flight_recorder_display_buffer(FILE *file);
35 +weston_log_scope_get_description(struct weston_log_scope *scope);
38 +weston_log_scope_get_name(struct weston_log_scope *scope);
40 +struct weston_log_scope *
41 +weston_log_scopes_iterate(struct weston_log_context *log_ctx,
42 + struct weston_log_scope *nscope);
47 diff --git a/libweston/weston-log.c b/libweston/weston-log.c
48 index 276fde26..8b4c78a5 100644
49 --- a/libweston/weston-log.c
50 +++ b/libweston/weston-log.c
51 @@ -1009,3 +1009,66 @@ weston_log_subscription_iterate(struct weston_log_scope *scope,
53 return container_of(node, struct weston_log_subscription, source_link);
56 +/** Iterate over all debug scopes added to a weston_log_context
58 + * @param log_ctx the log context
59 + * @param nscope the iterator, use NULL to start from the head of the list
60 + * @returns the next log scope from list added to weston_log_ctx
62 + * Note that that \c nscope needs to be NULL-initialized before calling
65 + * This helper can be used by libweston users to grab all the debug scopes
66 + * created. This would be an alternative to using weston-debug private
70 +WL_EXPORT struct weston_log_scope *
71 +weston_log_scopes_iterate(struct weston_log_context *log_ctx,
72 + struct weston_log_scope *nscope)
74 + struct wl_list *list;
75 + struct wl_list *node;
79 + list = &log_ctx->scope_list;
82 + node = nscope->compositor_link.next;
88 + assert(!nscope || node != &nscope->compositor_link);
93 + return container_of(node, struct weston_log_scope, compositor_link);
96 +/** Helper to retrieve, in human readable form, the name of a log scope
98 + * @param scope the scope in question
99 + * @returns the name of the scope as a pointer to a string
101 +WL_EXPORT const char *
102 +weston_log_scope_get_name(struct weston_log_scope *scope)
104 + return scope->name;
107 +/** Helper to retreive, in human reable form, the description of a log scope
109 + * @param scope the scope in question
110 + * @returns the description of the scope as pointer to a string
113 +WL_EXPORT const char *
114 +weston_log_scope_get_description(struct weston_log_scope *scope)
116 + return scope->desc;
118 diff --git a/tests/iterate-debug-scopes-test.c b/tests/iterate-debug-scopes-test.c
120 index 00000000..82c6c5c8
122 +++ b/tests/iterate-debug-scopes-test.c
125 + * Copyright 2023 Collabora, Ltd.
127 + * Permission is hereby granted, free of charge, to any person obtaining
128 + * a copy of this software and associated documentation files (the
129 + * "Software"), to deal in the Software without restriction, including
130 + * without limitation the rights to use, copy, modify, merge, publish,
131 + * distribute, sublicense, and/or sell copies of the Software, and to
132 + * permit persons to whom the Software is furnished to do so, subject to
133 + * the following conditions:
135 + * The above copyright notice and this permission notice (including the
136 + * next paragraph) shall be included in all copies or substantial
137 + * portions of the Software.
139 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
140 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
141 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
142 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
143 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
144 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
145 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
156 +#include <libweston/weston-log.h>
157 +#include "weston-test-client-helper.h"
158 +#include "weston-test-fixture-compositor.h"
161 +static enum test_result_code
162 +fixture_setup(struct weston_test_harness *harness)
164 + struct compositor_setup setup;
166 + compositor_setup_defaults(&setup);
167 + setup.shell = SHELL_TEST_DESKTOP;
169 + return weston_test_harness_execute_as_plugin(harness, &setup);
172 +DECLARE_FIXTURE_SETUP(fixture_setup);
175 +iterate_debug_scopes(struct weston_compositor *compositor)
177 + struct weston_log_scope *nscope = NULL;
178 + const char *test_harness_scope = "test-harness-plugin";
179 + bool found_test_harness_debug_scope = false;
180 + struct weston_log_context *log_ctx = compositor->weston_log_ctx;
182 + weston_log("Printing available debug scopes:\n");
184 + while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) {
185 + const char *scope_name;
186 + const char *desc_name;
188 + scope_name = weston_log_scope_get_name(nscope);
189 + assert(scope_name);
191 + desc_name = weston_log_scope_get_description(nscope);
194 + weston_log("\tscope name: %s, desc: %s\n", scope_name, desc_name);
196 + if (strcmp(test_harness_scope, scope_name) == 0)
197 + found_test_harness_debug_scope = true;
201 + assert(found_test_harness_debug_scope);
204 +PLUGIN_TEST(iterate_default_debug_scopes)
206 + iterate_debug_scopes(compositor);
208 diff --git a/tests/meson.build b/tests/meson.build
209 index d8e96e77..e52ff5a6 100644
210 --- a/tests/meson.build
211 +++ b/tests/meson.build
212 @@ -224,6 +224,12 @@ tests = [
214 'dep_objs': [ dep_lib_desktop ]
216 + { 'name': 'iterate-debug-scopes',
218 + 'iterate-debug-scopes-test.c',
220 + 'dep_objs': [ dep_libweston_public ]