4 * Copyright (C) 2022 Red Hat Inc.
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
10 #include "qemu/osdep.h"
11 #include "glib-compat.h"
14 #include "qemu/error-report.h"
15 #include "qapi/error.h"
18 test_error_report_simple(void)
20 if (g_test_subprocess()) {
21 error_report("%s", "test error");
22 warn_report("%s", "test warn");
23 info_report("%s", "test info");
27 g_test_trap_subprocess(NULL, 0, 0);
28 g_test_trap_assert_passed();
29 g_test_trap_assert_stderr("\
30 test-error-report: test error*\
31 test-error-report: warning: test warn*\
32 test-error-report: info: test info*\
37 test_error_report_loc(void)
39 if (g_test_subprocess()) {
40 loc_set_file("some-file.c", 7717);
41 error_report("%s", "test error1");
43 error_report("%s", "test error2");
47 g_test_trap_subprocess(NULL, 0, 0);
48 g_test_trap_assert_passed();
49 g_test_trap_assert_stderr("\
50 test-error-report:some-file.c:7717: test error1*\
51 test-error-report: test error2*\
56 test_error_report_glog(void)
58 if (g_test_subprocess()) {
59 g_message("gmessage");
63 g_test_trap_subprocess(NULL, 0, 0);
64 g_test_trap_assert_passed();
65 g_test_trap_assert_stderr("test-error-report: info: gmessage*");
69 test_error_report_once(void)
73 if (g_test_subprocess()) {
74 for (i = 0; i < 3; i++) {
75 warn_report_once("warn");
76 error_report_once("err");
81 g_test_trap_subprocess(NULL, 0, 0);
82 g_test_trap_assert_passed();
83 g_test_trap_assert_stderr("\
84 test-error-report: warning: warn*\
85 test-error-report: err*\
90 test_error_report_timestamp(void)
92 if (g_test_subprocess()) {
93 message_with_timestamp = true;
99 g_test_trap_subprocess(NULL, 0, 0);
100 g_test_trap_assert_passed();
101 g_test_trap_assert_stderr("\
102 *-*-*:*:* test-error-report: warning: warn*\
103 *-*-*:*:* test-error-report: err*\
108 test_error_warn(void)
110 if (g_test_subprocess()) {
111 error_setg(&error_warn, "Testing &error_warn");
115 g_test_trap_subprocess(NULL, 0, 0);
116 g_test_trap_assert_passed();
117 g_test_trap_assert_stderr("\
118 test-error-report: warning: Testing &error_warn*\
124 main(int argc, char *argv[])
126 setlocale(LC_ALL, "");
128 g_test_init(&argc, &argv, NULL);
129 error_init("test-error-report");
131 g_test_add_func("/error-report/simple", test_error_report_simple);
132 g_test_add_func("/error-report/loc", test_error_report_loc);
133 g_test_add_func("/error-report/glog", test_error_report_glog);
134 g_test_add_func("/error-report/once", test_error_report_once);
135 g_test_add_func("/error-report/timestamp", test_error_report_timestamp);
136 g_test_add_func("/error-report/warn", test_error_warn);