Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rz-test '-y' option to accept all #4772

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion binrz/rz-test/rz-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ static void interact(RzTestState *state);
static bool interact_fix(RzTestResultInfo *result, RzPVector /*<RzTestResultInfo *>*/ *fixup_results);
static void interact_break(RzTestResultInfo *result, RzPVector /*<RzTestResultInfo *>*/ *fixup_results);
static void interact_commands(RzTestResultInfo *result, RzPVector /*<RzTestResultInfo *>*/ *fixup_results);
static void accept_all(RzTestState *state);

static int help(bool verbose) {
XVilka marked this conversation as resolved.
Show resolved Hide resolved
printf("%s%s%s", Color_CYAN, "Usage: ", Color_RESET);
Expand All @@ -71,6 +72,7 @@ static int help(bool verbose) {
"-q", "", "Quiet mode",
"-V", "", "Be verbose",
"-i", "", "Interactive mode",
"-y", "", "Accept all interactive changes",
"-n", "", "Do nothing (don't run any test, just load/parse them)",
"-L", "", "Log mode (better printing for CI, logfiles, etc.)",
"-F", "[dir]", "Run fuzz tests (open and default analysis) on all files in the given dir",
Expand Down Expand Up @@ -176,6 +178,7 @@ int rz_test_main(int argc, const char **argv) {
bool nothing = false;
bool quiet = false;
bool interactive = false;
bool accept = false;
char *rizin_cmd = NULL;
char *rz_asm_cmd = NULL;
char *json_test_file = NULL;
Expand Down Expand Up @@ -209,7 +212,7 @@ int rz_test_main(int argc, const char **argv) {
#endif

RzGetopt opt;
rz_getopt_init(&opt, argc, (const char **)argv, "hqvj:r:m:f:C:LnVt:F:io:e:s:x:");
rz_getopt_init(&opt, argc, (const char **)argv, "hqvj:r:m:f:C:LnVt:F:io:e:s:x:y");

int c;
while ((c = rz_getopt_next(&opt)) != -1) {
Expand All @@ -236,6 +239,9 @@ int rz_test_main(int argc, const char **argv) {
case 'i':
interactive = true;
break;
case 'y':
accept = true;
break;
case 'L':
log_mode = true;
break;
Expand Down Expand Up @@ -561,6 +567,10 @@ int rz_test_main(int argc, const char **argv) {
interact(&state);
}

if (accept) {
accept_all(&state);
}

if (expect_succ > 0 && expect_succ != state.ok_count) {
ret = 1;
}
Expand Down Expand Up @@ -1050,6 +1060,40 @@ static void interact(RzTestState *state) {
rz_pvector_clear(&failed_results);
}

static void accept_all(RzTestState *state) {
void **it;
RzPVector failed_results;
rz_pvector_init(&failed_results, NULL);
rz_pvector_foreach (&state->results, it) {
RzTestResultInfo *result = *it;
if (result->result == RZ_TEST_RESULT_FAILED) {
rz_pvector_push(&failed_results, result);
}
}
if (rz_pvector_empty(&failed_results)) {
goto beach;
}

#if __WINDOWS__
(void)SetConsoleOutputCP(65001); // UTF-8
#endif

rz_pvector_foreach (&failed_results, it) {
RzTestResultInfo *result = *it;
if (result->test->type != RZ_TEST_TYPE_CMD && result->test->type != RZ_TEST_TYPE_ASM) {
continue;
}
if (!interact_fix(result, &failed_results)) {
char *name = rz_test_test_name(result->test);
printf("This test %s has failed too hard to be fixed.\n", name ? name : "");
free(name);
}
}

beach:
rz_pvector_clear(&failed_results);
}

static char *format_cmd_kv(const char *key, const char *val) {
RzStrBuf buf;
rz_strbuf_init(&buf);
Expand Down
Loading