1.1 --- a/tests/dstest_exec.cc Mon Dec 11 19:17:25 2023 +0100
1.2 +++ b/tests/dstest_exec.cc Mon Dec 11 19:23:39 2023 +0100
1.3 @@ -21,20 +21,54 @@
1.4
1.5 #include <l4/sys/err.h>
1.6
1.7 +#include <fsclient/client.h>
1.8 #include <fsclient/process.h>
1.9 +#include <systypes/fcntl.h>
1.10 #include <systypes/format.h>
1.11
1.12 #include <stdio.h>
1.13
1.14
1.15
1.16 +/* Transfer size for communication. */
1.17 +
1.18 +const offset_t TO_TRANSFER = 1024;
1.19 +
1.20 +
1.21 +
1.22 +/* Test process initiation and interaction. */
1.23 +
1.24 static long test_process(int argc, const char *argv[])
1.25 {
1.26 process_t *process;
1.27 + file_t *reader, *writer;
1.28 + long err;
1.29 +
1.30 + /* Obtain the common notifier. */
1.31 +
1.32 + notifier_t *notifier = client_notifier_task();
1.33 +
1.34 + /* Create a pipe for process output. */
1.35 +
1.36 + err = client_pipe(&reader, &writer, O_NONBLOCK);
1.37 +
1.38 + if (err)
1.39 + {
1.40 + printf("Could not obtain pipe: %s\n", l4sys_errtostr(err));
1.41 + return err;
1.42 + }
1.43 +
1.44 + err = client_subscribe(reader, NOTIFY_CONTENT_AVAILABLE | NOTIFY_PEER_CLOSED, notifier);
1.45 +
1.46 + if (err)
1.47 + {
1.48 + printf("Could not subscribe to pipe notifications: %s\n", l4sys_errtostr(err));
1.49 + return err;
1.50 + }
1.51
1.52 /* Start the process. */
1.53
1.54 - long err = process_spawn(argc, argv, &process);
1.55 + err = process_spawn(argc, argv, writer, &process);
1.56
1.57 if (err)
1.58 {
1.59 @@ -44,21 +78,60 @@
1.60
1.61 printf("Finished program initiation.\n");
1.62
1.63 - /* Wait for a signal from the process. */
1.64 + /* Wait for a signal from the process or input from the process. */
1.65
1.66 - notify_flags_t flags;
1.67 - notify_values_t values;
1.68 -
1.69 - err = process_wait(process, &flags, &values);
1.70 + err = notify_subscribe(process_notifiable(process), NOTIFY_TASK_ALL, notifier);
1.71
1.72 if (err)
1.73 {
1.74 - printf("Could not wait for process: %s\n", l4sys_errtostr(err));
1.75 + printf("Could not subscribe to task notifications: %s\n", l4sys_errtostr(err));
1.76 return err;
1.77 }
1.78
1.79 + notifiable_t *notifiable;
1.80 +
1.81 + while (1)
1.82 + {
1.83 + err = notify_wait_many(¬ifiable, notifier);
1.84 +
1.85 + if (err)
1.86 + {
1.87 + printf("Could not wait for process: %s\n", l4sys_errtostr(err));
1.88 + return err;
1.89 + }
1.90 +
1.91 + /* Handle any signal. */
1.92 +
1.93 + if (notifiable == process_notifiable(process))
1.94 + break;
1.95 +
1.96 + /* Handle any input. */
1.97 +
1.98 + else if (notifiable == file_notifiable(reader))
1.99 + {
1.100 + char buffer[TO_TRANSFER];
1.101 + offset_t nread = client_read(reader, buffer, TO_TRANSFER);
1.102 +
1.103 + while (nread)
1.104 + {
1.105 + fwrite(buffer, sizeof(char), nread, stdout);
1.106 + nread = client_read(reader, buffer, TO_TRANSFER);
1.107 + }
1.108 + }
1.109 + }
1.110 +
1.111 + notify_flags_t flags = process_notifications(process);
1.112 + notify_values_t values = process_notification_values(process);
1.113 +
1.114 printf("End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", flags, values.sig, values.val);
1.115 - return L4_EOK;
1.116 +
1.117 + err = process_error(process);
1.118 +
1.119 + client_close(reader);
1.120 + process_free(process);
1.121 + client_notifier_close(notifier);
1.122 +
1.123 + return err;
1.124 }
1.125
1.126
1.127 @@ -73,10 +146,6 @@
1.128 return 1;
1.129 }
1.130
1.131 - /* Obtain the common notifier. */
1.132 -
1.133 - notifier_t *notifier = notify_get_task();
1.134 -
1.135 /* Start a process for a non-existent program. */
1.136
1.137 printf("Start non-existent program...\n");
1.138 @@ -102,8 +171,6 @@
1.139 if (err)
1.140 return 1;
1.141
1.142 - notify_close(notifier);
1.143 -
1.144 printf("End of test.\n");
1.145 return 0;
1.146 }