Skip to content

Commit d2001b5

Browse files
committed
feat: added type related unit tests
reworked existing tests to the core and KB changes
1 parent 58fe09f commit d2001b5

11 files changed

Lines changed: 1121 additions & 66 deletions

File tree

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,18 @@ endmacro()
4242
# units
4343
rd_add_test(test_utils unit/test_utils.c)
4444
rd_add_test(test_memory unit/test_memory.c)
45+
rd_add_test(test_types unit/test_types.c)
4546

4647
add_test(NAME utils COMMAND test_utils)
4748
add_test(NAME memory COMMAND test_memory)
49+
add_test(NAME types COMMAND test_types)
4850

4951
# encoding
5052
rd_add_test(test_encoding_x86 encoding/test_x86.c)
5153

52-
add_test(NAME test_encoding_x86 COMMAND test_encoding_x86)
54+
add_test(NAME encoding_x86 COMMAND test_encoding_x86)
5355

54-
set_tests_properties(test_encoding_x86 PROPERTIES DEPENDS "memory utils")
56+
set_tests_properties(encoding_x86 PROPERTIES DEPENDS "memory utils")
5557

5658
# integrations
5759
rd_add_test(test_tier0 integration/test_tier0.c)
@@ -64,7 +66,7 @@ add_test(NAME tier1 COMMAND test_tier1 --samples "${REDASM_SAMPLES}")
6466
add_test(NAME vb COMMAND test_vb --samples "${REDASM_SAMPLES}")
6567
add_test(NAME ioli COMMAND test_ioli --samples "${REDASM_SAMPLES}")
6668

67-
set_tests_properties(tier0 PROPERTIES DEPENDS "memory utils")
69+
set_tests_properties(tier0 PROPERTIES DEPENDS "memory utils types")
6870
set_tests_properties(tier1 PROPERTIES DEPENDS "tier0")
6971
set_tests_properties(vb PROPERTIES DEPENDS "tier1")
7072
set_tests_properties(ioli PROPERTIES DEPENDS "vb")

integration/test_ioli.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ static int test_0x00_linux(void) {
1919
};
2020

2121
static const RDTestType TYPES[] = {
22-
{0x8048568, {.name = "char", .count = 25}},
23-
{0x8048581, {.name = "char", .count = 11}},
24-
{0x804858c, {.name = "char", .count = 3}},
25-
{0x804858f, {.name = "char", .count = 7}},
26-
{0x8048596, {.name = "char", .count = 19}},
27-
{0x80485a9, {.name = "char", .count = 16}},
22+
{0x8048568, .name = "char", .count = 25},
23+
{0x8048581, .name = "char", .count = 11},
24+
{0x804858c, .name = "char", .count = 3},
25+
{0x804858f, .name = "char", .count = 7},
26+
{0x8048596, .name = "char", .count = 19},
27+
{0x80485a9, .name = "char", .count = 16},
2828
{0},
2929
};
3030

@@ -129,18 +129,18 @@ static int test_0x00_pocketpc(void) {
129129
};
130130

131131
static const RDTestType TYPES[] = {
132-
{0x13000, {.name = "char", .count = 24}},
133-
{0x13018, {.name = "char", .count = 11}},
134-
{0x13024, {.name = "char", .count = 3}},
135-
{0x13028, {.name = "char", .count = 7}},
136-
{0x13030, {.name = "char", .count = 18}},
137-
{0x13044, {.name = "char", .count = 15}},
138-
{0x110c4, {.name = "u32", .mod = RD_TYPE_PTR}},
139-
{0x110c8, {.name = "u32", .mod = RD_TYPE_PTR}},
140-
{0x110cc, {.name = "u32", .mod = RD_TYPE_PTR}},
141-
{0x110d0, {.name = "u32", .mod = RD_TYPE_PTR}},
142-
{0x110d4, {.name = "u32", .mod = RD_TYPE_PTR}},
143-
{0x110d8, {.name = "u32", .mod = RD_TYPE_PTR}},
132+
{0x13000, .name = "char", .count = 24},
133+
{0x13018, .name = "char", .count = 11},
134+
{0x13024, .name = "char", .count = 3},
135+
{0x13028, .name = "char", .count = 7},
136+
{0x13030, .name = "char", .count = 18},
137+
{0x13044, .name = "char", .count = 15},
138+
{0x110c4, .name = "u32", .mod = RD_TYPE_PTR},
139+
{0x110c8, .name = "u32", .mod = RD_TYPE_PTR},
140+
{0x110cc, .name = "u32", .mod = RD_TYPE_PTR},
141+
{0x110d0, .name = "u32", .mod = RD_TYPE_PTR},
142+
{0x110d4, .name = "u32", .mod = RD_TYPE_PTR},
143+
{0x110d8, .name = "u32", .mod = RD_TYPE_PTR},
144144
{0},
145145
};
146146

