From 15310fc90dc6ab2ba52603027eebe8aa5a606a27 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 24 Apr 2025 20:37:36 +0300 Subject: add some tests to increase coverage --- tests/bger_d.c | 31 +++++++++++++++++++++++++++++++ tests/bger_f.c | 31 +++++++++++++++++++++++++++++++ tests/blti_u.c | 4 ++-- tests/ger_d.c | 27 +++++++++++++++++++++++++++ tests/ger_f.c | 27 +++++++++++++++++++++++++++ tests/ldxr_i16.c | 35 +++++++++++++++++++++++++++++++++++ tests/ldxr_u64.c | 29 +++++++++++++++++++++++++++++ tests/ler64_u.c | 37 +++++++++++++++++++++++++++++++++++++ tests/ltr_u.c | 35 +++++++++++++++++++++++++++++++++++ 9 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 tests/bger_d.c create mode 100644 tests/bger_f.c create mode 100644 tests/ger_d.c create mode 100644 tests/ger_f.c create mode 100644 tests/ldxr_i16.c create mode 100644 tests/ldxr_u64.c create mode 100644 tests/ler64_u.c create mode 100644 tests/ltr_u.c (limited to 'tests') diff --git a/tests/bger_d.c b/tests/bger_d.c new file mode 100644 index 0000000..97b6141 --- /dev/null +++ b/tests/bger_d.c @@ -0,0 +1,31 @@ +#include +#include +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(double)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + struct ejit_reloc r = ejit_bger_d(f, EJIT_FPR(0), EJIT_FPR(1)); + ejit_reti(f, 0); + + struct ejit_label l = ejit_label(f); + ejit_patch(f, r, l); + ejit_reti(f, 1); + + ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit, true); + + assert(erfi2(f, EJIT_ARG( 0, double), EJIT_ARG( 0, double)) == 1); + assert(erfi2(f, EJIT_ARG( 0, double), EJIT_ARG( 1, double)) == 0); + assert(erfi2(f, EJIT_ARG( 1, double), EJIT_ARG( 0, double)) == 1); + assert(erfi2(f, EJIT_ARG(-1, double), EJIT_ARG( 0, double)) == 0); + assert(erfi2(f, EJIT_ARG( 0, double), EJIT_ARG(-1, double)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/bger_f.c b/tests/bger_f.c new file mode 100644 index 0000000..9e863cb --- /dev/null +++ b/tests/bger_f.c @@ -0,0 +1,31 @@ +#include +#include +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(float)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(float)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + struct ejit_reloc r = ejit_bger_f(f, EJIT_FPR(0), EJIT_FPR(1)); + ejit_reti(f, 0); + + struct ejit_label l = ejit_label(f); + ejit_patch(f, r, l); + ejit_reti(f, 1); + + ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit, true); + + assert(erfi2(f, EJIT_ARG( 0, float), EJIT_ARG( 0, float)) == 1); + assert(erfi2(f, EJIT_ARG( 0, float), EJIT_ARG( 1, float)) == 0); + assert(erfi2(f, EJIT_ARG( 1, float), EJIT_ARG( 0, float)) == 1); + assert(erfi2(f, EJIT_ARG(-1, float), EJIT_ARG( 0, float)) == 0); + assert(erfi2(f, EJIT_ARG( 0, float), EJIT_ARG(-1, float)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/blti_u.c b/tests/blti_u.c index 3e4ed27..52d3b2c 100644 --- a/tests/blti_u.c +++ b/tests/blti_u.c @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) }; struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 1, operands); - struct ejit_reloc r = ejit_blti_u(f, EJIT_GPR(0), 0); + struct ejit_reloc r = ejit_blti_u(f, EJIT_GPR(0), 1); ejit_reti(f, 0); struct ejit_label l = ejit_label(f); @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) ejit_select_compile_func(f, 1, 0, EJIT_USE64(long), do_jit, true); - assert(erfi1(f, EJIT_ARG( 0, long)) == 0); + assert(erfi1(f, EJIT_ARG( 0, long)) == 1); assert(erfi1(f, EJIT_ARG( 1, long)) == 0); assert(erfi1(f, EJIT_ARG(-1, long)) == 0); diff --git a/tests/ger_d.c b/tests/ger_d.c new file mode 100644 index 0000000..74835b8 --- /dev/null +++ b/tests/ger_d.c @@ -0,0 +1,27 @@ +#include +#include +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(double)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(double)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + + ejit_ger_d(f, EJIT_GPR(0), EJIT_FPR(0), EJIT_FPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit, true); + + assert(erfi2(f, EJIT_ARG(1, double), EJIT_ARG(1, double)) == 1); + assert(erfi2(f, EJIT_ARG(1, double), EJIT_ARG(0, double)) == 1); + assert(erfi2(f, EJIT_ARG(-1, double), EJIT_ARG(0, double)) == 0); + assert(erfi2(f, EJIT_ARG(-1, double), EJIT_ARG(-1, double)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/ger_f.c b/tests/ger_f.c new file mode 100644 index 0000000..d1be5ab --- /dev/null +++ b/tests/ger_f.c @@ -0,0 +1,27 @@ +#include +#include +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_FPR(0, EJIT_TYPE(float)), + EJIT_OPERAND_FPR(1, EJIT_TYPE(float)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + + ejit_ger_f(f, EJIT_GPR(0), EJIT_FPR(0), EJIT_FPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 1, 2, EJIT_USE64(long), do_jit, true); + + assert(erfi2(f, EJIT_ARG(1, float), EJIT_ARG(1, float)) == 1); + assert(erfi2(f, EJIT_ARG(1, float), EJIT_ARG(0, float)) == 1); + assert(erfi2(f, EJIT_ARG(-1, float), EJIT_ARG(0, float)) == 0); + assert(erfi2(f, EJIT_ARG(-1, float), EJIT_ARG(-1, float)) == 1); + + ejit_destroy_func(f); +} diff --git a/tests/ldxr_i16.c b/tests/ldxr_i16.c new file mode 100644 index 0000000..c423bce --- /dev/null +++ b/tests/ldxr_i16.c @@ -0,0 +1,35 @@ +#include +#include +#include "do_jit.h" + +static uint16_t data[] = { 0xffff, 0x0000, 0x4242 }; + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_POINTER), + EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + ejit_ldxr_i16(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, false, do_jit, true); + + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int16_t) * 0, unsigned) + ) == -1); + + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int16_t) * 1, unsigned) + ) == 0); + + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(sizeof(int16_t) * 2, unsigned) + ) == 0x4242); + + ejit_destroy_func(f); +} diff --git a/tests/ldxr_u64.c b/tests/ldxr_u64.c new file mode 100644 index 0000000..3ad3c28 --- /dev/null +++ b/tests/ldxr_u64.c @@ -0,0 +1,29 @@ +#include +#include +#include "do_jit.h" + +static uint64_t data[] = { 0xffffffffffffffff, 0, 0x4242424212345678 }; + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_POINTER), + EJIT_OPERAND_GPR(1, EJIT_TYPE(unsigned)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + ejit_ldxr_u64(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, true, do_jit, true); + + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(0, unsigned)) == (int64_t)0xffffffffffffffff); + assert(erfi2(f, EJIT_ARG(data, void *), EJIT_ARG(8, unsigned)) == 0); + assert(erfi2(f, EJIT_ARG(data, void *), + EJIT_ARG(16, unsigned)) == 0x4242424212345678); + + ejit_destroy_func(f); +} diff --git a/tests/ler64_u.c b/tests/ler64_u.c new file mode 100644 index 0000000..6c3f473 --- /dev/null +++ b/tests/ler64_u.c @@ -0,0 +1,37 @@ +#include +#include +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(int64_t)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(int64_t)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(int64_t), 2, operands); + + ejit_ler_u(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(int64_t), do_jit, true); + + assert(erfl2(f, + EJIT_ARG(1, int64_t), + EJIT_ARG(1, int64_t)) == 1); + + assert(erfl2(f, + EJIT_ARG(1, int64_t), + EJIT_ARG(0, int64_t)) == 0); + + assert(erfl2(f, + EJIT_ARG(0x0fffffffffffffff, int64_t), + EJIT_ARG(0x0ffffffffffffff0, int64_t)) == 0); + + assert(erfl2(f, + EJIT_ARG(0x7fffffffffffffff, int64_t), + EJIT_ARG(0x6fffffffffffffff, int64_t)) == 0); + ejit_destroy_func(f); +} diff --git a/tests/ltr_u.c b/tests/ltr_u.c new file mode 100644 index 0000000..07bd745 --- /dev/null +++ b/tests/ltr_u.c @@ -0,0 +1,35 @@ +#include +#include +#include "do_jit.h" + +int main(int argc, char *argv[]) +{ + (void)argv; + bool do_jit = argc > 1; + struct ejit_operand operands[2] = { + EJIT_OPERAND_GPR(0, EJIT_TYPE(long)), + EJIT_OPERAND_GPR(1, EJIT_TYPE(long)) + }; + + struct ejit_func *f = ejit_create_func(EJIT_TYPE(long), 2, operands); + + ejit_ltr_u(f, EJIT_GPR(0), EJIT_GPR(0), EJIT_GPR(1)); + ejit_retr(f, EJIT_GPR(0)); + + ejit_select_compile_func(f, 2, 0, EJIT_USE64(long), do_jit, true); + + assert(erfi2(f, EJIT_ARG(1, long), EJIT_ARG(1, long)) == 0); + assert(erfi2(f, EJIT_ARG(1, long), EJIT_ARG(0, long)) == 0); + + assert(erfi2(f, EJIT_ARG(-1, long), EJIT_ARG(1, long)) == 0); + assert(erfi2(f, EJIT_ARG(-1, long), EJIT_ARG(0, long)) == 0); + + assert(erfi2(f, + EJIT_ARG(0x0fffffffffffffff, long), + EJIT_ARG(0x0ffffffffffffff0, long)) == 0); + + assert(erfi2(f, + EJIT_ARG(0x7fffffffffffffff, long), + EJIT_ARG(0x6fffffffffffffff, long)) == 0); + ejit_destroy_func(f); +} -- cgit v1.2.3