Skip to content

Commit

Permalink
fuzz: simplify the log statements a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrc0mmand committed Jul 6, 2022
1 parent 11936a5 commit f4fc4e0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 45 deletions.
68 changes: 26 additions & 42 deletions src/fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

0 comments on commit f4fc4e0

Please sign in to comment.