|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v2 4/9] 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>
---
Changes in v2:
- Open Xenctrl, to remove the Xenctrl. prefixes
- Destroy domain without Fun.protect (needs OCaml >= 4.08)
---
tools/ocaml/tests/bindings/main.ml | 116 +++++++++++++++++++++++++++++
1 file changed, 116 insertions(+)
diff --git a/tools/ocaml/tests/bindings/main.ml
b/tools/ocaml/tests/bindings/main.ml
index 9c85829275..3f670f1158 100644
--- a/tools/ocaml/tests/bindings/main.ml
+++ b/tools/ocaml/tests/bindings/main.ml
@@ -120,6 +120,121 @@ let test_domain_getinfolist () =
List.iter check_dom doms
+(* Check the domain test_domain_create created against the values it was
+ created with. *)
+let check_created_domain domid ~handle ~handle_bytes ~max_vcpus ~flags
+ ~(arch : arch_domainconfig) =
+ 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 and it will just report XEN_INVALID_MAX_VCPU_ID. *)
+ let di = domain_getinfo xch domid in
+ if di.max_vcpu_id >= 0 && di.max_vcpu_id < max_vcpus then
+ fail "%s: max_vcpu_id %d before creating the vCPUs" name di.max_vcpu_id;
+ domain_max_vcpus xch domid max_vcpus;
+
+ let di = domain_getinfo xch domid in
+ check_record name di ~size:17;
+
+ if di.domid <> domid then
+ fail "%s: domid %d" name di.domid;
+ if di.handle <> handle_bytes then
+ fail "%s: handle %s, expected %s" name
+ (String.concat ":" (Array.to_list (Array.map (sprintf "%02x")
di.handle)))
+ handle;
+ if di.ssidref <> 0l then
+ fail "%s: ssidref %ld, expected 0" name di.ssidref;
+ if di.max_vcpu_id <> max_vcpus - 1 then
+ fail "%s: max_vcpu_id %d, expected %d" name di.max_vcpu_id (max_vcpus - 1);
+ if di.nr_online_vcpus <> 0 then
+ fail "%s: %d vCPUs online, expected 0" name di.nr_online_vcpus;
+ if di.hvm_guest <> List.mem CDF_HVM flags then
+ fail "%s: hvm_guest %b" name di.hvm_guest;
+ if not di.paused then
+ fail "%s: not paused after creation" name;
+
+ (* XEN_DOMCTL_getdomaininfo reports neither nr_spis nor misc_flags. *)
+ match di.arch_config, arch with
+ | (ARM got as a), 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.gic_version);
+ if got.gic_version <> want.gic_version then
+ fail "%s: gic_version %d, expected %d" name
+ got.gic_version want.gic_version
+ | (X86 got as a), 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.emulation_flags);
+ if List.sort compare got.emulation_flags
+ <> List.sort compare want.emulation_flags then
+ fail "%s: emulation_flags differ from the requested ones" name
+ | _ ->
+ fail "%s: arch_config of a different architecture" name
+
+(* 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 = physinfo xch in
+ let has cap = List.mem cap p.capabilities in
+
+ (* ARM: HVM and HAP are mandatory, and the vGIC of d0 is the GIC of the host.
+ x86: a PVH guest (HAP if available, else shadow), or PV without HVM. *)
+(* ARM and X86 are constructors of both arch_domainconfig and
+ arch_physinfo_cap_flags. Without the annotation, ARM { ... } and X86 {... }
+ below would be taken as arch_physinfo_cap_flags, the type defined last in
+ xenctrl.mli, and fail to compile. *)
+ let flags, (arch : arch_domainconfig) =
+ match (domain_getinfo xch 0).arch_config with
+ | ARM d0 ->
+ [ CDF_HVM; CDF_HAP ],
+ ARM { gic_version = d0.gic_version; nr_spis = 0 }
+ | X86 _ when has CAP_HVM
+ && (has CAP_HAP || has CAP_Shadow) ->
+ CDF_HVM :: (if has CAP_HAP then [ CDF_HAP ] else []),
+ X86 { emulation_flags = [ X86_EMU_LAPIC ];
+ misc_flags = [] }
+ | X86 _ ->
+ [],
+ X86 { emulation_flags = []; misc_flags = [] }
+ in
+
+ (* Xen just copies the handle as is, so use a recognizable pattern. *)
+ 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 = {
+ ssidref = 0l;
+ handle;
+ flags;
+ iommu_opts = [];
+ max_vcpus;
+ max_evtchn_port = -1;
+ max_grant_frames = -1;
+ max_maptrack_frames = -1;
+ max_grant_version = if has CAP_Gnttab_v2 then 2 else 1;
+ altp2m_opts = 0l;
+ altp2m_count = 0l;
+ vmtrace_buf_kb = 0l;
+ cpupool_id = 0l;
+ arch;
+ } in
+
+ let domid = domain_create xch config in
+ printf " Created d%d\n" domid;
+
+ (* Destroy the domain also if a check raises, e.g. Xenctrl.Error, so a
+ failing test doesn't leave it behind. *)
+ match check_created_domain domid ~handle ~handle_bytes ~max_vcpus ~flags
+ ~arch with
+ | () -> domain_destroy xch domid
+ | exception e -> domain_destroy xch domid; raise e
+
let run name f =
try f () with
| Xenctrl.Error e -> fail "%s: Xenctrl.Error %s" name e
@@ -131,6 +246,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 |