From patchwork Tue Sep 27 11:06:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12990497 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D819C07E9D for ; Tue, 27 Sep 2022 11:48:40 +0000 (UTC) Received: from localhost ([::1]:56368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1od94p-0006s1-B1 for qemu-devel@archiver.kernel.org; Tue, 27 Sep 2022 07:48:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1od8RG-0002oF-Am for qemu-devel@nongnu.org; Tue, 27 Sep 2022 07:07:49 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:41727) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1od8RE-0004yI-6D for qemu-devel@nongnu.org; Tue, 27 Sep 2022 07:07:46 -0400 Received: by mail-pl1-x632.google.com with SMTP id d11so8751372pll.8 for ; Tue, 27 Sep 2022 04:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=2qELv4fD6lZQNjqoSLTskKNLUucRsODzyqWeHTRxa0M=; b=pII52T+HV6pn8oWQbmQqlwecGHtVKcXojRBG7lPjQdUbIZcVNxkl/rZpvHoxDTExJE nPugh4OxVkFLfusjzyHLt1zwKh3pvVOyo2RICjNuKwtADeDubJV4b2QogAQNsbd1MI32 me+Ex6ukCaamIKMmeinpe7km2LQ3/OCXG3u8ppc8a3gCAwFLUxgI0Z78EA/OpngD4PJH 3Z30HQCF0zPteODiKLPWZcmMQKjBMiBsf0mib4w2e2WIJlzbpVsyUD233k15HsBCu1K8 9jqJJPYa4KYs/rhWakTlZGVZWXoU3M7ZJhWhPWSZIOj27Ee2CoE8HnFLJ5zRGfVCGvY2 rsYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=2qELv4fD6lZQNjqoSLTskKNLUucRsODzyqWeHTRxa0M=; b=2/NPEfWFy+YZkbFrjNiCsdQ/1UKleBcamYD3/3AwJs2Hrpym65IAutXm4ND9GlwtT9 /2xtePCWJs3V5gH18XLwC+SwSGF8dlqrXoV0yiBhcBHOOb33pdc41HxRAwybRIdF5Z65 FLX/9wKOUp8XWvEJJ8r2tojh0H1Gks6zAuzbFXTx6Z+oOP3pWIU6pjFp/box5QFJQqCG iyJjO4uIv/lEVpApnRMVCdFYJS6KLUldaPgca/DyBSwmrlboa0Bh9HdAMiRL2AsU211T EOjY3jFzZOQs/C77rGLW4r7vUGuTVxW8QYcNDHubRPil7elt0nihJ02lPxbOtmxx1su7 mbXg== X-Gm-Message-State: ACrzQf28NtBwCvZDmx8MPuOwwuRIFgU511znwjNc3ixRFcVB7/iy/rLm DOwQoYGrooAGbh5Vva7PMYlPQrZkS3Y= X-Google-Smtp-Source: AMsMyM4ZzmG+HCWrpPUJg5Xpwg7enR4USz8X8wcPhrP1QbrUdtS7s518MvprAno+okthntWLsV4Vsg== X-Received: by 2002:a17:903:245:b0:178:e0ba:e507 with SMTP id j5-20020a170903024500b00178e0bae507mr27653326plh.115.1664276861275; Tue, 27 Sep 2022 04:07:41 -0700 (PDT) Received: from ubuntu.. (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id i7-20020a626d07000000b00540f2323f67sm1453601pfc.95.2022.09.27.04.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 04:07:40 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org, Thomas Huth Cc: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Bin Meng Subject: [PATCH v4 22/54] tests/unit: test-image-locking: Avoid using hardcoded /tmp Date: Tue, 27 Sep 2022 19:06:00 +0800 Message-Id: <20220927110632.1973965-23-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220927110632.1973965-1-bmeng.cn@gmail.com> References: <20220927110632.1973965-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=bmeng.cn@gmail.com; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng This case was written to use hardcoded /tmp directory for temporary files. Update to use g_file_open_tmp() for a portable implementation. Signed-off-by: Bin Meng Reviewed-by: Marc-André Lureau --- (no changes since v3) Changes in v3: - Split to a separate patch - Ensure g_autofree variable is initialized tests/unit/test-image-locking.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/test-image-locking.c b/tests/unit/test-image-locking.c index ba057bd66c..a47299c247 100644 --- a/tests/unit/test-image-locking.c +++ b/tests/unit/test-image-locking.c @@ -76,10 +76,10 @@ static void check_locked_bytes(int fd, uint64_t perm_locks, static void test_image_locking_basic(void) { BlockBackend *blk1, *blk2, *blk3; - char img_path[] = "/tmp/qtest.XXXXXX"; + g_autofree char *img_path = NULL; uint64_t perm, shared_perm; - int fd = mkstemp(img_path); + int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL); assert(fd >= 0); perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ; @@ -117,10 +117,10 @@ static void test_image_locking_basic(void) static void test_set_perm_abort(void) { BlockBackend *blk1, *blk2; - char img_path[] = "/tmp/qtest.XXXXXX"; + g_autofree char *img_path = NULL; uint64_t perm, shared_perm; int r; - int fd = mkstemp(img_path); + int fd = g_file_open_tmp("qtest.XXXXXX", &img_path, NULL); assert(fd >= 0); perm = BLK_PERM_WRITE | BLK_PERM_CONSISTENT_READ;