diff options
Diffstat (limited to 'tools/libxen/test/test_bindings.c')
-rw-r--r-- | tools/libxen/test/test_bindings.c | 106 |
1 files changed, 89 insertions, 17 deletions
diff --git a/tools/libxen/test/test_bindings.c b/tools/libxen/test/test_bindings.c index 88fce8b35b..c1df98dcea 100644 --- a/tools/libxen/test/test_bindings.c +++ b/tools/libxen/test/test_bindings.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006 XenSource, Inc. + * Copyright (c) 2006-2007 XenSource, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -29,6 +29,7 @@ #include "xen_sr.h" #include "xen_vbd.h" #include "xen_vdi.h" +#include "xen_console.h" #include "xen_vm.h" @@ -58,7 +59,7 @@ typedef struct } xen_comms; -static xen_vm create_new_vm(xen_session *session); +static xen_vm create_new_vm(xen_session *session, bool hvm); static void print_vm_power_state(xen_session *session, xen_vm vm); @@ -205,6 +206,20 @@ int main(int argc, char **argv) return 1; } + char *dmesg; + if (!xen_host_dmesg(session, &dmesg, host)) + { + print_error(session); + xen_string_string_map_free(versions); + xen_host_free(host); + xen_vm_record_free(vm_record); + xen_uuid_bytes_free(vm_uuid_bytes); + xen_uuid_free(vm_uuid); + xen_vm_free(vm); + CLEANUP; + return 1; + } + printf("%s.\n", vm_uuid); fprintf(stderr, "In bytes, the VM UUID is "); @@ -222,6 +237,8 @@ int main(int argc, char **argv) versions->contents[i].val); } + printf("Host dmesg follows:\n%s\n\n", dmesg); + printf("%s.\n", vm_record->uuid); printf("Resident on %s.\n", (char *)vm_record->resident_on->u.handle); @@ -243,9 +260,10 @@ int main(int argc, char **argv) xen_host_free(host); xen_string_string_map_free(versions); + free(dmesg); - xen_vm new_vm = create_new_vm(session); + xen_vm new_vm = create_new_vm(session, true); if (!session->ok) { /* Error has been logged, just clean up. */ @@ -275,13 +293,28 @@ int main(int argc, char **argv) * allocation patterns can be used, as long as the allocation and free are * paired correctly. */ -static xen_vm create_new_vm(xen_session *session) +static xen_vm create_new_vm(xen_session *session, bool hvm) { xen_string_string_map *vcpus_params = xen_string_string_map_alloc(1); + vcpus_params->contents[0].key = strdup("weight"); + vcpus_params->contents[0].val = strdup("300"); + + xen_string_string_map *hvm_boot_params; + if (hvm) + { + hvm_boot_params = xen_string_string_map_alloc(1); + hvm_boot_params->contents[0].key = strdup("order"); + hvm_boot_params->contents[0].val = strdup("cd"); + } + else + { + hvm_boot_params = NULL; + } + xen_vm_record vm_record = { - .name_label = "NewVM", - .name_description = "New VM Description", + .name_label = hvm ? "NewHVM" : "NewPV", + .name_description = hvm ? "New HVM VM" : "New PV VM", .user_version = 1, .is_a_template = false, .memory_static_max = 256, @@ -294,18 +327,18 @@ static xen_vm create_new_vm(xen_session *session) .actions_after_shutdown = XEN_ON_NORMAL_EXIT_DESTROY, .actions_after_reboot = XEN_ON_NORMAL_EXIT_RESTART, .actions_after_crash = XEN_ON_CRASH_BEHAVIOUR_PRESERVE, - .hvm_boot = "", - .pv_bootloader = "pygrub", - .pv_kernel = "/boot/vmlinuz-2.6.16.33-xen", - .pv_ramdisk = "", - .pv_args = "", - .pv_bootloader_args = "" + .hvm_boot_policy = hvm ? "BIOS order" : NULL, + .hvm_boot_params = hvm ? hvm_boot_params : NULL, + .pv_bootloader = hvm ? NULL : "pygrub", + .pv_kernel = hvm ? NULL : "/boot/vmlinuz-2.6.16.33-xen", }; - xen_vm vm; xen_vm_create(session, &vm, &vm_record); + xen_string_string_map_free(vcpus_params); + xen_string_string_map_free(hvm_boot_params); + if (!session->ok) { fprintf(stderr, "VM creation failed.\n"); @@ -368,7 +401,8 @@ static xen_vm create_new_vm(xen_session *session) .vm = &vm_record_opt, .vdi = &vdi0_record_opt, .device = "xvda1", - .mode = XEN_VBD_MODE_RW + .mode = XEN_VBD_MODE_RW, + .bootable = 1, }; xen_vbd vbd0; @@ -383,13 +417,38 @@ static xen_vm create_new_vm(xen_session *session) return NULL; } + xen_console vnc_console = NULL; + if (hvm) { + xen_console_record vnc_console_record = + { + .protocol = XEN_CONSOLE_PROTOCOL_RFB, + .vm = &vm_record_opt, + }; + + if (!xen_console_create(session, &vnc_console, &vnc_console_record)) + { + fprintf(stderr, "VNC console creation failed.\n"); + print_error(session); + + xen_vbd_free(vbd0); + xen_vdi_free(vdi0); + xen_sr_set_free(srs); + xen_vm_free(vm); + return NULL; + } + } + char *vm_uuid; char *vdi0_uuid; char *vbd0_uuid; + char *vnc_uuid = NULL; xen_vm_get_uuid(session, &vm_uuid, vm); xen_vdi_get_uuid(session, &vdi0_uuid, vdi0); xen_vbd_get_uuid(session, &vbd0_uuid, vbd0); + if (hvm) { + xen_console_get_uuid(session, &vnc_uuid, vnc_console); + } if (!session->ok) { @@ -399,22 +458,35 @@ static xen_vm create_new_vm(xen_session *session) xen_uuid_free(vm_uuid); xen_uuid_free(vdi0_uuid); xen_uuid_free(vbd0_uuid); + xen_uuid_free(vnc_uuid); xen_vbd_free(vbd0); xen_vdi_free(vdi0); + xen_console_free(vnc_console); xen_sr_set_free(srs); xen_vm_free(vm); return NULL; } - fprintf(stderr, - "Created a new VM, with UUID %s, VDI UUID %s, and VBD UUID %s.\n", - vm_uuid, vdi0_uuid, vbd0_uuid); + if (hvm) { + fprintf(stderr, + "Created a new HVM VM, with UUID %s, VDI UUID %s, VBD " + "UUID %s, and VNC console UUID %s.\n", + vm_uuid, vdi0_uuid, vbd0_uuid, vnc_uuid); + } + else { + fprintf(stderr, + "Created a new PV VM, with UUID %s, VDI UUID %s, and VBD " + "UUID %s.\n", + vm_uuid, vdi0_uuid, vbd0_uuid); + } xen_uuid_free(vm_uuid); xen_uuid_free(vdi0_uuid); xen_uuid_free(vbd0_uuid); + xen_uuid_free(vnc_uuid); xen_vbd_free(vbd0); xen_vdi_free(vdi0); + xen_console_free(vnc_console); xen_sr_set_free(srs); return vm; |