diff --git a/test/unit/Makefile b/test/unit/Makefile index 9b5aed65..0eac4063 100644 --- a/test/unit/Makefile +++ b/test/unit/Makefile @@ -1,13 +1,33 @@ + +CFLAGS += -L ../../ CFLAGS += -lcmocka -lunicorn +CFLAGS += -I ../../include +ALL_TESTS = test_x86 test_mem_map -ALL_TESTS = test_x86 - +.PHONY: all all: ${ALL_TESTS} +.PHONY: clean clean: rm ${ALL_TESTS} +.PHONY: test +test: export LD_LIBRARY_PATH=../../ +test: ${ALL_TESTS} + @#echo ${ALL_TESTS} | xargs -n1 | xargs -I CMD sh -c ./CMD + @for test in ${ALL_TESTS}; do \ + echo -e "\n--------------------------------------------------------------------------------"; \ + echo "TEST: $$test"; \ + ./$$test || break; \ + done + test_x86: test_x86.c +test_mem_map: test_mem_map.c + +${ALL_TESTS}: gcc ${CFLAGS} -o $@ $^ + + + diff --git a/test/unit/test_mem_map.c b/test/unit/test_mem_map.c new file mode 100644 index 00000000..58e2a779 --- /dev/null +++ b/test/unit/test_mem_map.c @@ -0,0 +1,35 @@ +#include "unicorn_test.h" +#include + +static int setup(void **state) +{ + fprintf(stderr, "~~~ setup() ~~~\n"); + + uc_engine *uc; + + uc_assert_success(uc_open(UC_ARCH_X86, UC_MODE_32, &uc)); + + *state = uc; + return 0; +} + +static int teardown(void **state) +{ + uc_engine *uc = *state; + fprintf(stderr, "~~~ teardown() ~~~\n"); + + uc_assert_success(uc_close(uc)); + return 0; +} + + +static void test_basic(void **state) +{ +} + +int main(void) { + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_basic), + }; + return cmocka_run_group_tests(tests, setup, teardown); +} diff --git a/test/unit/unicorn_test.h b/test/unit/unicorn_test.h new file mode 100644 index 00000000..03f9e556 --- /dev/null +++ b/test/unit/unicorn_test.h @@ -0,0 +1,16 @@ +#ifndef UNICORN_TEST_H +#define UNICORN_TEST_H + +#include +#include +#include +#include +#include + +static void uc_assert_success(uc_err err) +{ + assert_int_equal(err, 0); + // uc_strerror(err) +} + +#endif /* UNICORN_TEST_H */