Skip to content

Commit

Permalink
x86/emul: Debugging improvements to the test harness
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Jan Beulich <[email protected]>
  • Loading branch information
andyhhp committed Dec 5, 2016
1 parent 750c5f7 commit c31f3be
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/tests/x86_emulator/test_x86_emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 *);
Expand Down

0 comments on commit c31f3be

Please sign in to comment.