From nobody Wed Feb 11 00:59:57 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=1657620712; cv=none; d=zohomail.com; s=zohoarc; b=GJxY3CP2TpVWEffns6nurBpTgLceFVRW2bMQ/nQ/c8ZB0dqqqMfFIYzP9JG3p7ouLLEGmBoLX9L/UMDBK3T/JhKk5tmZsWnmOiwg4Vgn9fJFaCKHYZG1bvUxIvzhcEEYpE+smPe4qcPyj0I7fRujtNmKtRkLvHiAgwzM6tEuRmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657620712; 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=DGLKwGrwExfiJ5yPSl55RdoLzgPPkGL6kvwwHPribIk=; b=F/iiAjKTT0DyK6jbVeIr1efqfOhEvLlaxPZtd2MoqMIMWXUvyWtCOpMt5WA4NXqqj0xzYqsPKaCSR5co7Y7fMC7J5V+ViV9uVLbnh0+Duuu0JF0sAk56QKt1a870rsJKUfUlS9k+KwpenAXdX13N1r6QfPEGSkvme3noeGwf7XA= 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 165762071253099.41824670811502; Tue, 12 Jul 2022 03:11:52 -0700 (PDT) Received: from localhost ([::1]:50490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBCrv-00017y-E4 for importer@patchew.org; Tue, 12 Jul 2022 06:11:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBCKc-0006Jd-4E for qemu-devel@nongnu.org; Tue, 12 Jul 2022 05:37:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32864) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBCKU-0002HP-Ay for qemu-devel@nongnu.org; Tue, 12 Jul 2022 05:37:25 -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-317-Zi9bg23aMtCIlcqDpFgTjg-1; Tue, 12 Jul 2022 05:37:13 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8810180029D; Tue, 12 Jul 2022 09:37:12 +0000 (UTC) Received: from localhost (unknown [10.39.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DFB21415117; Tue, 12 Jul 2022 09:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657618637; 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=DGLKwGrwExfiJ5yPSl55RdoLzgPPkGL6kvwwHPribIk=; b=QE2YQZBfDotreJT11JP0WY9VVVTgJPTRdE7HPUSBZsHJmK/7AQlED5hyF1UYe23dqkKc+M /MQyFMMQbGCRPvLnUfvo973ERtn1/NrdMJprCaNWDTP4dx2YwFDZ3hIrdVw0F0FsHMYMHf +L516ReTJVmGOeUZvGzFGzMOsxMq2II= X-MC-Unique: Zi9bg23aMtCIlcqDpFgTjg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Eric Blake , Cleber Rosa , qemu-block@nongnu.org, Paolo Bonzini , Xie Yongji , Kyle Evans , Peter Maydell , John Snow , Michael Roth , Warner Losh , Kevin Wolf , "Dr. David Alan Gilbert" , Markus Armbruster , Vladimir Sementsov-Ogievskiy , Laurent Vivier , Fam Zheng , Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 15/15] qemu-common: add error-report test Date: Tue, 12 Jul 2022 13:35:28 +0400 Message-Id: <20220712093528.4144184-16-marcandre.lureau@redhat.com> In-Reply-To: <20220712093528.4144184-1-marcandre.lureau@redhat.com> References: <20220712093528.4144184-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.7 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.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 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_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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: 1657620714249100001 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 000000000000..09a2d122a0e1 --- /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 05bca6d30d49..991aaac52040 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 000000000000..3dd10c180b50 --- /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.0.rc0