~ubuntu-branches/ubuntu/trusty/qemu/trusty

« back to all changes in this revision

Viewing changes to tests/test-qmp-output-visitor.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2013-10-22 22:47:07 UTC
  • mfrom: (1.8.3) (10.1.42 sid)
  • Revision ID: package-import@ubuntu.com-20131022224707-1lya34fw3k3f24tv
Tags: 1.6.0+dfsg-2ubuntu1
* Merge 1.6.0~rc0+dfsg-2exp from debian experimental.  Remaining changes:
  - debian/control
    * update maintainer
    * remove libiscsi, usb-redir, vde, vnc-jpeg, and libssh2-1-dev
      from build-deps
    * enable rbd
    * add qemu-system and qemu-common B/R to qemu-keymaps
    * add D:udev, R:qemu, R:qemu-common and B:qemu-common to
      qemu-system-common
    * qemu-system-arm, qemu-system-ppc, qemu-system-sparc:
      - add qemu-kvm to Provides
      - add qemu-common, qemu-kvm, kvm to B/R
      - remove openbios-sparc from qemu-system-sparc D
      - drop openbios-ppc and openhackware Depends to Suggests (for now)
    * qemu-system-x86:
      - add qemu-common to Breaks/Replaces.
      - add cpu-checker to Recommends.
    * qemu-user: add B/R:qemu-kvm
    * qemu-kvm:
      - add armhf armel powerpc sparc to Architecture
      - C/R/P: qemu-kvm-spice
    * add qemu-common package
    * drop qemu-slof which is not packaged in ubuntu
  - add qemu-system-common.links for tap ifup/down scripts and OVMF link.
  - qemu-system-x86.links:
    * remove pxe rom links which are in kvm-ipxe
    * add symlink for kvm.1 manpage
  - debian/rules
    * add kvm-spice symlink to qemu-kvm
    * call dh_installmodules for qemu-system-x86
    * update dh_installinit to install upstart script
    * run dh_installman (Closes: #709241) (cherrypicked from 1.5.0+dfsg-2)
  - Add qemu-utils.links for kvm-* symlinks.
  - Add qemu-system-x86.qemu-kvm.upstart and .default
  - Add qemu-system-x86.modprobe to set nesting=1
  - Add qemu-system-common.preinst to add kvm group
  - qemu-system-common.postinst: remove bad group acl if there, then have
    udev relabel /dev/kvm.
  - New linaro patches from qemu-linaro rebasing branch
  - Dropped patches:
    * xen-simplify-xen_enabled.patch
    * sparc-linux-user-fix-missing-symbols-in-.rel-.rela.plt-sections.patch
    * main_loop-do-not-set-nonblocking-if-xen_enabled.patch
    * xen_machine_pv-do-not-create-a-dummy-CPU-in-machine-.patch
    * virtio-rng-fix-crash
  - Kept patches:
    * expose_vms_qemu64cpu.patch - updated
    * linaro arm patches from qemu-linaro rebasing branch
  - New patches:
    * fix-pci-add: change CONFIG variable in ifdef to make sure that
      pci_add is defined.
* Add linaro patches
* Add experimental mach-virt patches for arm virtualization.
* qemu-system-common.install: add debian/tmp/usr/lib to install the
  qemu-bridge-helper

Show diffs side-by-side

added added

removed removed

Lines of Context:
295
295
 
296
296
typedef struct TestStructList
297
297
{
298
 
    TestStruct *value;
 
298
    union {
 
299
        TestStruct *value;
 
300
        uint64_t padding;
 
301
    };
299
302
    struct TestStructList *next;
300
303
} TestStructList;
301
304
 
431
434
    QDECREF(qdict);
432
435
}
433
436
 
 
437
static void init_native_list(UserDefNativeListUnion *cvalue)
 
