[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/9] tools/ocaml: check physinfo in the bindings test



Call physinfo() and check the returned record, that the capability flags
are valid constructors, and the arch_capabilities variant, including the
Arm specific arm_physinfo_caps. Also print every field.

Signed-off-by: Julian Vetter <julian.vetter@xxxxxxxxxx>
---
Changes in v2:
- New patch split out of the v1 patch
---
 tools/ocaml/tests/bindings/main.ml | 40 ++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/tools/ocaml/tests/bindings/main.ml 
b/tools/ocaml/tests/bindings/main.ml
index 3302a7f054..f4ebb2b1e2 100644
--- a/tools/ocaml/tests/bindings/main.ml
+++ b/tools/ocaml/tests/bindings/main.ml
@@ -27,11 +27,50 @@ let check_enum name v ~nr =
     fail "%s: not one of the %d constructors" name nr;
   ok
 
+let string_of_cap_flag = function
+  | CAP_HVM -> "hvm"
+  | CAP_PV -> "pv"
+  | CAP_DirectIO -> "directio"
+  | CAP_HAP -> "hap"
+  | CAP_Shadow -> "shadow"
+  | CAP_IOMMU_HAP_PT_SHARE -> "iommu_hap_pt_share"
+  | CAP_Vmtrace -> "vmtrace"
+  | CAP_Vpmu -> "vpmu"
+  | CAP_Gnttab_v1 -> "gnttab-v1"
+  | CAP_Gnttab_v2 -> "gnttab-v2"
+
 let test_xenversion () =
   let ver = version xch in
   check_record "version" ver ~size:3;
   printf "Xen version: %d.%d%s\n" ver.major ver.minor ver.extra
 
+let test_physinfo () =
+  printf "Test physinfo\n";
+
+  let p = physinfo xch in
+  check_record "physinfo" p ~size:11;
+  printf "  threads_per_core %d, cores_per_socket %d, nr_cpus %d\n"
+    p.threads_per_core p.cores_per_socket p.nr_cpus;
+  printf "  max_node_id %d, cpu_khz %d, max_nr_cpus %d\n"
+    p.max_node_id p.cpu_khz p.max_nr_cpus;
+  printf "  total_pages %nd, free_pages %nd, scrub_pages %nd\n"
+    p.total_pages p.free_pages p.scrub_pages;
+
+  (* Only match on the flags once they are known to be valid constructors. *)
+  if List.for_all (fun f -> check_enum "physinfo cap flag" f ~nr:10)
+      p.capabilities then
+    printf "  capabilities: %s\n"
+      (String.concat " " (List.map string_of_cap_flag p.capabilities));
+
+  match p.arch_capabilities with
+  | ARM caps as a ->
+    check_block "arch_capabilities" a ~tag:0 ~size:1;
+    check_record "arm_physinfo_caps" caps ~size:1;
+    printf "  ARM: sve_vl %d\n" caps.sve_vl
+  | X86 flags as a ->
+    check_block "arch_capabilities" a ~tag:1 ~size:1;
+    printf "  x86: %d arch capability flags\n" (List.length flags)
+
 let run name f =
   try f () with
   | Xenctrl.Error e -> fail "%s: Xenctrl.Error %s" name e
@@ -41,6 +80,7 @@ let () =
   printf "Test Ocaml Bindings\n%!";
 
   run "version" test_xenversion;
+  run "physinfo" test_physinfo;
 
   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

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.