Skip to contentSkip to conversation

tools/ocaml: Gitlab CI test for bindings

PATCH In review Andrew Cooper 3 participants 3 messages Oct 26 – Oct 27

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/ocaml: Gitlab CI test for bindings

... as building and interpreting Ocaml objects in C is rather fragile.

For C producing objects for Ocaml to consume, one trick to check validity is Gc.compact() which forces a major sweep, walking all objects. If this doesn't segfault, then we at least got the pointer <-> integer aspect right.

For now, start with a very simple version call. (Re)introduce tools/ocaml/tests and add test-ocaml-bindings which is installed into $(DESTDIR)$(LIBEXEC)/tests to be picked up automatically with the other dom0 tests.

---
CC: Andrii Sultanov <[email protected]>
CC: Guillaume Thouvenin <[email protected]>
CC: Julian Vetter <[email protected]>

https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2990559670/test_report

---
 tools/ocaml/Makefile                  |  1 +
 tools/ocaml/tests/Makefile            |  8 +++++++
 tools/ocaml/tests/bindings/.gitignore |  1 +
 tools/ocaml/tests/bindings/Makefile   | 34 +++++++++++++++++++++++++++
 tools/ocaml/tests/bindings/main.ml    | 19 +++++++++++++++
 5 files changed, 63 insertions(+)
 create mode 100644 tools/ocaml/tests/Makefile
 create mode 100644 tools/ocaml/tests/bindings/.gitignore
 create mode 100644 tools/ocaml/tests/bindings/Makefile
 create mode 100644 tools/ocaml/tests/bindings/main.ml
tools/ocaml/Makefile +1 -0
index 7252eb23d798..e570e30a6e8d 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 SUBDIRS := libs
 SUBDIRS += xenstored
+SUBDIRS += tests
 
 .NOTPARALLEL:
 # targets here must be run in order, otherwise we can try
tools/ocaml/tests/Makefile new file +8 -0
new file mode 100644
index 000000000000..e9f3557f1219
@@ -0,0 +1,8 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SUBDIRS-y :=
+SUBDIRS-y += bindings
+
+.PHONY: all clean install distclean uninstall
+all clean distclean install uninstall: %: subdirs-%
tools/ocaml/tests/bindings/.gitignore new file +1 -0
new file mode 100644
index 000000000000..6e9a7f429b49
@@ -0,0 +1 @@
+test-ocaml-bindings
tools/ocaml/tests/bindings/Makefile new file +34 -0
new file mode 100644
index 000000000000..75f8babbafca
@@ -0,0 +1,34 @@
+XEN_ROOT = $(CURDIR)/../../../..
+OCAML_TOPLEVEL = $(CURDIR)/../..
+include $(OCAML_TOPLEVEL)/common.make
+
+OBJS = main
+
+OCAMLINCLUDE += \
+	-I $(OCAML_TOPLEVEL)/libs/xb \
+	-I $(OCAML_TOPLEVEL)/libs/mmap \
+	-I $(OCAML_TOPLEVEL)/libs/xc \
+	-I $(OCAML_TOPLEVEL)/libs/eventchn
+
+LIBS = \
+	unix.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/mmap $(OCAML_TOPLEVEL)/libs/mmap/xenmmap.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/eventchn/xeneventchn.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xenctrl.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xenbus.cmxa \
+	-ccopt -L -ccopt $(XEN_ROOT)/tools/libs/ctrl
+
+PROGRAMS = test-ocaml-bindings
+OCAML_PROGRAM = test-ocaml-bindings
+
+test-ocaml-bindings_LIBS = $(LIBS)
+test-ocaml-bindings_MLSORTED = $(shell $(OCAMLDEP) -sort $(OBJS:=.ml))
+test-ocaml-bindings_OBJS = $(test-ocaml-bindings_MLSORTED:.ml=)
+
+all: test-ocaml-bindings
+
+install: all
+	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
+	$(INSTALL_PROG) test-ocaml-bindings $(DESTDIR)$(LIBEXEC)/tests
+
+include $(OCAML_TOPLEVEL)/Makefile.rules
tools/ocaml/tests/bindings/main.ml new file +19 -0
new file mode 100644
index 000000000000..785837e270ad
@@ -0,0 +1,19 @@
+open Printf
+
+let xch = Xenctrl.interface_open ()
+
+let test_xenversion () =
+  let ver = Xenctrl.version xch in
+  printf "Xen version: %d.%d%s\n" ver.major ver.minor ver.extra
+
+
+let () =
+  printf "Test Ocaml Bindings\n%!";
+
+  test_xenversion ();
+
+  printf "Starting GC.compact()\n%!";
+  Gc.compact ();
+  printf "GC done\n";
+
+  ()

base-commit: 46678752be2d97f61317d793408a59927a429847

Signature · 1 line
2.39.5
Acked-by on v1 1/1
#1 lore raw
Quoted 129 lines · Andrew Cooper

... as building and interpreting Ocaml objects in C is rather fragile.

For C producing objects for Ocaml to consume, one trick to check validity is Gc.compact() which forces a major sweep, walking all objects. If this doesn't segfault, then we at least got the pointer <-> integer aspect right.