438
{
 
439
    int i;
 
440
    switch (cvalue->kind) {
 
441
    case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER: {
 
442
        intList **list = &cvalue->integer;
 
443
        for (i = 0; i < 32; i++) {
 
444
            *list = g_new0(intList, 1);
 
445
            (*list)->value = i;
 
446
            (*list)->next = NULL;
 
447
            list = &(*list)->next;
 
448
        }
 
449
        break;
 
450
    }
 
451
    case USER_DEF_NATIVE_LIST_UNION_KIND_S8: {
 
452
        int8List **list = &cvalue->s8;
 
453
        for (i = 0; i < 32; i++) {
 
454
            *list = g_new0(int8List, 1);
 
455
            (*list)->value = i;
 
456
            (*list)->next = NULL;
 
457
            list = &(*list)->next;
 
458
        }
 
459
        break;
 
460
    }
 
461
    case USER_DEF_NATIVE_LIST_UNION_KIND_S16: {
 
462
        int16List **list = &cvalue->s16;
 
463
        for (i = 0; i < 32; i++) {
 
464
            *list = g_new0(int16List, 1);
 
465
            (*list)->value = i;
 
466
            (*list)->next = NULL;
 
467
            list = &(*list)->next;
 
468
        }
 
469
        break;
 
470
    }
 
471
    case USER_DEF_NATIVE_LIST_UNION_KIND_S32: {
 
472
        int32List **list = &cvalue->s32;
 
473
        for (i = 0; i < 32; i++) {
 
474
            *list = g_new0(int32List, 1);
 
475
            (*list)->value = i;
 
476
            (*list)->next = NULL;
 
477
            list = &(*list)->next;
 
478
        }
 
479
        break;
 
480
    }
 
481
    case USER_DEF_NATIVE_LIST_UNION_KIND_S64: {
 
482
        int64List **list = &cvalue->s64;
 
483
        for (i = 0; i < 32; i++) {
 
484
            *list = g_new0(int64List, 1);
 
485
            (*list)->value = i;
 
486
            (*list)->next = NULL;
 
487
            list = &(*list)->next;
 
488
        }
 
489
        break;
 
490
    }
 
491
    case USER_DEF_NATIVE_LIST_UNION_KIND_U8: {
 
492
        uint8List **list = &cvalue->u8;
 
493
        for (i = 0; i < 32; i++) {
 
494
            *list = g_new0(uint8List, 1);
 
495
            (*list)->value = i;
 
496
            (*list)->next = NULL;
 
497
            list = &(*list)->next;
 
498
        }
 
499
        break;
 
500
    }
 
501
    case USER_DEF_NATIVE_LIST_UNION_KIND_U16: {
 
502
        uint16List **list = &cvalue->u16;
 
503
        for (i = 0; i < 32; i++) {
 
504
            *list = g_new0(uint16List, 1);
 
505
            (*list)->value = i;
 
506
            (*list)->next = NULL;
 
507
            list = &(*list)->next;
 
508
        }
 
509
        break;
 
510
    }
 
511
    case USER_DEF_NATIVE_LIST_UNION_KIND_U32: {
 
512
        uint32List **list = &cvalue->u32;
 
513
        for (i = 0; i < 32; i++) {
 
514
            *list = g_new0(uint32List, 1);
 
515
            (*list)->value = i;
 
516
            (*list)->next = NULL;
 
517
            list = &(*list)->next;
 
518
        }
 
519
        break;
 
520
    }
 
521
    case USER_DEF_NATIVE_LIST_UNION_KIND_U64: {
 
522
        uint64List **list = &cvalue->u64;
 
523
        for (i = 0; i < 32; i++) {
 
524
            *list = g_new0(uint64List, 1);
 
525
            (*list)->value = i;
 
526
            (*list)->next = NULL;
 
527
            list = &(*list)->next;
 
528
        }
 
529
        break;
 
530
    }
 
531
    case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN: {
 
532
        boolList **list = &cvalue->boolean;
 
533
        for (i = 0; i < 32; i++) {
 
534
            *list = g_new0(boolList, 1);
 
535
            (*list)->value = (i % 3 == 0);
 
536
            (*list)->next = NULL;
 
537
            list = &(*list)->next;
 
538
        }
 
539
        break;
 
540
    }
 
541
    case USER_DEF_NATIVE_LIST_UNION_KIND_STRING: {
 
542
        strList **list = &cvalue->string;
 
543
        for (i = 0; i < 32; i++) {
 
544
            *list = g_new0(strList, 1);
 
545
            (*list)->value = g_strdup_printf("%d", i);
 
546
            (*list)->next = NULL;
 
547
            list = &(*list)->next;
 
548
        }
 
549
        break;
 
550
    }
 
551
    case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER: {
 
552
        numberList **list = &cvalue->number;
 
553
        for (i = 0; i < 32; i++) {
 
554
            *list = g_new0(numberList, 1);
 
555
            (*list)->value = (double)i / 3;
 
556
            (*list)->next = NULL;
 
557
            list = &(*list)->next;
 
558
        }
 
559
        break;
 
560
    }
 
561
    default:
 
562
        g_assert_not_reached();
 
563
    }
 
564
}
 
565
 
 
566
static void check_native_list(QObject *qobj,
 
567
                              UserDefNativeListUnionKind kind)
 
