1 /* 2 * A test of executing code in new tasks and threads. 3 * 4 * Copyright (C) 2022, 2023 Paul Boddie <paul@boddie.org.uk> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA 20 */ 21 22 #include <l4/sys/err.h> 23 24 #include <fsclient/process.h> 25 #include <systypes/format.h> 26 27 #include <stdio.h> 28 29 30 31 static long test_process(int argc, const char *argv[]) 32 { 33 process_t *process; 34 35 /* Start the process. */ 36 37 long err = process_spawn(argc, argv, &process); 38 39 if (err) 40 { 41 printf("Could not start process: %s\n", l4sys_errtostr(err)); 42 return err; 43 } 44 45 printf("Finished program initiation.\n"); 46 47 /* Wait for a signal from the process. */ 48 49 notify_flags_t flags; 50 notify_values_t values; 51 52 err = process_wait(process, &flags, &values); 53 54 if (err) 55 { 56 printf("Could not wait for process: %s\n", l4sys_errtostr(err)); 57 return err; 58 } 59 60 printf("End process (flags %" pFMTnotify_flags "x values: %ld, %ld)\n", flags, values.sig, values.val); 61 return L4_EOK; 62 } 63 64 65 66 int main(int argc, char *argv[]) 67 { 68 long err; 69 70 if (argc < 2) 71 { 72 printf("Need the program to run.\n"); 73 return 1; 74 } 75 76 /* Obtain the common notifier. */ 77 78 notifier_t *notifier = notify_get_task(); 79 80 /* Start a process for a non-existent program. */ 81 82 printf("Start non-existent program...\n"); 83 84 const char *bad_argv[] = {"non_existent_program"}; 85 86 err = test_process(1, bad_argv); 87 88 if (!err) 89 { 90 printf("Non-existent program was apparently successfully started.\n"); 91 return 1; 92 } 93 94 printf("Non-existent program result: %s\n", l4sys_errtostr(err)); 95 96 /* Start a process for the given program. */ 97 98 printf("Start process...\n"); 99 100 err = test_process(argc - 1, (const char **) argv + 1); 101 102 if (err) 103 return 1; 104 105 notify_close(notifier); 106 107 printf("End of test.\n"); 108 return 0; 109 } 110 111 /* vim: tabstop=2 expandtab shiftwidth=2 112 */