From f4fc4e093030c929b7f3ee1d36fb583e59c06670 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 5 Jul 2022 18:58:49 +0200 Subject: [PATCH] fuzz: simplify the log statements a bit --- src/fuzz.c | 68 +++++++++++++++++++++--------------------------------- src/log.h | 7 +++--- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/src/fuzz.c b/src/fuzz.c index f8bc5ac..cfafbd2 100644 --- a/src/fuzz.c +++ b/src/fuzz.c @@ -301,20 +301,16 @@ static int df_fuzz_call_method(const struct df_dbus_method *method, GVariant *va sleep(10); return -1; } else if (g_str_equal(dbus_error, "org.freedesktop.DBus.Error.AccessDenied") || - g_str_equal(dbus_error, "org.freedesktop.DBus.Error.AuthFailed")) { - df_verbose("%s %sSKIP%s [M] %s - raised exception '%s'\n", - ansi_cr(), ansi_blue(), ansi_normal(), - method->name, dbus_error); - return 2; - } + g_str_equal(dbus_error, "org.freedesktop.DBus.Error.AuthFailed")) + return df_verbose_ret(2, "%s %sSKIP%s [M] %s - raised exception '%s'\n", + ansi_cr(), ansi_blue(), ansi_normal(), + method->name, dbus_error); } g_dbus_error_strip_remote_error(error); - if (strstr(error->message, "Timeout")) { - df_verbose("%s %sSKIP%s [M] %s - timeout reached\n", - ansi_cr(), ansi_blue(), ansi_normal(), method->name); - return 2; - } + if (strstr(error->message, "Timeout")) + return df_verbose_ret(2, "%s %sSKIP%s [M] %s - timeout reached\n", + ansi_cr(), ansi_blue(), ansi_normal(), method->name); df_debug("%s EXCE %s - D-Bus exception thrown: %s\n", ansi_cr(), method->name, error->message); @@ -324,11 +320,9 @@ static int df_fuzz_call_method(const struct df_dbus_method *method, GVariant *va /* Check if a method without return value returns void */ if (!method->returns_value) { fmt = g_variant_get_type_string(response); - if (!g_str_equal(fmt, "()")) { - df_fail("%s %sFAIL%s [M] %s - void method returns '%s' instead of '()'\n", - ansi_cr(), ansi_red(), ansi_normal(), method->name, fmt); - return 1; - } + if (!g_str_equal(fmt, "()")) + return df_fail_ret(1, "%s %sFAIL%s [M] %s - void method returns '%s' instead of '()'\n", + ansi_cr(), ansi_red(), ansi_normal(), method->name, fmt); } } @@ -514,20 +508,16 @@ static int df_fuzz_set_property(GDBusProxy *pproxy, const char *interface, sleep(10); return -1; } else if (g_str_equal(dbus_error, "org.freedesktop.DBus.Error.AccessDenied") || - g_str_equal(dbus_error, "org.freedesktop.DBus.Error.AuthFailed")) { - df_verbose("%s %sSKIP%s [P] %s - raised exception '%s'\n", - ansi_cr(), ansi_blue(), ansi_normal(), - property->name, dbus_error); - return 2; - } + g_str_equal(dbus_error, "org.freedesktop.DBus.Error.AuthFailed")) + return df_verbose_ret(2, "%s %sSKIP%s [P] %s - raised exception '%s'\n", + ansi_cr(), ansi_blue(), ansi_normal(), + property->name, dbus_error); } g_dbus_error_strip_remote_error(error); - if (strstr(error->message, "Timeout")) { - df_verbose("%s %sSKIP%s [P] %s - timeout reached\n", - ansi_cr(), ansi_blue(), ansi_normal(), property->name); - return 2; - } + if (strstr(error->message, "Timeout")) + return df_verbose_ret(2, "%s %sSKIP%s [P] %s - timeout reached\n", + ansi_cr(), ansi_blue(), ansi_normal(), property->name); df_debug("%s EXCE [P] %s - D-Bus exception thrown: %s\n", ansi_cr(), property->name, error->message); @@ -573,11 +563,9 @@ int df_fuzz_test_property(GDBusConnection *dcon, const struct df_dbus_property * for (guint8 i = 0; i < iterations; i++) { r = df_fuzz_get_property(pproxy, interface, property); - if (r < 0) { - df_fail("%s %sFAIL%s [P] %s - unexpected response while reading a property\n", - ansi_cr(), ansi_red(), ansi_normal(), property->name); - return 1; - } + if (r < 0) + return df_fail_ret(1, "%s %sFAIL%s [P] %s - unexpected response while reading a property\n", + ansi_cr(), ansi_red(), ansi_normal(), property->name); } /* Check if the remote side is still alive */ @@ -617,22 +605,18 @@ int df_fuzz_test_property(GDBusConnection *dcon, const struct df_dbus_property * /* Convert the floating variant reference into a full one */ value = g_variant_ref_sink(value); r = df_fuzz_set_property(pproxy, interface, property, value); - if (r < 0) { - df_fail("%s %sFAIL%s [P] %s (write) - unexpected response while writing to a property\n", - ansi_cr(), ansi_red(), ansi_normal(), property->name); - return 1; - } + if (r < 0) + return df_fail_ret(1, "%s %sFAIL%s [P] %s (write) - unexpected response while writing to a property\n", + ansi_cr(), ansi_red(), ansi_normal(), property->name); } /* Check if the remote side is still alive */ r = df_check_if_exited(pid); if (r < 0) return df_fail_ret(-1, "Error while reading process' stat file: %m\n"); - else if (r == 0) { - df_fail("%s %sFAIL%s [P] %s (write) - process %d exited\n", - ansi_cr(), ansi_red(), ansi_normal(), property->name, pid); - return 1; - } + else if (r == 0) + return df_fail_ret(1, "%s %sFAIL%s [P] %s (write) - process %d exited\n", + ansi_cr(), ansi_red(), ansi_normal(), property->name, pid); df_verbose("%s %sPASS%s [P] %s (write)\n", ansi_cr(), ansi_green(), ansi_normal(), property->name); diff --git a/src/log.h b/src/log.h index d8123f7..50ec44b 100644 --- a/src/log.h +++ b/src/log.h @@ -35,6 +35,7 @@ void df_error(const char *message, GError *error); ret; \ }) -#define df_oom(void) df_log_ret_internal(-ENOMEM, df_fail, "Allocation error: %m\n") -#define df_fail_ret(ret, ...) df_log_ret_internal(ret, df_fail, __VA_ARGS__) -#define df_debug_ret(ret, ...) df_log_ret_internal(ret, df_debug, __VA_ARGS__) +#define df_oom(void) df_log_ret_internal(-ENOMEM, df_fail, "Allocation error: %m\n") +#define df_fail_ret(ret, ...) df_log_ret_internal(ret, df_fail, __VA_ARGS__) +#define df_verbose_ret(ret, ...) df_log_ret_internal(ret, df_verbose, __VA_ARGS__) +#define df_debug_ret(ret, ...) df_log_ret_internal(ret, df_debug, __VA_ARGS__)