libxl: ocaml: add simple test case for xentoollog
authorRob Hoes <rob.hoes@citrix.com>
Tue, 10 Dec 2013 16:48:25 +0000 (16:48 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 11 Dec 2013 13:17:24 +0000 (13:17 +0000)
Add a simple noddy test case (tools/ocaml/test) for the the Xentoollog OCaml
module.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
Acked-by: David Scott <dave.scott@eu.citrix.com>
.gitignore
.hgignore
tools/ocaml/Makefile
tools/ocaml/test/Makefile [new file with mode: 0644]
tools/ocaml/test/xtl.ml [new file with mode: 0644]

index 93aae7130b510fad0efa1e7d6101386eb3e9aaef..20f20ed69799fb878e167a6b6eab1137de0f3568 100644 (file)
@@ -385,6 +385,7 @@ tools/ocaml/libs/xentoollog/_xtl_levels.*
 tools/ocaml/libs/xentoollog/xentoollog.ml
 tools/ocaml/libs/xentoollog/xentoollog.mli
 tools/ocaml/xenstored/oxenstored
+tools/ocaml/test/xtl
 
 tools/debugger/kdd/kdd
 tools/firmware/etherboot/ipxe.tar.gz
index 05cb0de4cb72164ad13179443cfa8c569fc40164..bb1b67d9d5b20490ee2d85ebd5d161c5cb1e6619 100644 (file)
--- a/.hgignore
+++ b/.hgignore
 ^tools/ocaml/libs/xl/xenlight\.ml$
 ^tools/ocaml/libs/xl/xenlight\.mli$
 ^tools/ocaml/xenstored/oxenstored$
+^tools/ocaml/test/xtl$
 ^tools/autom4te\.cache$
 ^tools/config\.h$
 ^tools/config\.log$
index 6b22bbe779569aa754377a496243fc86b7bac788..8e4ca368b0dc7e5eef39a352819db6ea08b162cf 100644 (file)
@@ -1,7 +1,7 @@
 XEN_ROOT = $(CURDIR)/../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-SUBDIRS_PROGRAMS = xenstored
+SUBDIRS_PROGRAMS = xenstored test
 
 SUBDIRS = libs $(SUBDIRS_PROGRAMS)
 
diff --git a/tools/ocaml/test/Makefile b/tools/ocaml/test/Makefile
new file mode 100644 (file)
index 0000000..3a35d04
--- /dev/null
@@ -0,0 +1,28 @@
+XEN_ROOT = $(CURDIR)/../../..
+OCAML_TOPLEVEL = $(CURDIR)/..
+include $(OCAML_TOPLEVEL)/common.make
+
+OCAMLINCLUDE += \
+       -I $(OCAML_TOPLEVEL)/libs/xentoollog
+
+OBJS = xtl
+
+PROGRAMS = xtl
+
+xtl_LIBS =  \
+       -ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xentoollog $(OCAML_TOPLEVEL)/libs/xentoollog/xentoollog.cmxa \
+       -cclib $(LDLIBS_libxenctrl)
+
+xtl_OBJS = xtl
+
+OCAML_PROGRAM = xtl
+
+all: $(PROGRAMS)
+
+bins: $(PROGRAMS)
+
+install: all
+       $(INSTALL_DIR) $(DESTDIR)$(BINDIR)
+       $(INSTALL_PROG) $(PROGRAMS) $(DESTDIR)$(BINDIR)
+
+include $(OCAML_TOPLEVEL)/Makefile.rules
diff --git a/tools/ocaml/test/xtl.ml b/tools/ocaml/test/xtl.ml
new file mode 100644 (file)
index 0000000..6f4d85b
--- /dev/null
@@ -0,0 +1,40 @@
+open Arg
+open Printf
+open Xentoollog
+
+let stdio_vmessage min_level level errno ctx msg =
+       let level_str = level_to_string level
+       and errno_str = match errno with None -> "" | Some s -> sprintf ": errno=%d" s
+       and ctx_str = match ctx with None -> "" | Some s -> sprintf ": %s" s in
+       if compare min_level level <= 0 then begin
+               printf "%s%s%s: %s\n" level_str ctx_str errno_str msg;
+               flush stdout;
+       end
+
+let stdio_progress ctx what percent dne total =
+       let nl = if dne = total then "\n" else "" in
+       printf "\rProgress %s %d%% (%Ld/%Ld)%s" what percent dne total nl;
+       flush stdout
+
+let create_stdio_logger ?(level=Info) () =
+       let cbs = {
+               vmessage = stdio_vmessage level;
+               progress = stdio_progress; } in
+       create "Xentoollog.stdio_logger" cbs
+
+let do_test level =
+  let lgr = create_stdio_logger ~level:level () in
+  begin
+    test lgr;
+  end
+
+let () =
+  let debug_level = ref Info in
+  let speclist = [
+    ("-v", Arg.Unit (fun () -> debug_level := Debug), "Verbose");
+    ("-q", Arg.Unit (fun () -> debug_level := Critical), "Quiet");
+  ] in
+  let usage_msg = "usage: xtl [OPTIONS]" in
+  Arg.parse speclist (fun s -> ()) usage_msg;
+
+  do_test !debug_level