568
{
 
569
    QDict *qdict;
 
570
    QList *qlist;
 
571
    int i;
 
572
 
 
573
    g_assert(qobj);
 
574
    g_assert(qobject_type(qobj) == QTYPE_QDICT);
 
575
    qdict = qobject_to_qdict(qobj);
 
576
    g_assert(qdict);
 
577
    g_assert(qdict_haskey(qdict, "data"));
 
578
    qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data")));
 
579
 
 
580
    switch (kind) {
 
581
    case USER_DEF_NATIVE_LIST_UNION_KIND_S8:
 
582
    case USER_DEF_NATIVE_LIST_UNION_KIND_S16:
 
583
    case USER_DEF_NATIVE_LIST_UNION_KIND_S32:
 
584
    case USER_DEF_NATIVE_LIST_UNION_KIND_S64:
 
585
    case USER_DEF_NATIVE_LIST_UNION_KIND_U8:
 
586
    case USER_DEF_NATIVE_LIST_UNION_KIND_U16:
 
587
    case USER_DEF_NATIVE_LIST_UNION_KIND_U32:
 
588
    case USER_DEF_NATIVE_LIST_UNION_KIND_U64:
 
589
        /* all integer elements in JSON arrays get stored into QInts when
 
590
         * we convert to QObjects, so we can check them all in the same
 
591
         * fashion, so simply fall through here
 
592
         */
 
593
    case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER:
 
594
        for (i = 0; i < 32; i++) {
 
595
            QObject *tmp;
 
596
            QInt *qvalue;
 
597
            tmp = qlist_peek(qlist);
 
598
            g_assert(tmp);
 
599
            qvalue = qobject_to_qint(tmp);
 
600
            g_assert_cmpint(qint_get_int(qvalue), ==, i);
 
601
            qobject_decref(qlist_pop(qlist));
 
602
        }
 
603
        break;
 
604
    case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN:
 
605
        for (i = 0; i < 32; i++) {
 
606
            QObject *tmp;
 
607
            QBool *qvalue;
 
608
            tmp = qlist_peek(qlist);
 
609
            g_assert(tmp);
 
610
            qvalue = qobject_to_qbool(tmp);
 
611
            g_assert_cmpint(qbool_get_int(qvalue), ==, (i % 3 == 0) ? 1 : 0);
 
612
            qobject_decref(qlist_pop(qlist));
 
613
        }
 
614
        break;
 
615
    case USER_DEF_NATIVE_LIST_UNION_KIND_STRING:
 
616
        for (i = 0; i < 32; i++) {
 
617
            QObject *tmp;
 
618
            QString *qvalue;
 
619
            gchar str[8];
 
620
            tmp = qlist_peek(qlist);
 
621
            g_assert(tmp);
 
622
            qvalue = qobject_to_qstring(tmp);
 
623
            sprintf(str, "%d", i);
 
624
            g_assert_cmpstr(qstring_get_str(qvalue), ==, str);
 
625
            qobject_decref(qlist_pop(qlist));
 
626
        }
 
627
        break;
 
628
    case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER:
 
629
        for (i = 0; i < 32; i++) {
 
630
            QObject *tmp;
 
631
            QFloat *qvalue;
 
632
            GString *double_expected = g_string_new("");
 
633
            GString *double_actual = g_string_new("");
 
634
 
 
635
            tmp = qlist_peek(qlist);
 
636
            g_assert(tmp);
 
637
            qvalue = qobject_to_qfloat(tmp);
 
638
            g_string_printf(double_expected, "%.6f", (double)i / 3);
 
639
            g_string_printf(double_actual, "%.6f", qfloat_get_double(qvalue));
 
640
            g_assert_cmpstr(double_actual->str, ==, double_expected->str);
 
641
 
 
642
            qobject_decref(qlist_pop(qlist));
 
643
            g_string_free(double_expected, true);
 
644
            g_string_free(double_actual, true);
 
645
        }
 
646
        break;
 
647
    default:
 
648
        g_assert_not_reached();
 
649
    }
 
650
    QDECREF(qlist);
 
651
}
 
652
 
 
653
static void test_native_list(TestOutputVisitorData *data,
 
654
                             const void *unused,
 
655
                             UserDefNativeListUnionKind kind)
 
656
{
 
657
    UserDefNativeListUnion *cvalue = g_new0(UserDefNativeListUnion, 1);
 
658
    Error *err = NULL;
 
659
    QObject *obj;
 
660
 
 
661
    cvalue->kind = kind;
 
662
    init_native_list(cvalue);
 
663
 
 
664
    visit_type_UserDefNativeListUnion(data->ov, &cvalue, NULL, &err);
 
665
    g_assert(err == NULL);
 
666
 
 
667
    obj = qmp_output_get_qobject(data->qov);
 
668
    check_native_list(obj, cvalue->kind);
 
669
    qapi_free_UserDefNativeListUnion(cvalue);
 
670
    qobject_decref(obj);
 
671
}
 
