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