1 From d8517b45bf11f5a1a838637a0474375549292d9a 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 Upstream-Status: Pending
19 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
22 include/libweston/weston-log.h | 10 ++++
23 libweston/weston-log.c | 63 +++++++++++++++++++++++
24 tests/iterate-debug-scopes-test.c | 84 +++++++++++++++++++++++++++++++
25 tests/meson.build | 6 +++
26 4 files changed, 163 insertions(+)
27 create mode 100644 tests/iterate-debug-scopes-test.c
29 diff --git a/include/libweston/weston-log.h b/include/libweston/weston-log.h
30 index 1786dea..818d9de 100644
31 --- a/include/libweston/weston-log.h
32 +++ b/include/libweston/weston-log.h
33 @@ -136,6 +136,16 @@ weston_log_subscription_iterate(struct weston_log_scope *scope,
35 weston_log_flight_recorder_display_buffer(FILE *file);
38 +weston_log_scope_get_description(struct weston_log_scope *scope);
41 +weston_log_scope_get_name(struct weston_log_scope *scope);
43 +struct weston_log_scope *
44 +weston_log_scopes_iterate(struct weston_log_context *log_ctx,
45 + struct weston_log_scope *nscope);
50 diff --git a/libweston/weston-log.c b/libweston/weston-log.c
51 index 93f95c9..5d6ff2b 100644
52 --- a/libweston/weston-log.c
53 +++ b/libweston/weston-log.c
54 @@ -1057,3 +1057,66 @@ weston_log_subscription_iterate(struct weston_log_scope *scope,
56 return container_of(node, struct weston_log_subscription, source_link);
59 +/** Iterate over all debug scopes added to a weston_log_context
61 + * @param log_ctx the log context
62 + * @param nscope the iterator, use NULL to start from the head of the list
63 + * @returns the next log scope from list added to weston_log_ctx
65 + * Note that that \c nscope needs to be NULL-initialized before calling
68 + * This helper can be used by libweston users to grab all the debug scopes
69 + * created. This would be an alternative to using weston-debug private
73 +WL_EXPORT struct weston_log_scope *
74 +weston_log_scopes_iterate(struct weston_log_context *log_ctx,
75 + struct weston_log_scope *nscope)
77 + struct wl_list *list;
78 + struct wl_list *node;
82 + list = &log_ctx->scope_list;
85 + node = nscope->compositor_link.next;
91 + assert(!nscope || node != &nscope->compositor_link);
96 + return container_of(node, struct weston_log_scope, compositor_link);
99 +/** Helper to retrieve, in human readable form, the name of a log scope
101 + * @param scope the scope in question
102 + * @returns the name of the scope as a pointer to a string
104 +WL_EXPORT const char *
105 +weston_log_scope_get_name(struct weston_log_scope *scope)
107 + return scope->name;
110 +/** Helper to retreive, in human reable form, the description of a log scope
112 + * @param scope the scope in question
113 + * @returns the description of the scope as pointer to a string
116 +WL_EXPORT const char *
117 +weston_log_scope_get_description(struct weston_log_scope *scope)
119 + return scope->desc;
121 diff --git a/tests/iterate-debug-scopes-test.c b/tests/iterate-debug-scopes-test.c
123 index 0000000..82c6c5c
125 +++ b/tests/iterate-debug-scopes-test.c
128 + * Copyright 2023 Collabora, Ltd.
130 + * Permission is hereby granted, free of charge, to any person obtaining
131 + * a copy of this software and associated documentation files (the
132 + * "Software"), to deal in the Software without restriction, including
133 + * without limitation the rights to use, copy, modify, merge, publish,
134 + * distribute, sublicense, and/or sell copies of the Software, and to
135 + * permit persons to whom the Software is furnished to do so, subject to
136 + * the following conditions:
138 + * The above copyright notice and this permission notice (including the
139 + * next paragraph) shall be included in all copies or substantial
140 + * portions of the Software.
142 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
143 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
144 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
145 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
146 + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
147 + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
159 +#include <libweston/weston-log.h>
160 +#include "weston-test-client-helper.h"
161 +#include "weston-test-fixture-compositor.h"
164 +static enum test_result_code
165 +fixture_setup(struct weston_test_harness *harness)
167 + struct compositor_setup setup;
169 + compositor_setup_defaults(&setup);
170 + setup.shell = SHELL_TEST_DESKTOP;
172 + return weston_test_harness_execute_as_plugin(harness, &setup);
175 +DECLARE_FIXTURE_SETUP(fixture_setup);
178 +iterate_debug_scopes(struct weston_compositor *compositor)
180 + struct weston_log_scope *nscope = NULL;
181 + const char *test_harness_scope = "test-harness-plugin";
182 + bool found_test_harness_debug_scope = false;
183 + struct weston_log_context *log_ctx = compositor->weston_log_ctx;
185 + weston_log("Printing available debug scopes:\n");
187 + while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) {
188 + const char *scope_name;
189 + const char *desc_name;
191 + scope_name = weston_log_scope_get_name(nscope);
192 + assert(scope_name);
194 + desc_name = weston_log_scope_get_description(nscope);
197 + weston_log("\tscope name: %s, desc: %s\n", scope_name, desc_name);
199 + if (strcmp(test_harness_scope, scope_name) == 0)
200 + found_test_harness_debug_scope = true;
204 + assert(found_test_harness_debug_scope);
207 +PLUGIN_TEST(iterate_default_debug_scopes)
209 + iterate_debug_scopes(compositor);
211 diff --git a/tests/meson.build b/tests/meson.build
212 index 1d59a93..7908896 100644
213 --- a/tests/meson.build
214 +++ b/tests/meson.build
215 @@ -269,6 +269,12 @@ tests = [
217 'dep_objs': [ dep_libweston_public ]
219 + { 'name': 'iterate-debug-scopes',
221 + 'iterate-debug-scopes-test.c',
223 + 'dep_objs': [ dep_libweston_public ]
227 if get_option('renderer-gl')