672
 
 
673
static void test_visitor_out_native_list_int(TestOutputVisitorData *data,
 
674
                                             const void *unused)
 
675
{
 
676
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER);
 
677
}
 
678
 
 
679
static void test_visitor_out_native_list_int8(TestOutputVisitorData *data,
 
680
                                              const void *unused)
 
681
{
 
682
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S8);
 
683
}
 
684
 
 
685
static void test_visitor_out_native_list_int16(TestOutputVisitorData *data,
 
686
                                               const void *unused)
 
687
{
 
688
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S16);
 
689
}
 
690
 
 
691
static void test_visitor_out_native_list_int32(TestOutputVisitorData *data,
 
692
                                               const void *unused)
 
693
{
 
694
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S32);
 
695
}
 
696
 
 
697
static void test_visitor_out_native_list_int64(TestOutputVisitorData *data,
 
698
                                               const void *unused)
 
699
{
 
700
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_S64);
 
701
}
 
702
 
 
703
static void test_visitor_out_native_list_uint8(TestOutputVisitorData *data,
 
704
                                               const void *unused)
 
705
{
 
706
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U8);
 
707
}
 
708
 
 
709
static void test_visitor_out_native_list_uint16(TestOutputVisitorData *data,
 
710
                                                const void *unused)
 
711
{
 
712
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U16);
 
713
}
 
714
 
 
715
static void test_visitor_out_native_list_uint32(TestOutputVisitorData *data,
 
716
                                                const void *unused)
 
717
{
 
718
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U32);
 
719
}
 
720
 
 
721
static void test_visitor_out_native_list_uint64(TestOutputVisitorData *data,
 
722
                                                const void *unused)
 
723
{
 
724
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_U64);
 
725
}
 
726
 
 
727
static void test_visitor_out_native_list_bool(TestOutputVisitorData *data,
 
728
                                              const void *unused)
 
729
{
 
730
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN);
 
731
}
 
732
 
 
733
static void test_visitor_out_native_list_str(TestOutputVisitorData *data,
 
734
                                              const void *unused)
 
735
{
 
736
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_STRING);
 
737
}
 
738
 
 
739
static void test_visitor_out_native_list_number(TestOutputVisitorData *data,
 
740
                                                const void *unused)
 
741
{
 
742
    test_native_list(data, unused, USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER);
 
743
}
 
744
 
434
745
static void output_visitor_test_add(const char *testpath,
435
746
                                    TestOutputVisitorData *data,
436
747
                                    void (*test_func)(TestOutputVisitorData *data, const void *user_data))
471
782
                            &out_visitor_data, test_visitor_out_list_qapi_free);
472
783
    output_visitor_test_add("/visitor/output/union",
473
784
                            &out_visitor_data, test_visitor_out_union);
 
785
    output_visitor_test_add("/visitor/output/native_list/int",
 
786
                            &out_visitor_data, test_visitor_out_native_list_int);
 
787
    output_visitor_test_add("/visitor/output/native_list/int8",
 
788
                            &out_visitor_data, test_visitor_out_native_list_int8);
 
789
    output_visitor_test_add("/visitor/output/native_list/int16",
 
790
                            &out_visitor_data, test_visitor_out_native_list_int16);
 
791
    output_visitor_test_add("/visitor/output/native_list/int32",
 
792
                            &out_visitor_data, test_visitor_out_native_list_int32);
 
793
    output_visitor_test_add("/visitor/output/native_list/int64",
 
794
                            &out_visitor_data, test_visitor_out_native_list_int64);
 
795
    output_visitor_test_add("/visitor/output/native_list/uint8",
 
796
                            &out_visitor_data, test_visitor_out_native_list_uint8);
 
797
    output_visitor_test_add("/visitor/output/native_list/uint16",
 
798
                            &out_visitor_data, test_visitor_out_native_list_uint16);
 
799
    output_visitor_test_add("/visitor/output/native_list/uint32",
 
800
                            &out_visitor_data, test_visitor_out_native_list_uint32);
 
801
    output_visitor_test_add("/visitor/output/native_list/uint64",
 
802
                            &out_visitor_data, test_visitor_out_native_list_uint64);
 
803
    output_visitor_test_add("/visitor/output/native_list/bool",
 
804
                            &out_visitor_data, test_visitor_out_native_list_bool);
 
805
    output_visitor_test_add("/visitor/output/native_list/string",
 
806
                            &out_visitor_data, test_visitor_out_native_list_str);
 
807
    output_visitor_test_add("/visitor/output/native_list/number",
 
808
                            &out_visitor_data, test_visitor_out_native_list_number);
474
809
 
475
810
    g_test_run();
476
811