x86/emul: Debugging improvements to the test harness
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 25 Oct 2016 18:41:01 +0000 (19:41 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 5 Dec 2016 14:44:53 +0000 (14:44 +0000)
Disable stdout buffering, so logging gets out even if the harness crashes.
Add a verbose option (compile time disabled) which dumps all read/write calls
the harness makes

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
tools/tests/x86_emulator/test_x86_emulator.c

index b54fd11fe053cbff4d6fb696fee8e794976e4e6e..b5eca867f9bee64a5b3571a286f692276deaf50d 100644 (file)
@@ -12,6 +12,8 @@
 #include "x86_emulate/x86_emulate.h"
 #include "blowfish.h"
 
+#define verbose false /* Switch to true for far more logging. */
+
 static const struct {
     const void *code;
     size_t size;
@@ -47,6 +49,9 @@ static int read(
     unsigned int bytes,
     struct x86_emulate_ctxt *ctxt)
 {
+    if ( verbose )
+        printf("** %s(%u, %p,, %u,)\n", __func__, seg, (void *)offset, bytes);
+
     bytes_read += bytes;
     memcpy(p_data, (void *)offset, bytes);
     return X86EMUL_OKAY;
@@ -59,6 +64,9 @@ static int fetch(
     unsigned int bytes,
     struct x86_emulate_ctxt *ctxt)
 {
+    if ( verbose )
+        printf("** %s(%u, %p,, %u,)\n", __func__, seg, (void *)offset, bytes);
+
     memcpy(p_data, (void *)offset, bytes);
     return X86EMUL_OKAY;
 }
@@ -70,6 +78,9 @@ static int write(
     unsigned int bytes,
     struct x86_emulate_ctxt *ctxt)
 {
+    if ( verbose )
+        printf("** %s(%u, %p,, %u,)\n", __func__, seg, (void *)offset, bytes);
+
     memcpy((void *)offset, p_data, bytes);
     return X86EMUL_OKAY;
 }
@@ -82,6 +93,9 @@ static int cmpxchg(
     unsigned int bytes,
     struct x86_emulate_ctxt *ctxt)
 {
+    if ( verbose )
+        printf("** %s(%u, %p,, %u,)\n", __func__, seg, (void *)offset, bytes);
+
     memcpy((void *)offset, new, bytes);
     return X86EMUL_OKAY;
 }
@@ -233,6 +247,9 @@ int main(int argc, char **argv)
     unsigned int bcdres_native, bcdres_emul;
 #endif
 
+    /* Disable output buffering. */
+    setbuf(stdout, NULL);
+
     ctxt.regs = &regs;
     ctxt.force_writeback = 0;
     ctxt.addr_size = 8 * sizeof(void *);