For now, start with a very simple version call. (Re)introduce tools/ocaml/tests and add test-ocaml-bindings which is installed into $(DESTDIR)$(LIBEXEC)/tests to be picked up automatically with the other dom0 tests.

---
CC: Andrii Sultanov <[email protected]>
CC: Guillaume Thouvenin <[email protected]>
CC: Julian Vetter <[email protected]>

https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2990559670/test_report

---
  tools/ocaml/Makefile                  |  1 +
  tools/ocaml/tests/Makefile            |  8 +++++++
  tools/ocaml/tests/bindings/.gitignore |  1 +
  tools/ocaml/tests/bindings/Makefile   | 34 +++++++++++++++++++++++++++
  tools/ocaml/tests/bindings/main.ml    | 19 +++++++++++++++
  5 files changed, 63 insertions(+)

create mode 100644 tools/ocaml/tests/Makefile create mode 100644 tools/ocaml/tests/bindings/.gitignore create mode 100644 tools/ocaml/tests/bindings/Makefile create mode 100644 tools/ocaml/tests/bindings/main.ml

tools/ocaml/Makefile +1 -0
index 7252eb23d798..e570e30a6e8d 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
  SUBDIRS := libs
  SUBDIRS += xenstored
+SUBDIRS += tests
 
  .NOTPARALLEL:
  # targets here must be run in order, otherwise we can try
tools/ocaml/tests/Makefile new file +8 -0
new file mode 100644
index 000000000000..e9f3557f1219
@@ -0,0 +1,8 @@
+XEN_ROOT = $(CURDIR)/../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+SUBDIRS-y :=
+SUBDIRS-y += bindings
+
+.PHONY: all clean install distclean uninstall
+all clean distclean install uninstall: %: subdirs-%
tools/ocaml/tests/bindings/.gitignore new file +1 -0
new file mode 100644
index 000000000000..6e9a7f429b49
@@ -0,0 +1 @@
+test-ocaml-bindings
tools/ocaml/tests/bindings/Makefile new file +34 -0
new file mode 100644
index 000000000000..75f8babbafca
@@ -0,0 +1,34 @@
+XEN_ROOT = $(CURDIR)/../../../..
+OCAML_TOPLEVEL = $(CURDIR)/../..
+include $(OCAML_TOPLEVEL)/common.make
+
+OBJS = main
+
+OCAMLINCLUDE += \
+	-I $(OCAML_TOPLEVEL)/libs/xb \
+	-I $(OCAML_TOPLEVEL)/libs/mmap \
+	-I $(OCAML_TOPLEVEL)/libs/xc \
+	-I $(OCAML_TOPLEVEL)/libs/eventchn
+
+LIBS = \
+	unix.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/mmap $(OCAML_TOPLEVEL)/libs/mmap/xenmmap.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/eventchn/xeneventchn.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xenctrl.cmxa \
+	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xb $(OCAML_TOPLEVEL)/libs/xb/xenbus.cmxa \
+	-ccopt -L -ccopt $(XEN_ROOT)/tools/libs/ctrl
+
+PROGRAMS = test-ocaml-bindings
+OCAML_PROGRAM = test-ocaml-bindings
+
+test-ocaml-bindings_LIBS = $(LIBS)
+test-ocaml-bindings_MLSORTED = $(shell $(OCAMLDEP) -sort $(OBJS:=.ml))
+test-ocaml-bindings_OBJS = $(test-ocaml-bindings_MLSORTED:.ml=)
+
+all: test-ocaml-bindings
+
+install: all
+	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)/tests
+	$(INSTALL_PROG) test-ocaml-bindings $(DESTDIR)$(LIBEXEC)/tests
+
+include $(OCAML_TOPLEVEL)/Makefile.rules
tools/ocaml/tests/bindings/main.ml new file +19 -0
new file mode 100644
index 000000000000..785837e270ad
@@ -0,0 +1,19 @@
+open Printf
+
+let xch = Xenctrl.interface_open ()
+
+let test_xenversion () =
+  let ver = Xenctrl.version xch in
+  printf "Xen version: %d.%d%s\n" ver.major ver.minor ver.extra
+
+
+let () =
+  printf "Test Ocaml Bindings\n%!";
+
+  test_xenversion ();
+
+  printf "Starting GC.compact()\n%!";
+  Gc.compact ();
+  printf "GC done\n";
+
+  ()
Quoted 1 line

base-commit: 46678752be2d97f61317d793408a59927a429847

Acked-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 15 lines
tools/ocaml/tests/bindings/main.ml new file +13 -0
+  printf "Xen version: %d.%d%s\n" ver.major ver.minor ver.extra
+
+
+let () =
+  printf "Test Ocaml Bindings\n%!";
+
+  test_xenversion ();
+
+  printf "Starting GC.compact()\n%!";
+  Gc.compact ();
+  printf "GC done\n";
+
+  ()
Quoted 1 line

base-commit: 46678752be2d97f61317d793408a59927a429847

Thank you Andrew, I will add the other test next to this one.

--
Julian Vetter | Vates Hypervisor & Kernel Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech