Changes in tests/configs/parsebools.cfa [481f882:fd90096]
- File:
-
- 1 edited
-
tests/configs/parsebools.cfa (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/configs/parsebools.cfa
r481f882 rfd90096 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // configs/parsebools.cfa 8 // Testing parsing of boolean arguments 9 // 10 // Author : Thierry Delisle 11 // Created On : Wed Oct 12 15:28:01 2022 12 // Last Modified By : 13 // Last Modified On : 14 // Update Count : 15 // 1 #include <stdlib.h> 2 #include <stdio.h> 3 #include <string.h> 4 5 #include <errno.h> 6 #include <signal.h> 7 8 extern "C" { 9 #include <sys/types.h> 10 #include <sys/wait.h> 11 #include <unistd.h> 12 } 16 13 17 14 #include <parseargs.hfa> 18 15 #include <fstream.hfa> 19 16 20 #include "../meta/fork+exec.hfa" 17 int true_main(const char * exec); 21 18 22 19 int main(int argc, char * argv[]) { 23 check_main(argv[0]);20 if(!getenv("CFATEST_FORK_EXEC_TEXT")) return true_main(argv[0]); 24 21 25 22 bool YN = false; … … 51 48 } 52 49 53 int true_main(const char * path, char * env[]) { 50 int do_wait(pid_t pid) { 51 int wstatus; 52 int options = 0; 53 pid_t ret = waitpid(pid, &wstatus, options); 54 fflush(stdout); 55 if(ret < 0) { 56 fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno)); 57 exit(1); 58 } 59 return wstatus; 60 } 61 62 pid_t strict_fork(void) { 63 fflush(stdout); 64 pid_t ret = fork(); 65 if(ret < 0) { 66 fprintf(stderr, "Fork returned with error: %d '%s'\n", errno, strerror(errno)); 67 exit(1); 68 } 69 return ret; 70 } 71 72 void print_status(int wstatus) { 73 printf("Child status:\n"); 74 printf(" WIFEXITED : %d", WIFEXITED(wstatus)); 75 printf(" WEXITSTATUS : %d", WEXITSTATUS(wstatus)); 76 printf(" WIFSIGNALED : %d", WIFSIGNALED(wstatus)); 77 printf(" WTERMSIG : %d", WTERMSIG(wstatus)); 78 printf(" WCOREDUMP : %d", WCOREDUMP(wstatus)); 79 printf(" WIFSTOPPED : %d", WIFSTOPPED(wstatus)); 80 printf(" WSTOPSIG : %d", WSTOPSIG(wstatus)); 81 printf(" WIFCONTINUED: %d\n", WIFCONTINUED(wstatus)); 82 } 83 84 int true_main(const char * path) { 85 char * env[] = { "CFATEST_FORK_EXEC_TEXT=1", 0p }; 86 54 87 printf("no arg:\n"); 55 88 if(pid_t child = strict_fork(); child == 0) { … … 64 97 print_status(status); 65 98 } 99 printf("\n"); 66 100 67 101 printf("all true/set arg:\n"); … … 77 111 print_status(status); 78 112 } 113 printf("\n"); 79 114 80 115 printf("all false/unset arg:\n"); … … 90 125 print_status(status); 91 126 } 127 printf("\n"); 92 128 93 129 printf("gibberish arg 1:\n"); … … 103 139 print_status(status); 104 140 } 141 printf("\n"); 105 142 106 143 printf("gibberish arg 2:\n"); … … 116 153 print_status(status); 117 154 } 155 printf("\n"); 118 156 119 157 printf("gibberish arg 3:\n"); … … 129 167 print_status(status); 130 168 } 169 printf("\n"); 131 170 132 171 printf("gibberish arg 4:\n"); … … 142 181 print_status(status); 143 182 } 183 printf("\n"); 144 184 145 185 printf("All Done!\n");
Note:
See TracChangeset
for help on using the changeset viewer.