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

[Xen-API] [PATCH 06 of 12] [PCR0047] Adds unit tests for functions "VM_memory_constraints.{are_pinned, are_pinned_at_static_max, are_valid, are_valid_and_pinned_at_static_max}



# HG changeset patch
# User Jonathan Knowles <jonathan.knowles@xxxxxxxxxxxxx>
# Date 1265039943 0
# Node ID 98e9bcbce80e3165aff609962ac2a6fc23ecc22d
# Parent  10fc547a82d50bf41dd2172962e441da575bded4
[PCR0047] Adds unit tests for functions "VM_memory_constraints.{are_pinned, 
are_pinned_at_static_max, are_valid, are_valid_and_pinned_at_static_max}.

Signed-off-by: Jonathan Knowles <jonathan.knowles@xxxxxxxxxxxxx>

diff -r 10fc547a82d5 -r 98e9bcbce80e 
ocaml/xapi/quicktest_vm_memory_constraints.ml
--- a/ocaml/xapi/quicktest_vm_memory_constraints.ml     Mon Feb 01 15:59:03 
2010 +0000
+++ b/ocaml/xapi/quicktest_vm_memory_constraints.ml     Mon Feb 01 15:59:03 
2010 +0000
@@ -13,6 +13,7 @@
  *)
 open Quicktest_ocamltest
 open Ocamltest
+open Printf
 open Vm_memory_constraints.Vm_memory_constraints
 
 let ( ++ ) = Int64.add
@@ -24,12 +25,69 @@
 memory constraints tuple (with values in MiB). *)
 let create (static_min, dynamic_min, target, dynamic_max, static_max) =
        let scale value = (Int64.of_int value) ** 1024L ** 1024L in
-       { static_min  = scale static_min
-       ; dynamic_min = scale dynamic_min
-       ; target      = scale target
-       ; dynamic_max = scale dynamic_max
-       ; static_max  = scale static_max
+       {
+               static_min  = scale static_min ;
+               dynamic_min = scale dynamic_min;
+               target      = scale target     ;
+               dynamic_max = scale dynamic_max;
+               static_max  = scale static_max ;
        }
+
+let constraints_pinned = [
+               (0,0,0,0,5); (0,1,1,1,5);
+               (0,2,2,2,5); (0,3,3,3,5);
+               (0,4,4,4,5); (0,5,5,5,5);
+       ]
+
+let constraints_unpinned = [
+               (0,0,0,1,5); (0,1,1,2,5);
+               (0,2,2,3,5); (0,2,3,3,5);
+               (0,3,4,4,5); (0,4,5,5,5);
+       ]
+
+let constraints_valid = [
+               (0,1,2,3,4); (1,2,3,4,5);
+               (1,1,2,3,4); (1,2,3,4,4);
+               (2,2,2,3,4); (1,2,3,3,3);
+               (3,3,3,3,4); (1,2,2,2,2);
+               (4,4,4,4,4); (1,1,1,1,1);
+       ]
+
+let constraints_invalid = [
+               (2,1,2,3,4); (4,1,2,3,4);
+               (5,1,2,3,4); (0,4,2,3,4);
+               (0,5,2,3,4); (0,1,2,5,4);
+       ]
+
+let constraints_pinned_at_static_max = [
+               (0,0,0,0,0); (0,1,1,1,1);
+               (0,2,2,2,2); (1,2,2,2,2);
+       ]
+
+(** Tests that [fn i] evaluates to [output] for all values [i] in [inputs]. *)
+let test_indicator_function fn fn_name output output_name inputs =
+       make_test_case
+               (sprintf "%s_%s" fn_name output_name)
+               (sprintf "Tests that function %s returns %s" fn_name 
output_name)
+               (fun () ->
+                       List.iter
+                               (fun i -> assert_equal (fn ~constraints:(create 
i)) output)
+                               (inputs))
+
+let test_are_pinned_true = test_indicator_function
+       are_pinned "are_pinned" true "true" constraints_pinned
+let test_are_pinned_false = test_indicator_function
+       are_pinned "are_pinned" false "false" constraints_unpinned
+let test_are_valid_true = test_indicator_function
+       are_valid "are_valid" true "true" constraints_valid
+let test_are_valid_false = test_indicator_function
+       are_valid "are_valid" false "false" constraints_invalid
+let test_are_valid_and_pinned_at_static_max_true = test_indicator_function
+       are_valid_and_pinned_at_static_max "are_valid_and_pinned_at_static_max"
+       true "true" constraints_pinned_at_static_max
+let test_are_valid_and_pinned_at_static_max_false = test_indicator_function
+       are_valid_and_pinned_at_static_max "are_valid_and_pinned_at_static_max"
+       false "false" (constraints_invalid @ constraints_unpinned)
 
 let test_reset_to_safe_defaults = make_function_test_case
        "reset_to_safe_defaults"
@@ -38,14 +96,20 @@
                        (fun (input, output) ->
                                let reset constraints = reset_to_safe_defaults 
~constraints in
                                assert_equal (reset (create input)) (create 
output))
-                       [( 256, 512,1024,2048,4096), ( 256,4096,4096,4096,4096)
-                       ;(4096,2048,1024, 512, 256), ( 256, 256, 256, 256, 256)
-                       ;(1024,1024,1024,1024,1024), (1024,1024,1024,1024,1024)
-                       ]
-       )
+                       [
+                               ( 256, 512,1024,2048,4096), ( 
256,4096,4096,4096,4096);
+                               (4096,2048,1024, 512, 256), ( 256, 256, 256, 
256, 256);
+                               (1024,1024,1024,1024,1024), 
(1024,1024,1024,1024,1024);
+                       ])
 
 let tests = make_module_test_suite "VM_memory_constraints"
 [
+       test_are_pinned_true;
+       test_are_pinned_false;
+       test_are_valid_true;
+       test_are_valid_false;
+       test_are_valid_and_pinned_at_static_max_true;
+       test_are_valid_and_pinned_at_static_max_false;
        test_reset_to_safe_defaults;
 ]
 
1 file changed, 74 insertions(+), 10 deletions(-)
ocaml/xapi/quicktest_vm_memory_constraints.ml |   84 ++++++++++++++++++++++---


Attachment: xen-api.hg-12.patch
Description: Text Data

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

 


Rackspace

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