Skip to content

Commit 1292384

Browse files
committed
fix test codes
1 parent dca14c9 commit 1292384

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ set(CMAKE_BUILD_TYPE Release)
77
include_directories(include)
88

99
include(${CMAKE_SYSTEM_NAME}.cmake)
10+
11+
add_subdirectory(test)

test/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 2.4)
2+
3+
project(hv_test)
4+
5+
set(CMAKE_C_FLAGS_RELEASE "-Wall -Wextra -O2")
6+
set(CMAKE_C_FLAGS_DEBUG "-Wall -Wextra -g -O0")
7+
8+
add_executable(main main.c)
9+
target_link_libraries(main hv)
10+
11+
add_test(test_main COMMAND main)

test/main.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
#include "hv.h"
2828
#include <stdio.h>
29+
#include <stdlib.h>
30+
#include <string.h>
31+
#include <fcntl.h>
32+
#include <sys/mman.h>
2933

3034
int main(void)
3135
{
@@ -44,8 +48,10 @@ int main(void)
4448

4549
/* Allocate one aligned page of guest memory to hold the code. */
4650
mem = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
47-
if (!mem)
48-
err(1, "allocating guest memory");
51+
if (!mem) {
52+
fprintf(stderr, "allocating guest memory");
53+
abort();
54+
}
4955
memcpy(mem, code, sizeof(code));
5056

5157
/* Map it to the second page frame (to avoid the real-mode IDT at 0). */
@@ -85,7 +91,7 @@ int main(void)
8591
/* case KVM_EXIT_INTERNAL_ERROR: */
8692
/* errx(1, "KVM_EXIT_INTERNAL_ERROR: suberror = 0x%x", run->internal.suberror); */
8793
default:
88-
fprintf(stderr, "exit_reason = 0x%x", exit_reason);
94+
fprintf(stderr, "exit_reason = 0x%llx", exit_reason);
8995
abort();
9096
}
9197
}

0 commit comments

Comments
 (0)