Skip to content

Commit

Permalink
KVM: selftests: Convert the x86 userspace I/O test to printf guest as…
Browse files Browse the repository at this point in the history
…sert

Convert x86's userspace I/O test to use printf-based guest asserts.

Link: https://lore.kernel.org/r/20230729003643.1053367-30-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
  • Loading branch information
sean-jc committed Aug 2, 2023
1 parent 847ae07 commit 417bfd0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tools/testing/selftests/kvm/x86_64/userspace_io_test.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#define USE_GUEST_ASSERT_PRINTF 1

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -20,8 +22,8 @@ static void guest_ins_port80(uint8_t *buffer, unsigned int count)
end = (unsigned long)buffer + 8192;

asm volatile("cld; rep; insb" : "+D"(buffer), "+c"(count) : "d"(0x80) : "memory");
GUEST_ASSERT_1(count == 0, count);
GUEST_ASSERT_2((unsigned long)buffer == end, buffer, end);
GUEST_ASSERT_EQ(count, 0);
GUEST_ASSERT_EQ((unsigned long)buffer, end);
}

static void guest_code(void)
Expand All @@ -43,7 +45,9 @@ static void guest_code(void)
memset(buffer, 0, sizeof(buffer));
guest_ins_port80(buffer, 8192);
for (i = 0; i < 8192; i++)
GUEST_ASSERT_2(buffer[i] == 0xaa, i, buffer[i]);
__GUEST_ASSERT(buffer[i] == 0xaa,
"Expected '0xaa', got '0x%x' at buffer[%u]",
buffer[i], i);

GUEST_DONE();
}
Expand Down Expand Up @@ -91,7 +95,7 @@ int main(int argc, char *argv[])
case UCALL_DONE:
break;
case UCALL_ABORT:
REPORT_GUEST_ASSERT_2(uc, "argN+1 = 0x%lx, argN+2 = 0x%lx");
REPORT_GUEST_ASSERT(uc);
default:
TEST_FAIL("Unknown ucall %lu", uc.cmd);
}
Expand Down

0 comments on commit 417bfd0

Please sign in to comment.