aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-04-24 20:37:36 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-04-24 20:37:36 +0300
commit15310fc90dc6ab2ba52603027eebe8aa5a606a27 (patch)
treead7606ede5d486a841d2b70498c1393134716380 /tests
parentd9e7718b03596c9af89411a8991f5a1da7b4ad5f (diff)
downloadejit-15310fc90dc6ab2ba52603027eebe8aa5a606a27.tar.gz
ejit-15310fc90dc6ab2ba52603027eebe8aa5a606a27.zip
add some tests to increase coverageHEADmaster
Diffstat (limited to 'tests')
-rw-r--r--tests/bger_d.c31
-rw-r--r--tests/bger_f.c31
-rw-r--r--tests/blti_u.c4
-rw-r--r--tests/ger_d.c27
-rw-r--r--tests/ger_f.c27
-rw-r--r--tests/ldxr_i16.c35
-rw-r--r--tests/ldxr_u64.c29
-rw-r--r--tests/ler64_u.c37
-rw-r--r--tests/ltr_u.c35
9 files changed, 254 insertions, 2 deletions
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 <ejit/ejit.h>
+#include <assert.h>
+#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 <ejit/ejit.h>
+#include <assert.h>
+#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 <ejit/ejit.h>
+#include <assert.h>
+#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 <ejit/ejit.h>
+#include <assert.h>
+#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 <ejit/ejit.h>
+#include <assert.h>
+#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 <ejit/ejit.h>
+#include <assert.h>
+#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 <ejit/ejit.h>
+#include <assert.h>
+#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 <ejit/ejit.h>
+#include <assert.h>
+#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);
+}