summaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/Makefile.am18
-rw-r--r--tests/src/X.c45
-rw-r--r--tests/src/Xvnc.c19
-rw-r--r--tests/src/libsystem.c16
-rw-r--r--tests/src/status.c5
-rw-r--r--tests/src/test-gobject-greeter.c86
-rwxr-xr-xtests/src/test-python-greeter74
-rw-r--r--tests/src/test-qt-greeter.cpp62
-rw-r--r--tests/src/test-runner.c116
-rw-r--r--tests/src/test-session.c60
-rw-r--r--tests/src/x-server.c13
11 files changed, 316 insertions, 198 deletions
diff --git a/tests/src/Makefile.am b/tests/src/Makefile.am
index d96ebbce..d83c5c4b 100644
--- a/tests/src/Makefile.am
+++ b/tests/src/Makefile.am
@@ -73,14 +73,12 @@ test_gobject_greeter_CFLAGS = \
-I$(top_srcdir)/liblightdm-gobject \
$(WARN_CFLAGS) \
$(GLIB_CFLAGS) \
- $(GIO_UNIX_CFLAGS) \
- $(XCB_CFLAGS)
+ $(GIO_UNIX_CFLAGS)
test_gobject_greeter_LDADD = \
-L$(top_builddir)/liblightdm-gobject \
-llightdm-gobject-1 \
$(GLIB_LIBS) \
- $(GIO_UNIX_LIBS) \
- $(XCB_LIBS)
+ $(GIO_UNIX_LIBS)
guest_account_SOURCES = guest-account.c status.c status.h
guest_account_CFLAGS = \
@@ -111,8 +109,7 @@ nodist_test_qt4_greeter_SOURCES = test-qt4-greeter_moc4.cpp
nodist_test_qt5_greeter_SOURCES = test-qt5-greeter_moc5.cpp
common_qt_cflags = \
$(GLIB_CFLAGS) \
- $(GIO_UNIX_CFLAGS) \
- $(XCB_CFLAGS)
+ $(GIO_UNIX_CFLAGS)
test_qt4_greeter_CFLAGS = $(common_qt_cflags)
test_qt5_greeter_CFLAGS = $(common_qt_cflags)
common_qt_cxxflags = \
@@ -129,8 +126,7 @@ test_qt5_greeter_CXXFLAGS = \
common_qt_ldadd = \
-L$(top_builddir)/liblightdm-qt \
$(GLIB_LIBS) \
- $(GIO_UNIX_LIBS) \
- $(XCB_LIBS)
+ $(GIO_UNIX_LIBS)
test_qt4_greeter_LDADD = \
$(common_qt_ldadd) \
-llightdm-qt-2 \
@@ -144,12 +140,10 @@ test_session_SOURCES = test-session.c status.c status.h
test_session_CFLAGS = \
$(WARN_CFLAGS) \
$(GLIB_CFLAGS) \
- $(GIO_UNIX_CFLAGS) \
- $(XCB_CFLAGS)
+ $(GIO_UNIX_CFLAGS)
test_session_LDADD = \
$(GLIB_LIBS) \
- $(GIO_UNIX_LIBS) \
- $(XCB_LIBS)
+ $(GIO_UNIX_LIBS)
initctl_SOURCES = initctl.c
initctl_CFLAGS = \
diff --git a/tests/src/X.c b/tests/src/X.c
index 5318afdd..1fd3e577 100644
--- a/tests/src/X.c
+++ b/tests/src/X.c
@@ -62,7 +62,7 @@ indicate_ready ()
handler = signal (SIGUSR1, SIG_IGN);
if (handler == SIG_IGN)
{
- status_notify ("XSERVER :%d INDICATE-READY", display_number);
+ status_notify ("XSERVER-%d INDICATE-READY", display_number);
kill (getppid (), SIGUSR1);
}
signal (SIGUSR1, handler);
@@ -73,12 +73,12 @@ signal_cb (int signum)
{
if (signum == SIGHUP)
{
- status_notify ("XSERVER :%d DISCONNECT-CLIENTS", display_number);
+ status_notify ("XSERVER-%d DISCONNECT-CLIENTS", display_number);
indicate_ready ();
}
else
{
- status_notify ("XSERVER :%d TERMINATE SIGNAL=%d", display_number, signum);
+ status_notify ("XSERVER-%d TERMINATE SIGNAL=%d", display_number, signum);
quit (EXIT_SUCCESS);
}
}
@@ -90,7 +90,7 @@ xdmcp_query_cb (XDMCPClient *client)
if (!notified_query)
{
- status_notify ("XSERVER :%d SEND-QUERY", display_number);
+ status_notify ("XSERVER-%d SEND-QUERY", display_number);
notified_query = TRUE;
}
}
@@ -101,9 +101,9 @@ xdmcp_willing_cb (XDMCPClient *client, XDMCPWilling *message)
gchar **authorization_names;
GInetAddress *addresses[2];
- status_notify ("XSERVER :%d GOT-WILLING AUTHENTICATION-NAME=\"%s\" HOSTNAME=\"%s\" STATUS=\"%s\"", display_number, message->authentication_name, message->hostname, message->status);
+ status_notify ("XSERVER-%d GOT-WILLING AUTHENTICATION-NAME=\"%s\" HOSTNAME=\"%s\" STATUS=\"%s\"", display_number, message->authentication_name, message->hostname, message->status);
- status_notify ("XSERVER :%d SEND-REQUEST DISPLAY-NUMBER=%d AUTHORIZATION-NAME=\"%s\" MFID=\"%s\"", display_number, display_number, "MIT-MAGIC-COOKIE-1", "TEST XSERVER");
+ status_notify ("XSERVER-%d SEND-REQUEST DISPLAY-NUMBER=%d AUTHORIZATION-NAME=\"%s\" MFID=\"%s\"", display_number, display_number, "MIT-MAGIC-COOKIE-1", "TEST XSERVER");
authorization_names = g_strsplit ("MIT-MAGIC-COOKIE-1", " ", -1);
addresses[0] = xdmcp_client_get_local_address (client);
@@ -118,7 +118,7 @@ xdmcp_willing_cb (XDMCPClient *client, XDMCPWilling *message)
static void
xdmcp_accept_cb (XDMCPClient *client, XDMCPAccept *message)
{
- status_notify ("XSERVER :%d GOT-ACCEPT SESSION-ID=%d AUTHENTICATION-NAME=\"%s\" AUTHORIZATION-NAME=\"%s\"", display_number, message->session_id, message->authentication_name, message->authorization_name);
+ status_notify ("XSERVER-%d GOT-ACCEPT SESSION-ID=%d AUTHENTICATION-NAME=\"%s\" AUTHORIZATION-NAME=\"%s\"", display_number, message->session_id, message->authentication_name, message->authorization_name);
/* Ignore if haven't picked a valid authorization */
if (strcmp (message->authorization_name, "MIT-MAGIC-COOKIE-1") != 0)
@@ -129,20 +129,20 @@ xdmcp_accept_cb (XDMCPClient *client, XDMCPAccept *message)
xdmcp_cookie = g_malloc (message->authorization_data_length);
memcpy (xdmcp_cookie, message->authorization_data, message->authorization_data_length);
- status_notify ("XSERVER :%d SEND-MANAGE SESSION-ID=%d DISPLAY-NUMBER=%d DISPLAY-CLASS=\"%s\"", display_number, message->session_id, display_number, "DISPLAY CLASS");
+ status_notify ("XSERVER-%d SEND-MANAGE SESSION-ID=%d DISPLAY-NUMBER=%d DISPLAY-CLASS=\"%s\"", display_number, message->session_id, display_number, "DISPLAY CLASS");
xdmcp_client_send_manage (client, message->session_id, display_number, "DISPLAY CLASS");
}
static void
xdmcp_decline_cb (XDMCPClient *client, XDMCPDecline *message)
{
- status_notify ("XSERVER :%d GOT-DECLINE STATUS=\"%s\" AUTHENTICATION-NAME=\"%s\"", display_number, message->status, message->authentication_name);
+ status_notify ("XSERVER-%d GOT-DECLINE STATUS=\"%s\" AUTHENTICATION-NAME=\"%s\"", display_number, message->status, message->authentication_name);
}
static void
xdmcp_failed_cb (XDMCPClient *client, XDMCPFailed *message)
{
- status_notify ("XSERVER :%d GOT-FAILED SESSION-ID=%d STATUS=\"%s\"", display_number, message->session_id, message->status);
+ status_notify ("XSERVER-%d GOT-FAILED SESSION-ID=%d STATUS=\"%s\"", display_number, message->session_id, message->status);
}
static void
@@ -151,9 +151,9 @@ x_client_connect_cb (XClient *client, XConnect *message)
gchar *auth_error = NULL;
if (x_client_get_address (client))
- status_notify ("XSERVER :%d TCP-ACCEPT-CONNECT", display_number);
+ status_notify ("XSERVER-%d TCP-ACCEPT-CONNECT", display_number);
else
- status_notify ("XSERVER :%d ACCEPT-CONNECT", display_number);
+ status_notify ("XSERVER-%d ACCEPT-CONNECT", display_number);
if (xdmcp_client)
{
@@ -239,7 +239,7 @@ request_cb (const gchar *request)
return;
}
- r = g_strdup_printf ("XSERVER :%d CRASH", display_number);
+ r = g_strdup_printf ("XSERVER-%d CRASH", display_number);
if (strcmp (request, r) == 0)
{
cleanup ();
@@ -258,6 +258,7 @@ main (int argc, char **argv)
gboolean do_xdmcp = FALSE;
guint xdmcp_port = 0;
gchar *xdmcp_host = NULL;
+ gchar *lock_filename;
int lock_file;
signal (SIGINT, signal_cb);
@@ -351,7 +352,7 @@ main (int argc, char **argv)
/* Add fake screen so that libx11 calls don't freak out when they can't find a screen */
x_server_add_screen (xserver, 0xffffff, 0x000000, 0, 1024, 768, 1000, 1000);
- status_notify ("XSERVER :%d START", display_number);
+ status_notify ("XSERVER-%d START", display_number);
config = g_key_file_new ();
g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
@@ -359,11 +360,13 @@ main (int argc, char **argv)
if (g_key_file_has_key (config, "test-xserver-config", "return-value", NULL))
{
int return_value = g_key_file_get_integer (config, "test-xserver-config", "return-value", NULL);
- status_notify ("XSERVER :%d EXIT CODE=%d", display_number, return_value);
+ status_notify ("XSERVER-%d EXIT CODE=%d", display_number, return_value);
return return_value;
}
- lock_path = g_strdup_printf ("/tmp/.X%d-lock", display_number);
+ lock_filename = g_strdup_printf (".X%d-lock", display_number);
+ lock_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", lock_filename, NULL);
+ g_free (lock_filename);
lock_file = open (lock_path, O_CREAT | O_EXCL | O_WRONLY, 0444);
if (lock_file < 0)
{
@@ -380,14 +383,22 @@ main (int argc, char **argv)
proc_filename = g_strdup_printf ("/proc/%d", pid);
if (!g_file_test (proc_filename, G_FILE_TEST_EXISTS))
{
+ gchar *socket_dir;
+ gchar *socket_filename;
gchar *socket_path;
- socket_path = g_strdup_printf ("/tmp/.X11-unix/X%d", display_number);
+ socket_dir = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", ".X11-unix", NULL);
+ g_mkdir_with_parents (socket_dir, 0755);
+
+ socket_filename = g_strdup_printf ("X%d", display_number);
+ socket_path = g_build_filename (socket_dir, socket_filename, NULL);
g_printerr ("Breaking lock on non-existant process %d\n", pid);
unlink (lock_path);
unlink (socket_path);
+ g_free (socket_dir);
+ g_free (socket_filename);
g_free (socket_path);
}
g_free (proc_filename);
diff --git a/tests/src/Xvnc.c b/tests/src/Xvnc.c
index e684951b..889e7f4e 100644
--- a/tests/src/Xvnc.c
+++ b/tests/src/Xvnc.c
@@ -35,7 +35,7 @@ indicate_ready ()
handler = signal (SIGUSR1, SIG_IGN);
if (handler == SIG_IGN)
{
- status_notify ("XSERVER :%d INDICATE-READY", display_number);
+ status_notify ("XSERVER-%d INDICATE-READY", display_number);
kill (getppid (), SIGUSR1);
}
signal (SIGUSR1, handler);
@@ -62,12 +62,12 @@ signal_cb (int signum)
{
if (signum == SIGHUP)
{
- status_notify ("XSERVER :%d DISCONNECT-CLIENTS", display_number);
+ status_notify ("XSERVER-%d DISCONNECT-CLIENTS", display_number);
indicate_ready ();
}
else
{
- status_notify ("XSERVER :%d TERMINATE SIGNAL=%d", display_number, signum);
+ status_notify ("XSERVER-%d TERMINATE SIGNAL=%d", display_number, signum);
quit (EXIT_SUCCESS);
}
}
@@ -78,9 +78,9 @@ x_client_connect_cb (XClient *client, XConnect *message)
gchar *auth_error = NULL;
if (x_client_get_address (client))
- status_notify ("XSERVER :%d TCP-ACCEPT-CONNECT", display_number);
+ status_notify ("XSERVER-%d TCP-ACCEPT-CONNECT", display_number);
else
- status_notify ("XSERVER :%d ACCEPT-CONNECT", display_number);
+ status_notify ("XSERVER-%d ACCEPT-CONNECT", display_number);
if (auth_path)
{
@@ -151,7 +151,7 @@ vnc_data_cb (GIOChannel *channel, GIOCondition condition, gpointer data)
buffer[n_read] = '\0';
if (g_str_has_suffix (buffer, "\n"))
buffer[n_read-1] = '\0';
- status_notify ("XSERVER :%d VNC-CLIENT-CONNECT VERSION=\"%s\"", display_number, buffer);
+ status_notify ("XSERVER-%d VNC-CLIENT-CONNECT VERSION=\"%s\"", display_number, buffer);
}
return TRUE;
@@ -176,6 +176,7 @@ main (int argc, char **argv)
gboolean use_inetd = FALSE;
gchar *geometry = g_strdup ("640x480");
gint depth = 8;
+ gchar *lock_filename;
int lock_file;
int i;
@@ -248,7 +249,7 @@ main (int argc, char **argv)
x_server_set_listen_unix (xserver, listen_unix);
x_server_set_listen_tcp (xserver, listen_tcp);
- status_notify ("XSERVER :%d START GEOMETRY=%s DEPTH=%d", display_number, geometry, depth);
+ status_notify ("XSERVER-%d START GEOMETRY=%s DEPTH=%d", display_number, geometry, depth);
config = g_key_file_new ();
g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
@@ -267,7 +268,9 @@ main (int argc, char **argv)
return EXIT_FAILURE;
}
- lock_path = g_strdup_printf ("/tmp/.X%d-lock", display_number);
+ lock_filename = g_strdup_printf (".X%d-lock", display_number);
+ lock_path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", lock_filename, NULL);
+ g_free (lock_filename);
lock_file = open (lock_path, O_CREAT | O_EXCL | O_WRONLY, 0444);
if (lock_file < 0)
{
diff --git a/tests/src/libsystem.c b/tests/src/libsystem.c
index 5c20ddce..c7c0bdbb 100644
--- a/tests/src/libsystem.c
+++ b/tests/src/libsystem.c
@@ -212,6 +212,22 @@ open64 (const char *pathname, int flags, ...)
}
int
+access (const char *pathname, int mode)
+{
+ int (*_access) (const char *pathname, int mode);
+ gchar *new_path = NULL;
+ int ret;
+
+ _access = (int (*)(const char *pathname, int mode)) dlsym (RTLD_NEXT, "access");
+
+ new_path = redirect_path (pathname);
+ ret = _access (new_path, mode);
+ g_free (new_path);
+
+ return ret;
+}
+
+int
ioctl (int d, int request, void *data)
{
int (*_ioctl) (int d, int request, void *data);
diff --git a/tests/src/status.c b/tests/src/status.c
index cc9b46a7..6ca6ce42 100644
--- a/tests/src/status.c
+++ b/tests/src/status.c
@@ -96,11 +96,6 @@ status_notify (const gchar *format, ...)
if (error)
g_printerr ("Failed to write to status socket: %s\n", error->message);
g_clear_error (&error);
- /* We sync filesystem here, to guarantee that statuses sent from
- multiple process (e.g. greeter and X) are all ordered correctly.
- Without this, there is a race that manifests occasionally between
- close status_notify calls. fsync does not seem to do the trick. */
- sync ();
}
else
g_printerr ("%s\n", status);
diff --git a/tests/src/test-gobject-greeter.c b/tests/src/test-gobject-greeter.c
index 6597b92e..4bfd4471 100644
--- a/tests/src/test-gobject-greeter.c
+++ b/tests/src/test-gobject-greeter.c
@@ -3,11 +3,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <xcb/xcb.h>
#include <lightdm.h>
#include "status.h"
+static gchar *greeter_id;
static GMainLoop *loop;
static LightDMGreeter *greeter;
static xcb_connection_t *connection = NULL;
@@ -16,39 +16,39 @@ static GKeyFile *config;
static void
show_message_cb (LightDMGreeter *greeter, const gchar *text, LightDMMessageType type)
{
- status_notify ("GREETER %s SHOW-MESSAGE TEXT=\"%s\"", getenv ("DISPLAY"), text);
+ status_notify ("%s SHOW-MESSAGE TEXT=\"%s\"", greeter_id, text);
}
static void
show_prompt_cb (LightDMGreeter *greeter, const gchar *text, LightDMPromptType type)
{
- status_notify ("GREETER %s SHOW-PROMPT TEXT=\"%s\"", getenv ("DISPLAY"), text);
+ status_notify ("%s SHOW-PROMPT TEXT=\"%s\"", greeter_id, text);
}
static void
authentication_complete_cb (LightDMGreeter *greeter)
{
if (lightdm_greeter_get_authentication_user (greeter))
- status_notify ("GREETER %s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s",
- getenv ("DISPLAY"),
+ status_notify ("%s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s",
+ greeter_id,
lightdm_greeter_get_authentication_user (greeter),
lightdm_greeter_get_is_authenticated (greeter) ? "TRUE" : "FALSE");
else
- status_notify ("GREETER %s AUTHENTICATION-COMPLETE AUTHENTICATED=%s",
- getenv ("DISPLAY"),
+ status_notify ("%s AUTHENTICATION-COMPLETE AUTHENTICATED=%s",
+ greeter_id,
lightdm_greeter_get_is_authenticated (greeter) ? "TRUE" : "FALSE");
}
static void
autologin_timer_expired_cb (LightDMGreeter *greeter)
{
- status_notify ("GREETER %s AUTOLOGIN-TIMER-EXPIRED", getenv ("DISPLAY"));
+ status_notify ("%s AUTOLOGIN-TIMER-EXPIRED", greeter_id);
}
static void
signal_cb (int signum)
{
- status_notify ("GREETER %s TERMINATE SIGNAL=%d", getenv ("DISPLAY"), signum);
+ status_notify ("%s TERMINATE SIGNAL=%d", greeter_id, signum);
exit (EXIT_SUCCESS);
}
@@ -63,32 +63,32 @@ request_cb (const gchar *request)
return;
}
- r = g_strdup_printf ("GREETER %s AUTHENTICATE", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE", greeter_id);
if (strcmp (request, r) == 0)
lightdm_greeter_authenticate (greeter, NULL);
g_free (r);
- r = g_strdup_printf ("GREETER %s AUTHENTICATE USERNAME=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE USERNAME=", greeter_id);
if (g_str_has_prefix (request, r))
lightdm_greeter_authenticate (greeter, request + strlen (r));
g_free (r);
- r = g_strdup_printf ("GREETER %s AUTHENTICATE-GUEST", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE-GUEST", greeter_id);
if (strcmp (request, r) == 0)
lightdm_greeter_authenticate_as_guest (greeter);
g_free (r);
- r = g_strdup_printf ("GREETER %s AUTHENTICATE-AUTOLOGIN", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE-AUTOLOGIN", greeter_id);
if (strcmp (request, r) == 0)
lightdm_greeter_authenticate_autologin (greeter);
g_free (r);
- r = g_strdup_printf ("GREETER %s AUTHENTICATE-REMOTE SESSION=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE-REMOTE SESSION=", greeter_id);
if (g_str_has_prefix (request, r))
lightdm_greeter_authenticate_remote (greeter, request + strlen (r), NULL);
g_free (r);
- r = g_strdup_printf ("GREETER %s RESPOND TEXT=\"", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s RESPOND TEXT=\"", greeter_id);
if (g_str_has_prefix (request, r))
{
gchar *text = g_strdup (request + strlen (r));
@@ -98,31 +98,31 @@ request_cb (const gchar *request)
}
g_free (r);
- r = g_strdup_printf ("GREETER %s START-SESSION", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s START-SESSION", greeter_id);
if (strcmp (request, r) == 0)
{
if (!lightdm_greeter_start_session_sync (greeter, NULL, NULL))
- status_notify ("GREETER %s SESSION-FAILED", getenv ("DISPLAY"));
+ status_notify ("%s SESSION-FAILED", greeter_id);
}
g_free (r);
- r = g_strdup_printf ("GREETER %s START-SESSION SESSION=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s START-SESSION SESSION=", greeter_id);
if (g_str_has_prefix (request, r))
{
if (!lightdm_greeter_start_session_sync (greeter, request + strlen (r), NULL))
- status_notify ("GREETER %s SESSION-FAILED", getenv ("DISPLAY"));
+ status_notify ("%s SESSION-FAILED", greeter_id);
}
g_free (r);
- r = g_strdup_printf ("GREETER %s LOG-LAYOUT", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LOG-LAYOUT", greeter_id);
if (strcmp (request, r) == 0)
{
const gchar *layout;
layout = lightdm_layout_get_name (lightdm_get_layout ());
- status_notify ("GREETER %s LOG-LAYOUT LAYOUT='%s'", getenv ("DISPLAY"), layout ? layout : "");
+ status_notify ("%s LOG-LAYOUT LAYOUT='%s'", greeter_id, layout ? layout : "");
}
- r = g_strdup_printf ("GREETER %s LOG-LAYOUT USERNAME=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LOG-LAYOUT USERNAME=", greeter_id);
if (g_str_has_prefix (request, r))
{
LightDMUser *user;
@@ -132,11 +132,11 @@ request_cb (const gchar *request)
user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username);
layout = lightdm_user_get_layout (user);
- status_notify ("GREETER %s LOG-LAYOUT USERNAME=%s LAYOUT='%s'", getenv ("DISPLAY"), username, layout ? layout : "");
+ status_notify ("%s LOG-LAYOUT USERNAME=%s LAYOUT='%s'", greeter_id, username, layout ? layout : "");
}
g_free (r);
- r = g_strdup_printf ("GREETER %s LOG-LAYOUTS USERNAME=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LOG-LAYOUTS USERNAME=", greeter_id);
if (g_str_has_prefix (request, r))
{
LightDMUser *user;
@@ -149,11 +149,11 @@ request_cb (const gchar *request)
layouts = lightdm_user_get_layouts (user);
for (i = 0; layouts[i]; i++)
- status_notify ("GREETER %s LOG-LAYOUTS USERNAME=%s LAYOUT='%s'", getenv ("DISPLAY"), username, layouts[i]);
+ status_notify ("%s LOG-LAYOUTS USERNAME=%s LAYOUT='%s'", greeter_id, username, layouts[i]);
}
g_free (r);
- r = g_strdup_printf ("GREETER %s LOG-VARIANTS LAYOUT=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LOG-VARIANTS LAYOUT=", greeter_id);
if (g_str_has_prefix (request, r))
{
GList *layouts, *iter;
@@ -171,12 +171,12 @@ request_cb (const gchar *request)
name = lightdm_layout_get_name (layout);
if (g_str_has_prefix (name, layout_prefix))
- status_notify ("GREETER %s LOG-VARIANTS LAYOUT='%s'", getenv ("DISPLAY"), name);
+ status_notify ("%s LOG-VARIANTS LAYOUT='%s'", greeter_id, name);
}
}
g_free (r);
- r = g_strdup_printf ("GREETER %s LOG-LANGUAGE USERNAME=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LOG-LANGUAGE USERNAME=", greeter_id);
if (g_str_has_prefix (request, r))
{
LightDMUser *user;
@@ -186,7 +186,7 @@ request_cb (const gchar *request)
user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username);
language = lightdm_user_get_language (user);
- status_notify ("GREETER %s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s", getenv ("DISPLAY"), username, language ? language : "");
+ status_notify ("%s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s", greeter_id, username, language ? language : "");
}
g_free (r);
}
@@ -194,6 +194,8 @@ request_cb (const gchar *request)
int
main (int argc, char **argv)
{
+ gchar *display;
+
signal (SIGINT, signal_cb);
signal (SIGTERM, signal_cb);
@@ -201,11 +203,19 @@ main (int argc, char **argv)
g_type_init ();
#endif
+ display = getenv ("DISPLAY");
+ if (display == NULL)
+ greeter_id = g_strdup ("GREETER-?");
+ else if (display[0] == ':')
+ greeter_id = g_strdup_printf ("GREETER-X-%s", display + 1);
+ else
+ greeter_id = g_strdup_printf ("GREETER-X-%s", display);
+
loop = g_main_loop_new (NULL, FALSE);
status_connect (request_cb);
- status_notify ("GREETER %s START", getenv ("DISPLAY"));
+ status_notify ("%s START", greeter_id);
config = g_key_file_new ();
g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
@@ -213,7 +223,7 @@ main (int argc, char **argv)
if (g_key_file_has_key (config, "test-greeter-config", "return-value", NULL))
{
int return_value = g_key_file_get_integer (config, "test-greeter-config", "return-value", NULL);
- status_notify ("GREETER %s EXIT CODE=%d", getenv ("DISPLAY"), return_value);
+ status_notify ("%s EXIT CODE=%d", greeter_id, return_value);
return return_value;
}
@@ -221,11 +231,11 @@ main (int argc, char **argv)
if (xcb_connection_has_error (connection))
{
- status_notify ("GREETER %s FAIL-CONNECT-XSERVER", getenv ("DISPLAY"));
+ status_notify ("%s FAIL-CONNECT-XSERVER", greeter_id);
return EXIT_FAILURE;
}
- status_notify ("GREETER %s CONNECT-XSERVER", getenv ("DISPLAY"));
+ status_notify ("%s CONNECT-XSERVER", greeter_id);
greeter = lightdm_greeter_new ();
g_signal_connect (greeter, "show-message", G_CALLBACK (show_message_cb), NULL);
@@ -233,19 +243,19 @@ main (int argc, char **argv)
g_signal_connect (greeter, "authentication-complete", G_CALLBACK (authentication_complete_cb), NULL);
g_signal_connect (greeter, "autologin-timer-expired", G_CALLBACK (autologin_timer_expired_cb), NULL);
- status_notify ("GREETER %s CONNECT-TO-DAEMON", getenv ("DISPLAY"));
+ status_notify ("%s CONNECT-TO-DAEMON", greeter_id);
if (!lightdm_greeter_connect_sync (greeter, NULL))
{
- status_notify ("GREETER %s FAIL-CONNECT-DAEMON", getenv ("DISPLAY"));
+ status_notify ("%s FAIL-CONNECT-DAEMON", greeter_id);
return EXIT_FAILURE;
}
- status_notify ("GREETER %s CONNECTED-TO-DAEMON", getenv ("DISPLAY"));
+ status_notify ("%s CONNECTED-TO-DAEMON", greeter_id);
if (lightdm_greeter_get_select_user_hint (greeter))
- status_notify ("GREETER %s SELECT-USER-HINT USERNAME=%s", getenv ("DISPLAY"), lightdm_greeter_get_select_user_hint (greeter));
+ status_notify ("%s SELECT-USER-HINT USERNAME=%s", greeter_id, lightdm_greeter_get_select_user_hint (greeter));
if (lightdm_greeter_get_lock_hint (greeter))
- status_notify ("GREETER %s LOCK-HINT", getenv ("DISPLAY"));
+ status_notify ("%s LOCK-HINT", greeter_id);
g_main_loop_run (loop);
diff --git a/tests/src/test-python-greeter b/tests/src/test-python-greeter
index 44c3e482..d41344a8 100755
--- a/tests/src/test-python-greeter
+++ b/tests/src/test-python-greeter
@@ -9,10 +9,18 @@ import signal
from gi.repository import GLib
from gi.repository import LightDM
+display = os.getenv ('DISPLAY');
+if display is None:
+ greeter_id = 'GREETER-?'
+elif display.startswith (':'):
+ greeter_id = 'GREETER-X-%s' % display[1:]
+else:
+ greeter_id = 'GREETER-X-%s' % display
+
loop = GLib.MainLoop ()
def sigterm_cb (data):
- status_notify ('GREETER %s TERMINATE SIGNAL=%d' % (os.getenv ('DISPLAY'), signal.SIGTERM))
+ status_notify ('%s TERMINATE SIGNAL=%d' % (greeter_id, signal.SIGTERM))
loop.quit ()
GLib.unix_signal_add (GLib.PRIORITY_DEFAULT, signal.SIGTERM, sigterm_cb, None)
@@ -33,62 +41,62 @@ def request_cb (channel, condition):
(l,) = struct.unpack ('i', length)
request = status_socket.recv (l)
- r = 'GREETER %s AUTHENTICATE' % os.getenv ('DISPLAY')
+ r = '%s AUTHENTICATE' % greeter_id
if request == r:
greeter.authenticate (None)
- r = 'GREETER %s AUTHENTICATE USERNAME=' % os.getenv ('DISPLAY')
+ r = '%s AUTHENTICATE USERNAME=' % greeter_id
if request.startswith (r):
greeter.authenticate (request[len(r):])
- r = 'GREETER %s AUTHENTICATE-GUEST' % os.getenv ('DISPLAY')
+ r = '%s AUTHENTICATE-GUEST' % greeter_id
if request == r:
greeter.authenticate_as_guest ()
- r = 'GREETER %s AUTHENTICATE-AUTOLOGIN' % os.getenv ('DISPLAY')
+ r = '%s AUTHENTICATE-AUTOLOGIN' % greeter_id
if request == r:
greeter.authenticate_autologin ()
- r = 'GREETER %s AUTHENTICATE-REMOTE SESSION=' % os.getenv ('DISPLAY')
+ r = '%s AUTHENTICATE-REMOTE SESSION=' % greeter_id
if request.startswith (r):
greeter.authenticate_remote (request[len(r):], None)
- r = 'GREETER %s RESPOND TEXT=\"' % os.getenv ('DISPLAY')
+ r = '%s RESPOND TEXT=\"' % greeter_id
if request.startswith (r):
greeter.respond (request[len (r):-1])
- r = 'GREETER %s START-SESSION' % os.getenv ('DISPLAY')
+ r = '%s START-SESSION' % greeter_id
if request == r:
if not greeter.start_session_sync (None):
- status_notify ('GREETER %s SESSION-FAILED' % os.getenv ('DISPLAY'))
+ status_notify ('%s SESSION-FAILED' % greeter_id)
- r = 'GREETER %s START-SESSION SESSION=' % os.getenv ('DISPLAY')
+ r = '%s START-SESSION SESSION=' % greeter_id
if request.startswith (r):
if not greeter.start_session_sync (request[len(r):]):
- status_notify ('GREETER %s SESSION-FAILED' % os.getenv ('DISPLAY'))
+ status_notify ('%s SESSION-FAILED' % greeter_id)
- r = 'GREETER %s LOG-LAYOUT' % os.getenv ('DISPLAY')
+ r = '%s LOG-LAYOUT' % greeter_id
if request == r:
layout = LightDM.get_layout ().get_name ()
- status_notify ('GREETER %s LOG-LAYOUT LAYOUT=%s' % (os.getenv ('DISPLAY'), layout))
+ status_notify ('%s LOG-LAYOUT LAYOUT=%s' % (greeter_id, layout))
- r = 'GREETER %s LOG-LAYOUT USERNAME=' % os.getenv ('DISPLAY')
+ r = '%s LOG-LAYOUT USERNAME=' % greeter_id
if request.startswith (r):
username = request[len(r):]
user = LightDM.UserList.get_instance ().get_user_by_name (username)
layout = user.get_layout ()
if layout is None:
layout = ''
- status_notify ('GREETER %s LOG-LAYOUT USERNAME=%s LAYOUT=%s' % (os.getenv ('DISPLAY'), username, layout))
+ status_notify ('%s LOG-LAYOUT USERNAME=%s LAYOUT=%s' % (greeter_id, username, layout))
- r = 'GREETER %s LOG-LANGUAGE USERNAME=' % os.getenv ('DISPLAY')
+ r = '%s LOG-LANGUAGE USERNAME=' % greeter_id
if request.startswith (r):
username = request[len(r):]
user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username)
language = lightdm_user_get_language (user)
if language is None:
language = ''
- status_notify ('GREETER %s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s' % (os.getenv ('DISPLAY'), username, language))
+ status_notify ('%s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s' % (greeter_id, username, language))
return True
@@ -97,16 +105,16 @@ status_socket = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM)
status_socket.connect (path)
GLib.io_add_watch (status_socket.fileno (), GLib.IO_IN | GLib.IO_HUP, request_cb)
-status_notify ('GREETER %s START' % os.getenv ('DISPLAY'))
+status_notify ('%s START' % greeter_id)
# NOTE: There don't seem to be any good X bindings so we have to mock up our own...
-(host, display) = os.getenv ('DISPLAY').split (':')
+(host, display_number) = display.split (':')
if host == '':
x_socket = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM)
- x_socket.connect ('/tmp/.X11-unix/X%s' % display)
+ x_socket.connect ('/tmp/.X11-unix/X%s' % display_number)
else:
x_socket = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
- x_socket.connect ((host, 6000 + int (display)))
+ x_socket.connect ((host, 6000 + int (display_number)))
authority = subprocess.check_output(['xauth', 'list']).split ()
auth_name = ''
auth_data = ''
@@ -124,16 +132,16 @@ def pad (value):
x_socket.send (struct.pack ('!cxHHHHxx', 'B', 11, 0, len (auth_name), len (auth_data)) + pad (auth_name) + pad (auth_data))
data = x_socket.recv (1024)
if ord (data[0]) != 1:
- status_notify ('GREETER %s FAIL-CONNECT-XSERVER' % os.getenv ('DISPLAY'))
+ status_notify ('%s FAIL-CONNECT-XSERVER' % greeter_id)
exit (1)
-status_notify ('GREETER %s CONNECT-XSERVER' % (os.getenv ('DISPLAY')))
+status_notify ('%s CONNECT-XSERVER' % (greeter_id))
def show_message_cb (greeter, text, type):
- status_notify ('GREETER %s SHOW-MESSAGE TEXT=\"%s\"' % (os.getenv ('DISPLAY'), text))
+ status_notify ('%s SHOW-MESSAGE TEXT=\"%s\"' % (greeter_id, text))
def show_prompt_cb (greeter, text, type):
- status_notify ('GREETER %s SHOW-PROMPT TEXT=\"%s\"' % (os.getenv ('DISPLAY'), text))
+ status_notify ('%s SHOW-PROMPT TEXT=\"%s\"' % (greeter_id, text))
def authentication_complete_cb (greeter):
if greeter.get_is_authenticated ():
@@ -141,12 +149,12 @@ def authentication_complete_cb (greeter):
else:
is_authenticated = 'FALSE'
if greeter.get_authentication_user () is not None:
- status_notify ('GREETER %s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s' % (os.getenv ('DISPLAY'), greeter.get_authentication_user (), is_authenticated))
+ status_notify ('%s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s' % (greeter_id, greeter.get_authentication_user (), is_authenticated))
else:
- status_notify ('GREETER %s AUTHENTICATION-COMPLETE AUTHENTICATED=%s' % (os.getenv ('DISPLAY'), is_authenticated))
+ status_notify ('%s AUTHENTICATION-COMPLETE AUTHENTICATED=%s' % (greeter_id, is_authenticated))
def autologin_timer_expired_cb (greeter):
- status_notify ('GREETER %s AUTOLOGIN-TIMER-EXPIRED' % os.getenv ('DISPLAY'))
+ status_notify ('%s AUTOLOGIN-TIMER-EXPIRED' % greeter_id)
greeter = LightDM.Greeter ()
greeter.connect ('show-message', show_message_cb)
@@ -154,16 +162,16 @@ greeter.connect ('show-prompt', show_prompt_cb)
greeter.connect ('authentication-complete', authentication_complete_cb)
greeter.connect ('autologin-timer-expired', autologin_timer_expired_cb)
-status_notify ('GREETER %s CONNECT-TO-DAEMON' % os.getenv ('DISPLAY'))
+status_notify ('%s CONNECT-TO-DAEMON' % greeter_id)
if not greeter.connect_sync ():
- status_notify ('GREETER %s FAIL-CONNECT-DAEMON' % os.getenv ('DISPLAY'))
+ status_notify ('%s FAIL-CONNECT-DAEMON' % greeter_id)
exit (1)
-status_notify ('GREETER %s CONNECTED-TO-DAEMON' % os.getenv ('DISPLAY'))
+status_notify ('%s CONNECTED-TO-DAEMON' % greeter_id)
if greeter.get_select_user_hint () is not None:
- status_notify ('GREETER %s SELECT-USER-HINT USERNAME=%s' % (os.getenv ('DISPLAY'), greeter.get_select_user_hint ()))
+ status_notify ('%s SELECT-USER-HINT USERNAME=%s' % (greeter_id, greeter.get_select_user_hint ()))
if greeter.get_lock_hint ():
- status_notify ('GREETER %s LOCK-HINT' % os.getenv ('DISPLAY'));
+ status_notify ('%s LOCK-HINT' % greeter_id);
loop.run ()
diff --git a/tests/src/test-qt-greeter.cpp b/tests/src/test-qt-greeter.cpp
index 68ab1674..9a34567c 100644
--- a/tests/src/test-qt-greeter.cpp
+++ b/tests/src/test-qt-greeter.cpp
@@ -3,7 +3,6 @@
#include <stdio.h>
#include <signal.h>
#include <glib-object.h>
-#include <xcb/xcb.h>
#include <QLightDM/Greeter>
#include <QtCore/QSettings>
#include <QtCore/QDebug>
@@ -12,6 +11,7 @@
#include "test-qt-greeter.h"
#include "status.h"
+static gchar *greeter_id;
static QCoreApplication *app = NULL;
static QSettings *config = NULL;
static TestGreeter *greeter = NULL;
@@ -26,33 +26,33 @@ TestGreeter::TestGreeter ()
void TestGreeter::showMessage (QString text, QLightDM::Greeter::MessageType type)
{
- status_notify ("GREETER %s SHOW-MESSAGE TEXT=\"%s\"", getenv ("DISPLAY"), text.toAscii ().constData ());
+ status_notify ("%s SHOW-MESSAGE TEXT=\"%s\"", greeter_id, text.toAscii ().constData ());
}
void TestGreeter::showPrompt (QString text, QLightDM::Greeter::PromptType type)
{
- status_notify ("GREETER %s SHOW-PROMPT TEXT=\"%s\"", getenv ("DISPLAY"), text.toAscii ().constData ());
+ status_notify ("%s SHOW-PROMPT TEXT=\"%s\"", greeter_id, text.toAscii ().constData ());
}
void TestGreeter::authenticationComplete ()
{
if (authenticationUser () != "")
- status_notify ("GREETER %s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s",
- getenv ("DISPLAY"),
+ status_notify ("%s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s",
+ greeter_id,
authenticationUser ().toAscii ().constData (), isAuthenticated () ? "TRUE" : "FALSE");
else
- status_notify ("GREETER %s AUTHENTICATION-COMPLETE AUTHENTICATED=%s", getenv ("DISPLAY"), isAuthenticated () ? "TRUE" : "FALSE");
+ status_notify ("%s AUTHENTICATION-COMPLETE AUTHENTICATED=%s", greeter_id, isAuthenticated () ? "TRUE" : "FALSE");
}
void TestGreeter::autologinTimerExpired ()
{
- status_notify ("GREETER %s AUTOLOGIN-TIMER-EXPIRED", getenv ("DISPLAY"));
+ status_notify ("%s AUTOLOGIN-TIMER-EXPIRED", greeter_id);
}
static void
signal_cb (int signum)
{
- status_notify ("GREETER %s TERMINATE SIGNAL=%d", getenv ("DISPLAY"), signum);
+ status_notify ("%s TERMINATE SIGNAL=%d", greeter_id, signum);
_exit (EXIT_SUCCESS);
}
@@ -67,32 +67,32 @@ request_cb (const gchar *request)
return;
}
- r = g_strdup_printf ("GREETER %s AUTHENTICATE", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE", greeter_id);
if (strcmp (request, r) == 0)
greeter->authenticate ();
g_free (r);
- r = g_strdup_printf ("GREETER %s AUTHENTICATE USERNAME=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE USERNAME=", greeter_id);
if (g_str_has_prefix (request, r))
greeter->authenticate (request + strlen (r));
g_free (r);
- r = g_strdup_printf ("GREETER %s AUTHENTICATE-GUEST", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE-GUEST", greeter_id);
if (strcmp (request, r) == 0)
greeter->authenticateAsGuest ();
g_free (r);
- r = g_strdup_printf ("GREETER %s AUTHENTICATE-AUTOLOGIN", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE-AUTOLOGIN", greeter_id);
if (strcmp (request, r) == 0)
greeter->authenticateAutologin ();
g_free (r);
- r = g_strdup_printf ("GREETER %s AUTHENTICATE-REMOTE SESSION=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s AUTHENTICATE-REMOTE SESSION=", greeter_id);
if (g_str_has_prefix (request, r))
greeter->authenticateRemote (request + strlen (r), NULL);
g_free (r);
- r = g_strdup_printf ("GREETER %s RESPOND TEXT=\"", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s RESPOND TEXT=\"", greeter_id);
if (g_str_has_prefix (request, r))
{
gchar *text = g_strdup (request + strlen (r));
@@ -102,19 +102,19 @@ request_cb (const gchar *request)
}
g_free (r);
- r = g_strdup_printf ("GREETER %s START-SESSION", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s START-SESSION", greeter_id);
if (strcmp (request, r) == 0)
{
if (!greeter->startSessionSync ())
- status_notify ("GREETER %s SESSION-FAILED", getenv ("DISPLAY"));
+ status_notify ("%s SESSION-FAILED", greeter_id);
}
g_free (r);
- r = g_strdup_printf ("GREETER %s START-SESSION SESSION=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s START-SESSION SESSION=", greeter_id);
if (g_str_has_prefix (request, r))
{
if (!greeter->startSessionSync (request + strlen (r)))
- status_notify ("GREETER %s SESSION-FAILED", getenv ("DISPLAY"));
+ status_notify ("%s SESSION-FAILED", greeter_id);
}
g_free (r);
}
@@ -122,10 +122,20 @@ request_cb (const gchar *request)
int
main(int argc, char *argv[])
{
+ gchar *display;
+
#if !defined(GLIB_VERSION_2_36)
g_type_init ();
#endif
+ display = getenv ("DISPLAY");
+ if (display == NULL)
+ greeter_id = g_strdup ("GREETER-?");
+ else if (display[0] == ':')
+ greeter_id = g_strdup_printf ("GREETER-X-%s", display + 1);
+ else
+ greeter_id = g_strdup_printf ("GREETER-X-%s", display);
+
status_connect (request_cb);
app = new QCoreApplication (argc, argv);
@@ -133,7 +143,7 @@ main(int argc, char *argv[])
signal (SIGINT, signal_cb);
signal (SIGTERM, signal_cb);
- status_notify ("GREETER %s START", getenv ("DISPLAY"));
+ status_notify ("%s START", greeter_id);
config = new QSettings (g_build_filename (getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), QSettings::IniFormat);
@@ -141,27 +151,27 @@ main(int argc, char *argv[])
if (xcb_connection_has_error (connection))
{
- status_notify ("GREETER %s FAIL-CONNECT-XSERVER", getenv ("DISPLAY"));
+ status_notify ("%s FAIL-CONNECT-XSERVER", greeter_id);
return EXIT_FAILURE;
}
- status_notify ("GREETER %s CONNECT-XSERVER", getenv ("DISPLAY"));
+ status_notify ("%s CONNECT-XSERVER", greeter_id);
greeter = new TestGreeter();
- status_notify ("GREETER %s CONNECT-TO-DAEMON", getenv ("DISPLAY"));
+ status_notify ("%s CONNECT-TO-DAEMON", greeter_id);
if (!greeter->connectSync())
{
- status_notify ("GREETER %s FAIL-CONNECT-DAEMON", getenv ("DISPLAY"));
+ status_notify ("%s FAIL-CONNECT-DAEMON", greeter_id);
return EXIT_FAILURE;
}
- status_notify ("GREETER %s CONNECTED-TO-DAEMON", getenv ("DISPLAY"));
+ status_notify ("%s CONNECTED-TO-DAEMON", greeter_id);
if (greeter->selectUserHint() != "")
- status_notify ("GREETER %s SELECT-USER-HINT USERNAME=%s", getenv ("DISPLAY"), greeter->selectUserHint ().toAscii ().constData ());
+ status_notify ("%s SELECT-USER-HINT USERNAME=%s", greeter_id, greeter->selectUserHint ().toAscii ().constData ());
if (greeter->lockHint())
- status_notify ("GREETER %s LOCK-HINT", getenv ("DISPLAY"));
+ status_notify ("%s LOCK-HINT", greeter_id);
return app->exec();
}
diff --git a/tests/src/test-runner.c b/tests/src/test-runner.c
index 40e9a937..cf755917 100644
--- a/tests/src/test-runner.c
+++ b/tests/src/test-runner.c
@@ -22,8 +22,12 @@ static GKeyFile *config;
static GSocket *status_socket = NULL;
static gchar *status_socket_name = NULL;
static GList *statuses = NULL;
+typedef struct
+{
+ gchar *text;
+ gboolean done;
+} ScriptLine;
static GList *script = NULL;
-static GList *script_iter = NULL;
static guint status_timeout = 0;
static gchar *temp_dir = NULL;
static int service_count;
@@ -223,8 +227,8 @@ quit (int status)
if (temp_dir)
{
gchar *command = g_strdup_printf ("rm -r %s", temp_dir);
- if (system (command))
- perror ("Failed to delete temp directory");
+ //if (system (command))
+ // perror ("Failed to delete temp directory");
}
exit (status);
@@ -251,12 +255,47 @@ fail (const gchar *event, const gchar *expected)
quit (EXIT_FAILURE);
}
-static const gchar *
-get_script_line ()
+static gchar *
+get_prefix (const gchar *text)
+{
+ gchar *prefix;
+ gint i;
+
+ prefix = g_strdup (text);
+ for (i = 0; prefix[i] != '\0' && prefix[i] != ' '; i++);
+ prefix[i] = '\0';
+
+ return prefix;
+}
+
+static ScriptLine *
+get_script_line (const gchar *prefix)
{
- if (!script_iter)
- return NULL;
- return script_iter->data;
+ GList *link;
+
+ for (link = script; link; link = link->next)
+ {
+ ScriptLine *line = link->data;
+
+ /* Ignore lines with other prefixes */
+ if (prefix)
+ {
+ gchar *p;
+ gboolean matches;
+
+ p = get_prefix (line->text);
+ matches = strcmp (prefix, p) == 0;
+ g_free (p);
+
+ if (!matches)
+ continue;
+ }
+
+ if (!line->done)
+ return line;
+ }
+
+ return NULL;
}
static void
@@ -444,9 +483,9 @@ handle_command (const gchar *command)
}
}
/* Forward to external processes */
- else if (strcmp (name, "SESSION") == 0 ||
- strcmp (name, "GREETER") == 0 ||
- strcmp (name, "XSERVER") == 0)
+ else if (g_str_has_prefix (name, "SESSION-") ||
+ g_str_has_prefix (name, "GREETER-") ||
+ g_str_has_prefix (name, "XSERVER-"))
{
GList *link;
for (link = status_clients; link; link = link->next)
@@ -479,60 +518,70 @@ run_commands ()
/* Stop daemon if requested */
while (TRUE)
{
- const gchar *command;
+ ScriptLine *line;
/* Commands start with an asterisk */
- command = get_script_line ();
- if (!command || command[0] != '*')
+ line = get_script_line (NULL);
+ if (!line || line->text[0] != '*')
break;
- statuses = g_list_append (statuses, g_strdup (command));
- script_iter = script_iter->next;
+ statuses = g_list_append (statuses, g_strdup (line->text));
+ line->done = TRUE;
- handle_command (command + 1);
+ handle_command (line->text + 1);
}
/* Stop at the end of the script */
- if (get_script_line () == NULL)
+ if (get_script_line (NULL) == NULL)
quit (EXIT_SUCCESS);
}
static gboolean
status_timeout_cb (gpointer data)
{
- fail ("(timeout)", get_script_line ());
+ ScriptLine *line;
+
+ line = get_script_line (NULL);
+ fail ("(timeout)", line ? line->text : NULL);
+
return FALSE;
}
static void
check_status (const gchar *status)
{
- const gchar *pattern;
+ ScriptLine *line;
gboolean result = FALSE;
+ gchar *prefix;
if (stop)
return;
statuses = g_list_append (statuses, g_strdup (status));
-
+
if (getenv ("DEBUG"))
g_print ("%s\n", status);
/* Try and match against expected */
- pattern = get_script_line ();
- if (pattern)
+ prefix = get_prefix (status);
+ line = get_script_line (prefix);
+ g_free (prefix);
+ if (line)
{
- gchar *full_pattern = g_strdup_printf ("^%s$", pattern);
+ gchar *full_pattern = g_strdup_printf ("^%s$", line->text);
result = g_regex_match_simple (full_pattern, status, 0, 0);
g_free (full_pattern);
}
if (!result)
{
- fail (NULL, pattern);
+ if (line == NULL)
+ line = get_script_line (NULL);
+ fail (NULL, line ? line->text : NULL);
return;
}
- script_iter = script_iter->next;
+
+ line->done = TRUE;
/* Restart timeout */
g_source_remove (status_timeout);
@@ -615,11 +664,16 @@ load_script (const gchar *filename)
/* Load lines with #? prefix as expected behaviour */
for (i = 0; lines[i]; i++)
{
- gchar *line = g_strstrip (lines[i]);
- if (g_str_has_prefix (line, "#?"))
- script = g_list_append (script, g_strdup (line+2));
+ gchar *text = g_strstrip (lines[i]);
+ if (g_str_has_prefix (text, "#?"))
+ {
+ ScriptLine *line;
+ line = g_malloc0 (sizeof (ScriptLine));
+ line->text = g_strdup (text + 2);
+ line->done = FALSE;
+ script = g_list_append (script, line);
+ }
}
- script_iter = script;
g_strfreev (lines);
}
@@ -1291,7 +1345,7 @@ main (int argc, char **argv)
/* Set up a skeleton file system */
g_mkdir_with_parents (g_strdup_printf ("%s/etc", temp_dir), 0755);
g_mkdir_with_parents (g_strdup_printf ("%s/usr/share", temp_dir), 0755);
- g_mkdir_with_parents (g_strdup_printf ("%s/usr/tmp", temp_dir), 0755);
+ g_mkdir_with_parents (g_strdup_printf ("%s/tmp", temp_dir), 0755);
/* Copy over the configuration */
g_mkdir_with_parents (g_strdup_printf ("%s/etc/lightdm", temp_dir), 0755);
diff --git a/tests/src/test-session.c b/tests/src/test-session.c
index 49f3f5c0..ebbfa8a6 100644
--- a/tests/src/test-session.c
+++ b/tests/src/test-session.c
@@ -6,25 +6,24 @@
#include <unistd.h>
#include <fcntl.h>
#include <grp.h>
-#include <xcb/xcb.h>
#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include "status.h"
+static gchar *session_id;
+
static GMainLoop *loop;
static GString *open_fds;
static GKeyFile *config;
-static xcb_connection_t *connection;
-
static void
quit_cb (int signum)
{
- status_notify ("SESSION %s TERMINATE SIGNAL=%d", getenv ("DISPLAY"), signum);
+ status_notify ("%s TERMINATE SIGNAL=%d", session_id, signum);
exit (EXIT_SUCCESS);
}
@@ -39,20 +38,20 @@ request_cb (const gchar *request)
return;
}
- r = g_strdup_printf ("SESSION %s LOGOUT", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LOGOUT", session_id);
if (strcmp (request, r) == 0)
exit (EXIT_SUCCESS);
g_free (r);
- r = g_strdup_printf ("SESSION %s CRASH", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s CRASH", session_id);
if (strcmp (request, r) == 0)
kill (getpid (), SIGSEGV);
g_free (r);
- r = g_strdup_printf ("SESSION %s LOCK-SEAT", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LOCK-SEAT", session_id);
if (strcmp (request, r) == 0)
{
- status_notify ("SESSION %s LOCK-SEAT", getenv ("DISPLAY"));
+ status_notify ("%s LOCK-SEAT", session_id);
g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
"org.freedesktop.DisplayManager",
getenv ("XDG_SEAT_PATH"),
@@ -67,10 +66,10 @@ request_cb (const gchar *request)
}
g_free (r);
- r = g_strdup_printf ("SESSION %s LOCK-SESSION", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LOCK-SESSION", session_id);
if (strcmp (request, r) == 0)
{
- status_notify ("SESSION %s LOCK-SESSION", getenv ("DISPLAY"));
+ status_notify ("%s LOCK-SESSION", session_id);
g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL),
"org.freedesktop.DisplayManager",
getenv ("XDG_SESSION_PATH"),
@@ -85,7 +84,7 @@ request_cb (const gchar *request)
}
g_free (r);
- r = g_strdup_printf ("SESSION %s LIST-GROUPS", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LIST-GROUPS", session_id);
if (strcmp (request, r) == 0)
{
int n_groups, i;
@@ -108,31 +107,31 @@ request_cb (const gchar *request)
else
g_string_append_printf (group_list, "%d", groups[i]);
}
- status_notify ("SESSION %s LIST-GROUPS GROUPS=%s", getenv ("DISPLAY"), group_list->str);
+ status_notify ("%s LIST-GROUPS GROUPS=%s", session_id, group_list->str);
g_string_free (group_list, TRUE);
free (groups);
}
- r = g_strdup_printf ("SESSION %s READ-ENV NAME=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s READ-ENV NAME=", session_id);
if (g_str_has_prefix (request, r))
{
const gchar *name = request + strlen (r);
const gchar *value = g_getenv (name);
- status_notify ("SESSION %s READ-ENV NAME=%s VALUE=%s", getenv ("DISPLAY"), name, value ? value : "");
+ status_notify ("%s READ-ENV NAME=%s VALUE=%s", session_id, name, value ? value : "");
}
g_free (r);
- r = g_strdup_printf ("SESSION %s WRITE-STDOUT TEXT=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s WRITE-STDOUT TEXT=", session_id);
if (g_str_has_prefix (request, r))
g_print ("%s", request + strlen (r));
g_free (r);
- r = g_strdup_printf ("SESSION %s WRITE-STDERR TEXT=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s WRITE-STDERR TEXT=", session_id);
if (g_str_has_prefix (request, r))
g_printerr ("%s", request + strlen (r));
g_free (r);
- r = g_strdup_printf ("SESSION %s READ FILE=", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s READ FILE=", session_id);
if (g_str_has_prefix (request, r))
{
const gchar *name = request + strlen (r);
@@ -140,24 +139,33 @@ request_cb (const gchar *request)
GError *error = NULL;
if (g_file_get_contents (name, &contents, NULL, &error))
- status_notify ("SESSION %s READ FILE=%s TEXT=%s", getenv ("DISPLAY"), name, contents);
+ status_notify ("%s READ FILE=%s TEXT=%s", session_id, name, contents);
else
- status_notify ("SESSION %s READ FILE=%s ERROR=%s", getenv ("DISPLAY"), name, error->message);
+ status_notify ("%s READ FILE=%s ERROR=%s", session_id, name, error->message);
g_clear_error (&error);
}
g_free (r);
- r = g_strdup_printf ("SESSION %s LIST-UNKNOWN-FILE-DESCRIPTORS", getenv ("DISPLAY"));
+ r = g_strdup_printf ("%s LIST-UNKNOWN-FILE-DESCRIPTORS", session_id);
if (strcmp (request, r) == 0)
- status_notify ("SESSION %s LIST-UNKNOWN-FILE-DESCRIPTORS FDS=%s", getenv ("DISPLAY"), open_fds->str);
+ status_notify ("%s LIST-UNKNOWN-FILE-DESCRIPTORS FDS=%s", session_id, open_fds->str);
g_free (r);
}
int
main (int argc, char **argv)
{
+ gchar *display;
int fd, open_max;
+ display = getenv ("DISPLAY");
+ if (display == NULL)
+ session_id = g_strdup ("SESSION-?");
+ else if (display[0] == ':')
+ session_id = g_strdup_printf ("SESSION-X-%s", display + 1);
+ else
+ session_id = g_strdup_printf ("SESSION-X-%s", display);
+
open_fds = g_string_new ("");
open_max = sysconf (_SC_OPEN_MAX);
for (fd = STDERR_FILENO + 1; fd < open_max; fd++)
@@ -180,9 +188,9 @@ main (int argc, char **argv)
status_connect (request_cb);
if (argc > 1)
- status_notify ("SESSION %s START NAME=%s USER=%s", getenv ("DISPLAY"), argv[1], getenv ("USER"));
+ status_notify ("%s START NAME=%s USER=%s", session_id, argv[1], getenv ("USER"));
else
- status_notify ("SESSION %s START USER=%s", getenv ("DISPLAY"), getenv ("USER"));
+ status_notify ("%s START USER=%s", session_id, getenv ("USER"));
config = g_key_file_new ();
g_key_file_load_from_file (config, g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "script", NULL), G_KEY_FILE_NONE, NULL);
@@ -191,13 +199,13 @@ main (int argc, char **argv)
if (xcb_connection_has_error (connection))
{
- status_notify ("SESSION %s CONNECT-XSERVER-ERROR", getenv ("DISPLAY"));
+ status_notify ("%s CONNECT-XSERVER-ERROR", session_id);
return EXIT_FAILURE;
}
- status_notify ("SESSION %s CONNECT-XSERVER", getenv ("DISPLAY"));
+ status_notify ("%s CONNECT-XSERVER", session_id);
- g_main_loop_run (loop);
+ g_main_loop_run (loop);
return EXIT_SUCCESS;
}
diff --git a/tests/src/x-server.c b/tests/src/x-server.c
index 9e76f80d..61af1724 100644
--- a/tests/src/x-server.c
+++ b/tests/src/x-server.c
@@ -775,8 +775,17 @@ x_server_start (XServer *server)
if (server->priv->listen_unix)
{
GError *error = NULL;
-
- server->priv->socket_path = g_strdup_printf ("/tmp/.X11-unix/X%d", server->priv->display_number);
+ gchar *socket_dir;
+ gchar *socket_filename;
+
+ socket_dir = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", ".X11-unix", NULL);
+ g_mkdir_with_parents (socket_dir, 0755);
+
+ socket_filename = g_strdup_printf ("X%d", server->priv->display_number);
+ server->priv->socket_path = g_build_filename (socket_dir, socket_filename, NULL);
+
+ g_free (socket_dir);
+ g_free (socket_filename);
server->priv->unix_socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, &error);
if (!server->priv->unix_socket ||