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 | //
|
---|
16 |
|
---|
17 | #include <fstream.hfa>
|
---|
18 |
|
---|
19 | #include "../meta/fork+exec.hfa"
|
---|
20 |
|
---|
21 | // last as workaround to parser bug
|
---|
22 | #include <parseargs.hfa>
|
---|
23 |
|
---|
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 |
|
---|
34 | int true_main(const char * exec);
|
---|
35 |
|
---|
36 | int main(int argc, char * argv[]) {
|
---|
37 | check_main(argv[0]);
|
---|
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 |
|
---|
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 };
|
---|
52 |
|
---|
53 | char **left;
|
---|
54 | parse_args( options, "[OPTIONS]...\ntesting bool parameters", left);
|
---|
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 |
|
---|
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 | }
|
---|
71 | }
|
---|
72 | else {
|
---|
73 | int status = do_wait(child);
|
---|
74 | print_status(status);
|
---|
75 | }
|
---|
76 |
|
---|
77 | printf("all 0 arg:\n");
|
---|
78 | if(pid_t child = strict_fork(); child == 0) {
|
---|
79 | int ret = execle(path, "parsenums", "-i=0", "-u=0", "-l=0", "-L=0", "-d=0", (const char*)0p, env);
|
---|
80 | if(ret < 0) {
|
---|
81 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
82 | exit(1);
|
---|
83 | }
|
---|
84 | }
|
---|
85 | else {
|
---|
86 | int status = do_wait(child);
|
---|
87 | print_status(status);
|
---|
88 | }
|
---|
89 |
|
---|
90 | printf("negative vals arg:\n");
|
---|
91 | if(pid_t child = strict_fork(); child == 0) {
|
---|
92 | int ret = execle(path, "parsenums", "-i=-1", "-d=-1", (const char*)0p, env);
|
---|
93 | if(ret < 0) {
|
---|
94 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
95 | exit(1);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | else {
|
---|
99 | int status = do_wait(child);
|
---|
100 | print_status(status);
|
---|
101 | }
|
---|
102 |
|
---|
103 | printf("funky notation arg:\n");
|
---|
104 | if(pid_t child = strict_fork(); child == 0) {
|
---|
105 | int ret = execle(path, "parsenums", "-i=0x10", "-u=0x20", "-l=0x300", "-L=0x4000", "-d=5e6", (const char*)0p, env);
|
---|
106 | if(ret < 0) {
|
---|
107 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
108 | exit(1);
|
---|
109 | }
|
---|
110 | }
|
---|
111 | else {
|
---|
112 | int status = do_wait(child);
|
---|
113 | print_status(status);
|
---|
114 | }
|
---|
115 |
|
---|
116 | printf("big values arg:\n");
|
---|
117 | if(pid_t child = strict_fork(); child == 0) {
|
---|
118 | int ret = execle(path, "parsenums", "-i=2147483647", "-u=4294967295", "-l=" BIG_UNSIGNED_LONG, "-L=18446744073709551615", "-d=5e6", (const char*)0p, env);
|
---|
119 | if(ret < 0) {
|
---|
120 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
121 | exit(1);
|
---|
122 | }
|
---|
123 | }
|
---|
124 | else {
|
---|
125 | int status = do_wait(child);
|
---|
126 | print_status(status);
|
---|
127 | }
|
---|
128 |
|
---|
129 | printf("too big values arg:\n");
|
---|
130 | if(pid_t child = strict_fork(); child == 0) {
|
---|
131 | int ret = execle(path, "parsenums", "-i=2147483648", (const char*)0p, env);
|
---|
132 | if(ret < 0) {
|
---|
133 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
134 | exit(1);
|
---|
135 | }
|
---|
136 | }
|
---|
137 | else {
|
---|
138 | int status = do_wait(child);
|
---|
139 | print_status(status);
|
---|
140 | }
|
---|
141 |
|
---|
142 | if(pid_t child = strict_fork(); child == 0) {
|
---|
143 | int ret = execle(path, "parsenums", "-u=4294967296", (const char*)0p, env);
|
---|
144 | if(ret < 0) {
|
---|
145 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
146 | exit(1);
|
---|
147 | }
|
---|
148 | }
|
---|
149 | else {
|
---|
150 | int status = do_wait(child);
|
---|
151 | print_status(status);
|
---|
152 | }
|
---|
153 |
|
---|
154 | if(pid_t child = strict_fork(); child == 0) {
|
---|
155 | int ret = execle(path, "parsenums", "-l=" TOO_BIG_UNSIGNED_LONG, (const char*)0p, env);
|
---|
156 | if(ret < 0) {
|
---|
157 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
158 | exit(1);
|
---|
159 | }
|
---|
160 | }
|
---|
161 | else {
|
---|
162 | int status = do_wait(child);
|
---|
163 | print_status(status);
|
---|
164 | }
|
---|
165 |
|
---|
166 | if(pid_t child = strict_fork(); child == 0) {
|
---|
167 | int ret = execle(path, "parsenums", "-L=18446744073709551616", (const char*)0p, env);
|
---|
168 | if(ret < 0) {
|
---|
169 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
170 | exit(1);
|
---|
171 | }
|
---|
172 | }
|
---|
173 | else {
|
---|
174 | int status = do_wait(child);
|
---|
175 | print_status(status);
|
---|
176 | }
|
---|
177 |
|
---|
178 | printf("negative errors arg:\n");
|
---|
179 | if(pid_t child = strict_fork(); child == 0) {
|
---|
180 | int ret = execle(path, "parsenums", "-u=-1", (const char*)0p, env);
|
---|
181 | if(ret < 0) {
|
---|
182 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
183 | exit(1);
|
---|
184 | }
|
---|
185 | }
|
---|
186 | else {
|
---|
187 | int status = do_wait(child);
|
---|
188 | print_status(status);
|
---|
189 | }
|
---|
190 |
|
---|
191 | if(pid_t child = strict_fork(); child == 0) {
|
---|
192 | int ret = execle(path, "parsenums", "-l=-1", (const char*)0p, env);
|
---|
193 | if(ret < 0) {
|
---|
194 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
195 | exit(1);
|
---|
196 | }
|
---|
197 | }
|
---|
198 | else {
|
---|
199 | int status = do_wait(child);
|
---|
200 | print_status(status);
|
---|
201 | }
|
---|
202 |
|
---|
203 | if(pid_t child = strict_fork(); child == 0) {
|
---|
204 | int ret = execle(path, "parsenums", "-L=-1", (const char*)0p, env);
|
---|
205 | if(ret < 0) {
|
---|
206 | fprintf(stderr, "Execl 2 returned with error: %d '%s'\n", errno, strerror(errno));
|
---|
207 | exit(1);
|
---|
208 | }
|
---|
209 | }
|
---|
210 | else {
|
---|
211 | int status = do_wait(child);
|
---|
212 | print_status(status);
|
---|
213 | }
|
---|
214 |
|
---|
215 | printf("All Done!\n");
|
---|
216 |
|
---|
217 | return 0;
|
---|
218 | }
|
---|