1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tests/dstest_exec_many.cc Sun Mar 19 01:18:23 2023 +0100
1.3 @@ -0,0 +1,103 @@
1.4 +/*
1.5 + * A test of executing code in new tasks and threads.
1.6 + *
1.7 + * Copyright (C) 2022, 2023 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#include <l4/sys/err.h>
1.26 +
1.27 +#include <fsclient/process.h>
1.28 +#include <systypes/format.h>
1.29 +
1.30 +#include <stdio.h>
1.31 +#include <stdlib.h>
1.32 +
1.33 +
1.34 +
1.35 +int main(int argc, char *argv[])
1.36 +{
1.37 + long err;
1.38 +
1.39 + if (argc < 3)
1.40 + {
1.41 + printf("Need a number and the program to run.\n");
1.42 + return 1;
1.43 + }
1.44 +
1.45 + int num_processes = atoi(argv[1]);
1.46 +
1.47 + /* Create a new process structure. */
1.48 +
1.49 + process_t process;
1.50 +
1.51 + process_init(&process);
1.52 +
1.53 + for (int i = 1; i <= num_processes; i++)
1.54 + {
1.55 + printf("[%d/%d] Start process...\n", i, num_processes);
1.56 +
1.57 + /* Start a process for the given program. */
1.58 +
1.59 + err = process_start(&process, argc - 2, argv + 2);
1.60 +
1.61 + if (err)
1.62 + {
1.63 + printf("Could not start process: %s\n", l4sys_errtostr(err));
1.64 + return 1;
1.65 + }
1.66 +
1.67 + printf("Finished program initiation.\n");
1.68 +
1.69 + /* Obtain the common notifier. */
1.70 +
1.71 + process_notifier_t *notifier = process_notify_task();
1.72 +
1.73 + /* Subscribe to the process for notifications. */
1.74 +
1.75 + err = process_notify_subscribe(&process, NOTIFY_TASK_SIGNAL, notifier);
1.76 +
1.77 + if (err)
1.78 + {
1.79 + printf("Could not subscribe to process: %s\n", l4sys_errtostr(err));
1.80 + return 1;
1.81 + }
1.82 +
1.83 + /* Wait for a signal from the process. */
1.84 +
1.85 + err = process_notify_wait_process(&process, notifier);
1.86 +
1.87 + if (err)
1.88 + {
1.89 + printf("Could not wait for process: %s\n", l4sys_errtostr(err));
1.90 + return 1;
1.91 + }
1.92 +
1.93 + notify_flags_t flags = process_notifications(&process);
1.94 + notify_values_t values = process_notification_values(&process);
1.95 +
1.96 + process_close(&process);
1.97 +
1.98 + printf("[%d/%d] End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", i, num_processes, flags, values.sig, values.val);
1.99 + }
1.100 +
1.101 + printf("End of test.\n");
1.102 + return 0;
1.103 +}
1.104 +
1.105 +/* vim: tabstop=2 expandtab shiftwidth=2
1.106 +*/