]> git.proxmox.com Git - mirror_qemu.git/blob - tests/test-cutils.c
Merge remote-tracking branch 'remotes/berrange/tags/socket-next-pull-request' into...
[mirror_qemu.git] / tests / test-cutils.c
1 /*
2 * cutils.c unit-tests
3 *
4 * Copyright (C) 2013 Red Hat Inc.
5 *
6 * Authors:
7 * Eduardo Habkost <ehabkost@redhat.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 */
27
28 #include "qemu/osdep.h"
29
30 #include "qemu/cutils.h"
31
32 static void test_parse_uint_null(void)
33 {
34 unsigned long long i = 999;
35 char f = 'X';
36 char *endptr = &f;
37 int r;
38
39 r = parse_uint(NULL, &i, &endptr, 0);
40
41 g_assert_cmpint(r, ==, -EINVAL);
42 g_assert_cmpint(i, ==, 0);
43 g_assert(endptr == NULL);
44 }
45
46 static void test_parse_uint_empty(void)
47 {
48 unsigned long long i = 999;
49 char f = 'X';
50 char *endptr = &f;
51 const char *str = "";
52 int r;
53
54 r = parse_uint(str, &i, &endptr, 0);
55
56 g_assert_cmpint(r, ==, -EINVAL);
57 g_assert_cmpint(i, ==, 0);
58 g_assert(endptr == str);
59 }
60
61 static void test_parse_uint_whitespace(void)
62 {
63 unsigned long long i = 999;
64 char f = 'X';
65 char *endptr = &f;
66 const char *str = " \t ";
67 int r;
68
69 r = parse_uint(str, &i, &endptr, 0);
70
71 g_assert_cmpint(r, ==, -EINVAL);
72 g_assert_cmpint(i, ==, 0);
73 g_assert(endptr == str);
74 }
75
76
77 static void test_parse_uint_invalid(void)
78 {
79 unsigned long long i = 999;
80 char f = 'X';
81 char *endptr = &f;
82 const char *str = " \t xxx";
83 int r;
84
85 r = parse_uint(str, &i, &endptr, 0);
86
87 g_assert_cmpint(r, ==, -EINVAL);
88 g_assert_cmpint(i, ==, 0);
89 g_assert(endptr == str);
90 }
91
92
93 static void test_parse_uint_trailing(void)
94 {
95 unsigned long long i = 999;
96 char f = 'X';
97 char *endptr = &f;
98 const char *str = "123xxx";
99 int r;
100
101 r = parse_uint(str, &i, &endptr, 0);
102
103 g_assert_cmpint(r, ==, 0);
104 g_assert_cmpint(i, ==, 123);
105 g_assert(endptr == str + 3);
106 }
107
108 static void test_parse_uint_correct(void)
109 {
110 unsigned long long i = 999;
111 char f = 'X';
112 char *endptr = &f;
113 const char *str = "123";
114 int r;
115
116 r = parse_uint(str, &i, &endptr, 0);
117
118 g_assert_cmpint(r, ==, 0);
119 g_assert_cmpint(i, ==, 123);
120 g_assert(endptr == str + strlen(str));
121 }
122
123 static void test_parse_uint_octal(void)
124 {
125 unsigned long long i = 999;
126 char f = 'X';
127 char *endptr = &f;
128 const char *str = "0123";
129 int r;
130
131 r = parse_uint(str, &i, &endptr, 0);
132
133 g_assert_cmpint(r, ==, 0);
134 g_assert_cmpint(i, ==, 0123);
135 g_assert(endptr == str + strlen(str));
136 }
137
138 static void test_parse_uint_decimal(void)
139 {
140 unsigned long long i = 999;
141 char f = 'X';
142 char *endptr = &f;
143 const char *str = "0123";
144 int r;
145
146 r = parse_uint(str, &i, &endptr, 10);
147
148 g_assert_cmpint(r, ==, 0);
149 g_assert_cmpint(i, ==, 123);
150 g_assert(endptr == str + strlen(str));
151 }
152
153
154 static void test_parse_uint_llong_max(void)
155 {
156 unsigned long long i = 999;
157 char f = 'X';
158 char *endptr = &f;
159 char *str = g_strdup_printf("%llu", (unsigned long long)LLONG_MAX + 1);
160 int r;
161
162 r = parse_uint(str, &i, &endptr, 0);
163
164 g_assert_cmpint(r, ==, 0);
165 g_assert_cmpint(i, ==, (unsigned long long)LLONG_MAX + 1);
166 g_assert(endptr == str + strlen(str));
167
168 g_free(str);
169 }
170
171 static void test_parse_uint_overflow(void)
172 {
173 unsigned long long i = 999;
174 char f = 'X';
175 char *endptr = &f;
176 const char *str = "99999999999999999999999999999999999999";
177 int r;
178
179 r = parse_uint(str, &i, &endptr, 0);
180
181 g_assert_cmpint(r, ==, -ERANGE);
182 g_assert_cmpint(i, ==, ULLONG_MAX);
183 g_assert(endptr == str + strlen(str));
184 }
185
186 static void test_parse_uint_negative(void)
187 {
188 unsigned long long i = 999;
189 char f = 'X';
190 char *endptr = &f;
191 const char *str = " \t -321";
192 int r;
193
194 r = parse_uint(str, &i, &endptr, 0);
195
196 g_assert_cmpint(r, ==, -ERANGE);
197 g_assert_cmpint(i, ==, 0);
198 g_assert(endptr == str + strlen(str));
199 }
200
201
202 static void test_parse_uint_full_trailing(void)
203 {
204 unsigned long long i = 999;
205 const char *str = "123xxx";
206 int r;
207
208 r = parse_uint_full(str, &i, 0);
209
210 g_assert_cmpint(r, ==, -EINVAL);
211 g_assert_cmpint(i, ==, 0);
212 }
213
214 static void test_parse_uint_full_correct(void)
215 {
216 unsigned long long i = 999;
217 const char *str = "123";
218 int r;
219
220 r = parse_uint_full(str, &i, 0);
221
222 g_assert_cmpint(r, ==, 0);
223 g_assert_cmpint(i, ==, 123);
224 }
225
226 static void test_qemu_strtoi_correct(void)
227 {
228 const char *str = "12345 foo";
229 char f = 'X';
230 const char *endptr = &f;
231 int res = 999;
232 int err;
233
234 err = qemu_strtoi(str, &endptr, 0, &res);
235
236 g_assert_cmpint(err, ==, 0);
237 g_assert_cmpint(res, ==, 12345);
238 g_assert(endptr == str + 5);
239 }
240
241 static void test_qemu_strtoi_null(void)
242 {
243 char f = 'X';
244 const char *endptr = &f;
245 int res = 999;
246 int err;
247
248 err = qemu_strtoi(NULL, &endptr, 0, &res);
249
250 g_assert_cmpint(err, ==, -EINVAL);
251 g_assert(endptr == NULL);
252 }
253
254 static void test_qemu_strtoi_empty(void)
255 {
256 const char *str = "";
257 char f = 'X';
258 const char *endptr = &f;
259 int res = 999;
260 int err;
261
262 err = qemu_strtoi(str, &endptr, 0, &res);
263
264 g_assert_cmpint(err, ==, -EINVAL);
265 g_assert(endptr == str);
266 }
267
268 static void test_qemu_strtoi_whitespace(void)
269 {
270 const char *str = " \t ";
271 char f = 'X';
272 const char *endptr = &f;
273 int res = 999;
274 int err;
275
276 err = qemu_strtoi(str, &endptr, 0, &res);
277
278 g_assert_cmpint(err, ==, -EINVAL);
279 g_assert(endptr == str);
280 }
281
282 static void test_qemu_strtoi_invalid(void)
283 {
284 const char *str = " xxxx \t abc";
285 char f = 'X';
286 const char *endptr = &f;
287 int res = 999;
288 int err;
289
290 err = qemu_strtoi(str, &endptr, 0, &res);
291
292 g_assert_cmpint(err, ==, -EINVAL);
293 g_assert(endptr == str);
294 }
295
296 static void test_qemu_strtoi_trailing(void)
297 {
298 const char *str = "123xxx";
299 char f = 'X';
300 const char *endptr = &f;
301 int res = 999;
302 int err;
303
304 err = qemu_strtoi(str, &endptr, 0, &res);
305
306 g_assert_cmpint(err, ==, 0);
307 g_assert_cmpint(res, ==, 123);
308 g_assert(endptr == str + 3);
309 }
310
311 static void test_qemu_strtoi_octal(void)
312 {
313 const char *str = "0123";
314 char f = 'X';
315 const char *endptr = &f;
316 int res = 999;
317 int err;
318
319 err = qemu_strtoi(str, &endptr, 8, &res);
320
321 g_assert_cmpint(err, ==, 0);
322 g_assert_cmpint(res, ==, 0123);
323 g_assert(endptr == str + strlen(str));
324
325 res = 999;
326 endptr = &f;
327 err = qemu_strtoi(str, &endptr, 0, &res);
328
329 g_assert_cmpint(err, ==, 0);
330 g_assert_cmpint(res, ==, 0123);
331 g_assert(endptr == str + strlen(str));
332 }
333
334 static void test_qemu_strtoi_decimal(void)
335 {
336 const char *str = "0123";
337 char f = 'X';
338 const char *endptr = &f;
339 int res = 999;
340 int err;
341
342 err = qemu_strtoi(str, &endptr, 10, &res);
343
344 g_assert_cmpint(err, ==, 0);
345 g_assert_cmpint(res, ==, 123);
346 g_assert(endptr == str + strlen(str));
347
348 str = "123";
349 res = 999;
350 endptr = &f;
351 err = qemu_strtoi(str, &endptr, 0, &res);
352
353 g_assert_cmpint(err, ==, 0);
354 g_assert_cmpint(res, ==, 123);
355 g_assert(endptr == str + strlen(str));
356 }
357
358 static void test_qemu_strtoi_hex(void)
359 {
360 const char *str = "0123";
361 char f = 'X';
362 const char *endptr = &f;
363 int res = 999;
364 int err;
365
366 err = qemu_strtoi(str, &endptr, 16, &res);
367
368 g_assert_cmpint(err, ==, 0);
369 g_assert_cmpint(res, ==, 0x123);
370 g_assert(endptr == str + strlen(str));
371
372 str = "0x123";
373 res = 999;
374 endptr = &f;
375 err = qemu_strtoi(str, &endptr, 0, &res);
376
377 g_assert_cmpint(err, ==, 0);
378 g_assert_cmpint(res, ==, 0x123);
379 g_assert(endptr == str + strlen(str));
380 }
381
382 static void test_qemu_strtoi_max(void)
383 {
384 char *str = g_strdup_printf("%d", INT_MAX);
385 char f = 'X';
386 const char *endptr = &f;
387 int res = 999;
388 int err;
389
390 err = qemu_strtoi(str, &endptr, 0, &res);
391
392 g_assert_cmpint(err, ==, 0);
393 g_assert_cmpint(res, ==, INT_MAX);
394 g_assert(endptr == str + strlen(str));
395 g_free(str);
396 }
397
398 static void test_qemu_strtoi_overflow(void)
399 {
400 char *str = g_strdup_printf("%lld", (long long)INT_MAX + 1ll);
401 char f = 'X';
402 const char *endptr = &f;
403 int res = 999;
404 int err;
405
406 err = qemu_strtoi(str, &endptr, 0, &res);
407
408 g_assert_cmpint(err, ==, -ERANGE);
409 g_assert_cmpint(res, ==, INT_MAX);
410 g_assert(endptr == str + strlen(str));
411 g_free(str);
412 }
413
414 static void test_qemu_strtoi_underflow(void)
415 {
416 char *str = g_strdup_printf("%lld", (long long)INT_MIN - 1ll);
417 char f = 'X';
418 const char *endptr = &f;
419 int res = 999;
420 int err;
421
422 err = qemu_strtoi(str, &endptr, 0, &res);
423
424 g_assert_cmpint(err, ==, -ERANGE);
425 g_assert_cmpint(res, ==, INT_MIN);
426 g_assert(endptr == str + strlen(str));
427 g_free(str);
428 }
429
430 static void test_qemu_strtoi_negative(void)
431 {
432 const char *str = " \t -321";
433 char f = 'X';
434 const char *endptr = &f;
435 int res = 999;
436 int err;
437
438 err = qemu_strtoi(str, &endptr, 0, &res);
439
440 g_assert_cmpint(err, ==, 0);
441 g_assert_cmpint(res, ==, -321);
442 g_assert(endptr == str + strlen(str));
443 }
444
445 static void test_qemu_strtoi_full_correct(void)
446 {
447 const char *str = "123";
448 int res = 999;
449 int err;
450
451 err = qemu_strtoi(str, NULL, 0, &res);
452
453 g_assert_cmpint(err, ==, 0);
454 g_assert_cmpint(res, ==, 123);
455 }
456
457 static void test_qemu_strtoi_full_null(void)
458 {
459 char f = 'X';
460 const char *endptr = &f;
461 int res = 999;
462 int err;
463
464 err = qemu_strtoi(NULL, &endptr, 0, &res);
465
466 g_assert_cmpint(err, ==, -EINVAL);
467 g_assert(endptr == NULL);
468 }
469
470 static void test_qemu_strtoi_full_empty(void)
471 {
472 const char *str = "";
473 int res = 999L;
474 int err;
475
476 err = qemu_strtoi(str, NULL, 0, &res);
477
478 g_assert_cmpint(err, ==, -EINVAL);
479 }
480
481 static void test_qemu_strtoi_full_negative(void)
482 {
483 const char *str = " \t -321";
484 int res = 999;
485 int err;
486
487 err = qemu_strtoi(str, NULL, 0, &res);
488
489 g_assert_cmpint(err, ==, 0);
490 g_assert_cmpint(res, ==, -321);
491 }
492
493 static void test_qemu_strtoi_full_trailing(void)
494 {
495 const char *str = "123xxx";
496 int res;
497 int err;
498
499 err = qemu_strtoi(str, NULL, 0, &res);
500
501 g_assert_cmpint(err, ==, -EINVAL);
502 }
503
504 static void test_qemu_strtoi_full_max(void)
505 {
506 char *str = g_strdup_printf("%d", INT_MAX);
507 int res;
508 int err;
509
510 err = qemu_strtoi(str, NULL, 0, &res);
511
512 g_assert_cmpint(err, ==, 0);
513 g_assert_cmpint(res, ==, INT_MAX);
514 g_free(str);
515 }
516
517 static void test_qemu_strtoui_correct(void)
518 {
519 const char *str = "12345 foo";
520 char f = 'X';
521 const char *endptr = &f;
522 unsigned int res = 999;
523 int err;
524
525 err = qemu_strtoui(str, &endptr, 0, &res);
526
527 g_assert_cmpint(err, ==, 0);
528 g_assert_cmpuint(res, ==, 12345);
529 g_assert(endptr == str + 5);
530 }
531
532 static void test_qemu_strtoui_null(void)
533 {
534 char f = 'X';
535 const char *endptr = &f;
536 unsigned int res = 999;
537 int err;
538
539 err = qemu_strtoui(NULL, &endptr, 0, &res);
540
541 g_assert_cmpint(err, ==, -EINVAL);
542 g_assert(endptr == NULL);
543 }
544
545 static void test_qemu_strtoui_empty(void)
546 {
547 const char *str = "";
548 char f = 'X';
549 const char *endptr = &f;
550 unsigned int res = 999;
551 int err;
552
553 err = qemu_strtoui(str, &endptr, 0, &res);
554
555 g_assert_cmpint(err, ==, -EINVAL);
556 g_assert(endptr == str);
557 }
558
559 static void test_qemu_strtoui_whitespace(void)
560 {
561 const char *str = " \t ";
562 char f = 'X';
563 const char *endptr = &f;
564 unsigned int res = 999;
565 int err;
566
567 err = qemu_strtoui(str, &endptr, 0, &res);
568
569 g_assert_cmpint(err, ==, -EINVAL);
570 g_assert(endptr == str);
571 }
572
573 static void test_qemu_strtoui_invalid(void)
574 {
575 const char *str = " xxxx \t abc";
576 char f = 'X';
577 const char *endptr = &f;
578 unsigned int res = 999;
579 int err;
580
581 err = qemu_strtoui(str, &endptr, 0, &res);
582
583 g_assert_cmpint(err, ==, -EINVAL);
584 g_assert(endptr == str);
585 }
586
587 static void test_qemu_strtoui_trailing(void)
588 {
589 const char *str = "123xxx";
590 char f = 'X';
591 const char *endptr = &f;
592 unsigned int res = 999;
593 int err;
594
595 err = qemu_strtoui(str, &endptr, 0, &res);
596
597 g_assert_cmpint(err, ==, 0);
598 g_assert_cmpuint(res, ==, 123);
599 g_assert(endptr == str + 3);
600 }
601
602 static void test_qemu_strtoui_octal(void)
603 {
604 const char *str = "0123";
605 char f = 'X';
606 const char *endptr = &f;
607 unsigned int res = 999;
608 int err;
609
610 err = qemu_strtoui(str, &endptr, 8, &res);
611
612 g_assert_cmpint(err, ==, 0);
613 g_assert_cmpuint(res, ==, 0123);
614 g_assert(endptr == str + strlen(str));
615
616 res = 999;
617 endptr = &f;
618 err = qemu_strtoui(str, &endptr, 0, &res);
619
620 g_assert_cmpint(err, ==, 0);
621 g_assert_cmpuint(res, ==, 0123);
622 g_assert(endptr == str + strlen(str));
623 }
624
625 static void test_qemu_strtoui_decimal(void)
626 {
627 const char *str = "0123";
628 char f = 'X';
629 const char *endptr = &f;
630 unsigned int res = 999;
631 int err;
632
633 err = qemu_strtoui(str, &endptr, 10, &res);
634
635 g_assert_cmpint(err, ==, 0);
636 g_assert_cmpuint(res, ==, 123);
637 g_assert(endptr == str + strlen(str));
638
639 str = "123";
640 res = 999;
641 endptr = &f;
642 err = qemu_strtoui(str, &endptr, 0, &res);
643
644 g_assert_cmpint(err, ==, 0);
645 g_assert_cmpuint(res, ==, 123);
646 g_assert(endptr == str + strlen(str));
647 }
648
649 static void test_qemu_strtoui_hex(void)
650 {
651 const char *str = "0123";
652 char f = 'X';
653 const char *endptr = &f;
654 unsigned int res = 999;
655 int err;
656
657 err = qemu_strtoui(str, &endptr, 16, &res);
658
659 g_assert_cmpint(err, ==, 0);
660 g_assert_cmphex(res, ==, 0x123);
661 g_assert(endptr == str + strlen(str));
662
663 str = "0x123";
664 res = 999;
665 endptr = &f;
666 err = qemu_strtoui(str, &endptr, 0, &res);
667
668 g_assert_cmpint(err, ==, 0);
669 g_assert_cmphex(res, ==, 0x123);
670 g_assert(endptr == str + strlen(str));
671 }
672
673 static void test_qemu_strtoui_max(void)
674 {
675 char *str = g_strdup_printf("%u", UINT_MAX);
676 char f = 'X';
677 const char *endptr = &f;
678 unsigned int res = 999;
679 int err;
680
681 err = qemu_strtoui(str, &endptr, 0, &res);
682
683 g_assert_cmpint(err, ==, 0);
684 g_assert_cmphex(res, ==, UINT_MAX);
685 g_assert(endptr == str + strlen(str));
686 g_free(str);
687 }
688
689 static void test_qemu_strtoui_overflow(void)
690 {
691 char *str = g_strdup_printf("%lld", (long long)UINT_MAX + 1ll);
692 char f = 'X';
693 const char *endptr = &f;
694 unsigned int res = 999;
695 int err;
696
697 err = qemu_strtoui(str, &endptr, 0, &res);
698
699 g_assert_cmpint(err, ==, -ERANGE);
700 g_assert_cmphex(res, ==, UINT_MAX);
701 g_assert(endptr == str + strlen(str));
702 g_free(str);
703 }
704
705 static void test_qemu_strtoui_underflow(void)
706 {
707 char *str = g_strdup_printf("%lld", (long long)INT_MIN - 1ll);
708 char f = 'X';
709 const char *endptr = &f;
710 unsigned int res = 999;
711 int err;
712
713 err = qemu_strtoui(str, &endptr, 0, &res);
714
715 g_assert_cmpint(err, ==, -ERANGE);
716 g_assert_cmpuint(res, ==, (unsigned int)-1);
717 g_assert(endptr == str + strlen(str));
718 g_free(str);
719 }
720
721 static void test_qemu_strtoui_negative(void)
722 {
723 const char *str = " \t -321";
724 char f = 'X';
725 const char *endptr = &f;
726 unsigned int res = 999;
727 int err;
728
729 err = qemu_strtoui(str, &endptr, 0, &res);
730
731 g_assert_cmpint(err, ==, 0);
732 g_assert_cmpuint(res, ==, (unsigned int)-321);
733 g_assert(endptr == str + strlen(str));
734 }
735
736 static void test_qemu_strtoui_full_correct(void)
737 {
738 const char *str = "123";
739 unsigned int res = 999;
740 int err;
741
742 err = qemu_strtoui(str, NULL, 0, &res);
743
744 g_assert_cmpint(err, ==, 0);
745 g_assert_cmpuint(res, ==, 123);
746 }
747
748 static void test_qemu_strtoui_full_null(void)
749 {
750 unsigned int res = 999;
751 int err;
752
753 err = qemu_strtoui(NULL, NULL, 0, &res);
754
755 g_assert_cmpint(err, ==, -EINVAL);
756 }
757
758 static void test_qemu_strtoui_full_empty(void)
759 {
760 const char *str = "";
761 unsigned int res = 999;
762 int err;
763
764 err = qemu_strtoui(str, NULL, 0, &res);
765
766 g_assert_cmpint(err, ==, -EINVAL);
767 }
768 static void test_qemu_strtoui_full_negative(void)
769 {
770 const char *str = " \t -321";
771 unsigned int res = 999;
772 int err;
773
774 err = qemu_strtoui(str, NULL, 0, &res);
775 g_assert_cmpint(err, ==, 0);
776 g_assert_cmpuint(res, ==, (unsigned int)-321);
777 }
778
779 static void test_qemu_strtoui_full_trailing(void)
780 {
781 const char *str = "123xxx";
782 unsigned int res;
783 int err;
784
785 err = qemu_strtoui(str, NULL, 0, &res);
786
787 g_assert_cmpint(err, ==, -EINVAL);
788 }
789
790 static void test_qemu_strtoui_full_max(void)
791 {
792 char *str = g_strdup_printf("%u", UINT_MAX);
793 unsigned int res = 999;
794 int err;
795
796 err = qemu_strtoui(str, NULL, 0, &res);
797
798 g_assert_cmpint(err, ==, 0);
799 g_assert_cmphex(res, ==, UINT_MAX);
800 g_free(str);
801 }
802
803 static void test_qemu_strtol_correct(void)
804 {
805 const char *str = "12345 foo";
806 char f = 'X';
807 const char *endptr = &f;
808 long res = 999;
809 int err;
810
811 err = qemu_strtol(str, &endptr, 0, &res);
812
813 g_assert_cmpint(err, ==, 0);
814 g_assert_cmpint(res, ==, 12345);
815 g_assert(endptr == str + 5);
816 }
817
818 static void test_qemu_strtol_null(void)
819 {
820 char f = 'X';
821 const char *endptr = &f;
822 long res = 999;
823 int err;
824
825 err = qemu_strtol(NULL, &endptr, 0, &res);
826
827 g_assert_cmpint(err, ==, -EINVAL);
828 g_assert(endptr == NULL);
829 }
830
831 static void test_qemu_strtol_empty(void)
832 {
833 const char *str = "";
834 char f = 'X';
835 const char *endptr = &f;
836 long res = 999;
837 int err;
838
839 err = qemu_strtol(str, &endptr, 0, &res);
840
841 g_assert_cmpint(err, ==, -EINVAL);
842 g_assert(endptr == str);
843 }
844
845 static void test_qemu_strtol_whitespace(void)
846 {
847 const char *str = " \t ";
848 char f = 'X';
849 const char *endptr = &f;
850 long res = 999;
851 int err;
852
853 err = qemu_strtol(str, &endptr, 0, &res);
854
855 g_assert_cmpint(err, ==, -EINVAL);
856 g_assert(endptr == str);
857 }
858
859 static void test_qemu_strtol_invalid(void)
860 {
861 const char *str = " xxxx \t abc";
862 char f = 'X';
863 const char *endptr = &f;
864 long res = 999;
865 int err;
866
867 err = qemu_strtol(str, &endptr, 0, &res);
868
869 g_assert_cmpint(err, ==, -EINVAL);
870 g_assert(endptr == str);
871 }
872
873 static void test_qemu_strtol_trailing(void)
874 {
875 const char *str = "123xxx";
876 char f = 'X';
877 const char *endptr = &f;
878 long res = 999;
879 int err;
880
881 err = qemu_strtol(str, &endptr, 0, &res);
882
883 g_assert_cmpint(err, ==, 0);
884 g_assert_cmpint(res, ==, 123);
885 g_assert(endptr == str + 3);
886 }
887
888 static void test_qemu_strtol_octal(void)
889 {
890 const char *str = "0123";
891 char f = 'X';
892 const char *endptr = &f;
893 long res = 999;
894 int err;
895
896 err = qemu_strtol(str, &endptr, 8, &res);
897
898 g_assert_cmpint(err, ==, 0);
899 g_assert_cmpint(res, ==, 0123);
900 g_assert(endptr == str + strlen(str));
901
902 res = 999;
903 endptr = &f;
904 err = qemu_strtol(str, &endptr, 0, &res);
905
906 g_assert_cmpint(err, ==, 0);
907 g_assert_cmpint(res, ==, 0123);
908 g_assert(endptr == str + strlen(str));
909 }
910
911 static void test_qemu_strtol_decimal(void)
912 {
913 const char *str = "0123";
914 char f = 'X';
915 const char *endptr = &f;
916 long res = 999;
917 int err;
918
919 err = qemu_strtol(str, &endptr, 10, &res);
920
921 g_assert_cmpint(err, ==, 0);
922 g_assert_cmpint(res, ==, 123);
923 g_assert(endptr == str + strlen(str));
924
925 str = "123";
926 res = 999;
927 endptr = &f;
928 err = qemu_strtol(str, &endptr, 0, &res);
929
930 g_assert_cmpint(err, ==, 0);
931 g_assert_cmpint(res, ==, 123);
932 g_assert(endptr == str + strlen(str));
933 }
934
935 static void test_qemu_strtol_hex(void)
936 {
937 const char *str = "0123";
938 char f = 'X';
939 const char *endptr = &f;
940 long res = 999;
941 int err;
942
943 err = qemu_strtol(str, &endptr, 16, &res);
944
945 g_assert_cmpint(err, ==, 0);
946 g_assert_cmpint(res, ==, 0x123);
947 g_assert(endptr == str + strlen(str));
948
949 str = "0x123";
950 res = 999;
951 endptr = &f;
952 err = qemu_strtol(str, &endptr, 0, &res);
953
954 g_assert_cmpint(err, ==, 0);
955 g_assert_cmpint(res, ==, 0x123);
956 g_assert(endptr == str + strlen(str));
957 }
958
959 static void test_qemu_strtol_max(void)
960 {
961 char *str = g_strdup_printf("%ld", LONG_MAX);
962 char f = 'X';
963 const char *endptr = &f;
964 long res = 999;
965 int err;
966
967 err = qemu_strtol(str, &endptr, 0, &res);
968
969 g_assert_cmpint(err, ==, 0);
970 g_assert_cmpint(res, ==, LONG_MAX);
971 g_assert(endptr == str + strlen(str));
972 g_free(str);
973 }
974
975 static void test_qemu_strtol_overflow(void)
976 {
977 const char *str = "99999999999999999999999999999999999999999999";
978 char f = 'X';
979 const char *endptr = &f;
980 long res = 999;
981 int err;
982
983 err = qemu_strtol(str, &endptr, 0, &res);
984
985 g_assert_cmpint(err, ==, -ERANGE);
986 g_assert_cmpint(res, ==, LONG_MAX);
987 g_assert(endptr == str + strlen(str));
988 }
989
990 static void test_qemu_strtol_underflow(void)
991 {
992 const char *str = "-99999999999999999999999999999999999999999999";
993 char f = 'X';
994 const char *endptr = &f;
995 long res = 999;
996 int err;
997
998 err = qemu_strtol(str, &endptr, 0, &res);
999
1000 g_assert_cmpint(err, ==, -ERANGE);
1001 g_assert_cmpint(res, ==, LONG_MIN);
1002 g_assert(endptr == str + strlen(str));
1003 }
1004
1005 static void test_qemu_strtol_negative(void)
1006 {
1007 const char *str = " \t -321";
1008 char f = 'X';
1009 const char *endptr = &f;
1010 long res = 999;
1011 int err;
1012
1013 err = qemu_strtol(str, &endptr, 0, &res);
1014
1015 g_assert_cmpint(err, ==, 0);
1016 g_assert_cmpint(res, ==, -321);
1017 g_assert(endptr == str + strlen(str));
1018 }
1019
1020 static void test_qemu_strtol_full_correct(void)
1021 {
1022 const char *str = "123";
1023 long res = 999;
1024 int err;
1025
1026 err = qemu_strtol(str, NULL, 0, &res);
1027
1028 g_assert_cmpint(err, ==, 0);
1029 g_assert_cmpint(res, ==, 123);
1030 }
1031
1032 static void test_qemu_strtol_full_null(void)
1033 {
1034 char f = 'X';
1035 const char *endptr = &f;
1036 long res = 999;
1037 int err;
1038
1039 err = qemu_strtol(NULL, &endptr, 0, &res);
1040
1041 g_assert_cmpint(err, ==, -EINVAL);
1042 g_assert(endptr == NULL);
1043 }
1044
1045 static void test_qemu_strtol_full_empty(void)
1046 {
1047 const char *str = "";
1048 long res = 999L;
1049 int err;
1050
1051 err = qemu_strtol(str, NULL, 0, &res);
1052
1053 g_assert_cmpint(err, ==, -EINVAL);
1054 }
1055
1056 static void test_qemu_strtol_full_negative(void)
1057 {
1058 const char *str = " \t -321";
1059 long res = 999;
1060 int err;
1061
1062 err = qemu_strtol(str, NULL, 0, &res);
1063
1064 g_assert_cmpint(err, ==, 0);
1065 g_assert_cmpint(res, ==, -321);
1066 }
1067
1068 static void test_qemu_strtol_full_trailing(void)
1069 {
1070 const char *str = "123xxx";
1071 long res;
1072 int err;
1073
1074 err = qemu_strtol(str, NULL, 0, &res);
1075
1076 g_assert_cmpint(err, ==, -EINVAL);
1077 }
1078
1079 static void test_qemu_strtol_full_max(void)
1080 {
1081 char *str = g_strdup_printf("%ld", LONG_MAX);
1082 long res;
1083 int err;
1084
1085 err = qemu_strtol(str, NULL, 0, &res);
1086
1087 g_assert_cmpint(err, ==, 0);
1088 g_assert_cmpint(res, ==, LONG_MAX);
1089 g_free(str);
1090 }
1091
1092 static void test_qemu_strtoul_correct(void)
1093 {
1094 const char *str = "12345 foo";
1095 char f = 'X';
1096 const char *endptr = &f;
1097 unsigned long res = 999;
1098 int err;
1099
1100 err = qemu_strtoul(str, &endptr, 0, &res);
1101
1102 g_assert_cmpint(err, ==, 0);
1103 g_assert_cmpuint(res, ==, 12345);
1104 g_assert(endptr == str + 5);
1105 }
1106
1107 static void test_qemu_strtoul_null(void)
1108 {
1109 char f = 'X';
1110 const char *endptr = &f;
1111 unsigned long res = 999;
1112 int err;
1113
1114 err = qemu_strtoul(NULL, &endptr, 0, &res);
1115
1116 g_assert_cmpint(err, ==, -EINVAL);
1117 g_assert(endptr == NULL);
1118 }
1119
1120 static void test_qemu_strtoul_empty(void)
1121 {
1122 const char *str = "";
1123 char f = 'X';
1124 const char *endptr = &f;
1125 unsigned long res = 999;
1126 int err;
1127
1128 err = qemu_strtoul(str, &endptr, 0, &res);
1129
1130 g_assert_cmpint(err, ==, -EINVAL);
1131 g_assert(endptr == str);
1132 }
1133
1134 static void test_qemu_strtoul_whitespace(void)
1135 {
1136 const char *str = " \t ";
1137 char f = 'X';
1138 const char *endptr = &f;
1139 unsigned long res = 999;
1140 int err;
1141
1142 err = qemu_strtoul(str, &endptr, 0, &res);
1143
1144 g_assert_cmpint(err, ==, -EINVAL);
1145 g_assert(endptr == str);
1146 }
1147
1148 static void test_qemu_strtoul_invalid(void)
1149 {
1150 const char *str = " xxxx \t abc";
1151 char f = 'X';
1152 const char *endptr = &f;
1153 unsigned long res = 999;
1154 int err;
1155
1156 err = qemu_strtoul(str, &endptr, 0, &res);
1157
1158 g_assert_cmpint(err, ==, -EINVAL);
1159 g_assert(endptr == str);
1160 }
1161
1162 static void test_qemu_strtoul_trailing(void)
1163 {
1164 const char *str = "123xxx";
1165 char f = 'X';
1166 const char *endptr = &f;
1167 unsigned long res = 999;
1168 int err;
1169
1170 err = qemu_strtoul(str, &endptr, 0, &res);
1171
1172 g_assert_cmpint(err, ==, 0);
1173 g_assert_cmpuint(res, ==, 123);
1174 g_assert(endptr == str + 3);
1175 }
1176
1177 static void test_qemu_strtoul_octal(void)
1178 {
1179 const char *str = "0123";
1180 char f = 'X';
1181 const char *endptr = &f;
1182 unsigned long res = 999;
1183 int err;
1184
1185 err = qemu_strtoul(str, &endptr, 8, &res);
1186
1187 g_assert_cmpint(err, ==, 0);
1188 g_assert_cmpuint(res, ==, 0123);
1189 g_assert(endptr == str + strlen(str));
1190
1191 res = 999;
1192 endptr = &f;
1193 err = qemu_strtoul(str, &endptr, 0, &res);
1194
1195 g_assert_cmpint(err, ==, 0);
1196 g_assert_cmpuint(res, ==, 0123);
1197 g_assert(endptr == str + strlen(str));
1198 }
1199
1200 static void test_qemu_strtoul_decimal(void)
1201 {
1202 const char *str = "0123";
1203 char f = 'X';
1204 const char *endptr = &f;
1205 unsigned long res = 999;
1206 int err;
1207
1208 err = qemu_strtoul(str, &endptr, 10, &res);
1209
1210 g_assert_cmpint(err, ==, 0);
1211 g_assert_cmpuint(res, ==, 123);
1212 g_assert(endptr == str + strlen(str));
1213
1214 str = "123";
1215 res = 999;
1216 endptr = &f;
1217 err = qemu_strtoul(str, &endptr, 0, &res);
1218
1219 g_assert_cmpint(err, ==, 0);
1220 g_assert_cmpuint(res, ==, 123);
1221 g_assert(endptr == str + strlen(str));
1222 }
1223
1224 static void test_qemu_strtoul_hex(void)
1225 {
1226 const char *str = "0123";
1227 char f = 'X';
1228 const char *endptr = &f;
1229 unsigned long res = 999;
1230 int err;
1231
1232 err = qemu_strtoul(str, &endptr, 16, &res);
1233
1234 g_assert_cmpint(err, ==, 0);
1235 g_assert_cmphex(res, ==, 0x123);
1236 g_assert(endptr == str + strlen(str));
1237
1238 str = "0x123";
1239 res = 999;
1240 endptr = &f;
1241 err = qemu_strtoul(str, &endptr, 0, &res);
1242
1243 g_assert_cmpint(err, ==, 0);
1244 g_assert_cmphex(res, ==, 0x123);
1245 g_assert(endptr == str + strlen(str));
1246 }
1247
1248 static void test_qemu_strtoul_max(void)
1249 {
1250 char *str = g_strdup_printf("%lu", ULONG_MAX);
1251 char f = 'X';
1252 const char *endptr = &f;
1253 unsigned long res = 999;
1254 int err;
1255
1256 err = qemu_strtoul(str, &endptr, 0, &res);
1257
1258 g_assert_cmpint(err, ==, 0);
1259 g_assert_cmphex(res, ==, ULONG_MAX);
1260 g_assert(endptr == str + strlen(str));
1261 g_free(str);
1262 }
1263
1264 static void test_qemu_strtoul_overflow(void)
1265 {
1266 const char *str = "99999999999999999999999999999999999999999999";
1267 char f = 'X';
1268 const char *endptr = &f;
1269 unsigned long res = 999;
1270 int err;
1271
1272 err = qemu_strtoul(str, &endptr, 0, &res);
1273
1274 g_assert_cmpint(err, ==, -ERANGE);
1275 g_assert_cmphex(res, ==, ULONG_MAX);
1276 g_assert(endptr == str + strlen(str));
1277 }
1278
1279 static void test_qemu_strtoul_underflow(void)
1280 {
1281 const char *str = "-99999999999999999999999999999999999999999999";
1282 char f = 'X';
1283 const char *endptr = &f;
1284 unsigned long res = 999;
1285 int err;
1286
1287 err = qemu_strtoul(str, &endptr, 0, &res);
1288
1289 g_assert_cmpint(err, ==, -ERANGE);
1290 g_assert_cmpuint(res, ==, -1ul);
1291 g_assert(endptr == str + strlen(str));
1292 }
1293
1294 static void test_qemu_strtoul_negative(void)
1295 {
1296 const char *str = " \t -321";
1297 char f = 'X';
1298 const char *endptr = &f;
1299 unsigned long res = 999;
1300 int err;
1301
1302 err = qemu_strtoul(str, &endptr, 0, &res);
1303
1304 g_assert_cmpint(err, ==, 0);
1305 g_assert_cmpuint(res, ==, -321ul);
1306 g_assert(endptr == str + strlen(str));
1307 }
1308
1309 static void test_qemu_strtoul_full_correct(void)
1310 {
1311 const char *str = "123";
1312 unsigned long res = 999;
1313 int err;
1314
1315 err = qemu_strtoul(str, NULL, 0, &res);
1316
1317 g_assert_cmpint(err, ==, 0);
1318 g_assert_cmpuint(res, ==, 123);
1319 }
1320
1321 static void test_qemu_strtoul_full_null(void)
1322 {
1323 unsigned long res = 999;
1324 int err;
1325
1326 err = qemu_strtoul(NULL, NULL, 0, &res);
1327
1328 g_assert_cmpint(err, ==, -EINVAL);
1329 }
1330
1331 static void test_qemu_strtoul_full_empty(void)
1332 {
1333 const char *str = "";
1334 unsigned long res = 999;
1335 int err;
1336
1337 err = qemu_strtoul(str, NULL, 0, &res);
1338
1339 g_assert_cmpint(err, ==, -EINVAL);
1340 }
1341 static void test_qemu_strtoul_full_negative(void)
1342 {
1343 const char *str = " \t -321";
1344 unsigned long res = 999;
1345 int err;
1346
1347 err = qemu_strtoul(str, NULL, 0, &res);
1348 g_assert_cmpint(err, ==, 0);
1349 g_assert_cmpuint(res, ==, -321ul);
1350 }
1351
1352 static void test_qemu_strtoul_full_trailing(void)
1353 {
1354 const char *str = "123xxx";
1355 unsigned long res;
1356 int err;
1357
1358 err = qemu_strtoul(str, NULL, 0, &res);
1359
1360 g_assert_cmpint(err, ==, -EINVAL);
1361 }
1362
1363 static void test_qemu_strtoul_full_max(void)
1364 {
1365 char *str = g_strdup_printf("%lu", ULONG_MAX);
1366 unsigned long res = 999;
1367 int err;
1368
1369 err = qemu_strtoul(str, NULL, 0, &res);
1370
1371 g_assert_cmpint(err, ==, 0);
1372 g_assert_cmphex(res, ==, ULONG_MAX);
1373 g_free(str);
1374 }
1375
1376 static void test_qemu_strtoi64_correct(void)
1377 {
1378 const char *str = "12345 foo";
1379 char f = 'X';
1380 const char *endptr = &f;
1381 int64_t res = 999;
1382 int err;
1383
1384 err = qemu_strtoi64(str, &endptr, 0, &res);
1385
1386 g_assert_cmpint(err, ==, 0);
1387 g_assert_cmpint(res, ==, 12345);
1388 g_assert(endptr == str + 5);
1389 }
1390
1391 static void test_qemu_strtoi64_null(void)
1392 {
1393 char f = 'X';
1394 const char *endptr = &f;
1395 int64_t res = 999;
1396 int err;
1397
1398 err = qemu_strtoi64(NULL, &endptr, 0, &res);
1399
1400 g_assert_cmpint(err, ==, -EINVAL);
1401 g_assert(endptr == NULL);
1402 }
1403
1404 static void test_qemu_strtoi64_empty(void)
1405 {
1406 const char *str = "";
1407 char f = 'X';
1408 const char *endptr = &f;
1409 int64_t res = 999;
1410 int err;
1411
1412 err = qemu_strtoi64(str, &endptr, 0, &res);
1413
1414 g_assert_cmpint(err, ==, -EINVAL);
1415 g_assert(endptr == str);
1416 }
1417
1418 static void test_qemu_strtoi64_whitespace(void)
1419 {
1420 const char *str = " \t ";
1421 char f = 'X';
1422 const char *endptr = &f;
1423 int64_t res = 999;
1424 int err;
1425
1426 err = qemu_strtoi64(str, &endptr, 0, &res);
1427
1428 g_assert_cmpint(err, ==, -EINVAL);
1429 g_assert(endptr == str);
1430 }
1431
1432 static void test_qemu_strtoi64_invalid(void)
1433 {
1434 const char *str = " xxxx \t abc";
1435 char f = 'X';
1436 const char *endptr = &f;
1437 int64_t res = 999;
1438 int err;
1439
1440 err = qemu_strtoi64(str, &endptr, 0, &res);
1441
1442 g_assert_cmpint(err, ==, -EINVAL);
1443 g_assert(endptr == str);
1444 }
1445
1446 static void test_qemu_strtoi64_trailing(void)
1447 {
1448 const char *str = "123xxx";
1449 char f = 'X';
1450 const char *endptr = &f;
1451 int64_t res = 999;
1452 int err;
1453
1454 err = qemu_strtoi64(str, &endptr, 0, &res);
1455
1456 g_assert_cmpint(err, ==, 0);
1457 g_assert_cmpint(res, ==, 123);
1458 g_assert(endptr == str + 3);
1459 }
1460
1461 static void test_qemu_strtoi64_octal(void)
1462 {
1463 const char *str = "0123";
1464 char f = 'X';
1465 const char *endptr = &f;
1466 int64_t res = 999;
1467 int err;
1468
1469 err = qemu_strtoi64(str, &endptr, 8, &res);
1470
1471 g_assert_cmpint(err, ==, 0);
1472 g_assert_cmpint(res, ==, 0123);
1473 g_assert(endptr == str + strlen(str));
1474
1475 endptr = &f;
1476 res = 999;
1477 err = qemu_strtoi64(str, &endptr, 0, &res);
1478
1479 g_assert_cmpint(err, ==, 0);
1480 g_assert_cmpint(res, ==, 0123);
1481 g_assert(endptr == str + strlen(str));
1482 }
1483
1484 static void test_qemu_strtoi64_decimal(void)
1485 {
1486 const char *str = "0123";
1487 char f = 'X';
1488 const char *endptr = &f;
1489 int64_t res = 999;
1490 int err;
1491
1492 err = qemu_strtoi64(str, &endptr, 10, &res);
1493
1494 g_assert_cmpint(err, ==, 0);
1495 g_assert_cmpint(res, ==, 123);
1496 g_assert(endptr == str + strlen(str));
1497
1498 str = "123";
1499 endptr = &f;
1500 res = 999;
1501 err = qemu_strtoi64(str, &endptr, 0, &res);
1502
1503 g_assert_cmpint(err, ==, 0);
1504 g_assert_cmpint(res, ==, 123);
1505 g_assert(endptr == str + strlen(str));
1506 }
1507
1508 static void test_qemu_strtoi64_hex(void)
1509 {
1510 const char *str = "0123";
1511 char f = 'X';
1512 const char *endptr = &f;
1513 int64_t res = 999;
1514 int err;
1515
1516 err = qemu_strtoi64(str, &endptr, 16, &res);
1517
1518 g_assert_cmpint(err, ==, 0);
1519 g_assert_cmpint(res, ==, 0x123);
1520 g_assert(endptr == str + strlen(str));
1521
1522 str = "0x123";
1523 endptr = &f;
1524 res = 999;
1525 err = qemu_strtoi64(str, &endptr, 0, &res);
1526
1527 g_assert_cmpint(err, ==, 0);
1528 g_assert_cmpint(res, ==, 0x123);
1529 g_assert(endptr == str + strlen(str));
1530 }
1531
1532 static void test_qemu_strtoi64_max(void)
1533 {
1534 char *str = g_strdup_printf("%lld", LLONG_MAX);
1535 char f = 'X';
1536 const char *endptr = &f;
1537 int64_t res = 999;
1538 int err;
1539
1540 err = qemu_strtoi64(str, &endptr, 0, &res);
1541
1542 g_assert_cmpint(err, ==, 0);
1543 g_assert_cmpint(res, ==, LLONG_MAX);
1544 g_assert(endptr == str + strlen(str));
1545 g_free(str);
1546 }
1547
1548 static void test_qemu_strtoi64_overflow(void)
1549 {
1550 const char *str = "99999999999999999999999999999999999999999999";
1551 char f = 'X';
1552 const char *endptr = &f;
1553 int64_t res = 999;
1554 int err;
1555
1556 err = qemu_strtoi64(str, &endptr, 0, &res);
1557
1558 g_assert_cmpint(err, ==, -ERANGE);
1559 g_assert_cmpint(res, ==, LLONG_MAX);
1560 g_assert(endptr == str + strlen(str));
1561 }
1562
1563 static void test_qemu_strtoi64_underflow(void)
1564 {
1565 const char *str = "-99999999999999999999999999999999999999999999";
1566 char f = 'X';
1567 const char *endptr = &f;
1568 int64_t res = 999;
1569 int err;
1570
1571 err = qemu_strtoi64(str, &endptr, 0, &res);
1572
1573 g_assert_cmpint(err, ==, -ERANGE);
1574 g_assert_cmpint(res, ==, LLONG_MIN);
1575 g_assert(endptr == str + strlen(str));
1576 }
1577
1578 static void test_qemu_strtoi64_negative(void)
1579 {
1580 const char *str = " \t -321";
1581 char f = 'X';
1582 const char *endptr = &f;
1583 int64_t res = 999;
1584 int err;
1585
1586 err = qemu_strtoi64(str, &endptr, 0, &res);
1587
1588 g_assert_cmpint(err, ==, 0);
1589 g_assert_cmpint(res, ==, -321);
1590 g_assert(endptr == str + strlen(str));
1591 }
1592
1593 static void test_qemu_strtoi64_full_correct(void)
1594 {
1595 const char *str = "123";
1596 int64_t res = 999;
1597 int err;
1598
1599 err = qemu_strtoi64(str, NULL, 0, &res);
1600
1601 g_assert_cmpint(err, ==, 0);
1602 g_assert_cmpint(res, ==, 123);
1603 }
1604
1605 static void test_qemu_strtoi64_full_null(void)
1606 {
1607 int64_t res = 999;
1608 int err;
1609
1610 err = qemu_strtoi64(NULL, NULL, 0, &res);
1611
1612 g_assert_cmpint(err, ==, -EINVAL);
1613 }
1614
1615 static void test_qemu_strtoi64_full_empty(void)
1616 {
1617 const char *str = "";
1618 int64_t res = 999;
1619 int err;
1620
1621 err = qemu_strtoi64(str, NULL, 0, &res);
1622
1623 g_assert_cmpint(err, ==, -EINVAL);
1624 }
1625
1626 static void test_qemu_strtoi64_full_negative(void)
1627 {
1628 const char *str = " \t -321";
1629 int64_t res = 999;
1630 int err;
1631
1632 err = qemu_strtoi64(str, NULL, 0, &res);
1633
1634 g_assert_cmpint(err, ==, 0);
1635 g_assert_cmpint(res, ==, -321);
1636 }
1637
1638 static void test_qemu_strtoi64_full_trailing(void)
1639 {
1640 const char *str = "123xxx";
1641 int64_t res = 999;
1642 int err;
1643
1644 err = qemu_strtoi64(str, NULL, 0, &res);
1645
1646 g_assert_cmpint(err, ==, -EINVAL);
1647 }
1648
1649 static void test_qemu_strtoi64_full_max(void)
1650 {
1651
1652 char *str = g_strdup_printf("%lld", LLONG_MAX);
1653 int64_t res;
1654 int err;
1655
1656 err = qemu_strtoi64(str, NULL, 0, &res);
1657
1658 g_assert_cmpint(err, ==, 0);
1659 g_assert_cmpint(res, ==, LLONG_MAX);
1660 g_free(str);
1661 }
1662
1663 static void test_qemu_strtou64_correct(void)
1664 {
1665 const char *str = "12345 foo";
1666 char f = 'X';
1667 const char *endptr = &f;
1668 uint64_t res = 999;
1669 int err;
1670
1671 err = qemu_strtou64(str, &endptr, 0, &res);
1672
1673 g_assert_cmpint(err, ==, 0);
1674 g_assert_cmpuint(res, ==, 12345);
1675 g_assert(endptr == str + 5);
1676 }
1677
1678 static void test_qemu_strtou64_null(void)
1679 {
1680 char f = 'X';
1681 const char *endptr = &f;
1682 uint64_t res = 999;
1683 int err;
1684
1685 err = qemu_strtou64(NULL, &endptr, 0, &res);
1686
1687 g_assert_cmpint(err, ==, -EINVAL);
1688 g_assert(endptr == NULL);
1689 }
1690
1691 static void test_qemu_strtou64_empty(void)
1692 {
1693 const char *str = "";
1694 char f = 'X';
1695 const char *endptr = &f;
1696 uint64_t res = 999;
1697 int err;
1698
1699 err = qemu_strtou64(str, &endptr, 0, &res);
1700
1701 g_assert_cmpint(err, ==, -EINVAL);
1702 g_assert(endptr == str);
1703 }
1704
1705 static void test_qemu_strtou64_whitespace(void)
1706 {
1707 const char *str = " \t ";
1708 char f = 'X';
1709 const char *endptr = &f;
1710 uint64_t res = 999;
1711 int err;
1712
1713 err = qemu_strtou64(str, &endptr, 0, &res);
1714
1715 g_assert_cmpint(err, ==, -EINVAL);
1716 g_assert(endptr == str);
1717 }
1718
1719 static void test_qemu_strtou64_invalid(void)
1720 {
1721 const char *str = " xxxx \t abc";
1722 char f = 'X';
1723 const char *endptr = &f;
1724 uint64_t res = 999;
1725 int err;
1726
1727 err = qemu_strtou64(str, &endptr, 0, &res);
1728
1729 g_assert_cmpint(err, ==, -EINVAL);
1730 g_assert(endptr == str);
1731 }
1732
1733 static void test_qemu_strtou64_trailing(void)
1734 {
1735 const char *str = "123xxx";
1736 char f = 'X';
1737 const char *endptr = &f;
1738 uint64_t res = 999;
1739 int err;
1740
1741 err = qemu_strtou64(str, &endptr, 0, &res);
1742
1743 g_assert_cmpint(err, ==, 0);
1744 g_assert_cmpuint(res, ==, 123);
1745 g_assert(endptr == str + 3);
1746 }
1747
1748 static void test_qemu_strtou64_octal(void)
1749 {
1750 const char *str = "0123";
1751 char f = 'X';
1752 const char *endptr = &f;
1753 uint64_t res = 999;
1754 int err;
1755
1756 err = qemu_strtou64(str, &endptr, 8, &res);
1757
1758 g_assert_cmpint(err, ==, 0);
1759 g_assert_cmpuint(res, ==, 0123);
1760 g_assert(endptr == str + strlen(str));
1761
1762 endptr = &f;
1763 res = 999;
1764 err = qemu_strtou64(str, &endptr, 0, &res);
1765
1766 g_assert_cmpint(err, ==, 0);
1767 g_assert_cmpuint(res, ==, 0123);
1768 g_assert(endptr == str + strlen(str));
1769 }
1770
1771 static void test_qemu_strtou64_decimal(void)
1772 {
1773 const char *str = "0123";
1774 char f = 'X';
1775 const char *endptr = &f;
1776 uint64_t res = 999;
1777 int err;
1778
1779 err = qemu_strtou64(str, &endptr, 10, &res);
1780
1781 g_assert_cmpint(err, ==, 0);
1782 g_assert_cmpuint(res, ==, 123);
1783 g_assert(endptr == str + strlen(str));
1784
1785 str = "123";
1786 endptr = &f;
1787 res = 999;
1788 err = qemu_strtou64(str, &endptr, 0, &res);
1789
1790 g_assert_cmpint(err, ==, 0);
1791 g_assert_cmpuint(res, ==, 123);
1792 g_assert(endptr == str + strlen(str));
1793 }
1794
1795 static void test_qemu_strtou64_hex(void)
1796 {
1797 const char *str = "0123";
1798 char f = 'X';
1799 const char *endptr = &f;
1800 uint64_t res = 999;
1801 int err;
1802
1803 err = qemu_strtou64(str, &endptr, 16, &res);
1804
1805 g_assert_cmpint(err, ==, 0);
1806 g_assert_cmphex(res, ==, 0x123);
1807 g_assert(endptr == str + strlen(str));
1808
1809 str = "0x123";
1810 endptr = &f;
1811 res = 999;
1812 err = qemu_strtou64(str, &endptr, 0, &res);
1813
1814 g_assert_cmpint(err, ==, 0);
1815 g_assert_cmphex(res, ==, 0x123);
1816 g_assert(endptr == str + strlen(str));
1817 }
1818
1819 static void test_qemu_strtou64_max(void)
1820 {
1821 char *str = g_strdup_printf("%llu", ULLONG_MAX);
1822 char f = 'X';
1823 const char *endptr = &f;
1824 uint64_t res = 999;
1825 int err;
1826
1827 err = qemu_strtou64(str, &endptr, 0, &res);
1828
1829 g_assert_cmpint(err, ==, 0);
1830 g_assert_cmphex(res, ==, ULLONG_MAX);
1831 g_assert(endptr == str + strlen(str));
1832 g_free(str);
1833 }
1834
1835 static void test_qemu_strtou64_overflow(void)
1836 {
1837 const char *str = "99999999999999999999999999999999999999999999";
1838 char f = 'X';
1839 const char *endptr = &f;
1840 uint64_t res = 999;
1841 int err;
1842
1843 err = qemu_strtou64(str, &endptr, 0, &res);
1844
1845 g_assert_cmpint(err, ==, -ERANGE);
1846 g_assert_cmphex(res, ==, ULLONG_MAX);
1847 g_assert(endptr == str + strlen(str));
1848 }
1849
1850 static void test_qemu_strtou64_underflow(void)
1851 {
1852 const char *str = "-99999999999999999999999999999999999999999999";
1853 char f = 'X';
1854 const char *endptr = &f;
1855 uint64_t res = 999;
1856 int err;
1857
1858 err = qemu_strtou64(str, &endptr, 0, &res);
1859
1860 g_assert_cmpint(err, ==, -ERANGE);
1861 g_assert_cmphex(res, ==, -1ull);
1862 g_assert(endptr == str + strlen(str));
1863 }
1864
1865 static void test_qemu_strtou64_negative(void)
1866 {
1867 const char *str = " \t -321";
1868 char f = 'X';
1869 const char *endptr = &f;
1870 uint64_t res = 999;
1871 int err;
1872
1873 err = qemu_strtou64(str, &endptr, 0, &res);
1874
1875 g_assert_cmpint(err, ==, 0);
1876 g_assert_cmpuint(res, ==, -321ull);
1877 g_assert(endptr == str + strlen(str));
1878 }
1879
1880 static void test_qemu_strtou64_full_correct(void)
1881 {
1882 const char *str = "18446744073709551614";
1883 uint64_t res = 999;
1884 int err;
1885
1886 err = qemu_strtou64(str, NULL, 0, &res);
1887
1888 g_assert_cmpint(err, ==, 0);
1889 g_assert_cmpuint(res, ==, 18446744073709551614ull);
1890 }
1891
1892 static void test_qemu_strtou64_full_null(void)
1893 {
1894 uint64_t res = 999;
1895 int err;
1896
1897 err = qemu_strtou64(NULL, NULL, 0, &res);
1898
1899 g_assert_cmpint(err, ==, -EINVAL);
1900 }
1901
1902 static void test_qemu_strtou64_full_empty(void)
1903 {
1904 const char *str = "";
1905 uint64_t res = 999;
1906 int err;
1907
1908 err = qemu_strtou64(str, NULL, 0, &res);
1909
1910 g_assert_cmpint(err, ==, -EINVAL);
1911 }
1912
1913 static void test_qemu_strtou64_full_negative(void)
1914 {
1915 const char *str = " \t -321";
1916 uint64_t res = 999;
1917 int err;
1918
1919 err = qemu_strtou64(str, NULL, 0, &res);
1920
1921 g_assert_cmpint(err, ==, 0);
1922 g_assert_cmpuint(res, ==, -321ull);
1923 }
1924
1925 static void test_qemu_strtou64_full_trailing(void)
1926 {
1927 const char *str = "18446744073709551614xxxxxx";
1928 uint64_t res = 999;
1929 int err;
1930
1931 err = qemu_strtou64(str, NULL, 0, &res);
1932
1933 g_assert_cmpint(err, ==, -EINVAL);
1934 }
1935
1936 static void test_qemu_strtou64_full_max(void)
1937 {
1938 char *str = g_strdup_printf("%lld", ULLONG_MAX);
1939 uint64_t res = 999;
1940 int err;
1941
1942 err = qemu_strtou64(str, NULL, 0, &res);
1943
1944 g_assert_cmpint(err, ==, 0);
1945 g_assert_cmphex(res, ==, ULLONG_MAX);
1946 g_free(str);
1947 }
1948
1949 static void test_qemu_strtosz_simple(void)
1950 {
1951 const char *str;
1952 char *endptr = NULL;
1953 int err;
1954 uint64_t res = 0xbaadf00d;
1955
1956 str = "0";
1957 err = qemu_strtosz(str, &endptr, &res);
1958 g_assert_cmpint(err, ==, 0);
1959 g_assert_cmpint(res, ==, 0);
1960 g_assert(endptr == str + 1);
1961
1962 str = "12345";
1963 err = qemu_strtosz(str, &endptr, &res);
1964 g_assert_cmpint(err, ==, 0);
1965 g_assert_cmpint(res, ==, 12345);
1966 g_assert(endptr == str + 5);
1967
1968 err = qemu_strtosz(str, NULL, &res);
1969 g_assert_cmpint(err, ==, 0);
1970 g_assert_cmpint(res, ==, 12345);
1971
1972 /* Note: precision is 53 bits since we're parsing with strtod() */
1973
1974 str = "9007199254740991"; /* 2^53-1 */
1975 err = qemu_strtosz(str, &endptr, &res);
1976 g_assert_cmpint(err, ==, 0);
1977 g_assert_cmpint(res, ==, 0x1fffffffffffff);
1978 g_assert(endptr == str + 16);
1979
1980 str = "9007199254740992"; /* 2^53 */
1981 err = qemu_strtosz(str, &endptr, &res);
1982 g_assert_cmpint(err, ==, 0);
1983 g_assert_cmpint(res, ==, 0x20000000000000);
1984 g_assert(endptr == str + 16);
1985
1986 str = "9007199254740993"; /* 2^53+1 */
1987 err = qemu_strtosz(str, &endptr, &res);
1988 g_assert_cmpint(err, ==, 0);
1989 g_assert_cmpint(res, ==, 0x20000000000000); /* rounded to 53 bits */
1990 g_assert(endptr == str + 16);
1991
1992 str = "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
1993 err = qemu_strtosz(str, &endptr, &res);
1994 g_assert_cmpint(err, ==, 0);
1995 g_assert_cmpint(res, ==, 0xfffffffffffff800);
1996 g_assert(endptr == str + 20);
1997
1998 str = "18446744073709550591"; /* 0xfffffffffffffbff */
1999 err = qemu_strtosz(str, &endptr, &res);
2000 g_assert_cmpint(err, ==, 0);
2001 g_assert_cmpint(res, ==, 0xfffffffffffff800); /* rounded to 53 bits */
2002 g_assert(endptr == str + 20);
2003
2004 /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to
2005 * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */
2006 }
2007
2008 static void test_qemu_strtosz_units(void)
2009 {
2010 const char *none = "1";
2011 const char *b = "1B";
2012 const char *k = "1K";
2013 const char *m = "1M";
2014 const char *g = "1G";
2015 const char *t = "1T";
2016 const char *p = "1P";
2017 const char *e = "1E";
2018 int err;
2019 char *endptr = NULL;
2020 uint64_t res = 0xbaadf00d;
2021
2022 /* default is M */
2023 err = qemu_strtosz_MiB(none, &endptr, &res);
2024 g_assert_cmpint(err, ==, 0);
2025 g_assert_cmpint(res, ==, M_BYTE);
2026 g_assert(endptr == none + 1);
2027
2028 err = qemu_strtosz(b, &endptr, &res);
2029 g_assert_cmpint(err, ==, 0);
2030 g_assert_cmpint(res, ==, 1);
2031 g_assert(endptr == b + 2);
2032
2033 err = qemu_strtosz(k, &endptr, &res);
2034 g_assert_cmpint(err, ==, 0);
2035 g_assert_cmpint(res, ==, K_BYTE);
2036 g_assert(endptr == k + 2);
2037
2038 err = qemu_strtosz(m, &endptr, &res);
2039 g_assert_cmpint(err, ==, 0);
2040 g_assert_cmpint(res, ==, M_BYTE);
2041 g_assert(endptr == m + 2);
2042
2043 err = qemu_strtosz(g, &endptr, &res);
2044 g_assert_cmpint(err, ==, 0);
2045 g_assert_cmpint(res, ==, G_BYTE);
2046 g_assert(endptr == g + 2);
2047
2048 err = qemu_strtosz(t, &endptr, &res);
2049 g_assert_cmpint(err, ==, 0);
2050 g_assert_cmpint(res, ==, T_BYTE);
2051 g_assert(endptr == t + 2);
2052
2053 err = qemu_strtosz(p, &endptr, &res);
2054 g_assert_cmpint(err, ==, 0);
2055 g_assert_cmpint(res, ==, P_BYTE);
2056 g_assert(endptr == p + 2);
2057
2058 err = qemu_strtosz(e, &endptr, &res);
2059 g_assert_cmpint(err, ==, 0);
2060 g_assert_cmpint(res, ==, E_BYTE);
2061 g_assert(endptr == e + 2);
2062 }
2063
2064 static void test_qemu_strtosz_float(void)
2065 {
2066 const char *str = "12.345M";
2067 int err;
2068 char *endptr = NULL;
2069 uint64_t res = 0xbaadf00d;
2070
2071 err = qemu_strtosz(str, &endptr, &res);
2072 g_assert_cmpint(err, ==, 0);
2073 g_assert_cmpint(res, ==, 12.345 * M_BYTE);
2074 g_assert(endptr == str + 7);
2075 }
2076
2077 static void test_qemu_strtosz_invalid(void)
2078 {
2079 const char *str;
2080 char *endptr = NULL;
2081 int err;
2082 uint64_t res = 0xbaadf00d;
2083
2084 str = "";
2085 err = qemu_strtosz(str, &endptr, &res);
2086 g_assert_cmpint(err, ==, -EINVAL);
2087 g_assert(endptr == str);
2088
2089 str = " \t ";
2090 err = qemu_strtosz(str, &endptr, &res);
2091 g_assert_cmpint(err, ==, -EINVAL);
2092 g_assert(endptr == str);
2093
2094 str = "crap";
2095 err = qemu_strtosz(str, &endptr, &res);
2096 g_assert_cmpint(err, ==, -EINVAL);
2097 g_assert(endptr == str);
2098 }
2099
2100 static void test_qemu_strtosz_trailing(void)
2101 {
2102 const char *str;
2103 char *endptr = NULL;
2104 int err;
2105 uint64_t res = 0xbaadf00d;
2106
2107 str = "123xxx";
2108 err = qemu_strtosz_MiB(str, &endptr, &res);
2109 g_assert_cmpint(res, ==, 123 * M_BYTE);
2110 g_assert(endptr == str + 3);
2111
2112 err = qemu_strtosz(str, NULL, &res);
2113 g_assert_cmpint(err, ==, -EINVAL);
2114
2115 str = "1kiB";
2116 err = qemu_strtosz(str, &endptr, &res);
2117 g_assert_cmpint(err, ==, 0);
2118 g_assert_cmpint(res, ==, 1024);
2119 g_assert(endptr == str + 2);
2120
2121 err = qemu_strtosz(str, NULL, &res);
2122 g_assert_cmpint(err, ==, -EINVAL);
2123 }
2124
2125 static void test_qemu_strtosz_erange(void)
2126 {
2127 const char *str;
2128 char *endptr = NULL;
2129 int err;
2130 uint64_t res = 0xbaadf00d;
2131
2132 str = "-1";
2133 err = qemu_strtosz(str, &endptr, &res);
2134 g_assert_cmpint(err, ==, -ERANGE);
2135 g_assert(endptr == str + 2);
2136
2137 str = "18446744073709550592"; /* 0xfffffffffffffc00 */
2138 err = qemu_strtosz(str, &endptr, &res);
2139 g_assert_cmpint(err, ==, -ERANGE);
2140 g_assert(endptr == str + 20);
2141
2142 str = "18446744073709551615"; /* 2^64-1 */
2143 err = qemu_strtosz(str, &endptr, &res);
2144 g_assert_cmpint(err, ==, -ERANGE);
2145 g_assert(endptr == str + 20);
2146
2147 str = "18446744073709551616"; /* 2^64 */
2148 err = qemu_strtosz(str, &endptr, &res);
2149 g_assert_cmpint(err, ==, -ERANGE);
2150 g_assert(endptr == str + 20);
2151
2152 str = "20E";
2153 err = qemu_strtosz(str, &endptr, &res);
2154 g_assert_cmpint(err, ==, -ERANGE);
2155 g_assert(endptr == str + 3);
2156 }
2157
2158 static void test_qemu_strtosz_metric(void)
2159 {
2160 const char *str = "12345k";
2161 int err;
2162 char *endptr = NULL;
2163 uint64_t res = 0xbaadf00d;
2164
2165 err = qemu_strtosz_metric(str, &endptr, &res);
2166 g_assert_cmpint(err, ==, 0);
2167 g_assert_cmpint(res, ==, 12345000);
2168 g_assert(endptr == str + 6);
2169 }
2170
2171 int main(int argc, char **argv)
2172 {
2173 g_test_init(&argc, &argv, NULL);
2174
2175 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null);
2176 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty);
2177 g_test_add_func("/cutils/parse_uint/whitespace",
2178 test_parse_uint_whitespace);
2179 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid);
2180 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing);
2181 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct);
2182 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal);
2183 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal);
2184 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max);
2185 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow);
2186 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative);
2187 g_test_add_func("/cutils/parse_uint_full/trailing",
2188 test_parse_uint_full_trailing);
2189 g_test_add_func("/cutils/parse_uint_full/correct",
2190 test_parse_uint_full_correct);
2191
2192 /* qemu_strtoi() tests */
2193 g_test_add_func("/cutils/qemu_strtoi/correct",
2194 test_qemu_strtoi_correct);
2195 g_test_add_func("/cutils/qemu_strtoi/null",
2196 test_qemu_strtoi_null);
2197 g_test_add_func("/cutils/qemu_strtoi/empty",
2198 test_qemu_strtoi_empty);
2199 g_test_add_func("/cutils/qemu_strtoi/whitespace",
2200 test_qemu_strtoi_whitespace);
2201 g_test_add_func("/cutils/qemu_strtoi/invalid",
2202 test_qemu_strtoi_invalid);
2203 g_test_add_func("/cutils/qemu_strtoi/trailing",
2204 test_qemu_strtoi_trailing);
2205 g_test_add_func("/cutils/qemu_strtoi/octal",
2206 test_qemu_strtoi_octal);
2207 g_test_add_func("/cutils/qemu_strtoi/decimal",
2208 test_qemu_strtoi_decimal);
2209 g_test_add_func("/cutils/qemu_strtoi/hex",
2210 test_qemu_strtoi_hex);
2211 g_test_add_func("/cutils/qemu_strtoi/max",
2212 test_qemu_strtoi_max);
2213 g_test_add_func("/cutils/qemu_strtoi/overflow",
2214 test_qemu_strtoi_overflow);
2215 g_test_add_func("/cutils/qemu_strtoi/underflow",
2216 test_qemu_strtoi_underflow);
2217 g_test_add_func("/cutils/qemu_strtoi/negative",
2218 test_qemu_strtoi_negative);
2219 g_test_add_func("/cutils/qemu_strtoi_full/correct",
2220 test_qemu_strtoi_full_correct);
2221 g_test_add_func("/cutils/qemu_strtoi_full/null",
2222 test_qemu_strtoi_full_null);
2223 g_test_add_func("/cutils/qemu_strtoi_full/empty",
2224 test_qemu_strtoi_full_empty);
2225 g_test_add_func("/cutils/qemu_strtoi_full/negative",
2226 test_qemu_strtoi_full_negative);
2227 g_test_add_func("/cutils/qemu_strtoi_full/trailing",
2228 test_qemu_strtoi_full_trailing);
2229 g_test_add_func("/cutils/qemu_strtoi_full/max",
2230 test_qemu_strtoi_full_max);
2231
2232 /* qemu_strtoui() tests */
2233 g_test_add_func("/cutils/qemu_strtoui/correct",
2234 test_qemu_strtoui_correct);
2235 g_test_add_func("/cutils/qemu_strtoui/null",
2236 test_qemu_strtoui_null);
2237 g_test_add_func("/cutils/qemu_strtoui/empty",
2238 test_qemu_strtoui_empty);
2239 g_test_add_func("/cutils/qemu_strtoui/whitespace",
2240 test_qemu_strtoui_whitespace);
2241 g_test_add_func("/cutils/qemu_strtoui/invalid",
2242 test_qemu_strtoui_invalid);
2243 g_test_add_func("/cutils/qemu_strtoui/trailing",
2244 test_qemu_strtoui_trailing);
2245 g_test_add_func("/cutils/qemu_strtoui/octal",
2246 test_qemu_strtoui_octal);
2247 g_test_add_func("/cutils/qemu_strtoui/decimal",
2248 test_qemu_strtoui_decimal);
2249 g_test_add_func("/cutils/qemu_strtoui/hex",
2250 test_qemu_strtoui_hex);
2251 g_test_add_func("/cutils/qemu_strtoui/max",
2252 test_qemu_strtoui_max);
2253 g_test_add_func("/cutils/qemu_strtoui/overflow",
2254 test_qemu_strtoui_overflow);
2255 g_test_add_func("/cutils/qemu_strtoui/underflow",
2256 test_qemu_strtoui_underflow);
2257 g_test_add_func("/cutils/qemu_strtoui/negative",
2258 test_qemu_strtoui_negative);
2259 g_test_add_func("/cutils/qemu_strtoui_full/correct",
2260 test_qemu_strtoui_full_correct);
2261 g_test_add_func("/cutils/qemu_strtoui_full/null",
2262 test_qemu_strtoui_full_null);
2263 g_test_add_func("/cutils/qemu_strtoui_full/empty",
2264 test_qemu_strtoui_full_empty);
2265 g_test_add_func("/cutils/qemu_strtoui_full/negative",
2266 test_qemu_strtoui_full_negative);
2267 g_test_add_func("/cutils/qemu_strtoui_full/trailing",
2268 test_qemu_strtoui_full_trailing);
2269 g_test_add_func("/cutils/qemu_strtoui_full/max",
2270 test_qemu_strtoui_full_max);
2271
2272 /* qemu_strtol() tests */
2273 g_test_add_func("/cutils/qemu_strtol/correct",
2274 test_qemu_strtol_correct);
2275 g_test_add_func("/cutils/qemu_strtol/null",
2276 test_qemu_strtol_null);
2277 g_test_add_func("/cutils/qemu_strtol/empty",
2278 test_qemu_strtol_empty);
2279 g_test_add_func("/cutils/qemu_strtol/whitespace",
2280 test_qemu_strtol_whitespace);
2281 g_test_add_func("/cutils/qemu_strtol/invalid",
2282 test_qemu_strtol_invalid);
2283 g_test_add_func("/cutils/qemu_strtol/trailing",
2284 test_qemu_strtol_trailing);
2285 g_test_add_func("/cutils/qemu_strtol/octal",
2286 test_qemu_strtol_octal);
2287 g_test_add_func("/cutils/qemu_strtol/decimal",
2288 test_qemu_strtol_decimal);
2289 g_test_add_func("/cutils/qemu_strtol/hex",
2290 test_qemu_strtol_hex);
2291 g_test_add_func("/cutils/qemu_strtol/max",
2292 test_qemu_strtol_max);
2293 g_test_add_func("/cutils/qemu_strtol/overflow",
2294 test_qemu_strtol_overflow);
2295 g_test_add_func("/cutils/qemu_strtol/underflow",
2296 test_qemu_strtol_underflow);
2297 g_test_add_func("/cutils/qemu_strtol/negative",
2298 test_qemu_strtol_negative);
2299 g_test_add_func("/cutils/qemu_strtol_full/correct",
2300 test_qemu_strtol_full_correct);
2301 g_test_add_func("/cutils/qemu_strtol_full/null",
2302 test_qemu_strtol_full_null);
2303 g_test_add_func("/cutils/qemu_strtol_full/empty",
2304 test_qemu_strtol_full_empty);
2305 g_test_add_func("/cutils/qemu_strtol_full/negative",
2306 test_qemu_strtol_full_negative);
2307 g_test_add_func("/cutils/qemu_strtol_full/trailing",
2308 test_qemu_strtol_full_trailing);
2309 g_test_add_func("/cutils/qemu_strtol_full/max",
2310 test_qemu_strtol_full_max);
2311
2312 /* qemu_strtoul() tests */
2313 g_test_add_func("/cutils/qemu_strtoul/correct",
2314 test_qemu_strtoul_correct);
2315 g_test_add_func("/cutils/qemu_strtoul/null",
2316 test_qemu_strtoul_null);
2317 g_test_add_func("/cutils/qemu_strtoul/empty",
2318 test_qemu_strtoul_empty);
2319 g_test_add_func("/cutils/qemu_strtoul/whitespace",
2320 test_qemu_strtoul_whitespace);
2321 g_test_add_func("/cutils/qemu_strtoul/invalid",
2322 test_qemu_strtoul_invalid);
2323 g_test_add_func("/cutils/qemu_strtoul/trailing",
2324 test_qemu_strtoul_trailing);
2325 g_test_add_func("/cutils/qemu_strtoul/octal",
2326 test_qemu_strtoul_octal);
2327 g_test_add_func("/cutils/qemu_strtoul/decimal",
2328 test_qemu_strtoul_decimal);
2329 g_test_add_func("/cutils/qemu_strtoul/hex",
2330 test_qemu_strtoul_hex);
2331 g_test_add_func("/cutils/qemu_strtoul/max",
2332 test_qemu_strtoul_max);
2333 g_test_add_func("/cutils/qemu_strtoul/overflow",
2334 test_qemu_strtoul_overflow);
2335 g_test_add_func("/cutils/qemu_strtoul/underflow",
2336 test_qemu_strtoul_underflow);
2337 g_test_add_func("/cutils/qemu_strtoul/negative",
2338 test_qemu_strtoul_negative);
2339 g_test_add_func("/cutils/qemu_strtoul_full/correct",
2340 test_qemu_strtoul_full_correct);
2341 g_test_add_func("/cutils/qemu_strtoul_full/null",
2342 test_qemu_strtoul_full_null);
2343 g_test_add_func("/cutils/qemu_strtoul_full/empty",
2344 test_qemu_strtoul_full_empty);
2345 g_test_add_func("/cutils/qemu_strtoul_full/negative",
2346 test_qemu_strtoul_full_negative);
2347 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
2348 test_qemu_strtoul_full_trailing);
2349 g_test_add_func("/cutils/qemu_strtoul_full/max",
2350 test_qemu_strtoul_full_max);
2351
2352 /* qemu_strtoi64() tests */
2353 g_test_add_func("/cutils/qemu_strtoi64/correct",
2354 test_qemu_strtoi64_correct);
2355 g_test_add_func("/cutils/qemu_strtoi64/null",
2356 test_qemu_strtoi64_null);
2357 g_test_add_func("/cutils/qemu_strtoi64/empty",
2358 test_qemu_strtoi64_empty);
2359 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
2360 test_qemu_strtoi64_whitespace);
2361 g_test_add_func("/cutils/qemu_strtoi64/invalid"
2362 ,
2363 test_qemu_strtoi64_invalid);
2364 g_test_add_func("/cutils/qemu_strtoi64/trailing",
2365 test_qemu_strtoi64_trailing);
2366 g_test_add_func("/cutils/qemu_strtoi64/octal",
2367 test_qemu_strtoi64_octal);
2368 g_test_add_func("/cutils/qemu_strtoi64/decimal",
2369 test_qemu_strtoi64_decimal);
2370 g_test_add_func("/cutils/qemu_strtoi64/hex",
2371 test_qemu_strtoi64_hex);
2372 g_test_add_func("/cutils/qemu_strtoi64/max",
2373 test_qemu_strtoi64_max);
2374 g_test_add_func("/cutils/qemu_strtoi64/overflow",
2375 test_qemu_strtoi64_overflow);
2376 g_test_add_func("/cutils/qemu_strtoi64/underflow",
2377 test_qemu_strtoi64_underflow);
2378 g_test_add_func("/cutils/qemu_strtoi64/negative",
2379 test_qemu_strtoi64_negative);
2380 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
2381 test_qemu_strtoi64_full_correct);
2382 g_test_add_func("/cutils/qemu_strtoi64_full/null",
2383 test_qemu_strtoi64_full_null);
2384 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
2385 test_qemu_strtoi64_full_empty);
2386 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
2387 test_qemu_strtoi64_full_negative);
2388 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
2389 test_qemu_strtoi64_full_trailing);
2390 g_test_add_func("/cutils/qemu_strtoi64_full/max",
2391 test_qemu_strtoi64_full_max);
2392
2393 /* qemu_strtou64() tests */
2394 g_test_add_func("/cutils/qemu_strtou64/correct",
2395 test_qemu_strtou64_correct);
2396 g_test_add_func("/cutils/qemu_strtou64/null",
2397 test_qemu_strtou64_null);
2398 g_test_add_func("/cutils/qemu_strtou64/empty",
2399 test_qemu_strtou64_empty);
2400 g_test_add_func("/cutils/qemu_strtou64/whitespace",
2401 test_qemu_strtou64_whitespace);
2402 g_test_add_func("/cutils/qemu_strtou64/invalid",
2403 test_qemu_strtou64_invalid);
2404 g_test_add_func("/cutils/qemu_strtou64/trailing",
2405 test_qemu_strtou64_trailing);
2406 g_test_add_func("/cutils/qemu_strtou64/octal",
2407 test_qemu_strtou64_octal);
2408 g_test_add_func("/cutils/qemu_strtou64/decimal",
2409 test_qemu_strtou64_decimal);
2410 g_test_add_func("/cutils/qemu_strtou64/hex",
2411 test_qemu_strtou64_hex);
2412 g_test_add_func("/cutils/qemu_strtou64/max",
2413 test_qemu_strtou64_max);
2414 g_test_add_func("/cutils/qemu_strtou64/overflow",
2415 test_qemu_strtou64_overflow);
2416 g_test_add_func("/cutils/qemu_strtou64/underflow",
2417 test_qemu_strtou64_underflow);
2418 g_test_add_func("/cutils/qemu_strtou64/negative",
2419 test_qemu_strtou64_negative);
2420 g_test_add_func("/cutils/qemu_strtou64_full/correct",
2421 test_qemu_strtou64_full_correct);
2422 g_test_add_func("/cutils/qemu_strtou64_full/null",
2423 test_qemu_strtou64_full_null);
2424 g_test_add_func("/cutils/qemu_strtou64_full/empty",
2425 test_qemu_strtou64_full_empty);
2426 g_test_add_func("/cutils/qemu_strtou64_full/negative",
2427 test_qemu_strtou64_full_negative);
2428 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
2429 test_qemu_strtou64_full_trailing);
2430 g_test_add_func("/cutils/qemu_strtou64_full/max",
2431 test_qemu_strtou64_full_max);
2432
2433 g_test_add_func("/cutils/strtosz/simple",
2434 test_qemu_strtosz_simple);
2435 g_test_add_func("/cutils/strtosz/units",
2436 test_qemu_strtosz_units);
2437 g_test_add_func("/cutils/strtosz/float",
2438 test_qemu_strtosz_float);
2439 g_test_add_func("/cutils/strtosz/invalid",
2440 test_qemu_strtosz_invalid);
2441 g_test_add_func("/cutils/strtosz/trailing",
2442 test_qemu_strtosz_trailing);
2443 g_test_add_func("/cutils/strtosz/erange",
2444 test_qemu_strtosz_erange);
2445 g_test_add_func("/cutils/strtosz/metric",
2446 test_qemu_strtosz_metric);
2447
2448 return g_test_run();
2449 }