Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add unit tests for the platformdata checks

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information...
commit 17665ba67f6eccb2c2e06641878a5c8c21b1a78f 1 parent e0a272f
@johnelse authored
View
1  ocaml/test/OMakefile
@@ -34,5 +34,6 @@ OCAML_OBJS = \
test_ca98944 \
test_pr1510 \
test_pool_license \
+ test_platformdata \
OCamlProgram(suite, suite $(OCAML_OBJS) )
View
1  ocaml/test/suite.ml
@@ -24,6 +24,7 @@ let base_suite =
Test_ca98944.test;
Test_pr1510.suite;
Test_pool_license.test;
+ Test_platformdata.test;
]
let _ = run_test_tt_main base_suite
View
127 ocaml/test/test_platformdata.ml
@@ -0,0 +1,127 @@
+(*
+ * Copyright (C) 2006-2013 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+open Fun
+open OUnit
+open Test_highlevel
+
+module SanityCheck = struct
+ module Tests = Generic.Make(struct
+ module Io = struct
+ type input_t = ((string * string) list * bool)
+ type output_t = (string * string) list
+
+ let string_of_input_t input =
+ Printf.sprintf "(platformdata = %s, filter_out_unknowns = %b)"
+ (fst input |> Test_common.string_of_string_map)
+ (snd input)
+
+ let string_of_output_t = Test_common.string_of_string_map
+ end
+
+ let transform (platformdata, filter_out_unknowns) =
+ Xapi_xenops.Platform.sanity_check ~platformdata ~filter_out_unknowns
+ end)
+
+ let sanity_check_tests =
+ let usb_defaults = [
+ "usb", "true";
+ "usb_tablet", "true";
+ ] in
+ [
+ (* Check that we can filter out unknown platform flags. *)
+ (([
+ "nonsense", "abc";
+ "pae", "true";
+ "whatever", "def";
+ "viridian", "true";
+ ], true),
+ usb_defaults @
+ [
+ "pae", "true";
+ "viridian", "true";
+ ]);
+ (* Check that usb and usb_tablet are turned on by default. *)
+ (([], false),
+ usb_defaults);
+ (* Check that an invalid tsc_mode gets filtered out. *)
+ ((["tsc_mode", "17";], false),
+ usb_defaults);
+ (* Check that an invalid parallel port gets filtered out. *)
+ ((["parallel", "/dev/random"], false),
+ usb_defaults);
+ (* Check that we can't set usb_tablet to true if usb is false. *)
+ (([
+ "usb", "false";
+ "usb_tablet", "true";
+ ], false),
+ [
+ "usb", "false";
+ "usb_tablet", "false";
+ ]);
+ (* Check that we can fully disable usb. *)
+ (([
+ "usb", "false";
+ "usb_tablet", "false";
+ ], false),
+ [
+ "usb", "false";
+ "usb_tablet", "false";
+ ]);
+ (* Check that we can disable the parallel port. *)
+ ((["parallel", "none"], false),
+ usb_defaults @
+ ["parallel", "none"]);
+ (* Check that a set of valid fields is unchanged (apart from
+ * the ordering, which changes due to the implementation of
+ * List.update_assoc). *)
+ (([
+ "parallel", "/dev/parport2";
+ "pae", "true";
+ "usb_tablet", "false";
+ "tsc_mode", "2";
+ "viridian", "true";
+ "usb", "true";
+ ], false),
+ [
+ "usb", "true";
+ "usb_tablet", "false";
+ "parallel", "/dev/parport2";
+ "pae", "true";
+ "tsc_mode", "2";
+ "viridian", "true";
+ ]);
+ (* Check that combination of valid and invalid fields is dealt with
+ * correctly. *)
+ (([
+ "pae", "true";
+ "parallel", "/dev/parport0";
+ "tsc_mode", "blah";
+ ], false),
+ usb_defaults @
+ [
+ "pae", "true";
+ "parallel", "/dev/parport0";
+ ]);
+ ]
+
+ let test () =
+ Tests.test_equal_multiple ~input_output_pairs:sanity_check_tests
+end
+
+let test =
+ "platformdata" >:::
+ [
+ "test_platform_sanity_check" >:: SanityCheck.test
+ ]
Please sign in to comment.
Something went wrong with that request. Please try again.