From nobody Tue Feb 10 23:13:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1660137080; cv=none; d=zohomail.com; s=zohoarc; b=jYwaxcYe6zV9LqpBprDN0cSgct5jjnTp2B2hGAovZFtFcoeFb9LesCw4IJ1Muxz1hhtigsFy+ZjQZWH4uV+SAH6/Dh3AzF53PkCp0BsTz2/Qkv4nE4rXrXL774encWvpUiLwtdL0xAxqYQasyC/Lua6hmagi+ucFr6D82NhTZAo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660137080; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QW2JkB+lQDvso8ZSmM25soHjoDYOqnfuVmKcQmRfYOk=; b=U8xyQ6H7q6FfAUnzcQC5uKcdq60FOjQ2UelU2wkka/TArn4HPuVBvBS6oKizpt97IfvCSS3zHSPCqCgWMDLkJIuYK3Ah8RJQO5clqhkey7CaLFd8xfY/VDJMBJbb18oV9bUGToTKLhmmcDyMbTITYWMLXcAFoJKX3el/mYVo1VU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660137080056454.522991705904; Wed, 10 Aug 2022 06:11:20 -0700 (PDT) Received: from localhost ([::1]:58084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oLlUU-0001QD-T5 for importer@patchew.org; Wed, 10 Aug 2022 09:11:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLlAU-0001uM-VV for qemu-devel@nongnu.org; Wed, 10 Aug 2022 08:50:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50345) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLlAM-0007tQ-VJ for qemu-devel@nongnu.org; Wed, 10 Aug 2022 08:50:33 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-266-euwjXadhOz-qM6XeYva41A-1; Wed, 10 Aug 2022 08:50:28 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2CECD19711D0; Wed, 10 Aug 2022 12:50:23 +0000 (UTC) Received: from localhost (unknown [10.39.208.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC9D340315E; Wed, 10 Aug 2022 12:50:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660135830; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QW2JkB+lQDvso8ZSmM25soHjoDYOqnfuVmKcQmRfYOk=; b=CL48cim94Ubl0IpOeyH0MymYdqhhY8Uu31Jf9yBPzWUe3RX7Vh45xqKL901HClE0MEQ0yk I0gT7gbV+G97SFb/VQ8jFCy31ywQuZ/ATjgGbU1Illk+JZWse0MJrHpqIiCCo/ZdumT5X3 EkyqufGZUUCS6WCPjUTpbKA7GKnjPWQ= X-MC-Unique: euwjXadhOz-qM6XeYva41A-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Peter Maydell , Cleber Rosa , Michael Roth , John Snow , Xie Yongji , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v3 16/16] qemu-common: add error-report test Date: Wed, 10 Aug 2022 16:48:57 +0400 Message-Id: <20220810124857.1360211-17-marcandre.lureau@redhat.com> In-Reply-To: <20220810124857.1360211-1-marcandre.lureau@redhat.com> References: <20220810124857.1360211-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1660137082085100001 From: Marc-Andr=C3=A9 Lureau Add new tests to check the behaviour of error reporting functions. Signed-off-by: Marc-Andr=C3=A9 Lureau --- .../qemu-common/tests/test-error-report.c | 120 ++++++++++++++++++ subprojects/qemu-common/meson.build | 2 + subprojects/qemu-common/tests/meson.build | 12 ++ 3 files changed, 134 insertions(+) create mode 100644 subprojects/qemu-common/tests/test-error-report.c create mode 100644 subprojects/qemu-common/tests/meson.build diff --git a/subprojects/qemu-common/tests/test-error-report.c b/subproject= s/qemu-common/tests/test-error-report.c new file mode 100644 index 0000000000..09a2d122a0 --- /dev/null +++ b/subprojects/qemu-common/tests/test-error-report.c @@ -0,0 +1,120 @@ +/* + * Error reporting test + * + * Copyright (C) 2022 Red Hat Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "glib-compat.h" +#include + +#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 =3D 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 =3D 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/subprojects/qemu-common/meson.build b/subprojects/qemu-common/= meson.build index 05bca6d30d..991aaac520 100644 --- a/subprojects/qemu-common/meson.build +++ b/subprojects/qemu-common/meson.build @@ -22,3 +22,5 @@ qemu_common_dep =3D declare_dependency( include_directories: inc, dependencies: [glib_dep], ) + +subdir('tests') diff --git a/subprojects/qemu-common/tests/meson.build b/subprojects/qemu-c= ommon/tests/meson.build new file mode 100644 index 0000000000..3dd10c180b --- /dev/null +++ b/subprojects/qemu-common/tests/meson.build @@ -0,0 +1,12 @@ +env =3D [ + 'G_TEST_SRCDIR=3D@0@'.format(meson.current_source_dir()), + 'G_TEST_BUILDDIR=3D@0@'.format(meson.current_build_dir()), +] + +test('error-report', + executable('test-error-report', + sources: files('test-error-report.c'), + dependencies: qemu_common_dep, + ), + env: env, +) --=20 2.37.1