integration/test_tier0.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ static int test_cm01(void) {
7979
};
8080

8181
static const RDTestType TYPES[] = {
82-
{0x004020d6, {.name = "char", .count = 17}},
83-
{0x004020e7, {.name = "char", .count = 13}},
84-
{0x004020f4, {.name = "char", .count = 28}},
85-
{0x00402110, {.name = "char", .count = 5}},
86-
{0x00402115, {.name = "char", .count = 10}},
87-
{0x0040211f, {.name = "char", .count = 10}},
88-
{0x00402129, {.name = "char", .count = 11}},
89-
{0x00402134, {.name = "char", .count = 44}},
90-
{0x00402160, {.name = "char", .count = 9}},
91-
{0x00402169, {.name = "char", .count = 21}},
82+
{0x004020d6, .name = "char", .count = 17},
83+
{0x004020e7, .name = "char", .count = 13},
84+
{0x004020f4, .name = "char", .count = 28},
85+
{0x00402110, .name = "char", .count = 5},
86+
{0x00402115, .name = "char", .count = 10},
87+
{0x0040211f, .name = "char", .count = 10},
88+
{0x00402129, .name = "char", .count = 11},
89+
{0x00402134, .name = "char", .count = 44},
90+
{0x00402160, .name = "char", .count = 9},
91+
{0x00402169, .name = "char", .count = 21},
9292
{0},
9393
};
9494

