[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 04/25] tests: add test-error-report
From: |
marcandre . lureau |
Subject: |
[PULL v2 04/25] tests: add test-error-report |
Date: |
Mon, 13 Mar 2023 15:46:27 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Message-Id: <20230221124802.4103554-5-marcandre.lureau@redhat.com>
---
tests/unit/test-error-report.c | 121 +++++++++++++++++++++++++++++++++
tests/unit/meson.build | 1 +
2 files changed, 122 insertions(+)
create mode 100644 tests/unit/test-error-report.c
diff --git a/tests/unit/test-error-report.c b/tests/unit/test-error-report.c
new file mode 100644
index 0000000000..b09650687b
--- /dev/null
+++ b/tests/unit/test-error-report.c
@@ -0,0 +1,121 @@
+/*
+ * Error reporting test
+ *
+ * Copyright (C) 2022 Red Hat Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "glib-compat.h"
+#include <locale.h>
+
+#include "qemu/error-report.h"
+
+static void
+test_error_report_simple(void)
+{
+ if (g_test_subprocess()) {
+ error_report("%s", "test error");
+ warn_report("%s", "test warn");
+ info_report("%s", "test info");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+test-error-report: test error*\
+test-error-report: warning: test warn*\
+test-error-report: info: test info*\
+");
+}
+
+static void
+test_error_report_loc(void)
+{
+ if (g_test_subprocess()) {
+ loc_set_file("some-file.c", 7717);
+ error_report("%s", "test error1");
+ loc_set_none();
+ error_report("%s", "test error2");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+test-error-report:some-file.c:7717: test error1*\
+test-error-report: test error2*\
+");
+}
+
+static void
+test_error_report_glog(void)
+{
+ if (g_test_subprocess()) {
+ g_message("gmessage");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("test-error-report: info: gmessage*");
+}
+
+static void
+test_error_report_once(void)
+{
+ int i;
+
+ if (g_test_subprocess()) {
+ for (i = 0; i < 3; i++) {
+ warn_report_once("warn");
+ error_report_once("err");
+ }
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+test-error-report: warning: warn*\
+test-error-report: err*\
+");
+}
+
+static void
+test_error_report_timestamp(void)
+{
+ if (g_test_subprocess()) {
+ message_with_timestamp = true;
+ warn_report("warn");
+ error_report("err");
+ return;
+ }
+
+ g_test_trap_subprocess(NULL, 0, 0);
+ g_test_trap_assert_passed();
+ g_test_trap_assert_stderr("\
+*-*-*:*:* test-error-report: warning: warn*\
+*-*-*:*:* test-error-report: err*\
+");
+}
+
+int
+main(int argc, char *argv[])
+{
+ setlocale(LC_ALL, "");
+
+ g_test_init(&argc, &argv, NULL);
+ error_init("test-error-report");
+
+ g_test_add_func("/error-report/simple", test_error_report_simple);
+ g_test_add_func("/error-report/loc", test_error_report_loc);
+ g_test_add_func("/error-report/glog", test_error_report_glog);
+ g_test_add_func("/error-report/once", test_error_report_once);
+ g_test_add_func("/error-report/timestamp", test_error_report_timestamp);
+
+ return g_test_run();
+}
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
index d9c0a7eae6..fa63cfe6ff 100644
--- a/tests/unit/meson.build
+++ b/tests/unit/meson.build
@@ -11,6 +11,7 @@ tests = {
'check-qobject': [],
'check-qjson': [],
'check-qlit': [],
+ 'test-error-report': [],
'test-qobject-output-visitor': [testqapi],
'test-clone-visitor': [testqapi],
'test-qobject-input-visitor': [testqapi],
--
2.39.2
- [PULL v2 00/25] Win socket patches, marcandre . lureau, 2023/03/13
- [PULL v2 01/25] util: drop qemu_fork(), marcandre . lureau, 2023/03/13
- [PULL v2 02/25] tests: use closesocket(), marcandre . lureau, 2023/03/13
- [PULL v2 03/25] io: use closesocket(), marcandre . lureau, 2023/03/13
- [PULL v2 04/25] tests: add test-error-report,
marcandre . lureau <=
- [PULL v2 06/25] win32/socket: introduce qemu_socket_select() helper, marcandre . lureau, 2023/03/13
- [PULL v2 07/25] win32/socket: introduce qemu_socket_unselect() helper, marcandre . lureau, 2023/03/13
- [PULL v2 05/25] error: add global &error_warn destination, marcandre . lureau, 2023/03/13
- [PULL v2 08/25] aio: make aio_set_fd_poll() static to aio-posix.c, marcandre . lureau, 2023/03/13
- [PULL v2 09/25] aio/win32: aio_set_fd_handler() only supports SOCKET, marcandre . lureau, 2023/03/13
- [PULL v2 10/25] main-loop: remove qemu_fd_register(), win32/slirp/socket specific, marcandre . lureau, 2023/03/13
- [PULL v2 11/25] slirp: unregister the win32 SOCKET, marcandre . lureau, 2023/03/13
- [PULL v2 12/25] slirp: open-code qemu_socket_(un)select(), marcandre . lureau, 2023/03/13
- [PULL v2 14/25] os-posix: remove useless ioctlsocket() define, marcandre . lureau, 2023/03/13
- [PULL v2 15/25] win32: replace closesocket() with close() wrapper, marcandre . lureau, 2023/03/13