Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wireplumber
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pkg
wireplumber
Commits
3fd65ac9
Commit
3fd65ac9
authored
5 years ago
by
Julian Bouzas
Browse files
Options
Downloads
Patches
Plain Diff
tests: config-endpoints: run the main loop in the same thread
parent
fefa4b91
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/modules/config-endpoint.c
+46
-82
46 additions, 82 deletions
tests/modules/config-endpoint.c
tests/modules/config-endpoint/endpoint-audiotestsrc.c
+4
-3
4 additions, 3 deletions
tests/modules/config-endpoint/endpoint-audiotestsrc.c
with
50 additions
and
85 deletions
tests/modules/config-endpoint.c
+
46
−
82
View file @
3fd65ac9
...
...
@@ -16,38 +16,38 @@
typedef
struct
{
WpTestServer
server
;
GMutex
mutex
;
GCond
cond
;
gboolean
created
;
GThread
*
loop_thread
;
GMainContext
*
context
;
GMainLoop
*
loop
;
GSource
*
timeout_source
;
WpCore
*
core
;
}
TestConfigEndpointFixture
;
void
wait_for_created
(
TestConfigEndpointFixture
*
self
)
static
gboolean
timeout_callback
(
TestConfigEndpointFixture
*
self
)
{
g_m
utex_lock
(
&
self
->
mutex
);
wh
il
e
(
!
self
->
created
)
g_
cond_wa
it
(
&
self
->
cond
,
&
self
->
mutex
);
self
->
created
=
FALSE
;
g_mutex_unlock
(
&
self
->
mutex
)
;
g_m
essage
(
"test timed out"
);
g_test_fa
il
()
;
g_
main_loop_qu
it
(
self
->
loop
);
return
G_SOURCE_REMOVE
;
}
void
signal_created
(
TestConfigEndpointFixture
*
self
)
static
void
disconnected_callback
(
WpCore
*
core
,
TestConfigEndpointFixture
*
self
)
{
g_mutex_lock
(
&
self
->
mutex
);
self
->
created
=
TRUE
;
g_cond_signal
(
&
self
->
cond
);
g_mutex_unlock
(
&
self
->
mutex
);
g_message
(
"core disconnected"
);
g_test_fail
();
g_main_loop_quit
(
self
->
loop
);
}
static
void
c
reate_audiotestsrc
(
TestConfigEndpointFixture
*
self
)
c
onfig_endpoint_setup
(
TestConfigEndpointFixture
*
self
,
gconstpointer
data
)
{
g_autoptr
(
WpProperties
)
props
=
NULL
;
/* Create the server and load audiotestsrc */
wp_test_server_setup
(
&
self
->
server
);
pw_thread_loop_lock
(
self
->
server
.
thread_loop
);
pw_context_add_spa_lib
(
self
->
server
.
context
,
"audiotestsrc"
,
"audiotestsrc/libspa-audiotestsrc"
);
...
...
@@ -58,82 +58,37 @@ create_audiotestsrc (TestConfigEndpointFixture *self)
return
;
}
pw_thread_loop_unlock
(
self
->
server
.
thread_loop
);
}
static
void
*
loop_thread_start
(
void
*
d
)
{
TestConfigEndpointFixture
*
self
=
d
;
/* Create the main
loop using the default thread context
*/
self
->
context
=
g_main_context_
get_thread_default
();
/* Create the main
context and loop
*/
self
->
context
=
g_main_context_
new
();
self
->
loop
=
g_main_loop_new
(
self
->
context
,
FALSE
);
g_main_context_push_thread_default
(
self
->
context
);
/* Create the server */
wp_test_server_setup
(
&
self
->
server
);
/* Set a timeout source */
self
->
timeout_source
=
g_timeout_source_new_seconds
(
3
);
g_source_set_callback
(
self
->
timeout_source
,
(
GSourceFunc
)
timeout_callback
,
self
,
NULL
);
g_source_attach
(
self
->
timeout_source
,
self
->
context
);
/* Create the core and connect to the server */
g_autoptr
(
WpProperties
)
props
=
NULL
;
/* Create the core */
props
=
wp_properties_new
(
PW_KEY_REMOTE_NAME
,
self
->
server
.
name
,
NULL
);
self
->
core
=
wp_core_new
(
self
->
context
,
props
);
g_assert_true
(
wp_core_connect
(
self
->
core
));
g_signal_connect
(
self
->
core
,
"disconnected"
,
(
GCallback
)
disconnected_callback
,
self
);
/* Register the wp-endpoint-audiotestsrc */
wp_factory_new
(
self
->
core
,
"wp-endpoint-audiotestsrc"
,
wp_endpoint_audiotestsrc_factory
);
/* Create the audiotestsrc node */
create_audiotestsrc
(
self
);
/* Signal we are done */
signal_created
(
self
);
/* Run the main loop */
g_main_loop_run
(
self
->
loop
);
/* Clean up */
g_clear_object
(
&
self
->
core
);
wp_test_server_teardown
(
&
self
->
server
);
g_clear_pointer
(
&
self
->
loop
,
g_main_loop_unref
);
return
NULL
;
}
static
void
config_endpoint_setup
(
TestConfigEndpointFixture
*
self
,
gconstpointer
data
)
{
/* Data */
g_mutex_init
(
&
self
->
mutex
);
g_cond_init
(
&
self
->
cond
);
self
->
created
=
FALSE
;
/* Initialize main loop, server and core in a thread */
self
->
loop_thread
=
g_thread_new
(
"loop-thread"
,
&
loop_thread_start
,
self
);
/* Wait for everything to be created */
wait_for_created
(
self
);
}
static
gboolean
loop_thread_stop
(
gpointer
data
)
{
TestConfigEndpointFixture
*
self
=
data
;
g_main_loop_quit
(
self
->
loop
);
return
G_SOURCE_REMOVE
;
}
static
void
config_endpoint_teardown
(
TestConfigEndpointFixture
*
self
,
gconstpointer
data
)
{
/* Stop the main loop and wait until it is done */
g_autoptr
(
GSource
)
source
=
g_idle_source_new
();
g_source_set_callback
(
source
,
loop_thread_stop
,
self
,
NULL
);
g_source_attach
(
source
,
self
->
context
);
g_thread_join
(
self
->
loop_thread
);
/* Data */
g_mutex_clear
(
&
self
->
mutex
);
g_cond_clear
(
&
self
->
cond
);
self
->
created
=
FALSE
;
g_clear_object
(
&
self
->
core
);
g_clear_pointer
(
&
self
->
timeout_source
,
g_source_unref
);
g_clear_pointer
(
&
self
->
loop
,
g_main_loop_unref
);
g_clear_pointer
(
&
self
->
context
,
g_main_context_unref
);
wp_test_server_teardown
(
&
self
->
server
);
}
static
void
...
...
@@ -141,7 +96,7 @@ on_audiotestsrc_created (WpConfigEndpointContext *ctx, WpEndpoint *ep,
TestConfigEndpointFixture
*
f
)
{
g_assert_nonnull
(
ep
);
signal_created
(
f
);
g_main_loop_quit
(
f
->
loop
);
}
static
void
...
...
@@ -156,11 +111,20 @@ basic (TestConfigEndpointFixture *f, gconstpointer data)
g_autoptr
(
WpConfigEndpointContext
)
ctx
=
wp_config_endpoint_context_new
(
f
->
core
);
g_assert_nonnull
(
ctx
);
g_assert_cmpint
(
wp_config_endpoint_context_get_length
(
ctx
),
==
,
0
);
/* Add a handler to stop the main loop when the endpoint is created */
g_signal_connect
(
ctx
,
"endpoint-created"
,
(
GCallback
)
on_audiotestsrc_created
,
f
);
/* Wait for the endpoint to be created */
wait_for_created
(
f
);
/* Connect */
g_assert_true
(
wp_core_connect
(
f
->
core
));
/* Run the main loop */
g_main_loop_run
(
f
->
loop
);
/* Check if the endpoint was created */
g_assert_cmpint
(
wp_config_endpoint_context_get_length
(
ctx
),
==
,
1
);
}
int
...
...
This diff is collapsed.
Click to expand it.
tests/modules/config-endpoint/endpoint-audiotestsrc.c
+
4
−
3
View file @
3fd65ac9
...
...
@@ -162,9 +162,10 @@ wp_endpoint_audiotestsrc_init_async (GAsyncInitable *initable, int io_priority,
cancellable
,
callback
,
data
);
g_autoptr
(
WpCore
)
core
=
wp_base_endpoint_get_core
(
WP_BASE_ENDPOINT
(
self
));
if
(
core
)
wp_core_sync
(
core
,
NULL
,
(
GAsyncReadyCallback
)
wp_endpoint_audiotestsrc_finish_creation
,
self
);
g_return_if_fail
(
core
);
wp_core_sync
(
core
,
NULL
,
(
GAsyncReadyCallback
)
wp_endpoint_audiotestsrc_finish_creation
,
self
);
}
static
void
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment