test-runner: Add udevd and trigger events
authorFrédéric Danis <frederic.danis@collabora.com>
Fri, 10 Jun 2022 16:38:20 +0000 (18:38 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
Kernel events should have been managed so the audio card is accessible
from PipeWire

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
tools/test-runner.c

index 2de072c..de36b23 100755 (executable)
@@ -250,13 +250,14 @@ static void start_qemu(void)
                                "rootfstype=9p "
                                "rootflags=trans=virtio,version=9p2000.L "
                                "acpi=off pci=noacpi noapic quiet ro init=%s "
-                               "bluetooth.enable_ecred=1"
+                               "bluetooth.enable_ecred=1 "
                                "TESTHOME=%s TESTDBUS=%u TESTDAEMON=%u "
                                "TESTDBUSSESSION=%u XDG_RUNTIME_DIR=/run/user/0 "
+                               "TESTAUDIO=%u "
                                "TESTMONITOR=%u TESTEMULATOR=%u TESTDEVS=%d "
                                "TESTAUTO=%u TESTARGS=\'%s\'",
                                initcmd, cwd, start_dbus, start_daemon,
-                               start_dbus_session,
+                               start_dbus_session, audio_support,
                                start_monitor, start_emulator, num_devs,
                                run_auto, testargs);
 
@@ -723,6 +724,63 @@ static pid_t start_btvirt(const char *home)
        return pid;
 }
 
+static void trigger_udev(void)
+{
+       char *argv[3], *envp[1];
+       pid_t pid;
+
+       argv[0] = "/bin/udevadm";
+       argv[1] = "trigger";
+       argv[2] = NULL;
+
+       envp[0] = NULL;
+
+       printf("Triggering udev events\n");
+
+       pid = fork();
+       if (pid < 0) {
+               perror("Failed to fork new process");
+               return;
+       }
+
+       if (pid == 0) {
+               execve(argv[0], argv, envp);
+               exit(EXIT_SUCCESS);
+       }
+
+       printf("udev trigger process %d created\n", pid);
+}
+
+static pid_t start_udevd(void)
+{
+       char *argv[2], *envp[1];
+       pid_t pid;
+
+       argv[0] = "/lib/systemd/systemd-udevd";
+       argv[1] = NULL;
+
+       envp[0] = NULL;
+
+       printf("Starting udevd daemon\n");
+
+       pid = fork();
+       if (pid < 0) {
+               perror("Failed to fork new process");
+               return -1;
+       }
+
+       if (pid == 0) {
+               execve(argv[0], argv, envp);
+               exit(EXIT_SUCCESS);
+       }
+
+       printf("udevd daemon process %d created\n", pid);
+
+       trigger_udev();
+
+       return pid;
+}
+
 static void run_command(char *cmdname, char *home)
 {
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
@@ -733,7 +791,7 @@ static void run_command(char *cmdname, char *home)
        int pos = 0, idx = 0;
        int serial_fd;
        pid_t pid, dbus_pid, daemon_pid, monitor_pid, emulator_pid,
-             dbus_session_pid;
+             dbus_session_pid, udevd_pid;
 
        if (num_devs) {
                const char *node = "/dev/ttyS1";
@@ -749,6 +807,11 @@ static void run_command(char *cmdname, char *home)
        } else
                serial_fd = -1;
 
+       if (audio_support)
+               udevd_pid = start_udevd();
+       else
+               udevd_pid = -1;
+
        if (start_dbus) {
                create_dbus_system_conf();
                dbus_pid = start_dbus_daemon(false);
@@ -877,6 +940,11 @@ start_next:
                        monitor_pid = -1;
                }
 
+               if (corpse == udevd_pid) {
+                       printf("udevd terminated\n");
+                       udevd_pid = -1;
+               }
+
                if (corpse == pid)
                        break;
        }
@@ -901,6 +969,9 @@ start_next:
        if (monitor_pid > 0)
                kill(monitor_pid, SIGTERM);
 
+       if (udevd_pid > 0)
+               kill(udevd_pid, SIGTERM);
+
        if (serial_fd >= 0) {
                close(serial_fd);
                serial_fd = -1;
@@ -983,6 +1054,12 @@ static void run_tests(void)
                start_emulator = true;
        }
 
+       ptr = strstr(cmdline, "TESTAUDIO=1");
+       if (ptr) {
+               printf("Audio support requested\n");
+               audio_support = true;
+       }
+
        ptr = strstr(cmdline, "TESTHOME=");
        if (ptr) {
                home = ptr + 4;