[481f882] | 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/parsenums.cfa |
---|
| 8 | // Testing parsing of integer 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 | // |
---|
[fd90096] | 16 | |
---|
| 17 | #include <fstream.hfa> |
---|
| 18 | |
---|
[481f882] | 19 | #include "../meta/fork+exec.hfa" |
---|
| 20 | |
---|
[9e042d8] | 21 | // last as workaround to parser bug |
---|
| 22 | #include <parseargs.hfa> |
---|
| 23 | |
---|
[a46f7b6] | 24 | #if __SIZEOF_LONG__ == 4 |
---|
| 25 | #define BIG_UNSIGNED_LONG "4294967295" |
---|
| 26 | #define TOO_BIG_UNSIGNED_LONG "4294967296" |
---|
| 27 | #elif __SIZEOF_LONG__ == 8 |
---|
| 28 | #define BIG_UNSIGNED_LONG "18446744073709551615" |
---|
| 29 | #define TOO_BIG_UNSIGNED_LONG "18446744073709551616" |
---|
| 30 | #else |
---|
| 31 | #error unexpected size of long |
---|
| 32 | #endif |
---|
| 33 | |
---|
[0b6089f] | 34 | int true_main( const char * exec ); |
---|
[fd90096] | 35 | |
---|
[0b6089f] | 36 | int main( int argc, char * argv[]) { |
---|
| 37 | check_main( argv[0]); |
---|
[fd90096] | 38 | |
---|
| 39 | int i = -3; |
---|
| 40 | unsigned u = 3; |
---|
| 41 | unsigned long ul = 3; |
---|
| 42 | unsigned long long ull = 3; |
---|
| 43 | double d = 3.3; |
---|
| 44 | |
---|
| 45 | |
---|
[d1abc63c] | 46 | array( cfa_option, 5 ) options; |
---|
| 47 | options[0] = (cfa_option){ 'i', "int", "test int", i }; |
---|
| 48 | options[1] = (cfa_option){ 'u', "unsigned", "test unsigned", u }; |
---|
| 49 | options[2] = (cfa_option){ 'l', "unsignedlong", "test unsigned long", ul }; |
---|
| 50 | options[3] = (cfa_option){ 'L', "unsignedlonglong", "test unsigned long long", ull }; |
---|
| 51 | options[4] = (cfa_option){ 'd', "double", "test double", d }; |
---|
[fd90096] | 52 | |
---|
| 53 | char **left; |
---|
[0b6089f] | 54 | parse_args( options, "[OPTIONS]...\ntesting bool parameters", left ); |
---|
[fd90096] | 55 | |
---|
| 56 | sout | "int :" | i; |
---|
| 57 | sout | "unsigned :" | u; |
---|
| 58 | sout | "unsigned long :" | ul; |
---|
| 59 | sout | "unsigned long long :" | ull; |
---|
| 60 | sout | "double :" | d; |
---|
| 61 | } |
---|
| 62 | |
---|
[0b6089f] | 63 | int true_main( const char * path, char * env[] ) { |
---|
| 64 | printf( "no arg:\n" ); |
---|
| 65 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 66 | int ret = execle( path, "parsenums", (const char*)0p, env ); |
---|
| 67 | if ( ret < 0 ) { |
---|
| 68 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 69 | exit( 1 ); |
---|
| 70 | } // if |
---|
| 71 | } else { |
---|
| 72 | int status = do_wait( child ); |
---|
| 73 | print_status( status ); |
---|
| 74 | } // if |
---|
| 75 | |
---|
| 76 | printf( "all 0 arg:\n" ); |
---|
| 77 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 78 | int ret = execle( path, "parsenums", "-i=0", "-u=0", "-l=0", "-L=0", "-d=0", (const char*)0p, env ); |
---|
| 79 | if ( ret < 0 ) { |
---|
| 80 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 81 | exit( 1 ); |
---|
| 82 | } // if |
---|
| 83 | } else { |
---|
| 84 | int status = do_wait( child ); |
---|
| 85 | print_status( status ); |
---|
| 86 | } // if |
---|
| 87 | |
---|
| 88 | printf( "negative vals arg:\n" ); |
---|
| 89 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 90 | int ret = execle( path, "parsenums", "-i=-1", "-d=-1", (const char*)0p, env ); |
---|
| 91 | if ( ret < 0 ) { |
---|
| 92 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 93 | exit( 1 ); |
---|
| 94 | } // if |
---|
| 95 | } else { |
---|
| 96 | int status = do_wait( child ); |
---|
| 97 | print_status( status ); |
---|
| 98 | } // if |
---|
| 99 | |
---|
| 100 | printf( "funky notation arg:\n" ); |
---|
| 101 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 102 | int ret = execle( path, "parsenums", "-i=0x10", "-u=0x20", "-l=0x300", "-L=0x4000", "-d=5e6", (const char*)0p, env ); |
---|
| 103 | if ( ret < 0 ) { |
---|
| 104 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 105 | exit( 1 ); |
---|
| 106 | } // if |
---|
| 107 | } else { |
---|
| 108 | int status = do_wait( child ); |
---|
| 109 | print_status( status ); |
---|
| 110 | } // if |
---|
| 111 | |
---|
| 112 | printf( "big values arg:\n" ); |
---|
| 113 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 114 | int ret = execle( path, "parsenums", "-i=2147483647", "-u=4294967295", "-l=" BIG_UNSIGNED_LONG, "-L=18446744073709551615", "-d=5e6", (const char*)0p, env ); |
---|
| 115 | if ( ret < 0 ) { |
---|
| 116 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 117 | exit( 1 ); |
---|
| 118 | } // if |
---|
| 119 | } else { |
---|
| 120 | int status = do_wait( child ); |
---|
| 121 | print_status( status ); |
---|
| 122 | } // if |
---|
| 123 | |
---|
| 124 | printf( "too big values arg:\n" ); |
---|
| 125 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 126 | int ret = execle( path, "parsenums", "-i=2147483648", (const char*)0p, env ); |
---|
| 127 | if ( ret < 0 ) { |
---|
| 128 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 129 | exit( 1 ); |
---|
| 130 | } // if |
---|
| 131 | } else { |
---|
| 132 | int status = do_wait( child ); |
---|
| 133 | print_status( status ); |
---|
| 134 | } // if |
---|
| 135 | |
---|
| 136 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 137 | int ret = execle( path, "parsenums", "-u=4294967296", (const char*)0p, env ); |
---|
| 138 | if ( ret < 0 ) { |
---|
| 139 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 140 | exit( 1 ); |
---|
| 141 | } // if |
---|
| 142 | } else { |
---|
| 143 | int status = do_wait( child ); |
---|
| 144 | print_status( status ); |
---|
| 145 | } // if |
---|
| 146 | |
---|
| 147 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 148 | int ret = execle( path, "parsenums", "-l=" TOO_BIG_UNSIGNED_LONG, (const char*)0p, env ); |
---|
| 149 | if ( ret < 0 ) { |
---|
| 150 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 151 | exit( 1 ); |
---|
| 152 | } // if |
---|
| 153 | } else { |
---|
| 154 | int status = do_wait( child ); |
---|
| 155 | print_status( status ); |
---|
| 156 | } // if |
---|
| 157 | |
---|
| 158 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 159 | int ret = execle( path, "parsenums", "-L=18446744073709551616", (const char*)0p, env ); |
---|
| 160 | if ( ret < 0 ) { |
---|
| 161 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 162 | exit( 1 ); |
---|
| 163 | } // if |
---|
| 164 | } else { |
---|
| 165 | int status = do_wait( child ); |
---|
| 166 | print_status( status ); |
---|
| 167 | } // if |
---|
| 168 | |
---|
| 169 | printf( "negative errors arg:\n" ); |
---|
| 170 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 171 | int ret = execle( path, "parsenums", "-u=-1", (const char*)0p, env ); |
---|
| 172 | if ( ret < 0 ) { |
---|
| 173 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 174 | exit( 1 ); |
---|
| 175 | } // if |
---|
| 176 | } else { |
---|
| 177 | int status = do_wait( child ); |
---|
| 178 | print_status( status ); |
---|
| 179 | } // if |
---|
| 180 | |
---|
| 181 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 182 | int ret = execle( path, "parsenums", "-l=-1", (const char*)0p, env ); |
---|
| 183 | if ( ret < 0 ) { |
---|
| 184 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 185 | exit( 1 ); |
---|
| 186 | } // if |
---|
| 187 | } else { |
---|
| 188 | int status = do_wait( child ); |
---|
| 189 | print_status( status ); |
---|
| 190 | } // if |
---|
| 191 | |
---|
| 192 | if ( pid_t child = strict_fork(); child == 0 ) { |
---|
| 193 | int ret = execle( path, "parsenums", "-L=-1", (const char*)0p, env ); |
---|
| 194 | if ( ret < 0 ) { |
---|
| 195 | fprintf( stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror( errno ) ); |
---|
| 196 | exit( 1 ); |
---|
| 197 | } // if |
---|
| 198 | } else { |
---|
| 199 | int status = do_wait( child ); |
---|
| 200 | print_status( status ); |
---|
| 201 | } // if |
---|
| 202 | |
---|
| 203 | printf( "All Done!\n" ); |
---|
[fd90096] | 204 | |
---|
| 205 | return 0; |
---|
[9e042d8] | 206 | } |
---|