linux-user: Support for restarting system calls for OpenRISC targets
[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 #include <glib.h>
30
31 #include "qemu/cutils.h"
32
33 static void test_parse_uint_null(void)
34 {
35 unsigned long long i = 999;
36 char f = 'X';
37 char *endptr = &f;
38 int r;
39
40 r = parse_uint(NULL, &i, &endptr, 0);
41
42 g_assert_cmpint(r, ==, -EINVAL);
43 g_assert_cmpint(i, ==, 0);
44 g_assert(endptr == NULL);
45 }
46
47 static void test_parse_uint_empty(void)
48 {
49 unsigned long long i = 999;
50 char f = 'X';
51 char *endptr = &f;
52 const char *str = "";
53 int r;
54
55 r = parse_uint(str, &i, &endptr, 0);
56
57 g_assert_cmpint(r, ==, -EINVAL);
58 g_assert_cmpint(i, ==, 0);
59 g_assert(endptr == str);
60 }
61
62 static void test_parse_uint_whitespace(void)
63 {
64 unsigned long long i = 999;
65 char f = 'X';
66 char *endptr = &f;
67 const char *str = " \t ";
68 int r;
69
70 r = parse_uint(str, &i, &endptr, 0);
71
72 g_assert_cmpint(r, ==, -EINVAL);
73 g_assert_cmpint(i, ==, 0);
74 g_assert(endptr == str);
75 }
76
77
78 static void test_parse_uint_invalid(void)
79 {
80 unsigned long long i = 999;
81 char f = 'X';
82 char *endptr = &f;
83 const char *str = " \t xxx";
84 int r;
85
86 r = parse_uint(str, &i, &endptr, 0);
87
88 g_assert_cmpint(r, ==, -EINVAL);
89 g_assert_cmpint(i, ==, 0);
90 g_assert(endptr == str);
91 }
92
93
94 static void test_parse_uint_trailing(void)
95 {
96 unsigned long long i = 999;
97 char f = 'X';
98 char *endptr = &f;
99 const char *str = "123xxx";
100 int r;
101
102 r = parse_uint(str, &i, &endptr, 0);
103
104 g_assert_cmpint(r, ==, 0);
105 g_assert_cmpint(i, ==, 123);
106 g_assert(endptr == str + 3);
107 }
108
109 static void test_parse_uint_correct(void)
110 {
111 unsigned long long i = 999;
112 char f = 'X';
113 char *endptr = &f;
114 const char *str = "123";
115 int r;
116
117 r = parse_uint(str, &i, &endptr, 0);
118
119 g_assert_cmpint(r, ==, 0);
120 g_assert_cmpint(i, ==, 123);
121 g_assert(endptr == str + strlen(str));
122 }
123
124 static void test_parse_uint_octal(void)
125 {
126 unsigned long long i = 999;
127 char f = 'X';
128 char *endptr = &f;
129 const char *str = "0123";
130 int r;
131
132 r = parse_uint(str, &i, &endptr, 0);
133
134 g_assert_cmpint(r, ==, 0);
135 g_assert_cmpint(i, ==, 0123);
136 g_assert(endptr == str + strlen(str));
137 }
138
139 static void test_parse_uint_decimal(void)
140 {
141 unsigned long long i = 999;
142 char f = 'X';
143 char *endptr = &f;
144 const char *str = "0123";
145 int r;
146
147 r = parse_uint(str, &i, &endptr, 10);
148
149 g_assert_cmpint(r, ==, 0);
150 g_assert_cmpint(i, ==, 123);
151 g_assert(endptr == str + strlen(str));
152 }
153
154
155 static void test_parse_uint_llong_max(void)
156 {
157 unsigned long long i = 999;
158 char f = 'X';
159 char *endptr = &f;
160 char *str = g_strdup_printf("%llu", (unsigned long long)LLONG_MAX + 1);
161 int r;
162
163 r = parse_uint(str, &i, &endptr, 0);
164
165 g_assert_cmpint(r, ==, 0);
166 g_assert_cmpint(i, ==, (unsigned long long)LLONG_MAX + 1);
167 g_assert(endptr == str + strlen(str));
168
169 g_free(str);
170 }
171
172 static void test_parse_uint_overflow(void)
173 {
174 unsigned long long i = 999;
175 char f = 'X';
176 char *endptr = &f;
177 const char *str = "99999999999999999999999999999999999999";
178 int r;
179
180 r = parse_uint(str, &i, &endptr, 0);
181
182 g_assert_cmpint(r, ==, -ERANGE);
183 g_assert_cmpint(i, ==, ULLONG_MAX);
184 g_assert(endptr == str + strlen(str));
185 }
186
187 static void test_parse_uint_negative(void)
188 {
189 unsigned long long i = 999;
190 char f = 'X';
191 char *endptr = &f;
192 const char *str = " \t -321";
193 int r;
194
195 r = parse_uint(str, &i, &endptr, 0);
196
197 g_assert_cmpint(r, ==, -ERANGE);
198 g_assert_cmpint(i, ==, 0);
199 g_assert(endptr == str + strlen(str));
200 }
201
202
203 static void test_parse_uint_full_trailing(void)
204 {
205 unsigned long long i = 999;
206 const char *str = "123xxx";
207 int r;
208
209 r = parse_uint_full(str, &i, 0);
210
211 g_assert_cmpint(r, ==, -EINVAL);
212 g_assert_cmpint(i, ==, 0);
213 }
214
215 static void test_parse_uint_full_correct(void)
216 {
217 unsigned long long i = 999;
218 const char *str = "123";
219 int r;
220
221 r = parse_uint_full(str, &i, 0);
222
223 g_assert_cmpint(r, ==, 0);
224 g_assert_cmpint(i, ==, 123);
225 }
226
227 static void test_qemu_strtol_correct(void)
228 {
229 const char *str = "12345 foo";
230 char f = 'X';
231 const char *endptr = &f;
232 long res = 999;
233 int err;
234
235 err = qemu_strtol(str, &endptr, 0, &res);
236
237 g_assert_cmpint(err, ==, 0);
238 g_assert_cmpint(res, ==, 12345);
239 g_assert(endptr == str + 5);
240 }
241
242 static void test_qemu_strtol_null(void)
243 {
244 char f = 'X';
245 const char *endptr = &f;
246 long res = 999;
247 int err;
248
249 err = qemu_strtol(NULL, &endptr, 0, &res);
250
251 g_assert_cmpint(err, ==, -EINVAL);
252 g_assert(endptr == NULL);
253 }
254
255 static void test_qemu_strtol_empty(void)
256 {
257 const char *str = "";
258 char f = 'X';
259 const char *endptr = &f;
260 long res = 999;
261 int err;
262
263 err = qemu_strtol(str, &endptr, 0, &res);
264
265 g_assert_cmpint(err, ==, -EINVAL);
266 }
267
268 static void test_qemu_strtol_whitespace(void)
269 {
270 const char *str = " \t ";
271 char f = 'X';
272 const char *endptr = &f;
273 long res = 999;
274 int err;
275
276 err = qemu_strtol(str, &endptr, 0, &res);
277
278 g_assert_cmpint(err, ==, -EINVAL);
279 }
280
281 static void test_qemu_strtol_invalid(void)
282 {
283 const char *str = " xxxx \t abc";
284 char f = 'X';
285 const char *endptr = &f;
286 long res = 999;
287 int err;
288
289 err = qemu_strtol(str, &endptr, 0, &res);
290
291 g_assert_cmpint(err, ==, -EINVAL);
292 }
293
294 static void test_qemu_strtol_trailing(void)
295 {
296 const char *str = "123xxx";
297 char f = 'X';
298 const char *endptr = &f;
299 long res = 999;
300 int err;
301
302 err = qemu_strtol(str, &endptr, 0, &res);
303
304 g_assert_cmpint(err, ==, 0);
305 g_assert_cmpint(res, ==, 123);
306 g_assert(endptr == str + 3);
307 }
308
309 static void test_qemu_strtol_octal(void)
310 {
311 const char *str = "0123";
312 char f = 'X';
313 const char *endptr = &f;
314 long res = 999;
315 int err;
316
317 err = qemu_strtol(str, &endptr, 8, &res);
318
319 g_assert_cmpint(err, ==, 0);
320 g_assert_cmpint(res, ==, 0123);
321 g_assert(endptr == str + strlen(str));
322
323 res = 999;
324 endptr = &f;
325 err = qemu_strtol(str, &endptr, 0, &res);
326
327 g_assert_cmpint(err, ==, 0);
328 g_assert_cmpint(res, ==, 0123);
329 g_assert(endptr == str + strlen(str));
330 }
331
332 static void test_qemu_strtol_decimal(void)
333 {
334 const char *str = "0123";
335 char f = 'X';
336 const char *endptr = &f;
337 long res = 999;
338 int err;
339
340 err = qemu_strtol(str, &endptr, 10, &res);
341
342 g_assert_cmpint(err, ==, 0);
343 g_assert_cmpint(res, ==, 123);
344 g_assert(endptr == str + strlen(str));
345
346 str = "123";
347 res = 999;
348 endptr = &f;
349 err = qemu_strtol(str, &endptr, 0, &res);
350
351 g_assert_cmpint(err, ==, 0);
352 g_assert_cmpint(res, ==, 123);
353 g_assert(endptr == str + strlen(str));
354 }
355
356 static void test_qemu_strtol_hex(void)
357 {
358 const char *str = "0123";
359 char f = 'X';
360 const char *endptr = &f;
361 long res = 999;
362 int err;
363
364 err = qemu_strtol(str, &endptr, 16, &res);
365
366 g_assert_cmpint(err, ==, 0);
367 g_assert_cmpint(res, ==, 0x123);
368 g_assert(endptr == str + strlen(str));
369
370 str = "0x123";
371 res = 999;
372 endptr = &f;
373 err = qemu_strtol(str, &endptr, 0, &res);
374
375 g_assert_cmpint(err, ==, 0);
376 g_assert_cmpint(res, ==, 0x123);
377 g_assert(endptr == str + strlen(str));
378 }
379
380 static void test_qemu_strtol_max(void)
381 {
382 const char *str = g_strdup_printf("%ld", LONG_MAX);
383 char f = 'X';
384 const char *endptr = &f;
385 long res = 999;
386 int err;
387
388 err = qemu_strtol(str, &endptr, 0, &res);
389
390 g_assert_cmpint(err, ==, 0);
391 g_assert_cmpint(res, ==, LONG_MAX);
392 g_assert(endptr == str + strlen(str));
393 }
394
395 static void test_qemu_strtol_overflow(void)
396 {
397 const char *str = "99999999999999999999999999999999999999999999";
398 char f = 'X';
399 const char *endptr = &f;
400 long res = 999;
401 int err;
402
403 err = qemu_strtol(str, &endptr, 0, &res);
404
405 g_assert_cmpint(err, ==, -ERANGE);
406 g_assert_cmpint(res, ==, LONG_MAX);
407 g_assert(endptr == str + strlen(str));
408 }
409
410 static void test_qemu_strtol_underflow(void)
411 {
412 const char *str = "-99999999999999999999999999999999999999999999";
413 char f = 'X';
414 const char *endptr = &f;
415 long res = 999;
416 int err;
417
418 err = qemu_strtol(str, &endptr, 0, &res);
419
420 g_assert_cmpint(err, ==, -ERANGE);
421 g_assert_cmpint(res, ==, LONG_MIN);
422 g_assert(endptr == str + strlen(str));
423 }
424
425 static void test_qemu_strtol_negative(void)
426 {
427 const char *str = " \t -321";
428 char f = 'X';
429 const char *endptr = &f;
430 long res = 999;
431 int err;
432
433 err = qemu_strtol(str, &endptr, 0, &res);
434
435 g_assert_cmpint(err, ==, 0);
436 g_assert_cmpint(res, ==, -321);
437 g_assert(endptr == str + strlen(str));
438 }
439
440 static void test_qemu_strtol_full_correct(void)
441 {
442 const char *str = "123";
443 long res = 999;
444 int err;
445
446 err = qemu_strtol(str, NULL, 0, &res);
447
448 g_assert_cmpint(err, ==, 0);
449 g_assert_cmpint(res, ==, 123);
450 }
451
452 static void test_qemu_strtol_full_null(void)
453 {
454 char f = 'X';
455 const char *endptr = &f;
456 long res = 999;
457 int err;
458
459 err = qemu_strtol(NULL, &endptr, 0, &res);
460
461 g_assert_cmpint(err, ==, -EINVAL);
462 g_assert(endptr == NULL);
463 }
464
465 static void test_qemu_strtol_full_empty(void)
466 {
467 const char *str = "";
468 long res = 999L;
469 int err;
470
471 err = qemu_strtol(str, NULL, 0, &res);
472
473 g_assert_cmpint(err, ==, -EINVAL);
474 }
475
476 static void test_qemu_strtol_full_negative(void)
477 {
478 const char *str = " \t -321";
479 long res = 999;
480 int err;
481
482 err = qemu_strtol(str, NULL, 0, &res);
483
484 g_assert_cmpint(err, ==, 0);
485 g_assert_cmpint(res, ==, -321);
486 }
487
488 static void test_qemu_strtol_full_trailing(void)
489 {
490 const char *str = "123xxx";
491 long res;
492 int err;
493
494 err = qemu_strtol(str, NULL, 0, &res);
495
496 g_assert_cmpint(err, ==, -EINVAL);
497 }
498
499 static void test_qemu_strtol_full_max(void)
500 {
501 const char *str = g_strdup_printf("%ld", LONG_MAX);
502 long res;
503 int err;
504
505 err = qemu_strtol(str, NULL, 0, &res);
506
507 g_assert_cmpint(err, ==, 0);
508 g_assert_cmpint(res, ==, LONG_MAX);
509 }
510
511 static void test_qemu_strtoul_correct(void)
512 {
513 const char *str = "12345 foo";
514 char f = 'X';
515 const char *endptr = &f;
516 unsigned long res = 999;
517 int err;
518
519 err = qemu_strtoul(str, &endptr, 0, &res);
520
521 g_assert_cmpint(err, ==, 0);
522 g_assert_cmpint(res, ==, 12345);
523 g_assert(endptr == str + 5);
524 }
525
526 static void test_qemu_strtoul_null(void)
527 {
528 char f = 'X';
529 const char *endptr = &f;
530 unsigned long res = 999;
531 int err;
532
533 err = qemu_strtoul(NULL, &endptr, 0, &res);
534
535 g_assert_cmpint(err, ==, -EINVAL);
536 g_assert(endptr == NULL);
537 }
538
539 static void test_qemu_strtoul_empty(void)
540 {
541 const char *str = "";
542 char f = 'X';
543 const char *endptr = &f;
544 unsigned long res = 999;
545 int err;
546
547 err = qemu_strtoul(str, &endptr, 0, &res);
548
549 g_assert_cmpint(err, ==, -EINVAL);
550 }
551
552 static void test_qemu_strtoul_whitespace(void)
553 {
554 const char *str = " \t ";
555 char f = 'X';
556 const char *endptr = &f;
557 unsigned long res = 999;
558 int err;
559
560 err = qemu_strtoul(str, &endptr, 0, &res);
561
562 g_assert_cmpint(err, ==, -EINVAL);
563 }
564
565 static void test_qemu_strtoul_invalid(void)
566 {
567 const char *str = " xxxx \t abc";
568 char f = 'X';
569 const char *endptr = &f;
570 unsigned long res = 999;
571 int err;
572
573 err = qemu_strtoul(str, &endptr, 0, &res);
574
575 g_assert_cmpint(err, ==, -EINVAL);
576 }
577
578 static void test_qemu_strtoul_trailing(void)
579 {
580 const char *str = "123xxx";
581 char f = 'X';
582 const char *endptr = &f;
583 unsigned long res = 999;
584 int err;
585
586 err = qemu_strtoul(str, &endptr, 0, &res);
587
588 g_assert_cmpint(err, ==, 0);
589 g_assert_cmpint(res, ==, 123);
590 g_assert(endptr == str + 3);
591 }
592
593 static void test_qemu_strtoul_octal(void)
594 {
595 const char *str = "0123";
596 char f = 'X';
597 const char *endptr = &f;
598 unsigned long res = 999;
599 int err;
600
601 err = qemu_strtoul(str, &endptr, 8, &res);
602
603 g_assert_cmpint(err, ==, 0);
604 g_assert_cmpint(res, ==, 0123);
605 g_assert(endptr == str + strlen(str));
606
607 res = 999;
608 endptr = &f;
609 err = qemu_strtoul(str, &endptr, 0, &res);
610
611 g_assert_cmpint(err, ==, 0);
612 g_assert_cmpint(res, ==, 0123);
613 g_assert(endptr == str + strlen(str));
614 }
615
616 static void test_qemu_strtoul_decimal(void)
617 {
618 const char *str = "0123";
619 char f = 'X';
620 const char *endptr = &f;
621 unsigned long res = 999;
622 int err;
623
624 err = qemu_strtoul(str, &endptr, 10, &res);
625
626 g_assert_cmpint(err, ==, 0);
627 g_assert_cmpint(res, ==, 123);
628 g_assert(endptr == str + strlen(str));
629
630 str = "123";
631 res = 999;
632 endptr = &f;
633 err = qemu_strtoul(str, &endptr, 0, &res);
634
635 g_assert_cmpint(err, ==, 0);
636 g_assert_cmpint(res, ==, 123);
637 g_assert(endptr == str + strlen(str));
638 }
639
640 static void test_qemu_strtoul_hex(void)
641 {
642 const char *str = "0123";
643 char f = 'X';
644 const char *endptr = &f;
645 unsigned long res = 999;
646 int err;
647
648 err = qemu_strtoul(str, &endptr, 16, &res);
649
650 g_assert_cmpint(err, ==, 0);
651 g_assert_cmpint(res, ==, 0x123);
652 g_assert(endptr == str + strlen(str));
653
654 str = "0x123";
655 res = 999;
656 endptr = &f;
657 err = qemu_strtoul(str, &endptr, 0, &res);
658
659 g_assert_cmpint(err, ==, 0);
660 g_assert_cmpint(res, ==, 0x123);
661 g_assert(endptr == str + strlen(str));
662 }
663
664 static void test_qemu_strtoul_max(void)
665 {
666 const char *str = g_strdup_printf("%lu", ULONG_MAX);
667 char f = 'X';
668 const char *endptr = &f;
669 unsigned long res = 999;
670 int err;
671
672 err = qemu_strtoul(str, &endptr, 0, &res);
673
674 g_assert_cmpint(err, ==, 0);
675 g_assert_cmpint(res, ==, ULONG_MAX);
676 g_assert(endptr == str + strlen(str));
677 }
678
679 static void test_qemu_strtoul_overflow(void)
680 {
681 const char *str = "99999999999999999999999999999999999999999999";
682 char f = 'X';
683 const char *endptr = &f;
684 unsigned long res = 999;
685 int err;
686
687 err = qemu_strtoul(str, &endptr, 0, &res);
688
689 g_assert_cmpint(err, ==, -ERANGE);
690 g_assert_cmpint(res, ==, ULONG_MAX);
691 g_assert(endptr == str + strlen(str));
692 }
693
694 static void test_qemu_strtoul_underflow(void)
695 {
696 const char *str = "-99999999999999999999999999999999999999999999";
697 char f = 'X';
698 const char *endptr = &f;
699 unsigned long res = 999;
700 int err;
701
702 err = qemu_strtoul(str, &endptr, 0, &res);
703
704 g_assert_cmpint(err, ==, -ERANGE);
705 g_assert_cmpint(res, ==, -1ul);
706 g_assert(endptr == str + strlen(str));
707 }
708
709 static void test_qemu_strtoul_negative(void)
710 {
711 const char *str = " \t -321";
712 char f = 'X';
713 const char *endptr = &f;
714 unsigned long res = 999;
715 int err;
716
717 err = qemu_strtoul(str, &endptr, 0, &res);
718
719 g_assert_cmpint(err, ==, 0);
720 g_assert_cmpint(res, ==, -321ul);
721 g_assert(endptr == str + strlen(str));
722 }
723
724 static void test_qemu_strtoul_full_correct(void)
725 {
726 const char *str = "123";
727 unsigned long res = 999;
728 int err;
729
730 err = qemu_strtoul(str, NULL, 0, &res);
731
732 g_assert_cmpint(err, ==, 0);
733 g_assert_cmpint(res, ==, 123);
734 }
735
736 static void test_qemu_strtoul_full_null(void)
737 {
738 unsigned long res = 999;
739 int err;
740
741 err = qemu_strtoul(NULL, NULL, 0, &res);
742
743 g_assert_cmpint(err, ==, -EINVAL);
744 }
745
746 static void test_qemu_strtoul_full_empty(void)
747 {
748 const char *str = "";
749 unsigned long res = 999;
750 int err;
751
752 err = qemu_strtoul(str, NULL, 0, &res);
753
754 g_assert_cmpint(err, ==, -EINVAL);
755 }
756 static void test_qemu_strtoul_full_negative(void)
757 {
758 const char *str = " \t -321";
759 unsigned long res = 999;
760 int err;
761
762 err = qemu_strtoul(str, NULL, 0, &res);
763 g_assert_cmpint(err, ==, 0);
764 g_assert_cmpint(res, ==, -321ul);
765 }
766
767 static void test_qemu_strtoul_full_trailing(void)
768 {
769 const char *str = "123xxx";
770 unsigned long res;
771 int err;
772
773 err = qemu_strtoul(str, NULL, 0, &res);
774
775 g_assert_cmpint(err, ==, -EINVAL);
776 }
777
778 static void test_qemu_strtoul_full_max(void)
779 {
780 const char *str = g_strdup_printf("%lu", ULONG_MAX);
781 unsigned long res = 999;
782 int err;
783
784 err = qemu_strtoul(str, NULL, 0, &res);
785
786 g_assert_cmpint(err, ==, 0);
787 g_assert_cmpint(res, ==, ULONG_MAX);
788 }
789
790 static void test_qemu_strtoll_correct(void)
791 {
792 const char *str = "12345 foo";
793 char f = 'X';
794 const char *endptr = &f;
795 int64_t res = 999;
796 int err;
797
798 err = qemu_strtoll(str, &endptr, 0, &res);
799
800 g_assert_cmpint(err, ==, 0);
801 g_assert_cmpint(res, ==, 12345);
802 g_assert(endptr == str + 5);
803 }
804
805 static void test_qemu_strtoll_null(void)
806 {
807 char f = 'X';
808 const char *endptr = &f;
809 int64_t res = 999;
810 int err;
811
812 err = qemu_strtoll(NULL, &endptr, 0, &res);
813
814 g_assert_cmpint(err, ==, -EINVAL);
815 g_assert(endptr == NULL);
816 }
817
818 static void test_qemu_strtoll_empty(void)
819 {
820 const char *str = "";
821 char f = 'X';
822 const char *endptr = &f;
823 int64_t res = 999;
824 int err;
825
826 err = qemu_strtoll(str, &endptr, 0, &res);
827
828 g_assert_cmpint(err, ==, -EINVAL);
829 }
830
831 static void test_qemu_strtoll_whitespace(void)
832 {
833 const char *str = " \t ";
834 char f = 'X';
835 const char *endptr = &f;
836 int64_t res = 999;
837 int err;
838
839 err = qemu_strtoll(str, &endptr, 0, &res);
840
841 g_assert_cmpint(err, ==, -EINVAL);
842 }
843
844 static void test_qemu_strtoll_invalid(void)
845 {
846 const char *str = " xxxx \t abc";
847 char f = 'X';
848 const char *endptr = &f;
849 int64_t res = 999;
850 int err;
851
852 err = qemu_strtoll(str, &endptr, 0, &res);
853
854 g_assert_cmpint(err, ==, -EINVAL);
855 }
856
857 static void test_qemu_strtoll_trailing(void)
858 {
859 const char *str = "123xxx";
860 char f = 'X';
861 const char *endptr = &f;
862 int64_t res = 999;
863 int err;
864
865 err = qemu_strtoll(str, &endptr, 0, &res);
866
867 g_assert_cmpint(err, ==, 0);
868 g_assert_cmpint(res, ==, 123);
869 g_assert(endptr == str + 3);
870 }
871
872 static void test_qemu_strtoll_octal(void)
873 {
874 const char *str = "0123";
875 char f = 'X';
876 const char *endptr = &f;
877 int64_t res = 999;
878 int err;
879
880 err = qemu_strtoll(str, &endptr, 8, &res);
881
882 g_assert_cmpint(err, ==, 0);
883 g_assert_cmpint(res, ==, 0123);
884 g_assert(endptr == str + strlen(str));
885
886 endptr = &f;
887 res = 999;
888 err = qemu_strtoll(str, &endptr, 0, &res);
889
890 g_assert_cmpint(err, ==, 0);
891 g_assert_cmpint(res, ==, 0123);
892 g_assert(endptr == str + strlen(str));
893 }
894
895 static void test_qemu_strtoll_decimal(void)
896 {
897 const char *str = "0123";
898 char f = 'X';
899 const char *endptr = &f;
900 int64_t res = 999;
901 int err;
902
903 err = qemu_strtoll(str, &endptr, 10, &res);
904
905 g_assert_cmpint(err, ==, 0);
906 g_assert_cmpint(res, ==, 123);
907 g_assert(endptr == str + strlen(str));
908
909 str = "123";
910 endptr = &f;
911 res = 999;
912 err = qemu_strtoll(str, &endptr, 0, &res);
913
914 g_assert_cmpint(err, ==, 0);
915 g_assert_cmpint(res, ==, 123);
916 g_assert(endptr == str + strlen(str));
917 }
918
919 static void test_qemu_strtoll_hex(void)
920 {
921 const char *str = "0123";
922 char f = 'X';
923 const char *endptr = &f;
924 int64_t res = 999;
925 int err;
926
927 err = qemu_strtoll(str, &endptr, 16, &res);
928
929 g_assert_cmpint(err, ==, 0);
930 g_assert_cmpint(res, ==, 0x123);
931 g_assert(endptr == str + strlen(str));
932
933 str = "0x123";
934 endptr = &f;
935 res = 999;
936 err = qemu_strtoll(str, &endptr, 0, &res);
937
938 g_assert_cmpint(err, ==, 0);
939 g_assert_cmpint(res, ==, 0x123);
940 g_assert(endptr == str + strlen(str));
941 }
942
943 static void test_qemu_strtoll_max(void)
944 {
945 const char *str = g_strdup_printf("%lld", LLONG_MAX);
946 char f = 'X';
947 const char *endptr = &f;
948 int64_t res = 999;
949 int err;
950
951 err = qemu_strtoll(str, &endptr, 0, &res);
952
953 g_assert_cmpint(err, ==, 0);
954 g_assert_cmpint(res, ==, LLONG_MAX);
955 g_assert(endptr == str + strlen(str));
956 }
957
958 static void test_qemu_strtoll_overflow(void)
959 {
960 const char *str = "99999999999999999999999999999999999999999999";
961 char f = 'X';
962 const char *endptr = &f;
963 int64_t res = 999;
964 int err;
965
966 err = qemu_strtoll(str, &endptr, 0, &res);
967
968 g_assert_cmpint(err, ==, -ERANGE);
969 g_assert_cmpint(res, ==, LLONG_MAX);
970 g_assert(endptr == str + strlen(str));
971 }
972
973 static void test_qemu_strtoll_underflow(void)
974 {
975 const char *str = "-99999999999999999999999999999999999999999999";
976 char f = 'X';
977 const char *endptr = &f;
978 int64_t res = 999;
979 int err;
980
981 err = qemu_strtoll(str, &endptr, 0, &res);
982
983 g_assert_cmpint(err, ==, -ERANGE);
984 g_assert_cmpint(res, ==, LLONG_MIN);
985 g_assert(endptr == str + strlen(str));
986 }
987
988 static void test_qemu_strtoll_negative(void)
989 {
990 const char *str = " \t -321";
991 char f = 'X';
992 const char *endptr = &f;
993 int64_t res = 999;
994 int err;
995
996 err = qemu_strtoll(str, &endptr, 0, &res);
997
998 g_assert_cmpint(err, ==, 0);
999 g_assert_cmpint(res, ==, -321);
1000 g_assert(endptr == str + strlen(str));
1001 }
1002
1003 static void test_qemu_strtoll_full_correct(void)
1004 {
1005 const char *str = "123";
1006 int64_t res = 999;
1007 int err;
1008
1009 err = qemu_strtoll(str, NULL, 0, &res);
1010
1011 g_assert_cmpint(err, ==, 0);
1012 g_assert_cmpint(res, ==, 123);
1013 }
1014
1015 static void test_qemu_strtoll_full_null(void)
1016 {
1017 int64_t res = 999;
1018 int err;
1019
1020 err = qemu_strtoll(NULL, NULL, 0, &res);
1021
1022 g_assert_cmpint(err, ==, -EINVAL);
1023 }
1024
1025 static void test_qemu_strtoll_full_empty(void)
1026 {
1027 const char *str = "";
1028 int64_t res = 999;
1029 int err;
1030
1031 err = qemu_strtoll(str, NULL, 0, &res);
1032
1033 g_assert_cmpint(err, ==, -EINVAL);
1034 }
1035
1036 static void test_qemu_strtoll_full_negative(void)
1037 {
1038 const char *str = " \t -321";
1039 int64_t res = 999;
1040 int err;
1041
1042 err = qemu_strtoll(str, NULL, 0, &res);
1043
1044 g_assert_cmpint(err, ==, 0);
1045 g_assert_cmpint(res, ==, -321);
1046 }
1047
1048 static void test_qemu_strtoll_full_trailing(void)
1049 {
1050 const char *str = "123xxx";
1051 int64_t res = 999;
1052 int err;
1053
1054 err = qemu_strtoll(str, NULL, 0, &res);
1055
1056 g_assert_cmpint(err, ==, -EINVAL);
1057 }
1058
1059 static void test_qemu_strtoll_full_max(void)
1060 {
1061
1062 const char *str = g_strdup_printf("%lld", LLONG_MAX);
1063 int64_t res;
1064 int err;
1065
1066 err = qemu_strtoll(str, NULL, 0, &res);
1067
1068 g_assert_cmpint(err, ==, 0);
1069 g_assert_cmpint(res, ==, LLONG_MAX);
1070 }
1071
1072 static void test_qemu_strtoull_correct(void)
1073 {
1074 const char *str = "12345 foo";
1075 char f = 'X';
1076 const char *endptr = &f;
1077 uint64_t res = 999;
1078 int err;
1079
1080 err = qemu_strtoull(str, &endptr, 0, &res);
1081
1082 g_assert_cmpint(err, ==, 0);
1083 g_assert_cmpint(res, ==, 12345);
1084 g_assert(endptr == str + 5);
1085 }
1086
1087 static void test_qemu_strtoull_null(void)
1088 {
1089 char f = 'X';
1090 const char *endptr = &f;
1091 uint64_t res = 999;
1092 int err;
1093
1094 err = qemu_strtoull(NULL, &endptr, 0, &res);
1095
1096 g_assert_cmpint(err, ==, -EINVAL);
1097 g_assert(endptr == NULL);
1098 }
1099
1100 static void test_qemu_strtoull_empty(void)
1101 {
1102 const char *str = "";
1103 char f = 'X';
1104 const char *endptr = &f;
1105 uint64_t res = 999;
1106 int err;
1107
1108 err = qemu_strtoull(str, &endptr, 0, &res);
1109
1110 g_assert_cmpint(err, ==, -EINVAL);
1111 }
1112
1113 static void test_qemu_strtoull_whitespace(void)
1114 {
1115 const char *str = " \t ";
1116 char f = 'X';
1117 const char *endptr = &f;
1118 uint64_t res = 999;
1119 int err;
1120
1121 err = qemu_strtoull(str, &endptr, 0, &res);
1122
1123 g_assert_cmpint(err, ==, -EINVAL);
1124 }
1125
1126 static void test_qemu_strtoull_invalid(void)
1127 {
1128 const char *str = " xxxx \t abc";
1129 char f = 'X';
1130 const char *endptr = &f;
1131 uint64_t res = 999;
1132 int err;
1133
1134 err = qemu_strtoull(str, &endptr, 0, &res);
1135
1136 g_assert_cmpint(err, ==, -EINVAL);
1137 }
1138
1139 static void test_qemu_strtoull_trailing(void)
1140 {
1141 const char *str = "123xxx";
1142 char f = 'X';
1143 const char *endptr = &f;
1144 uint64_t res = 999;
1145 int err;
1146
1147 err = qemu_strtoull(str, &endptr, 0, &res);
1148
1149 g_assert_cmpint(err, ==, 0);
1150 g_assert_cmpint(res, ==, 123);
1151 g_assert(endptr == str + 3);
1152 }
1153
1154 static void test_qemu_strtoull_octal(void)
1155 {
1156 const char *str = "0123";
1157 char f = 'X';
1158 const char *endptr = &f;
1159 uint64_t res = 999;
1160 int err;
1161
1162 err = qemu_strtoull(str, &endptr, 8, &res);
1163
1164 g_assert_cmpint(err, ==, 0);
1165 g_assert_cmpint(res, ==, 0123);
1166 g_assert(endptr == str + strlen(str));
1167
1168 endptr = &f;
1169 res = 999;
1170 err = qemu_strtoull(str, &endptr, 0, &res);
1171
1172 g_assert_cmpint(err, ==, 0);
1173 g_assert_cmpint(res, ==, 0123);
1174 g_assert(endptr == str + strlen(str));
1175 }
1176
1177 static void test_qemu_strtoull_decimal(void)
1178 {
1179 const char *str = "0123";
1180 char f = 'X';
1181 const char *endptr = &f;
1182 uint64_t res = 999;
1183 int err;
1184
1185 err = qemu_strtoull(str, &endptr, 10, &res);
1186
1187 g_assert_cmpint(err, ==, 0);
1188 g_assert_cmpint(res, ==, 123);
1189 g_assert(endptr == str + strlen(str));
1190
1191 str = "123";
1192 endptr = &f;
1193 res = 999;
1194 err = qemu_strtoull(str, &endptr, 0, &res);
1195
1196 g_assert_cmpint(err, ==, 0);
1197 g_assert_cmpint(res, ==, 123);
1198 g_assert(endptr == str + strlen(str));
1199 }
1200
1201 static void test_qemu_strtoull_hex(void)
1202 {
1203 const char *str = "0123";
1204 char f = 'X';
1205 const char *endptr = &f;
1206 uint64_t res = 999;
1207 int err;
1208
1209 err = qemu_strtoull(str, &endptr, 16, &res);
1210
1211 g_assert_cmpint(err, ==, 0);
1212 g_assert_cmpint(res, ==, 0x123);
1213 g_assert(endptr == str + strlen(str));
1214
1215 str = "0x123";
1216 endptr = &f;
1217 res = 999;
1218 err = qemu_strtoull(str, &endptr, 0, &res);
1219
1220 g_assert_cmpint(err, ==, 0);
1221 g_assert_cmpint(res, ==, 0x123);
1222 g_assert(endptr == str + strlen(str));
1223 }
1224
1225 static void test_qemu_strtoull_max(void)
1226 {
1227 const char *str = g_strdup_printf("%llu", ULLONG_MAX);
1228 char f = 'X';
1229 const char *endptr = &f;
1230 uint64_t res = 999;
1231 int err;
1232
1233 err = qemu_strtoull(str, &endptr, 0, &res);
1234
1235 g_assert_cmpint(err, ==, 0);
1236 g_assert_cmpint(res, ==, ULLONG_MAX);
1237 g_assert(endptr == str + strlen(str));
1238 }
1239
1240 static void test_qemu_strtoull_overflow(void)
1241 {
1242 const char *str = "99999999999999999999999999999999999999999999";
1243 char f = 'X';
1244 const char *endptr = &f;
1245 uint64_t res = 999;
1246 int err;
1247
1248 err = qemu_strtoull(str, &endptr, 0, &res);
1249
1250 g_assert_cmpint(err, ==, -ERANGE);
1251 g_assert_cmpint(res, ==, ULLONG_MAX);
1252 g_assert(endptr == str + strlen(str));
1253 }
1254
1255 static void test_qemu_strtoull_underflow(void)
1256 {
1257 const char *str = "-99999999999999999999999999999999999999999999";
1258 char f = 'X';
1259 const char *endptr = &f;
1260 uint64_t res = 999;
1261 int err;
1262
1263 err = qemu_strtoull(str, &endptr, 0, &res);
1264
1265 g_assert_cmpint(err, ==, -ERANGE);
1266 g_assert_cmpint(res, ==, -1);
1267 g_assert(endptr == str + strlen(str));
1268 }
1269
1270 static void test_qemu_strtoull_negative(void)
1271 {
1272 const char *str = " \t -321";
1273 char f = 'X';
1274 const char *endptr = &f;
1275 uint64_t res = 999;
1276 int err;
1277
1278 err = qemu_strtoull(str, &endptr, 0, &res);
1279
1280 g_assert_cmpint(err, ==, 0);
1281 g_assert_cmpint(res, ==, -321);
1282 g_assert(endptr == str + strlen(str));
1283 }
1284
1285 static void test_qemu_strtoull_full_correct(void)
1286 {
1287 const char *str = "18446744073709551614";
1288 uint64_t res = 999;
1289 int err;
1290
1291 err = qemu_strtoull(str, NULL, 0, &res);
1292
1293 g_assert_cmpint(err, ==, 0);
1294 g_assert_cmpint(res, ==, 18446744073709551614LLU);
1295 }
1296
1297 static void test_qemu_strtoull_full_null(void)
1298 {
1299 uint64_t res = 999;
1300 int err;
1301
1302 err = qemu_strtoull(NULL, NULL, 0, &res);
1303
1304 g_assert_cmpint(err, ==, -EINVAL);
1305 }
1306
1307 static void test_qemu_strtoull_full_empty(void)
1308 {
1309 const char *str = "";
1310 uint64_t res = 999;
1311 int err;
1312
1313 err = qemu_strtoull(str, NULL, 0, &res);
1314
1315 g_assert_cmpint(err, ==, -EINVAL);
1316 }
1317
1318 static void test_qemu_strtoull_full_negative(void)
1319 {
1320 const char *str = " \t -321";
1321 uint64_t res = 999;
1322 int err;
1323
1324 err = qemu_strtoull(str, NULL, 0, &res);
1325
1326 g_assert_cmpint(err, ==, 0);
1327 g_assert_cmpint(res, ==, 18446744073709551295LLU);
1328 }
1329
1330 static void test_qemu_strtoull_full_trailing(void)
1331 {
1332 const char *str = "18446744073709551614xxxxxx";
1333 uint64_t res = 999;
1334 int err;
1335
1336 err = qemu_strtoull(str, NULL, 0, &res);
1337
1338 g_assert_cmpint(err, ==, -EINVAL);
1339 }
1340
1341 static void test_qemu_strtoull_full_max(void)
1342 {
1343 const char *str = g_strdup_printf("%lld", ULLONG_MAX);
1344 uint64_t res = 999;
1345 int err;
1346
1347 err = qemu_strtoull(str, NULL, 0, &res);
1348
1349 g_assert_cmpint(err, ==, 0);
1350 g_assert_cmpint(res, ==, ULLONG_MAX);
1351 }
1352
1353 static void test_qemu_strtosz_simple(void)
1354 {
1355 const char *str = "12345M";
1356 char *endptr = NULL;
1357 int64_t res;
1358
1359 res = qemu_strtosz(str, &endptr);
1360 g_assert_cmpint(res, ==, 12345 * M_BYTE);
1361 g_assert(endptr == str + 6);
1362
1363 res = qemu_strtosz(str, NULL);
1364 g_assert_cmpint(res, ==, 12345 * M_BYTE);
1365 }
1366
1367 static void test_qemu_strtosz_units(void)
1368 {
1369 const char *none = "1";
1370 const char *b = "1B";
1371 const char *k = "1K";
1372 const char *m = "1M";
1373 const char *g = "1G";
1374 const char *t = "1T";
1375 const char *p = "1P";
1376 const char *e = "1E";
1377 int64_t res;
1378
1379 /* default is M */
1380 res = qemu_strtosz(none, NULL);
1381 g_assert_cmpint(res, ==, M_BYTE);
1382
1383 res = qemu_strtosz(b, NULL);
1384 g_assert_cmpint(res, ==, 1);
1385
1386 res = qemu_strtosz(k, NULL);
1387 g_assert_cmpint(res, ==, K_BYTE);
1388
1389 res = qemu_strtosz(m, NULL);
1390 g_assert_cmpint(res, ==, M_BYTE);
1391
1392 res = qemu_strtosz(g, NULL);
1393 g_assert_cmpint(res, ==, G_BYTE);
1394
1395 res = qemu_strtosz(t, NULL);
1396 g_assert_cmpint(res, ==, T_BYTE);
1397
1398 res = qemu_strtosz(p, NULL);
1399 g_assert_cmpint(res, ==, P_BYTE);
1400
1401 res = qemu_strtosz(e, NULL);
1402 g_assert_cmpint(res, ==, E_BYTE);
1403 }
1404
1405 static void test_qemu_strtosz_float(void)
1406 {
1407 const char *str = "12.345M";
1408 int64_t res;
1409
1410 res = qemu_strtosz(str, NULL);
1411 g_assert_cmpint(res, ==, 12.345 * M_BYTE);
1412 }
1413
1414 static void test_qemu_strtosz_erange(void)
1415 {
1416 const char *str = "10E";
1417 int64_t res;
1418
1419 res = qemu_strtosz(str, NULL);
1420 g_assert_cmpint(res, ==, -ERANGE);
1421 }
1422
1423 static void test_qemu_strtosz_suffix_unit(void)
1424 {
1425 const char *str = "12345";
1426 int64_t res;
1427
1428 res = qemu_strtosz_suffix_unit(str, NULL,
1429 QEMU_STRTOSZ_DEFSUFFIX_KB, 1000);
1430 g_assert_cmpint(res, ==, 12345000);
1431 }
1432
1433 int main(int argc, char **argv)
1434 {
1435 g_test_init(&argc, &argv, NULL);
1436
1437 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null);
1438 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty);
1439 g_test_add_func("/cutils/parse_uint/whitespace",
1440 test_parse_uint_whitespace);
1441 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid);
1442 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing);
1443 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct);
1444 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal);
1445 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal);
1446 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max);
1447 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow);
1448 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative);
1449 g_test_add_func("/cutils/parse_uint_full/trailing",
1450 test_parse_uint_full_trailing);
1451 g_test_add_func("/cutils/parse_uint_full/correct",
1452 test_parse_uint_full_correct);
1453
1454 /* qemu_strtol() tests */
1455 g_test_add_func("/cutils/qemu_strtol/correct", test_qemu_strtol_correct);
1456 g_test_add_func("/cutils/qemu_strtol/null", test_qemu_strtol_null);
1457 g_test_add_func("/cutils/qemu_strtol/empty", test_qemu_strtol_empty);
1458 g_test_add_func("/cutils/qemu_strtol/whitespace",
1459 test_qemu_strtol_whitespace);
1460 g_test_add_func("/cutils/qemu_strtol/invalid", test_qemu_strtol_invalid);
1461 g_test_add_func("/cutils/qemu_strtol/trailing", test_qemu_strtol_trailing);
1462 g_test_add_func("/cutils/qemu_strtol/octal", test_qemu_strtol_octal);
1463 g_test_add_func("/cutils/qemu_strtol/decimal", test_qemu_strtol_decimal);
1464 g_test_add_func("/cutils/qemu_strtol/hex", test_qemu_strtol_hex);
1465 g_test_add_func("/cutils/qemu_strtol/max", test_qemu_strtol_max);
1466 g_test_add_func("/cutils/qemu_strtol/overflow", test_qemu_strtol_overflow);
1467 g_test_add_func("/cutils/qemu_strtol/underflow",
1468 test_qemu_strtol_underflow);
1469 g_test_add_func("/cutils/qemu_strtol/negative", test_qemu_strtol_negative);
1470 g_test_add_func("/cutils/qemu_strtol_full/correct",
1471 test_qemu_strtol_full_correct);
1472 g_test_add_func("/cutils/qemu_strtol_full/null",
1473 test_qemu_strtol_full_null);
1474 g_test_add_func("/cutils/qemu_strtol_full/empty",
1475 test_qemu_strtol_full_empty);
1476 g_test_add_func("/cutils/qemu_strtol_full/negative",
1477 test_qemu_strtol_full_negative);
1478 g_test_add_func("/cutils/qemu_strtol_full/trailing",
1479 test_qemu_strtol_full_trailing);
1480 g_test_add_func("/cutils/qemu_strtol_full/max",
1481 test_qemu_strtol_full_max);
1482
1483 /* qemu_strtoul() tests */
1484 g_test_add_func("/cutils/qemu_strtoul/correct", test_qemu_strtoul_correct);
1485 g_test_add_func("/cutils/qemu_strtoul/null", test_qemu_strtoul_null);
1486 g_test_add_func("/cutils/qemu_strtoul/empty", test_qemu_strtoul_empty);
1487 g_test_add_func("/cutils/qemu_strtoul/whitespace",
1488 test_qemu_strtoul_whitespace);
1489 g_test_add_func("/cutils/qemu_strtoul/invalid", test_qemu_strtoul_invalid);
1490 g_test_add_func("/cutils/qemu_strtoul/trailing",
1491 test_qemu_strtoul_trailing);
1492 g_test_add_func("/cutils/qemu_strtoul/octal", test_qemu_strtoul_octal);
1493 g_test_add_func("/cutils/qemu_strtoul/decimal", test_qemu_strtoul_decimal);
1494 g_test_add_func("/cutils/qemu_strtoul/hex", test_qemu_strtoul_hex);
1495 g_test_add_func("/cutils/qemu_strtoul/max", test_qemu_strtoul_max);
1496 g_test_add_func("/cutils/qemu_strtoul/overflow",
1497 test_qemu_strtoul_overflow);
1498 g_test_add_func("/cutils/qemu_strtoul/underflow",
1499 test_qemu_strtoul_underflow);
1500 g_test_add_func("/cutils/qemu_strtoul/negative",
1501 test_qemu_strtoul_negative);
1502 g_test_add_func("/cutils/qemu_strtoul_full/correct",
1503 test_qemu_strtoul_full_correct);
1504 g_test_add_func("/cutils/qemu_strtoul_full/null",
1505 test_qemu_strtoul_full_null);
1506 g_test_add_func("/cutils/qemu_strtoul_full/empty",
1507 test_qemu_strtoul_full_empty);
1508 g_test_add_func("/cutils/qemu_strtoul_full/negative",
1509 test_qemu_strtoul_full_negative);
1510 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
1511 test_qemu_strtoul_full_trailing);
1512 g_test_add_func("/cutils/qemu_strtoul_full/max",
1513 test_qemu_strtoul_full_max);
1514
1515 /* qemu_strtoll() tests */
1516 g_test_add_func("/cutils/qemu_strtoll/correct", test_qemu_strtoll_correct);
1517 g_test_add_func("/cutils/qemu_strtoll/null", test_qemu_strtoll_null);
1518 g_test_add_func("/cutils/qemu_strtoll/empty", test_qemu_strtoll_empty);
1519 g_test_add_func("/cutils/qemu_strtoll/whitespace",
1520 test_qemu_strtoll_whitespace);
1521 g_test_add_func("/cutils/qemu_strtoll/invalid", test_qemu_strtoll_invalid);
1522 g_test_add_func("/cutils/qemu_strtoll/trailing",
1523 test_qemu_strtoll_trailing);
1524 g_test_add_func("/cutils/qemu_strtoll/octal", test_qemu_strtoll_octal);
1525 g_test_add_func("/cutils/qemu_strtoll/decimal", test_qemu_strtoll_decimal);
1526 g_test_add_func("/cutils/qemu_strtoll/hex", test_qemu_strtoll_hex);
1527 g_test_add_func("/cutils/qemu_strtoll/max", test_qemu_strtoll_max);
1528 g_test_add_func("/cutils/qemu_strtoll/overflow",
1529 test_qemu_strtoll_overflow);
1530 g_test_add_func("/cutils/qemu_strtoll/underflow",
1531 test_qemu_strtoll_underflow);
1532 g_test_add_func("/cutils/qemu_strtoll/negative",
1533 test_qemu_strtoll_negative);
1534 g_test_add_func("/cutils/qemu_strtoll_full/correct",
1535 test_qemu_strtoll_full_correct);
1536 g_test_add_func("/cutils/qemu_strtoll_full/null",
1537 test_qemu_strtoll_full_null);
1538 g_test_add_func("/cutils/qemu_strtoll_full/empty",
1539 test_qemu_strtoll_full_empty);
1540 g_test_add_func("/cutils/qemu_strtoll_full/negative",
1541 test_qemu_strtoll_full_negative);
1542 g_test_add_func("/cutils/qemu_strtoll_full/trailing",
1543 test_qemu_strtoll_full_trailing);
1544 g_test_add_func("/cutils/qemu_strtoll_full/max",
1545 test_qemu_strtoll_full_max);
1546
1547 /* qemu_strtoull() tests */
1548 g_test_add_func("/cutils/qemu_strtoull/correct",
1549 test_qemu_strtoull_correct);
1550 g_test_add_func("/cutils/qemu_strtoull/null",
1551 test_qemu_strtoull_null);
1552 g_test_add_func("/cutils/qemu_strtoull/empty", test_qemu_strtoull_empty);
1553 g_test_add_func("/cutils/qemu_strtoull/whitespace",
1554 test_qemu_strtoull_whitespace);
1555 g_test_add_func("/cutils/qemu_strtoull/invalid",
1556 test_qemu_strtoull_invalid);
1557 g_test_add_func("/cutils/qemu_strtoull/trailing",
1558 test_qemu_strtoull_trailing);
1559 g_test_add_func("/cutils/qemu_strtoull/octal", test_qemu_strtoull_octal);
1560 g_test_add_func("/cutils/qemu_strtoull/decimal",
1561 test_qemu_strtoull_decimal);
1562 g_test_add_func("/cutils/qemu_strtoull/hex", test_qemu_strtoull_hex);
1563 g_test_add_func("/cutils/qemu_strtoull/max", test_qemu_strtoull_max);
1564 g_test_add_func("/cutils/qemu_strtoull/overflow",
1565 test_qemu_strtoull_overflow);
1566 g_test_add_func("/cutils/qemu_strtoull/underflow",
1567 test_qemu_strtoull_underflow);
1568 g_test_add_func("/cutils/qemu_strtoull/negative",
1569 test_qemu_strtoull_negative);
1570 g_test_add_func("/cutils/qemu_strtoull_full/correct",
1571 test_qemu_strtoull_full_correct);
1572 g_test_add_func("/cutils/qemu_strtoull_full/null",
1573 test_qemu_strtoull_full_null);
1574 g_test_add_func("/cutils/qemu_strtoull_full/empty",
1575 test_qemu_strtoull_full_empty);
1576 g_test_add_func("/cutils/qemu_strtoull_full/negative",
1577 test_qemu_strtoull_full_negative);
1578 g_test_add_func("/cutils/qemu_strtoull_full/trailing",
1579 test_qemu_strtoull_full_trailing);
1580 g_test_add_func("/cutils/qemu_strtoull_full/max",
1581 test_qemu_strtoull_full_max);
1582
1583 g_test_add_func("/cutils/strtosz/simple",
1584 test_qemu_strtosz_simple);
1585 g_test_add_func("/cutils/strtosz/units",
1586 test_qemu_strtosz_units);
1587 g_test_add_func("/cutils/strtosz/float",
1588 test_qemu_strtosz_float);
1589 g_test_add_func("/cutils/strtosz/erange",
1590 test_qemu_strtosz_erange);
1591 g_test_add_func("/cutils/strtosz/suffix-unit",
1592 test_qemu_strtosz_suffix_unit);
1593
1594 return g_test_run();
1595 }