[Pkg-libvirt-commits] [libguestfs] 27/65: v2v: test-harness: Match on subimages instead of screenshots.

Hilko Bengen bengen at moszumanska.debian.org
Tue Apr 21 12:10:58 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 12be9f831e0135eb94be2c87b3f0b35d51e14285
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu Apr 9 19:17:59 2015 +0100

    v2v: test-harness: Match on subimages instead of screenshots.
    
    Previously we fuzzy-matched on screenshots of the entire display.
    
    There were several problems:
    
     - dates/times in images required fuzzy matching, but it's not clear
       how much fuzz to use (Windows 8.1/2012R2 timestamp is huge,
       requiring an enormous amount of fuzz)
    
    - cannot cope with Windows 7 irregular placement of windows on
      the desktop
    
    It's better to match on subimages.
    
    This requires some changes to the test data, using gimp to clip the
    images and remove any changing elements (dates/times/etc) but in the
    long run it's more flexible than fuzzy matching on the whole display.
    
    Note that because of peculiarities in 'compare' we still need to have
    a little bit of fuzz in the matching.  Seemingly bit-for-bit identical
    images still have a similarity > 0.
---
 v2v/test-harness/v2v_test_harness.ml  | 58 ++++++++++++++++++++++-------------
 v2v/test-harness/v2v_test_harness.mli |  7 +++--
 2 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/v2v/test-harness/v2v_test_harness.ml b/v2v/test-harness/v2v_test_harness.ml
index b570f0f..a992680 100644
--- a/v2v/test-harness/v2v_test_harness.ml
+++ b/v2v/test-harness/v2v_test_harness.ml
@@ -206,11 +206,15 @@ let run ~test ?input_disk ?input_xml ?(test_plan = default_plan) () =
       filename
     in
 
-    let display_matches_screenshot screenshot1 screenshot2 =
+    (* Find subimage within display.  There must be a near-exact
+     * match.  By editing images (eg. removing dates/times) you can
+      ensure this.
+     *)
+    let display_matches_subimage display subimage =
+      (* Grrr compare sends its normal output to stderr. *)
       let cmd =
-        (* Grrr compare sends its normal output to stderr. *)
-        sprintf "compare -metric MAE %s %s null: 2>&1"
-          (quote screenshot1) (quote screenshot2) in
+        sprintf "compare -subimage-search -metric MAE %s %s null: 2>&1"
+                (quote display) (quote subimage) in
       printf "%s\n%!" cmd;
       let chan = open_process_in cmd in
       let lines = ref [] in
@@ -218,19 +222,31 @@ let run ~test ?input_disk ?input_xml ?(test_plan = default_plan) () =
        with End_of_file -> ());
       let lines = List.rev !lines in
       let stat = close_process_in chan in
-      let similarity =
-        match stat with
-        | WEXITED 0 -> 0.0              (* exact match *)
-        | WEXITED 1 ->
-          Scanf.sscanf (List.hd lines) "%f" (fun f -> f)
-        | WEXITED i ->
-          failwithf "external command '%s' exited with error %d" cmd i
-        | WSIGNALED i ->
-          failwithf "external command '%s' killed by signal %d" cmd i
-        | WSTOPPED i ->
-          failwithf "external command '%s' stopped by signal %d" cmd i in
-      printf "%s %s have similarity %f\n" screenshot1 screenshot2 similarity;
-      similarity <= 60.0
+      match stat with
+      | WEXITED 0 -> true       (* exact match *)
+      | WEXITED 1 ->            (* not exact match *)
+         let similarity = Scanf.sscanf (List.hd lines) "%f" (fun f -> f) in
+         similarity <= 60.0
+      | WEXITED 2 ->            (* error *)
+         (* We need to ignore the annoying 'compare: images too dissimilar'
+          * message.  Why?
+          *)
+         let rec loop = function
+           | [] ->              (* error *)
+              failwithf "external command '%s' exited with error %d" cmd 2;
+           | line::lines ->
+              if string_prefix line "compare: images too dissimilar" then
+                false           (* no match *)
+              else
+                loop lines
+         in
+         loop lines
+      | WEXITED i ->
+         failwithf "external command '%s' exited with error %d" cmd i
+      | WSIGNALED i ->
+         failwithf "external command '%s' killed by signal %d" cmd i
+      | WSTOPPED i ->
+         failwithf "external command '%s' stopped by signal %d" cmd i
     in
 
     let dom_is_alive () =
@@ -293,7 +309,7 @@ let run ~test ?input_disk ?input_xml ?(test_plan = default_plan) () =
       (* Make sure we take a screenshot on every iteration, as they
        * are incredibly useful for debugging.
        *)
-      let screenshot = take_screenshot t in
+      let display = take_screenshot t in
 
       (* Reached the final screenshot?  Reaching this state
        * terminates the boot immediately.
@@ -301,7 +317,7 @@ let run ~test ?input_disk ?input_xml ?(test_plan = default_plan) () =
       let reached_final_screenshot =
         match test_plan.boot_plan with
         | Boot_to_screenshot final_screenshot ->
-           if display_matches_screenshot screenshot final_screenshot then (
+           if display_matches_subimage display final_screenshot then (
              printf "%s: guest reached final screenshot\n" (timestamp t);
              true
            ) else false
@@ -324,8 +340,8 @@ let run ~test ?input_disk ?input_xml ?(test_plan = default_plan) () =
              * resets the timeouts.
              *)
             let waiting_in_known_good_state =
-              List.exists (display_matches_screenshot screenshot)
-                test_plan.boot_known_good_screenshots in
+              List.exists (display_matches_subimage display)
+                          test_plan.boot_known_good_screenshots in
             if waiting_in_known_good_state then (
               printf "%s: guest at known-good screenshot\n" (timestamp t);
               loop t t stats
diff --git a/v2v/test-harness/v2v_test_harness.mli b/v2v/test-harness/v2v_test_harness.mli
index 18926b5..f8b3f33 100644
--- a/v2v/test-harness/v2v_test_harness.mli
+++ b/v2v/test-harness/v2v_test_harness.mli
@@ -41,8 +41,9 @@ type test_plan = {
   (** For Boot_to_idle, no disk activity counts as idle (default: 60). *)
 
   boot_known_good_screenshots : string list;
-  (** List of known-good screenshots.  If the guest screen looks like
-      one of these, we will keep waiting regardless of timeouts. *)
+  (** List of known-good screenshots (subimages).  If the guest
+      display contains any of these subimages, we will keep waiting
+      regardless of timeouts. *)
 
   boot_graceful_shutdown : int;
   (** When gracefully shutting down the guest, max time we will wait
@@ -55,7 +56,7 @@ type test_plan = {
 and boot_plan =
 | No_boot                      (** Don't do the boot test at all. *)
 | Boot_to_idle                 (** Boot until VM is idle. *)
-| Boot_to_screenshot of string (** Boot until screenshot is displayed. *)
+| Boot_to_screenshot of string (** Boot until screenshot (subimage) is displayed. *)
 
 val default_plan : test_plan
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list