added ARM64 hang test

This commit is contained in:
jndok 2016-06-15 19:18:51 +02:00
parent 40ac55cf74
commit c6db9febe7
2 changed files with 61 additions and 1 deletions

View File

@ -13,7 +13,7 @@ endif
ALL_TESTS = test_sanity test_x86 test_mem_map test_mem_high test_mem_map_ptr \
test_tb_x86 test_multihook test_pc_change test_x86_soft_paging \
test_hookcounts
test_hookcounts test_hang
.PHONY: all
all: ${ALL_TESTS}
@ -35,6 +35,7 @@ test: ${ALL_TESTS}
./test_pc_change
./test_x86_soft_paging
./test_hookcounts
./test_hang
test_sanity: test_sanity.c
test_x86: test_x86.c
@ -46,6 +47,7 @@ test_multihook: test_multihook.c
test_pc_change: test_pc_change.c
test_x86_soft_paging: test_x86_soft_paging.c
test_hookcounts: test_hookcounts.c
test_hang: test_hang.c
${ALL_TESTS}:
${CC} ${CFLAGS} -o $@ $^

58
tests/unit/test_hang.c Normal file
View File

@ -0,0 +1,58 @@
/*
refer to issue #575.
to run correctly unicorn needs to be compiled for AArch64.
*/
#include "unicorn_test.h"
#include <stdio.h>
uint64_t trunc_page(uint64_t addr)
{
return (addr & ~(4095));
}
int main(void)
{
uint32_t code[] = {
0xd503201f, /* NOP */
0xd503201f, /* NOP */
0xd503201f, /* NOP */
0xaa0103e0 /* MOV X0, X1 */
};
uc_engine *uc;
uint64_t x0 = 0;
uint64_t x1 = 1;
if (uc_open(UC_ARCH_ARM64, UC_MODE_ARM, &uc) != UC_ERR_OK) {
printf("Error on open. Be sure that your unicorn library supports AArch64.\n");
return -1;
}
uint64_t addr = 0x13f0;
uint64_t trunc_addr = trunc_page(addr); // round down to nearest page
uc_mem_map(uc, trunc_addr, 2 * 1024 * 1024, UC_PROT_ALL);
if (uc_mem_write(uc, addr, &code, sizeof(code))) {
printf("error on write\n");
return -2;
}
uc_reg_write(uc, UC_ARM64_REG_X0, &x0);
uc_reg_write(uc, UC_ARM64_REG_X1, &x1);
if (uc_emu_start(uc, addr, addr + sizeof(code), 0, 0)) {
printf("error on start\n");
return -3;
}
uc_reg_read(uc, UC_ARM64_REG_X0, &x0);
uc_reg_read(uc, UC_ARM64_REG_X1, &x1);
printf("x0: %#llx\n", x0);
printf("x1: %#llx\n", x1);
return 0;
}