@@ -262,7 +262,7 @@ static int test_testfwd(void) {
262262

263263
static int test_com_hello(void) {
264264
static const RDTestType TYPES[] = {
265-
{0x108, {.name = "char", .count = 15}},
265+
{0x108, .name = "char", .count = 15},
266266
{0},
267267
};
268268

integration/test_tier1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static int test_helloworld32(void) {
1818
};
1919

2020
static const RDTestType TYPES[] = {
21-
{0x080484c0, {.name = "char", .count = 12}},
21+
{0x080484c0, .name = "char", .count = 12},
2222
{0},
2323
};
2424

@@ -89,7 +89,7 @@ static int test_helloworld64(void) {
8989
};
9090

9191
static const RDTestType TYPES[] = {
92-
{0x400594, {.name = "char", .count = 12}},
92+
{0x400594, .name = "char", .count = 12},
9393
{0},
9494
};
9595

integration/test_vb.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ static int test_vb5crkme(void) {
2323
};
2424

2525
static const RDTestType TYPES[] = {
26-
{0x40172c, {.name = "PE_VB_HEADER"}},
27-
{0x401eb8, {.name = "char16", .count = 29}},
28-
{0x401ef8, {.name = "char16", .count = 6}},
29-
{0x401f08, {.name = "char16", .count = 27}},
30-
{0x401f44, {.name = "char16", .count = 10}},
26+
{0x40172c, .name = "VB_HEADER"},
27+
{0x401eb8, .name = "char16", .count = 29},
28+
{0x401ef8, .name = "char16", .count = 6},
29+
{0x401f08, .name = "char16", .count = 27},
30+
{0x401f44, .name = "char16", .count = 10},
3131
{0},
3232
};
3333

@@ -147,12 +147,12 @@ static int test_newbies12(void) {
147147
};
148148

149149
static const RDTestType TYPES[] = {
150-
{0x401aa8, {.name = "PE_VB_HEADER"}},
151-
{0x402ad8, {.name = "char16", .count = 31}},
152-
{0x402b1c, {.name = "char16", .count = 5}},
153-
{0x402b2c, {.name = "char16", .count = 29}},
154-
{0x402b78, {.name = "char16", .count = 53}},
155-
{0x402be8, {.name = "char16", .count = 9}},
150+
{0x401aa8, .name = "VB_HEADER"},
151+
{0x402ad8, .name = "char16", .count = 31},
152+
{0x402b1c, .name = "char16", .count = 5},
153+
{0x402b2c, .name = "char16", .count = 29},
154+
{0x402b78, .name = "char16", .count = 53},
155+
{0x402be8, .name = "char16", .count = 9},
156156
{0},
157157
};
158158

rdtest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef struct {
2828
#define rdtest_assert_false(a) rdtest_assert(!(a), #a " is not FALSE")
2929
#define rdtest_assert_null(a) rdtest_assert((a) == NULL, #a " is not NULL")
3030
#define rdtest_assert_notnull(a) rdtest_assert((a) != NULL, #a " is NULL")
31-
#define rdtest_assert_str(a, b) rdtest_assert((a) && (b) && !strcmp((a), (b)), #a " != " #b)
31+
#define rdtest_assert_streq(a, b) rdtest_assert((a) && (b) && !strcmp((a), (b)), #a " != " #b)
3232
#define rdtest_assert_pass(a) rdtest_assert_eq((a), RDTEST_PASS)
3333
// clang-format on
3434

rdtest_helpers.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,24 +181,32 @@ int rdtest_check_names(RDContext* ctx, const RDTestName* names) {
181181
}
182182

183183
int rdtest_check_types(RDContext* ctx, const RDTestType* types) {
184-
const RDTestType* t = types;
184+
const RDTestType* tt = types;
185185

186-
while(t && !rd_type_is_void(&t->type)) {
186+
while(tt && tt->name) {
187187
RDType currt;
188188

189-
if(!rd_get_type(ctx, t->address, &currt)) {
189+
if(!rd_get_type(ctx, tt->address, &currt)) {
190190
fprintf(stderr, " TEST FAIL no type at 0x%08" PRIx64 "\n",
191-
t->address);
191+
tt->address);
192192
return RDTEST_FAIL;
193193
}
194194

195-
if(!rd_type_equals(&currt, &t->type)) {
195+
RDType t;
196+
if(!rd_type_init(&t, tt->name, tt->count, tt->mod, ctx)) {
197+
fprintf(stderr,
198+
" TEST FAIL type creation failed at 0x%08" PRIx64 "\n",
199+
tt->address);
200+
return RDTEST_FAIL;
201+
}
202+
203+
if(!rd_type_equals(&currt, &t)) {
196204
fprintf(stderr, " TEST FAIL type mismatch at 0x%08" PRIx64 "\n",
197-
t->address);
205+
tt->address);
198206
return RDTEST_FAIL;
199207
}
200208

201-
t++;
209+
tt++;
202210
}
203211

204212
return RDTEST_PASS;

rdtest_helpers.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ typedef struct RDTestName {
1616

1717
typedef struct RDTestType {
1818
RDAddress address;
19-
RDType type;
19+
const char* name;
20+
usize count;
21+
RDTypeModifier mod;
2022
} RDTestType;
2123

2224
typedef struct RDTestXRef {

unit/test_memory.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// --- roundtrip LE ---
55
static int test_roundtrip_u8(void) {
66
RDContext* ctx = rdtest_context_create();
7-
rdtest_assert(ctx, "failed to create test context");
87

98
rdtest_assert(rd_write_byte(ctx, 0x0, 0xAB), "write failed");
109
u8 v;

0 commit comments

Comments
 (0)