Skip to content

Commit

Permalink
kvm: Add force exit from tests
Browse files Browse the repository at this point in the history
To make so we write any value to port 0 and
start kvm in --dbgtest mode so we are expecting
for this exit.

Signed-off-by: Cyrill Gorcunov <[email protected]>
  • Loading branch information
cyrillos authored and wildea01 committed Jun 1, 2015
1 parent 339c64c commit 3db4f1b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 79,7 @@ bios/int10.o: bios/int10.S bios/int10-real.S

check: $(PROGRAM)
$(MAKE) -C tests
./$(PROGRAM) tests/pit/tick.bin
./$(PROGRAM) --dbgtest tests/pit/tick.bin
.PHONY: check

clean:
Expand Down
17 changes: 15 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 10,11 @@
#include <string.h>
#include <stdio.h>

unsigned int dbgtest_mode;

static void usage(char *argv[])
{
fprintf(stderr, " usage: %s [--single-step] [--kernel=]<kernel-image>\n",
fprintf(stderr, " usage: %s [--dbgtest] [--single-step] [--kernel=]<kernel-image>\n",
argv[0]);
exit(1);
}
Expand Down Expand Up @@ -48,6 50,9 @@ int main(int argc, char *argv[])
} else if (!strncmp("--params=", argv[i], 9)) {
kernel_cmdline = &argv[i][9];
continue;
} else if (!strncmp("--dbgtest", argv[i], 9)) {
dbgtest_mode = 1;
continue;
} else if (!strncmp("--single-step", argv[i], 13)) {
single_step = true;
continue;
Expand Down Expand Up @@ -126,6 131,14 @@ int main(int argc, char *argv[])
}

exit_kvm:

if (dbgtest_mode) {
if (kvm->kvm_run->exit_reason == KVM_EXIT_IO &&
kvm->kvm_run->io.port == 0)
fprintf(stderr, "KVM: this is an expected IO error\n");
goto out;
}

fprintf(stderr, "KVM exit reason: %" PRIu32 " (\"%s\")\n",
kvm->kvm_run->exit_reason, kvm_exit_reasons[kvm->kvm_run->exit_reason]);
if (kvm->kvm_run->exit_reason == KVM_EXIT_UNKNOWN)
Expand All @@ -135,7 148,7 @@ int main(int argc, char *argv[])
kvm__show_registers(kvm);
kvm__show_code(kvm);
kvm__show_page_tables(kvm);

out:
kvm__delete(kvm);

return 0;
Expand Down
6 changes: 5 additions & 1 deletion tests/pit/tick.S
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,8 @@
#define TIMER_FREQ 1193182
#define TIMER_DIV(x) ((TIMER_FREQ (x)/2)/(x))

#define DBG_PORT 0

#define TEST_COUNT 0x0200

.code16gcc
Expand Down Expand Up @@ -72,7 74,9 @@ test_ok:
cs lea msg2, %si
mov $(msg2_end-msg2), %cx
cs rep/outsb
hlt

/* not a valid port to force exit */
outb %al, $DBG_PORT

timer_isr:
cli
Expand Down

0 comments on commit 3db4f1b

Please sign in to comment.