summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2022-09-07 21:06:47 -0500
committerFederico Mena Quintero <federico@gnome.org>2023-05-09 10:04:25 -0600
commite2bb6b5593418f334ddf5d1e3404c434bedb403f (patch)
tree9555532bbf9291458c3b2bb520d22edca1dbadb3
parent11710e04c901d3202e8263e9a1766c7dd7ed23e2 (diff)
downloadat-spi2-core-e2bb6b5593418f334ddf5d1e3404c434bedb403f.tar.gz
Don't use a global variable for child_pid
Keep it in the TestAppFixture at all times.
-rw-r--r--tests/at-spi2-atk/atk_test_util.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/tests/at-spi2-atk/atk_test_util.c b/tests/at-spi2-atk/atk_test_util.c
index b22aa3f6..57f7098f 100644
--- a/tests/at-spi2-atk/atk_test_util.c
+++ b/tests/at-spi2-atk/atk_test_util.c
@@ -23,12 +23,10 @@
#include "atk_test_util.h"
#include <signal.h>
-static pid_t child_pid;
-
-static void
+static pid_t
run_app (const char *file_name)
{
- child_pid = fork ();
+ pid_t child_pid = fork ();
if (child_pid == 0)
{
execlp (TESTS_BUILD_DIR "/app-test",
@@ -42,6 +40,8 @@ run_app (const char *file_name)
}
if (child_pid)
fprintf (stderr, "child_pid %d\n", child_pid);
+
+ return child_pid;
}
static AtspiAccessible *
@@ -76,16 +76,18 @@ try_get_root_obj (AtspiAccessible *obj)
return NULL;
}
-static AtspiAccessible *
-get_root_obj (const char *file_name)
+static void
+get_root_obj (const char *file_name, AtspiAccessible **out_root_obj, pid_t *out_child_pid)
{
int tries = 0;
AtspiAccessible *child;
struct timespec timeout = { .tv_sec = 0, .tv_nsec = 10 * 1000000 };
AtspiAccessible *obj = NULL;
+ pid_t child_pid;
fprintf (stderr, "run_app: %s\n", file_name);
- run_app (file_name);
+ child_pid = run_app (file_name);
+ *out_child_pid = child_pid;
obj = atspi_get_desktop (0);
@@ -94,7 +96,10 @@ get_root_obj (const char *file_name)
{
child = try_get_root_obj (obj);
if (child)
- return child;
+ {
+ *out_root_obj = child;
+ return;
+ }
nanosleep (&timeout, NULL);
}
@@ -109,14 +114,18 @@ get_root_obj (const char *file_name)
}
g_test_fail ();
kill (child_pid, SIGTERM);
- return NULL;
+ *out_root_obj = NULL;
}
void
fixture_setup (TestAppFixture *fixture, gconstpointer user_data)
{
const char *file_name = user_data;
- AtspiAccessible *root_obj = get_root_obj (file_name);
+ pid_t child_pid;
+ AtspiAccessible *root_obj;
+
+ get_root_obj (file_name, &root_obj, &child_pid);
+ g_assert (root_obj != NULL);
fixture->child_pid = child_pid;
fixture->root_obj = root_obj;
@@ -131,7 +140,7 @@ fixture_teardown (TestAppFixture *fixture, gconstpointer user_data)
struct timespec timeout = { .tv_sec = 0, .tv_nsec = 10 * 1000000 };
AtspiAccessible *obj = NULL;
- kill (child_pid, SIGTERM);
+ kill (fixture->child_pid, SIGTERM);
obj = atspi_get_desktop (0);