summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/hook.test.c1
-rw-r--r--test/kv.test.c55
-rw-r--r--test/x86.test.c47
3 files changed, 29 insertions, 74 deletions
diff --git a/test/hook.test.c b/test/hook.test.c
index 7cbfd15..a2447cc 100644
--- a/test/hook.test.c
+++ b/test/hook.test.c
@@ -6,6 +6,7 @@
#include "../src/x86.c"
#include "../src/hook.c"
+#include "../src/os.c"
#include <stdarg.h>
#include <stdio.h>
diff --git a/test/kv.test.c b/test/kv.test.c
deleted file mode 100644
index 7f82b8a..0000000
--- a/test/kv.test.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* This file is dedicated to the public domain. */
-
-{.desc = "the KeyValues parser"};
-
-// undef conflicting macros
-#undef ERROR // windows.h
-#undef OUT // "
-#undef EOF // stdio.h
-#include "../src/kv.c"
-
-#include "../src/intdefs.h"
-#include "../src/noreturn.h"
-
-static noreturn die(const struct kv_parser *kvp) {
- fprintf(stderr, "parse error: %d:%d: %s\n", kvp->line, kvp->col,
- kvp->errmsg);
- exit(1);
-}
-
-static void tokcb(enum kv_token type, const char *p, uint len,
- void *ctxt) {
- // nop - we're just testing the tokeniser
-}
-
-static const char data[] =
-"KeyValues {\n\
- Key/1 Val1![conditional]\n\
- Key2\n\
-Val2// comment\n\
- \"String Key\" // also comment\n\
- Val3 Key4 [conditional!]{ Key5 \"Value Five\" } // one more\n\
-} \n\
-";
-static const int sz = sizeof(data) - 1;
-
-TEST("parsing should work with any buffer size") {
- for (int chunksz = 3; chunksz <= sz; ++chunksz) {
- struct kv_parser kvp = {0};
- // sending data in chunks to test reentrancy
- for (int chunk = 0; chunk * chunksz < sz; ++chunk) {
- int thischunk = chunksz;
- if (chunk * chunksz + thischunk > sz) {
- thischunk = sz - chunk * chunksz;
- }
- if (!kv_parser_feed(&kvp, data + chunk * chunksz, thischunk,
- tokcb, 0)) {
- die(&kvp);
- }
- }
- if (!kv_parser_done(&kvp)) die(&kvp);
- }
- return true;
-}
-
-// vi: sw=4 ts=4 noet tw=80 cc=80
diff --git a/test/x86.test.c b/test/x86.test.c
index ab0a679..bf6e6e8 100644
--- a/test/x86.test.c
+++ b/test/x86.test.c
@@ -5,25 +5,15 @@
#include "../src/x86.c"
#include "../src/intdefs.h"
+#include "../src/ppmagic.h"
+
TEST("The \"crazy\" instructions should be given correct lengths\n") {
- const uchar test8[] = {
- 0xF6, 0x05, 0x12, 0x34, 0x56, 0x78, 0x12
- };
- const uchar test16[] = {
- 0x66, 0xF7, 0x05, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34
- };
- const uchar test32[] = {
- 0xF7, 0x05, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78
- };
- const uchar not8[] = {
- 0xF6, 0x15, 0x12, 0x34, 0x56, 0x78
- };
- const uchar not16[] = {
- 0x66, 0xF7, 0x15, 0x12, 0x34, 0x56, 0x78
- };
- const uchar not32[] = {
- 0xF7, 0x15, 0x12, 0x34, 0x56, 0x78
- };
+ const uchar test8[] = HEXBYTES(F6, 05, 12, 34, 56, 78, 12);
+ const uchar test16[] = HEXBYTES(66, F7, 05, 12, 34, 56, 78, 12, 34);
+ const uchar test32[] = HEXBYTES(F7, 05, 12, 34, 56, 78, 12, 34, 56, 78);
+ const uchar not8[] = HEXBYTES(F6, 15, 12, 34, 56, 78);
+ const uchar not16[] = HEXBYTES(66, F7, 15, 12, 34, 56, 78);
+ const uchar not32[] = HEXBYTES(F7, 15, 12, 34, 56, 78);
if (x86_len(test8) != 7) return false;
if (x86_len(test16) != 9) return false;
if (x86_len(test32) != 10) return false;
@@ -34,8 +24,27 @@ TEST("The \"crazy\" instructions should be given correct lengths\n") {
}
TEST("SIB bytes should be decoded correctly") {
- const uchar fstp[] = {0xD9, 0x1C, 0x24}; // old buggy case, for regressions
+ const uchar fstp[] = HEXBYTES(D9, 1C, 24); // old buggy case for regressions
return x86_len(fstp) == 3;
}
+TEST("mov AL, moff8 instructions should be decoded correctly") {
+ // more fixed buggy cases for regressions
+ const uchar mov_moff8_al[] = HEXBYTES(A2, DA, 78, B4, 0D);
+ const uchar mov_al_moff8[] = HEXBYTES(A0, 28, DF, 5C, 66);
+ if (x86_len(mov_moff8_al) != 5) return false;
+ if (x86_len(mov_al_moff8) != 5) return false;
+ return true;
+}
+
+TEST("16-bit MRM instructions should be decoded correctly") {
+ const uchar fiadd_off16[] = HEXBYTES(67, DA, 06, DF, 11);
+ const uchar fld_tword[] = HEXBYTES(67, DB, 2E, 99, C4);
+ const uchar add_off16_bl[] = HEXBYTES(67, 00, 1E, F5, BB);
+ if (x86_len(fiadd_off16) != 5) return false;
+ if (x86_len(fld_tword) != 5) return false;
+ if (x86_len(add_off16_bl) != 5) return false;
+ return true;
+}
+
// vi: sw=4 ts=4 noet tw=80 cc=80