Changeset 481f882 for tests/configs/parsebools.cfa
- Timestamp:
- Oct 12, 2022, 4:32:49 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 38cc59f
- Parents:
- a51b8f6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/configs/parsebools.cfa
ra51b8f6 r481f882 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 } 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 // 13 16 14 17 #include <parseargs.hfa> 15 18 #include <fstream.hfa> 16 19 17 int true_main(const char * exec); 20 #include "../meta/fork+exec.hfa" 18 21 19 22 int main(int argc, char * argv[]) { 20 if(!getenv("CFATEST_FORK_EXEC_TEXT")) return true_main(argv[0]);23 check_main(argv[0]); 21 24 22 25 bool YN = false; … … 48 51 } 49 52 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 53 int true_main(const char * path, char * env[]) { 87 54 printf("no arg:\n"); 88 55 if(pid_t child = strict_fork(); child == 0) { … … 97 64 print_status(status); 98 65 } 99 printf("\n");100 66 101 67 printf("all true/set arg:\n"); … … 111 77 print_status(status); 112 78 } 113 printf("\n");114 79 115 80 printf("all false/unset arg:\n"); … … 125 90 print_status(status); 126 91 } 127 printf("\n");128 92 129 93 printf("gibberish arg 1:\n"); … … 139 103 print_status(status); 140 104 } 141 printf("\n");142 105 143 106 printf("gibberish arg 2:\n"); … … 153 116 print_status(status); 154 117 } 155 printf("\n");156 118 157 119 printf("gibberish arg 3:\n"); … … 167 129 print_status(status); 168 130 } 169 printf("\n");170 131 171 132 printf("gibberish arg 4:\n"); … … 181 142 print_status(status); 182 143 } 183 printf("\n");184 144 185 145 printf("All Done!\n");
Note: See TracChangeset
for help on using the changeset viewer.