10 #include <sys/types.h>
11 #include <sys/socket.h>
15 /* For some reason sys/un.h doesn't define this */
17 #define UNIX_PATH_MAX 108
20 /* Timeout in ms waiting for the status we expect */
21 #define STATUS_TIMEOUT 2000
23 /* Timeout in ms to wait for SIGTERM to be handled by a child process */
24 #define KILL_TIMEOUT 2000
26 static gchar *config_path;
27 static GKeyFile *config;
28 static gchar *status_socket_name = NULL;
29 static GList *statuses = NULL;
30 static GList *script = NULL;
31 static GList *script_iter = NULL;
32 static guint status_timeout = 0;
33 static gchar *temp_dir = NULL;
34 static int service_count;
40 static Process *lightdm_process = NULL;
41 static GHashTable *children = NULL;
42 static gboolean stop = FALSE;
43 static gint exit_status = 0;
44 static gchar *carols_xsession = NULL;
45 static GDBusConnection *accounts_connection = NULL;
46 static GDBusNodeInfo *accounts_info;
47 static GDBusNodeInfo *user_info;
48 static void handle_user_call (GDBusConnection *connection,
50 const gchar *object_path,
51 const gchar *interface_name,
52 const gchar *method_name,
54 GDBusMethodInvocation *invocation,
56 static GVariant *handle_user_get_property (GDBusConnection *connection,
58 const gchar *object_path,
59 const gchar *interface_name,
60 const gchar *property_name,
63 static const GDBusInterfaceVTable user_vtable =
66 handle_user_get_property,
69 static void run_lightdm (void);
70 static void quit (int status);
71 static void check_status (const gchar *status);
74 kill_timeout_cb (gpointer data)
76 Process *process = data;
79 g_print ("Sending SIGKILL to process %d\n", process->pid);
80 kill (process->pid, SIGKILL);
85 stop_process (Process *process)
87 if (process->kill_timeout != 0)
91 g_print ("Sending SIGTERM to process %d\n", process->pid);
92 kill (process->pid, SIGTERM);
93 process->kill_timeout = g_timeout_add (KILL_TIMEOUT, kill_timeout_cb, process);
97 process_exit_cb (GPid pid, gint status, gpointer data)
102 if (getenv ("DEBUG"))
104 if (WIFEXITED (status))
105 g_print ("Process %d exited with status %d\n", pid, WEXITSTATUS (status));
107 g_print ("Process %d terminated with signal %d\n", pid, WTERMSIG (status));
110 if (lightdm_process && pid == lightdm_process->pid)
112 process = lightdm_process;
113 lightdm_process = NULL;
114 if (WIFEXITED (status))
115 status_text = g_strdup_printf ("RUNNER DAEMON-EXIT STATUS=%d", WEXITSTATUS (status));
117 status_text = g_strdup_printf ("RUNNER DAEMON-TERMINATE SIGNAL=%d", WTERMSIG (status));
118 check_status (status_text);
122 process = g_hash_table_lookup (children, GINT_TO_POINTER (pid));
125 g_hash_table_remove (children, GINT_TO_POINTER (pid));
128 if (process->kill_timeout)
129 g_source_remove (process->kill_timeout);
130 process->kill_timeout = 0;
132 /* Quit once all children have stopped */
138 watch_process (pid_t pid)
142 process = g_malloc0 (sizeof (Process));
144 process->kill_timeout = 0;
146 if (getenv ("DEBUG"))
147 g_print ("Watching process %d\n", process->pid);
148 g_child_watch_add (process->pid, process_exit_cb, NULL);
159 exit_status = status;
162 /* Stop all the children */
163 g_hash_table_iter_init (&iter, children);
168 if (!g_hash_table_iter_next (&iter, &key, &value))
171 stop_process ((Process *)value);
174 /* Don't quit until all children are stopped */
175 if (g_hash_table_size (children) > 0)
178 /* Stop the daemon */
181 stop_process (lightdm_process);
185 if (status_socket_name)
186 unlink (status_socket_name);
190 gchar *command = g_strdup_printf ("rm -r %s", temp_dir);
191 if (system (command))
192 perror ("Failed to delete temp directory");
199 fail (const gchar *event, const gchar *expected)
206 g_printerr ("Test failed, got the following events:\n");
207 for (link = statuses; link; link = link->next)
208 g_printerr (" %s\n", (gchar *)link->data);
210 g_printerr (" %s\n", event);
212 g_printerr (" ^^^ expected \"%s\"\n", expected);
214 g_printerr ("^^^ expected nothing\n");
224 return script_iter->data;
228 open_unix_socket (const gchar *name)
231 struct sockaddr_un address;
233 s = socket (AF_UNIX, SOCK_DGRAM, 0);
236 address.sun_family = AF_UNIX;
237 strncpy (address.sun_path, name, UNIX_PATH_MAX);
238 if (bind (s, (struct sockaddr *) &address, sizeof (address)) < 0)
246 /* Stop daemon if requested */
249 gchar *command, *name = NULL, *c;
252 command = get_script_line ();
256 /* Commands start with an asterisk */
257 if (command[0] != '*')
259 statuses = g_list_append (statuses, g_strdup (command));
260 script_iter = script_iter->next;
263 while (*c && !isspace (*c))
265 name = g_strdup_printf ("%.*s", (int) (c - command - 1), command + 1);
267 params = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
270 gchar *start, *param_name, *param_value;
275 while (*c && !isspace (*c) && *c != '=')
280 param_name = g_strdup_printf ("%.*s", (int) (c - start), start);
289 gboolean escaped = FALSE;
293 value = g_string_new ("");
300 g_string_append_c (value, '\\');
306 else if (!escaped && *c == '\"')
309 g_string_append_c (value, *c);
312 param_value = value->str;
313 g_string_free (value, FALSE);
320 while (*c && !isspace (*c))
322 param_value = g_strdup_printf ("%.*s", (int) (c - start), start);
326 param_value = g_strdup ("");
328 g_hash_table_insert (params, param_name, param_value);
331 if (strcmp (name, "WAIT") == 0)
335 else if (strcmp (name, "SWITCH-TO-GREETER") == 0)
337 g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
338 "org.freedesktop.DisplayManager",
339 "/org/freedesktop/DisplayManager/Seat0",
340 "org.freedesktop.DisplayManager.Seat",
342 g_variant_new ("()"),
343 G_VARIANT_TYPE ("()"),
344 G_DBUS_CALL_FLAGS_NONE,
348 check_status ("RUNNER SWITCH-TO-GREETER");
350 else if (strcmp (name, "SWITCH-TO-USER") == 0)
352 gchar *status_text, *username;
354 username = g_hash_table_lookup (params, "USERNAME");
355 g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
356 "org.freedesktop.DisplayManager",
357 "/org/freedesktop/DisplayManager/Seat0",
358 "org.freedesktop.DisplayManager.Seat",
360 g_variant_new ("(ss)", username, ""),
361 G_VARIANT_TYPE ("()"),
362 G_DBUS_CALL_FLAGS_NONE,
366 status_text = g_strdup_printf ("RUNNER SWITCH-TO-USER USERNAME=%s", username);
367 check_status (status_text);
368 g_free (status_text);
370 else if (strcmp (name, "SWITCH-TO-GUEST") == 0)
372 g_dbus_connection_call_sync (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
373 "org.freedesktop.DisplayManager",
374 "/org/freedesktop/DisplayManager/Seat0",
375 "org.freedesktop.DisplayManager.Seat",
377 g_variant_new ("(s)", ""),
378 G_VARIANT_TYPE ("()"),
379 G_DBUS_CALL_FLAGS_NONE,
383 check_status ("RUNNER SWITCH-TO-GUEST");
385 else if (strcmp (name, "STOP-DAEMON") == 0)
386 stop_process (lightdm_process);
387 // FIXME: Make generic RUN-COMMAND
388 else if (strcmp (name, "START-XSERVER") == 0)
390 gchar *xserver_args, *command_line;
394 GError *error = NULL;
396 xserver_args = g_hash_table_lookup (params, "ARGS");
399 command_line = g_strdup_printf ("%s/tests/src/X %s", BUILDDIR, xserver_args);
401 if (!g_shell_parse_argv (command_line, NULL, &argv, &error) ||
402 !g_spawn_async (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &error))
404 g_printerr ("Error starting X server: %s", error->message);
408 process = watch_process (pid);
409 g_hash_table_insert (children, GINT_TO_POINTER (process->pid), process);
411 else if (strcmp (name, "START-VNC-CLIENT") == 0)
413 gchar *vnc_client_args, *command_line;
417 GError *error = NULL;
419 vnc_client_args = g_hash_table_lookup (params, "ARGS");
420 if (!vnc_client_args)
421 vnc_client_args = "";
422 command_line = g_strdup_printf ("%s/tests/src/vnc-client %s", BUILDDIR, vnc_client_args);
424 if (!g_shell_parse_argv (command_line, NULL, &argv, &error) ||
425 !g_spawn_async (NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &error))
427 g_printerr ("Error starting VNC client: %s", error->message);
431 process = watch_process (pid);
432 g_hash_table_insert (children, GINT_TO_POINTER (process->pid), process);
436 g_printerr ("Unknown command '%s'\n", name);
442 g_hash_table_unref (params);
445 /* Stop at the end of the script */
446 if (get_script_line () == NULL)
451 status_timeout_cb (gpointer data)
453 fail ("(timeout)", get_script_line ());
458 check_status (const gchar *status)
465 statuses = g_list_append (statuses, g_strdup (status));
467 if (getenv ("DEBUG"))
468 g_print ("%s\n", status);
470 /* Try and match against expected */
471 pattern = get_script_line ();
472 if (!pattern || !g_regex_match_simple (pattern, status, 0, 0))
474 fail (NULL, pattern);
477 script_iter = script_iter->next;
479 /* Restart timeout */
480 g_source_remove (status_timeout);
481 status_timeout = g_timeout_add (STATUS_TIMEOUT, status_timeout_cb, NULL);
487 status_message_cb (GIOChannel *channel, GIOCondition condition, gpointer data)
493 s = g_io_channel_unix_get_fd (channel);
494 n_read = recv (s, buffer, 1023, 0);
496 g_warning ("Error reading from socket: %s", strerror (errno));
497 else if (n_read == 0)
501 buffer[n_read] = '\0';
502 check_status ((gchar *) buffer);
509 signal_cb (int signum)
511 g_print ("Caught signal %d, quitting\n", signum);
516 load_script (const gchar *filename)
519 gchar *data, **lines;
521 if (!g_file_get_contents (filename, &data, NULL, NULL))
523 g_printerr ("Unable to load script: %s\n", filename);
527 lines = g_strsplit (data, "\n", -1);
530 /* Load lines with #? prefix as expected behaviour */
531 for (i = 0; lines[i]; i++)
533 gchar *line = g_strstrip (lines[i]);
534 if (g_str_has_prefix (line, "#?"))
535 script = g_list_append (script, g_strdup (line+2));
537 script_iter = script;
542 handle_ck_call (GDBusConnection *connection,
544 const gchar *object_path,
545 const gchar *interface_name,
546 const gchar *method_name,
547 GVariant *parameters,
548 GDBusMethodInvocation *invocation,
551 if (strcmp (method_name, "CanRestart") == 0)
553 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
555 else if (strcmp (method_name, "CanStop") == 0)
557 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
559 else if (strcmp (method_name, "CloseSession") == 0)
561 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
563 else if (strcmp (method_name, "OpenSession") == 0)
565 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "deadbeef"));
567 else if (strcmp (method_name, "OpenSessionWithParameters") == 0)
569 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", "deadbeef"));
571 else if (strcmp (method_name, "Restart") == 0)
573 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
575 else if (strcmp (method_name, "Stop") == 0)
577 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
582 ck_name_acquired_cb (GDBusConnection *connection,
586 const gchar *ck_interface =
588 " <interface name='org.freedesktop.ConsoleKit.Manager'>"
589 " <method name='CanRestart'>"
590 " <arg name='can_restart' direction='out' type='b'/>"
592 " <method name='CanStop'>"
593 " <arg name='can_stop' direction='out' type='b'/>"
595 " <method name='CloseSession'>"
596 " <arg name='cookie' direction='in' type='s'/>"
597 " <arg name='result' direction='out' type='b'/>"
599 " <method name='OpenSession'>"
600 " <arg name='cookie' direction='out' type='s'/>"
602 " <method name='OpenSessionWithParameters'>"
603 " <arg name='parameters' direction='in' type='a(sv)'/>"
604 " <arg name='cookie' direction='out' type='s'/>"
606 " <method name='Restart'/>"
607 " <method name='Stop'/>"
608 " <signal name='SeatAdded'>"
609 " <arg name='seat' type='o'/>"
611 " <signal name='SeatRemoved'>"
612 " <arg name='seat' type='o'/>"
616 static const GDBusInterfaceVTable ck_vtable =
620 GDBusNodeInfo *ck_info;
621 GError *error = NULL;
623 ck_info = g_dbus_node_info_new_for_xml (ck_interface, &error);
625 g_warning ("Failed to parse D-Bus interface: %s", error->message);
626 g_clear_error (&error);
629 g_dbus_connection_register_object (connection,
630 "/org/freedesktop/ConsoleKit/Manager",
631 ck_info->interfaces[0],
636 g_warning ("Failed to register console kit service: %s", error->message);
637 g_clear_error (&error);
638 g_dbus_node_info_unref (ck_info);
641 if (service_count == 0)
646 start_console_kit_daemon ()
648 g_bus_own_name (G_BUS_TYPE_SYSTEM,
649 "org.freedesktop.ConsoleKit",
650 G_BUS_NAME_OWNER_FLAGS_NONE,
659 handle_accounts_call (GDBusConnection *connection,
661 const gchar *object_path,
662 const gchar *interface_name,
663 const gchar *method_name,
664 GVariant *parameters,
665 GDBusMethodInvocation *invocation,
668 if (strcmp (method_name, "FindUserByName") == 0)
670 gchar *name, *data, **lines;
673 g_variant_get (parameters, "(&s)", &name);
675 g_file_get_contents (g_getenv ("LIGHTDM_TEST_PASSWD_FILE"), &data, NULL, NULL);
676 lines = g_strsplit (data, "\n", -1);
679 for (i = 0; lines[i]; i++)
682 fields = g_strsplit (lines[i], ":", -1);
683 if (strcmp (fields[0], name) == 0)
686 GError *error = NULL;
688 path = g_strdup_printf ("/org/freedesktop/Accounts/User%d", atoi (fields[2]));
690 g_dbus_connection_register_object (accounts_connection,
692 user_info->interfaces[0],
698 g_warning ("Failed to register user: %s", error->message);
699 g_clear_error (&error);
701 g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", path));
707 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such user: %s", name);
710 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
714 handle_user_call (GDBusConnection *connection,
716 const gchar *object_path,
717 const gchar *interface_name,
718 const gchar *method_name,
719 GVariant *parameters,
720 GDBusMethodInvocation *invocation,
723 if (strcmp (method_name, "SetXSession") == 0)
727 g_variant_get (parameters, "(&s)", &xsession);
729 g_free (carols_xsession);
730 carols_xsession = g_strdup (xsession);
732 g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
735 g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "No such method: %s", method_name);
739 handle_user_get_property (GDBusConnection *connection,
741 const gchar *object_path,
742 const gchar *interface_name,
743 const gchar *property_name,
747 if (strcmp (property_name, "BackgroundFile") == 0)
748 return g_variant_new_string ("");
749 else if (strcmp (property_name, "Language") == 0)
750 return g_variant_new_string ("en_US");
751 else if (strcmp (property_name, "XSession") == 0)
752 return g_variant_new_string (carols_xsession ? carols_xsession : "");
758 accounts_name_acquired_cb (GDBusConnection *connection,
762 const gchar *accounts_interface =
764 " <interface name='org.freedesktop.Accounts'>"
765 " <method name='FindUserByName'>"
766 " <arg name='name' direction='in' type='s'/>"
767 " <arg name='user' direction='out' type='o'/>"
771 static const GDBusInterfaceVTable accounts_vtable =
773 handle_accounts_call,
775 const gchar *user_interface =
777 " <interface name='org.freedesktop.Accounts.User'>"
778 " <method name='SetXSession'>"
779 " <arg name='x_session' direction='in' type='s'/>"
781 " <property name='BackgroundFile' type='s' access='read'/>"
782 " <property name='Language' type='s' access='read'/>"
783 " <property name='XSession' type='s' access='read'/>"
786 GError *error = NULL;
788 accounts_connection = connection;
790 accounts_info = g_dbus_node_info_new_for_xml (accounts_interface, &error);
792 g_warning ("Failed to parse D-Bus interface: %s", error->message);
793 g_clear_error (&error);
796 user_info = g_dbus_node_info_new_for_xml (user_interface, &error);
798 g_warning ("Failed to parse D-Bus interface: %s", error->message);
799 g_clear_error (&error);
802 g_dbus_connection_register_object (connection,
803 "/org/freedesktop/Accounts",
804 accounts_info->interfaces[0],
810 g_warning ("Failed to register accounts service: %s", error->message);
811 g_clear_error (&error);
812 g_dbus_node_info_unref (accounts_info);
815 if (service_count == 0)
820 start_accounts_service_daemon ()
822 g_bus_own_name (G_BUS_TYPE_SYSTEM,
823 "org.freedesktop.Accounts",
824 G_BUS_NAME_OWNER_FLAGS_NONE,
825 accounts_name_acquired_cb,
835 GString *command_line;
836 gchar **lightdm_argv;
838 GError *error = NULL;
842 status_timeout = g_timeout_add (STATUS_TIMEOUT, status_timeout_cb, NULL);
844 command_line = g_string_new ("../src/lightdm");
845 if (getenv ("DEBUG"))
846 g_string_append (command_line, " --debug");
847 if (!g_key_file_has_key (config, "test-runner-config", "have-config", NULL) ||
848 g_key_file_get_boolean (config, "test-runner-config", "have-config", NULL))
850 g_string_append_printf (command_line, " --config %s", config_path);
851 g_setenv ("LIGHTDM_TEST_CONFIG", config_path, TRUE);
853 g_string_append_printf (command_line, " --cache-dir %s/cache", temp_dir);
854 g_string_append_printf (command_line, " --xsessions-dir=%s/tests/data/xsessions", SRCDIR);
855 g_string_append_printf (command_line, " --xgreeters-dir=%s/tests", BUILDDIR);
857 g_print ("Start daemon with command: PATH=%s LD_PRELOAD=%s LD_LIBRARY_PATH=%s LIGHTDM_TEST_STATUS_SOCKET=%s DBUS_SESSION_BUS_ADDRESS=%s %s\n",
858 g_getenv ("PATH"), g_getenv ("LD_PRELOAD"), g_getenv ("LD_LIBRARY_PATH"), g_getenv ("LIGHTDM_TEST_STATUS_SOCKET"), g_getenv ("DBUS_SESSION_BUS_ADDRESS"),
861 if (!g_shell_parse_argv (command_line->str, NULL, &lightdm_argv, &error))
863 g_warning ("Error parsing command line: %s", error->message);
866 g_clear_error (&error);
868 if (!g_spawn_async (NULL, lightdm_argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &lightdm_pid, &error))
870 g_warning ("Error launching LightDM: %s", error->message);
873 g_clear_error (&error);
874 lightdm_process = watch_process (lightdm_pid);
876 check_status ("RUNNER DAEMON-START");
880 main (int argc, char **argv)
883 gchar *greeter = NULL, *script_name, *config_file, *path, *path1, *path2, *ld_preload, *ld_library_path, *home_dir;
884 GString *passwd_data;
888 signal (SIGINT, signal_cb);
889 signal (SIGTERM, signal_cb);
893 /* Use the session bus as the system bus */
894 g_setenv ("DBUS_SYSTEM_BUS_ADDRESS", g_getenv ("DBUS_SESSION_BUS_ADDRESS"), TRUE);
896 children = g_hash_table_new (g_direct_hash, g_direct_equal);
898 loop = g_main_loop_new (NULL, FALSE);
902 g_printerr ("Usage %s SCRIPT-NAME GREETER\n", argv[0]);
905 script_name = argv[1];
906 config_file = g_strdup_printf ("%s.conf", script_name);
907 config_path = g_build_filename (SRCDIR, "tests", "scripts", config_file, NULL);
908 g_free (config_file);
910 /* Link to the correct greeter */
911 path = g_build_filename (BUILDDIR, "tests", "default.desktop", NULL);
912 if (unlink (path) < 0 && errno != ENOENT)
914 g_printerr ("Failed to rm greeter symlink %s: %s\n", path, strerror (errno));
918 greeter = g_strdup_printf ("%s.desktop", argv[2]);
919 path1 = g_build_filename (SRCDIR, "tests", "data", "xgreeters", greeter, NULL);
921 if (symlink (path1, path) < 0)
923 g_printerr ("Failed to make greeter symlink %s->%s: %s\n", path, path1, strerror (errno));
929 config = g_key_file_new ();
930 g_key_file_load_from_file (config, config_path, G_KEY_FILE_NONE, NULL);
932 load_script (config_path);
934 g_print ("----------------------------------------\n");
935 g_print ("Running script %s\n", script_name);
937 if (!getcwd (cwd, 1024))
939 g_critical ("Error getting current directory: %s", strerror (errno));
943 /* Don't contact our X server */
944 g_unsetenv ("DISPLAY");
946 /* Start D-Bus services */
948 start_console_kit_daemon ();
949 start_accounts_service_daemon ();
951 /* Override system calls */
952 ld_preload = g_build_filename (BUILDDIR, "tests", "src", ".libs", "libsystem.so", NULL);
953 g_setenv ("LD_PRELOAD", ld_preload, TRUE);
956 /* Run test programs */
957 path = g_strdup_printf ("%s/tests/src/.libs:%s/tests/src:%s/tests/src:%s", BUILDDIR, BUILDDIR, SRCDIR, g_getenv ("PATH"));
958 g_setenv ("PATH", path, TRUE);
961 /* Use locally built libraries */
962 path1 = g_build_filename (BUILDDIR, "liblightdm-gobject", ".libs", NULL);
963 path2 = g_build_filename (BUILDDIR, "liblightdm-qt", ".libs", NULL);
964 ld_library_path = g_strdup_printf ("%s:%s", path1, path2);
967 g_setenv ("LD_LIBRARY_PATH", ld_library_path, TRUE);
968 g_free (ld_library_path);
970 /* Open socket for status */
971 status_socket_name = g_build_filename (cwd, ".status-socket", NULL);
972 g_setenv ("LIGHTDM_TEST_STATUS_SOCKET", status_socket_name, TRUE);
973 unlink (status_socket_name);
974 status_socket = open_unix_socket (status_socket_name);
975 if (status_socket < 0)
977 g_warning ("Error opening status socket: %s", strerror (errno));
980 g_io_add_watch (g_io_channel_unix_new (status_socket), G_IO_IN, status_message_cb, NULL);
982 /* Run from a temporary directory */
983 temp_dir = g_build_filename (cwd, "lightdm-test-XXXXXX", NULL);
984 if (!mkdtemp (temp_dir))
986 g_warning ("Error creating temporary directory: %s", strerror (errno));
989 home_dir = g_build_filename (temp_dir, "home", NULL);
990 g_setenv ("LIGHTDM_TEST_HOME_DIR", home_dir, TRUE);
991 passwd_data = g_string_new ("");
993 /* Make fake users */
1003 {"root", "", "root", NULL, 0},
1004 {"lightdm", "", "", NULL, 100},
1005 {"alice", "password", "Alice User", NULL, 1000},
1006 {"bob", "", "Bob User", NULL, 1001},
1007 {"carol", "", "Carol User", "alternative", 1002},
1008 {NULL, NULL, NULL, NULL, 0}
1011 for (i = 0; users[i].user_name; i++)
1013 path = g_build_filename (home_dir, users[i].user_name, NULL);
1014 g_mkdir_with_parents (path, 0755);
1017 if (users[i].xsession)
1019 path = g_build_filename (home_dir, users[i].user_name, ".dmrc", NULL);
1020 g_file_set_contents (path, g_strdup_printf ("[Desktop]\nSession=%s", users[i].xsession), -1, NULL);
1024 g_string_append_printf (passwd_data, "%s:%s:%d:%d:%s:%s/home/%s:/bin/sh\n", users[i].user_name, users[i].password, users[i].uid, users[i].uid, users[i].real_name, temp_dir, users[i].user_name);
1026 path = g_build_filename (temp_dir, "passwd", NULL);
1027 g_setenv ("LIGHTDM_TEST_PASSWD_FILE", path, TRUE);
1028 g_file_set_contents (path, passwd_data->str, -1, NULL);
1030 g_string_free (passwd_data, TRUE);
1032 g_main_loop_run (loop);
1034 return EXIT_FAILURE;