Skip to content

Commit 7980552

Browse files
committed
update test to check if cached result is correct or not
1 parent 03ec38b commit 7980552

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

test/unit/test_rop.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,25 @@ bool test_rz_direct_solver() {
144144
bool test_rop_cache() {
145145
RzCore *core = setup_rz_core("x86", 64);
146146
mu_assert_notnull(core, "setup_rz_core failed");
147-
mu_assert_null(core->analysis->ht_rop, "ht_rop should be NULL initially");
148-
ut8 buf[8];
149-
rz_hex_str2bin("48C7C301000000C3", buf);
150-
rz_io_write_at(core->io, 0, buf, 8);
151147
rz_config_set_b(core->config, "rop.cache", true);
152-
RzRopSearchContext *context = rz_core_rop_search_context_new(
153-
core, "mov", false, RZ_ROP_GADGET_PRINT, RZ_ROP_DETAIL_SEARCH_NON, NULL);
154-
RzCmdStatus status = rz_core_rop_search(core, context);
155-
mu_assert_eq(status, RZ_CMD_STATUS_OK, "rop search should succeed");
156-
mu_assert_notnull(core->analysis->ht_rop, "ht_rop should be initialized after cached search");
157-
rz_core_rop_search_context_free(context);
148+
149+
const char *greparg = "mov";
150+
const char *expected = "0x00000000: mov rbx, 1; ret;\n";
151+
ut64 cache_key = rz_str_djb2_hash(greparg);
152+
153+
core->analysis->ht_rop = ht_up_new(NULL, free);
154+
ht_up_insert(core->analysis->ht_rop, cache_key, strdup(expected));
155+
char *cached = ht_up_find(core->analysis->ht_rop, cache_key, NULL);
156+
mu_assert_streq(cached, expected, "cache store failed");
157+
158+
rz_cons_new();
159+
RzRopSearchContext *ctx = rz_core_rop_search_context_new(
160+
core, greparg, false, RZ_ROP_GADGET_PRINT, RZ_ROP_DETAIL_SEARCH_NON, NULL);
161+
rz_core_rop_search(core, ctx);
162+
rz_core_rop_search_context_free(ctx);
163+
mu_assert_streq(rz_cons_get_buffer(), expected, "cache retrieval failed");
164+
rz_cons_free();
165+
158166
rz_core_free(core);
159167
mu_end;
160168
}

0 commit comments

Comments
 (0)