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