|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 2/2] tools/ocaml: check domain_create in the bindings test
The bindings test so far only checks values the C stubs build for OCaml.
The opposite direction, stub_xc_domain_create() reading the
domctl_create_config record, accesses its fields by hard coded index, so
a field added to or moved in xenctrl.mli without updating the stub
passes the wrong values to Xen without any error.
So, create a domain with distinct values, i.e. the handle, max_vcpus and
the arch config, read it back with domain_getinfo() and compare. On Arm
the domain gets the GIC version, on x86 it is PVH, or PV without HVM.
domain_create() only sets the vCPU limit, the vCPUs are created by
XEN_DOMCTL_max_vcpus with the same number, so check max_vcpu_id before
and after domain_max_vcpus(). XEN_DOMCTL_getdomaininfo reports neither
nr_spis nor misc_flags, so those can't be compared.
Signed-off-by: Julian Vetter <julian.vetter@xxxxxxxxxx>
---
tools/ocaml/tests/bindings/main.ml | 104 +++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
diff --git a/tools/ocaml/tests/bindings/main.ml
b/tools/ocaml/tests/bindings/main.ml
index 02049d2f79..71fc9920f6 100644
--- a/tools/ocaml/tests/bindings/main.ml
+++ b/tools/ocaml/tests/bindings/main.ml
@@ -119,6 +119,109 @@ let test_domain_getinfolist () =
List.iter check_dom doms
+(* Create a domain, read it back and check that the values made the round
+ trip through the stubs and Xen. *)
+let test_domain_create () =
+ printf "Test domain_create\n";
+
+ let p = Xenctrl.physinfo xch in
+ let has cap = List.mem cap p.Xenctrl.capabilities in
+
+ (* ARM: HVM and HAP are mandatory, and d0's vGIC is the host's GIC.
+ x86: a PVH guest (HAP if available, else shadow), or PV without HVM. *)
+ (* The annotation picks arch_domainconfig's ARM/X86, not the ones of the
+ later arch_physinfo_cap_flags. *)
+ let flags, (arch : Xenctrl.arch_domainconfig) =
+ match (Xenctrl.domain_getinfo xch 0).Xenctrl.arch_config with
+ | Xenctrl.ARM d0 ->
+ [ Xenctrl.CDF_HVM; Xenctrl.CDF_HAP ],
+ Xenctrl.ARM { Xenctrl.gic_version = d0.Xenctrl.gic_version; nr_spis = 0 }
+ | Xenctrl.X86 _ when has Xenctrl.CAP_HVM
+ && (has Xenctrl.CAP_HAP || has Xenctrl.CAP_Shadow) ->
+ Xenctrl.CDF_HVM :: (if has Xenctrl.CAP_HAP then [ Xenctrl.CDF_HAP ] else
[]),
+ Xenctrl.X86 { Xenctrl.emulation_flags = [ Xenctrl.X86_EMU_LAPIC ];
+ misc_flags = [] }
+ | Xenctrl.X86 _ ->
+ [],
+ Xenctrl.X86 { Xenctrl.emulation_flags = []; misc_flags = [] }
+ in
+
+ (* Xen copies the handle verbatim, so use distinct bytes. *)
+ let handle = "00112233-4455-6677-8899-aabbccddeeff" in
+ let handle_bytes = Array.init 16 (fun i -> i * 0x11) in
+ let max_vcpus = 2 in
+
+ let config = {
+ Xenctrl.ssidref = 0l;
+ handle;
+ flags;
+ iommu_opts = [];
+ max_vcpus;
+ max_evtchn_port = -1;
+ max_grant_frames = -1; (* < 0: Xen's default *)
+ max_maptrack_frames = -1;
+ max_grant_version = if has Xenctrl.CAP_Gnttab_v2 then 2 else 1;
+ altp2m_opts = 0l;
+ altp2m_count = 0l;
+ vmtrace_buf_kb = 0l;
+ cpupool_id = 0l;
+ arch;
+ } in
+
+ let domid = Xenctrl.domain_create xch config in
+ printf " Created d%d\n" domid;
+
+ Fun.protect ~finally:(fun () -> Xenctrl.domain_destroy xch domid) @@ fun ()
->
+ let name = sprintf "d%d" domid in
+
+ (* domain_create only sets the limit, the vCPUs are created by
+ XEN_DOMCTL_max_vcpus, which must pass the same number. Until then
+ there is no vCPU, reported as XEN_INVALID_MAX_VCPU_ID. *)
+ let di = Xenctrl.domain_getinfo xch domid in
+ if di.Xenctrl.max_vcpu_id >= 0 && di.Xenctrl.max_vcpu_id < max_vcpus then
+ fail "%s: max_vcpu_id %d before creating the vCPUs" name
di.Xenctrl.max_vcpu_id;
+ Xenctrl.domain_max_vcpus xch domid max_vcpus;
+
+ let di = Xenctrl.domain_getinfo xch domid in
+ check_record name di ~size:17;
+
+ if di.Xenctrl.domid <> domid then
+ fail "%s: domid %d" name di.Xenctrl.domid;
+ if di.Xenctrl.handle <> handle_bytes then
+ fail "%s: handle %s, expected %s" name
+ (String.concat ":" (Array.to_list (Array.map (sprintf "%02x")
di.Xenctrl.handle)))
+ handle;
+ if di.Xenctrl.ssidref <> 0l then
+ fail "%s: ssidref %ld, expected 0" name di.Xenctrl.ssidref;
+ if di.Xenctrl.max_vcpu_id <> max_vcpus - 1 then
+ fail "%s: max_vcpu_id %d, expected %d" name di.Xenctrl.max_vcpu_id
(max_vcpus - 1);
+ if di.Xenctrl.nr_online_vcpus <> 0 then
+ fail "%s: %d vCPUs online, expected 0" name di.Xenctrl.nr_online_vcpus;
+ if di.Xenctrl.hvm_guest <> List.mem Xenctrl.CDF_HVM flags then
+ fail "%s: hvm_guest %b" name di.Xenctrl.hvm_guest;
+ if not di.Xenctrl.paused then
+ fail "%s: not paused after creation" name;
+
+ (* XEN_DOMCTL_getdomaininfo reports neither nr_spis nor misc_flags. *)
+ match di.Xenctrl.arch_config, arch with
+ | (Xenctrl.ARM got as a), Xenctrl.ARM want ->
+ check_block (name ^ " arch_config") a ~tag:0 ~size:1;
+ check_record (name ^ " xen_arm_arch_domainconfig") got ~size:2;
+ printf " %s: ARM %s\n" name (string_of_gic_version
got.Xenctrl.gic_version);
+ if got.Xenctrl.gic_version <> want.Xenctrl.gic_version then
+ fail "%s: gic_version %d, expected %d" name
+ got.Xenctrl.gic_version want.Xenctrl.gic_version
+ | (Xenctrl.X86 got as a), Xenctrl.X86 want ->
+ check_block (name ^ " arch_config") a ~tag:1 ~size:1;
+ check_record (name ^ " xen_x86_arch_domainconfig") got ~size:2;
+ printf " %s: x86, %d emulation flags\n" name
+ (List.length got.Xenctrl.emulation_flags);
+ if List.sort compare got.Xenctrl.emulation_flags
+ <> List.sort compare want.Xenctrl.emulation_flags then
+ fail "%s: emulation_flags differ from the requested ones" name
+ | _ ->
+ fail "%s: arch_config of a different architecture" name
+
let run name f =
try f () with
| Xenctrl.Error e -> fail "%s: Xenctrl.Error %s" name e
@@ -130,6 +233,7 @@ let () =
run "version" test_xenversion;
run "physinfo" test_physinfo;
run "domain_getinfolist" test_domain_getinfolist;
+ run "domain_create" test_domain_create;
printf "Starting GC.compact()\n%!";
Gc.compact ();
--
2.53.0
--
Julian Vetter | Vates Hypervisor & Kernel Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |