From patchwork Thu Sep 3 07:43:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?572X5YuH5YiaKFlvbmdnYW5nIEx1byk=?= X-Patchwork-Id: 274730 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C46D6C2BC0E for ; Thu, 3 Sep 2020 07:46:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 6B06320716 for ; Thu, 3 Sep 2020 07:46:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l8wxX/89" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B06320716 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDjxD-0005Gh-EF for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 03:46:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDjuM-0008Kk-E9 for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:43:46 -0400 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:54713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDjuI-0003rW-Ch for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:43:46 -0400 Received: by mail-pj1-x1044.google.com with SMTP id mm21so1098948pjb.4 for ; Thu, 03 Sep 2020 00:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=huTQukiVEQnbnV6oUpHw80TH1WL6GqzC6d5q3yiaZGo=; b=l8wxX/89oWmJ+w+iU3vMiZt+6q+eOpGBjvAPuNr4NRtO3yyQKof9+KPFKP3hG7Z5IY 71aQn7fXvTxZQtisUlj5Rs3ogce/Ha5mtVg+cpUENx83Rv3V5/g1hsQp3d8XwKMbwyM2 32wYu+DQVvgmAPwFuqZqkpFytUjMwbOwp5F0J/xrUllzdgsFRf3HzAKYszUKqExl7Ofx UwSilhsyrzWf8Y2aa921lBFBOOMa44xZA2pieGlBAv0dXZulDbJ5QB3IqfXL0cutx3oO qFHBzyNJCARG+pNgGdNpXbU1szGYkwgrSgRlKod8wNwuugPn4Gi/IOMjAyuz0Tl4Ls0S hrgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=huTQukiVEQnbnV6oUpHw80TH1WL6GqzC6d5q3yiaZGo=; b=kyGHCz8Cy4AL7i333ck3TUFGN5OkCtLZ2npG+F94ZIE7uW3G4AZTP70jXCxzuvv5xr h6/tC5Mz7e25XSYjQIg5GQtwxFmXhiol4ffMxTyOZbqINsTkaepCy5X3lRW3FTmt2Fjl GSs0CT7aVq9ujFyGMBI5w8+bCeULAlM76beB3CraAAz+MoiHJYVVIIP63CUQMsY1kbgi HBEKKXp/oVMgDKBjL2V1ZKUlwg+ZTe+fXaIqzNaj6KkNtEP41VrTKNfjyvMGfXpKFbzN vJXUt+8OGdQyegvxsYB3QYAfk/mMU9ZtxhUsBlqv7PVHRb+17SxTzMzSZSJnBSjOJgSD IgAQ== X-Gm-Message-State: AOAM531mDQ8usqNHXPeBwz4yvk1lT1/YYfvCgZ+PlcBFqFpppG0UZXtb 7fQ/tkzgHpU4UyGPfiwYFG07dV/M755xhgtE X-Google-Smtp-Source: ABdhPJxi5I3vbmjE7EHdfmTr3VoSQFncd3LDkgsP1epfOeOLwOo0iRUdoWa0Kg1ndZY2rO3CXDq3GA== X-Received: by 2002:a17:90a:a088:: with SMTP id r8mr1959182pjp.73.1599119019797; Thu, 03 Sep 2020 00:43:39 -0700 (PDT) Received: from localhost.localdomain ([222.95.248.6]) by smtp.googlemail.com with ESMTPSA id o6sm1512472pju.25.2020.09.03.00.43.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 00:43:38 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v3 04/12] tests: handling signal on win32 properly Date: Thu, 3 Sep 2020 15:43:05 +0800 Message-Id: <20200903074313.1498-5-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200903074313.1498-1-luoyonggang@gmail.com> References: <20200903074313.1498-1-luoyonggang@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=luoyonggang@gmail.com; helo=mail-pj1-x1044.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Yonggang Luo Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" SIGABRT should use signal(SIGABRT, sigabrt_handler) to handle on win32 The error: E:/CI-Cor-Ready/xemu/qemu.org/tests/test-replication.c:559:33: error: invalid use of undefined type 'struct sigaction' 559 | sigact = (struct sigaction) { | ^ Signed-off-by: Yonggang Luo --- tests/test-replication.c | 1214 +++++++++++++++++++------------------- 1 file changed, 609 insertions(+), 605 deletions(-) diff --git a/tests/test-replication.c b/tests/test-replication.c index e0b03dafc2..9ab3666a90 100644 --- a/tests/test-replication.c +++ b/tests/test-replication.c @@ -1,605 +1,609 @@ -/* - * Block replication tests - * - * Copyright (c) 2016 FUJITSU LIMITED - * Author: Changlong Xie - * - * 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 "qapi/error.h" -#include "qapi/qmp/qdict.h" -#include "qemu/option.h" -#include "qemu/main-loop.h" -#include "replication.h" -#include "block/block_int.h" -#include "block/qdict.h" -#include "sysemu/block-backend.h" - -#define IMG_SIZE (64 * 1024 * 1024) - -/* primary */ -#define P_ID "primary-id" -static char p_local_disk[] = "/tmp/p_local_disk.XXXXXX"; - -/* secondary */ -#define S_ID "secondary-id" -#define S_LOCAL_DISK_ID "secondary-local-disk-id" -static char s_local_disk[] = "/tmp/s_local_disk.XXXXXX"; -static char s_active_disk[] = "/tmp/s_active_disk.XXXXXX"; -static char s_hidden_disk[] = "/tmp/s_hidden_disk.XXXXXX"; - -/* FIXME: steal from blockdev.c */ -QemuOptsList qemu_drive_opts = { - .name = "drive", - .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), - .desc = { - { /* end of list */ } - }, -}; - -#define NOT_DONE 0x7fffffff - -static void blk_rw_done(void *opaque, int ret) -{ - *(int *)opaque = ret; -} - -static void test_blk_read(BlockBackend *blk, long pattern, - int64_t pattern_offset, int64_t pattern_count, - int64_t offset, int64_t count, - bool expect_failed) -{ - void *pattern_buf = NULL; - QEMUIOVector qiov; - void *cmp_buf = NULL; - int async_ret = NOT_DONE; - - if (pattern) { - cmp_buf = g_malloc(pattern_count); - memset(cmp_buf, pattern, pattern_count); - } - - pattern_buf = g_malloc(count); - if (pattern) { - memset(pattern_buf, pattern, count); - } else { - memset(pattern_buf, 0x00, count); - } - - qemu_iovec_init(&qiov, 1); - qemu_iovec_add(&qiov, pattern_buf, count); - - blk_aio_preadv(blk, offset, &qiov, 0, blk_rw_done, &async_ret); - while (async_ret == NOT_DONE) { - main_loop_wait(false); - } - - if (expect_failed) { - g_assert(async_ret != 0); - } else { - g_assert(async_ret == 0); - if (pattern) { - g_assert(memcmp(pattern_buf + pattern_offset, - cmp_buf, pattern_count) <= 0); - } - } - - g_free(pattern_buf); - g_free(cmp_buf); - qemu_iovec_destroy(&qiov); -} - -static void test_blk_write(BlockBackend *blk, long pattern, int64_t offset, - int64_t count, bool expect_failed) -{ - void *pattern_buf = NULL; - QEMUIOVector qiov; - int async_ret = NOT_DONE; - - pattern_buf = g_malloc(count); - if (pattern) { - memset(pattern_buf, pattern, count); - } else { - memset(pattern_buf, 0x00, count); - } - - qemu_iovec_init(&qiov, 1); - qemu_iovec_add(&qiov, pattern_buf, count); - - blk_aio_pwritev(blk, offset, &qiov, 0, blk_rw_done, &async_ret); - while (async_ret == NOT_DONE) { - main_loop_wait(false); - } - - if (expect_failed) { - g_assert(async_ret != 0); - } else { - g_assert(async_ret == 0); - } - - g_free(pattern_buf); - qemu_iovec_destroy(&qiov); -} - -/* - * Create a uniquely-named empty temporary file. - */ -static void make_temp(char *template) -{ - int fd; - - fd = mkstemp(template); - g_assert(fd >= 0); - close(fd); -} - -static void prepare_imgs(void) -{ - make_temp(p_local_disk); - make_temp(s_local_disk); - make_temp(s_active_disk); - make_temp(s_hidden_disk); - - /* Primary */ - bdrv_img_create(p_local_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE, - BDRV_O_RDWR, true, &error_abort); - - /* Secondary */ - bdrv_img_create(s_local_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE, - BDRV_O_RDWR, true, &error_abort); - bdrv_img_create(s_active_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE, - BDRV_O_RDWR, true, &error_abort); - bdrv_img_create(s_hidden_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE, - BDRV_O_RDWR, true, &error_abort); -} - -static void cleanup_imgs(void) -{ - /* Primary */ - unlink(p_local_disk); - - /* Secondary */ - unlink(s_local_disk); - unlink(s_active_disk); - unlink(s_hidden_disk); -} - -static BlockBackend *start_primary(void) -{ - BlockBackend *blk; - QemuOpts *opts; - QDict *qdict; - char *cmdline; - - cmdline = g_strdup_printf("driver=replication,mode=primary,node-name=xxx," - "file.driver=qcow2,file.file.filename=%s," - "file.file.locking=off" - , p_local_disk); - opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false); - g_free(cmdline); - - qdict = qemu_opts_to_qdict(opts, NULL); - qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); - qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); - - blk = blk_new_open(NULL, NULL, qdict, BDRV_O_RDWR, &error_abort); - g_assert(blk); - - monitor_add_blk(blk, P_ID, &error_abort); - - qemu_opts_del(opts); - - return blk; -} - -static void teardown_primary(void) -{ - BlockBackend *blk; - AioContext *ctx; - - /* remove P_ID */ - blk = blk_by_name(P_ID); - assert(blk); - - ctx = blk_get_aio_context(blk); - aio_context_acquire(ctx); - monitor_remove_blk(blk); - blk_unref(blk); - aio_context_release(ctx); -} - -static void test_primary_read(void) -{ - BlockBackend *blk; - - blk = start_primary(); - - /* read from 0 to IMG_SIZE */ - test_blk_read(blk, 0, 0, IMG_SIZE, 0, IMG_SIZE, true); - - teardown_primary(); -} - -static void test_primary_write(void) -{ - BlockBackend *blk; - - blk = start_primary(); - - /* write from 0 to IMG_SIZE */ - test_blk_write(blk, 0, 0, IMG_SIZE, true); - - teardown_primary(); -} - -static void test_primary_start(void) -{ - BlockBackend *blk = NULL; - - blk = start_primary(); - - replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); - - /* read from 0 to IMG_SIZE */ - test_blk_read(blk, 0, 0, IMG_SIZE, 0, IMG_SIZE, true); - - /* write 0x22 from 0 to IMG_SIZE */ - test_blk_write(blk, 0x22, 0, IMG_SIZE, false); - - teardown_primary(); -} - -static void test_primary_stop(void) -{ - bool failover = true; - - start_primary(); - - replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); - - replication_stop_all(failover, &error_abort); - - teardown_primary(); -} - -static void test_primary_do_checkpoint(void) -{ - start_primary(); - - replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); - - replication_do_checkpoint_all(&error_abort); - - teardown_primary(); -} - -static void test_primary_get_error_all(void) -{ - start_primary(); - - replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); - - replication_get_error_all(&error_abort); - - teardown_primary(); -} - -static BlockBackend *start_secondary(void) -{ - QemuOpts *opts; - QDict *qdict; - BlockBackend *blk; - char *cmdline; - - /* add s_local_disk and forge S_LOCAL_DISK_ID */ - cmdline = g_strdup_printf("file.filename=%s,driver=qcow2," - "file.locking=off", - s_local_disk); - opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false); - g_free(cmdline); - - qdict = qemu_opts_to_qdict(opts, NULL); - qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); - qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); - - blk = blk_new_open(NULL, NULL, qdict, BDRV_O_RDWR, &error_abort); - assert(blk); - monitor_add_blk(blk, S_LOCAL_DISK_ID, &error_abort); - - /* format s_local_disk with pattern "0x11" */ - test_blk_write(blk, 0x11, 0, IMG_SIZE, false); - - qemu_opts_del(opts); - - /* add S_(ACTIVE/HIDDEN)_DISK and forge S_ID */ - cmdline = g_strdup_printf("driver=replication,mode=secondary,top-id=%s," - "file.driver=qcow2,file.file.filename=%s," - "file.file.locking=off," - "file.backing.driver=qcow2," - "file.backing.file.filename=%s," - "file.backing.file.locking=off," - "file.backing.backing=%s" - , S_ID, s_active_disk, s_hidden_disk - , S_LOCAL_DISK_ID); - opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false); - g_free(cmdline); - - qdict = qemu_opts_to_qdict(opts, NULL); - qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); - qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); - - blk = blk_new_open(NULL, NULL, qdict, BDRV_O_RDWR, &error_abort); - assert(blk); - monitor_add_blk(blk, S_ID, &error_abort); - - qemu_opts_del(opts); - - return blk; -} - -static void teardown_secondary(void) -{ - /* only need to destroy two BBs */ - BlockBackend *blk; - AioContext *ctx; - - /* remove S_LOCAL_DISK_ID */ - blk = blk_by_name(S_LOCAL_DISK_ID); - assert(blk); - - ctx = blk_get_aio_context(blk); - aio_context_acquire(ctx); - monitor_remove_blk(blk); - blk_unref(blk); - aio_context_release(ctx); - - /* remove S_ID */ - blk = blk_by_name(S_ID); - assert(blk); - - ctx = blk_get_aio_context(blk); - aio_context_acquire(ctx); - monitor_remove_blk(blk); - blk_unref(blk); - aio_context_release(ctx); -} - -static void test_secondary_read(void) -{ - BlockBackend *blk; - - blk = start_secondary(); - - /* read from 0 to IMG_SIZE */ - test_blk_read(blk, 0, 0, IMG_SIZE, 0, IMG_SIZE, true); - - teardown_secondary(); -} - -static void test_secondary_write(void) -{ - BlockBackend *blk; - - blk = start_secondary(); - - /* write from 0 to IMG_SIZE */ - test_blk_write(blk, 0, 0, IMG_SIZE, true); - - teardown_secondary(); -} - -static void test_secondary_start(void) -{ - BlockBackend *top_blk, *local_blk; - bool failover = true; - - top_blk = start_secondary(); - replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); - - /* read from s_local_disk (0, IMG_SIZE) */ - test_blk_read(top_blk, 0x11, 0, IMG_SIZE, 0, IMG_SIZE, false); - - /* write 0x22 to s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ - local_blk = blk_by_name(S_LOCAL_DISK_ID); - test_blk_write(local_blk, 0x22, IMG_SIZE / 2, IMG_SIZE / 2, false); - - /* replication will backup s_local_disk to s_hidden_disk */ - test_blk_read(top_blk, 0x11, IMG_SIZE / 2, - IMG_SIZE / 2, 0, IMG_SIZE, false); - - /* write 0x33 to s_active_disk (0, IMG_SIZE / 2) */ - test_blk_write(top_blk, 0x33, 0, IMG_SIZE / 2, false); - - /* read from s_active_disk (0, IMG_SIZE/2) */ - test_blk_read(top_blk, 0x33, 0, IMG_SIZE / 2, - 0, IMG_SIZE / 2, false); - - /* unblock top_bs */ - replication_stop_all(failover, &error_abort); - - teardown_secondary(); -} - - -static void test_secondary_stop(void) -{ - BlockBackend *top_blk, *local_blk; - bool failover = true; - - top_blk = start_secondary(); - replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); - - /* write 0x22 to s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ - local_blk = blk_by_name(S_LOCAL_DISK_ID); - test_blk_write(local_blk, 0x22, IMG_SIZE / 2, IMG_SIZE / 2, false); - - /* replication will backup s_local_disk to s_hidden_disk */ - test_blk_read(top_blk, 0x11, IMG_SIZE / 2, - IMG_SIZE / 2, 0, IMG_SIZE, false); - - /* write 0x33 to s_active_disk (0, IMG_SIZE / 2) */ - test_blk_write(top_blk, 0x33, 0, IMG_SIZE / 2, false); - - /* do active commit */ - replication_stop_all(failover, &error_abort); - - /* read from s_local_disk (0, IMG_SIZE / 2) */ - test_blk_read(top_blk, 0x33, 0, IMG_SIZE / 2, - 0, IMG_SIZE / 2, false); - - - /* read from s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ - test_blk_read(top_blk, 0x22, IMG_SIZE / 2, - IMG_SIZE / 2, 0, IMG_SIZE, false); - - teardown_secondary(); -} - -static void test_secondary_continuous_replication(void) -{ - BlockBackend *top_blk, *local_blk; - - top_blk = start_secondary(); - replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); - - /* write 0x22 to s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ - local_blk = blk_by_name(S_LOCAL_DISK_ID); - test_blk_write(local_blk, 0x22, IMG_SIZE / 2, IMG_SIZE / 2, false); - - /* replication will backup s_local_disk to s_hidden_disk */ - test_blk_read(top_blk, 0x11, IMG_SIZE / 2, - IMG_SIZE / 2, 0, IMG_SIZE, false); - - /* write 0x33 to s_active_disk (0, IMG_SIZE / 2) */ - test_blk_write(top_blk, 0x33, 0, IMG_SIZE / 2, false); - - /* do failover (active commit) */ - replication_stop_all(true, &error_abort); - - /* it should ignore all requests from now on */ - - /* start after failover */ - replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); - - /* checkpoint */ - replication_do_checkpoint_all(&error_abort); - - /* stop */ - replication_stop_all(true, &error_abort); - - /* read from s_local_disk (0, IMG_SIZE / 2) */ - test_blk_read(top_blk, 0x33, 0, IMG_SIZE / 2, - 0, IMG_SIZE / 2, false); - - - /* read from s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ - test_blk_read(top_blk, 0x22, IMG_SIZE / 2, - IMG_SIZE / 2, 0, IMG_SIZE, false); - - teardown_secondary(); -} - -static void test_secondary_do_checkpoint(void) -{ - BlockBackend *top_blk, *local_blk; - bool failover = true; - - top_blk = start_secondary(); - replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); - - /* write 0x22 to s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ - local_blk = blk_by_name(S_LOCAL_DISK_ID); - test_blk_write(local_blk, 0x22, IMG_SIZE / 2, - IMG_SIZE / 2, false); - - /* replication will backup s_local_disk to s_hidden_disk */ - test_blk_read(top_blk, 0x11, IMG_SIZE / 2, - IMG_SIZE / 2, 0, IMG_SIZE, false); - - replication_do_checkpoint_all(&error_abort); - - /* after checkpoint, read pattern 0x22 from s_local_disk */ - test_blk_read(top_blk, 0x22, IMG_SIZE / 2, - IMG_SIZE / 2, 0, IMG_SIZE, false); - - /* unblock top_bs */ - replication_stop_all(failover, &error_abort); - - teardown_secondary(); -} - -static void test_secondary_get_error_all(void) -{ - bool failover = true; - - start_secondary(); - replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); - - replication_get_error_all(&error_abort); - - /* unblock top_bs */ - replication_stop_all(failover, &error_abort); - - teardown_secondary(); -} - -static void sigabrt_handler(int signo) -{ - cleanup_imgs(); -} - -static void setup_sigabrt_handler(void) -{ - struct sigaction sigact; - - sigact = (struct sigaction) { - .sa_handler = sigabrt_handler, - .sa_flags = SA_RESETHAND, - }; - sigemptyset(&sigact.sa_mask); - sigaction(SIGABRT, &sigact, NULL); -} - -int main(int argc, char **argv) -{ - int ret; - qemu_init_main_loop(&error_fatal); - bdrv_init(); - - g_test_init(&argc, &argv, NULL); - setup_sigabrt_handler(); - - prepare_imgs(); - - /* Primary */ - g_test_add_func("/replication/primary/read", test_primary_read); - g_test_add_func("/replication/primary/write", test_primary_write); - g_test_add_func("/replication/primary/start", test_primary_start); - g_test_add_func("/replication/primary/stop", test_primary_stop); - g_test_add_func("/replication/primary/do_checkpoint", - test_primary_do_checkpoint); - g_test_add_func("/replication/primary/get_error_all", - test_primary_get_error_all); - - /* Secondary */ - g_test_add_func("/replication/secondary/read", test_secondary_read); - g_test_add_func("/replication/secondary/write", test_secondary_write); - g_test_add_func("/replication/secondary/start", test_secondary_start); - g_test_add_func("/replication/secondary/stop", test_secondary_stop); - g_test_add_func("/replication/secondary/continuous_replication", - test_secondary_continuous_replication); - g_test_add_func("/replication/secondary/do_checkpoint", - test_secondary_do_checkpoint); - g_test_add_func("/replication/secondary/get_error_all", - test_secondary_get_error_all); - - ret = g_test_run(); - - cleanup_imgs(); - - return ret; -} +/* + * Block replication tests + * + * Copyright (c) 2016 FUJITSU LIMITED + * Author: Changlong Xie + * + * 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 "qapi/error.h" +#include "qapi/qmp/qdict.h" +#include "qemu/option.h" +#include "qemu/main-loop.h" +#include "replication.h" +#include "block/block_int.h" +#include "block/qdict.h" +#include "sysemu/block-backend.h" + +#define IMG_SIZE (64 * 1024 * 1024) + +/* primary */ +#define P_ID "primary-id" +static char p_local_disk[] = "/tmp/p_local_disk.XXXXXX"; + +/* secondary */ +#define S_ID "secondary-id" +#define S_LOCAL_DISK_ID "secondary-local-disk-id" +static char s_local_disk[] = "/tmp/s_local_disk.XXXXXX"; +static char s_active_disk[] = "/tmp/s_active_disk.XXXXXX"; +static char s_hidden_disk[] = "/tmp/s_hidden_disk.XXXXXX"; + +/* FIXME: steal from blockdev.c */ +QemuOptsList qemu_drive_opts = { + .name = "drive", + .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), + .desc = { + { /* end of list */ } + }, +}; + +#define NOT_DONE 0x7fffffff + +static void blk_rw_done(void *opaque, int ret) +{ + *(int *)opaque = ret; +} + +static void test_blk_read(BlockBackend *blk, long pattern, + int64_t pattern_offset, int64_t pattern_count, + int64_t offset, int64_t count, + bool expect_failed) +{ + void *pattern_buf = NULL; + QEMUIOVector qiov; + void *cmp_buf = NULL; + int async_ret = NOT_DONE; + + if (pattern) { + cmp_buf = g_malloc(pattern_count); + memset(cmp_buf, pattern, pattern_count); + } + + pattern_buf = g_malloc(count); + if (pattern) { + memset(pattern_buf, pattern, count); + } else { + memset(pattern_buf, 0x00, count); + } + + qemu_iovec_init(&qiov, 1); + qemu_iovec_add(&qiov, pattern_buf, count); + + blk_aio_preadv(blk, offset, &qiov, 0, blk_rw_done, &async_ret); + while (async_ret == NOT_DONE) { + main_loop_wait(false); + } + + if (expect_failed) { + g_assert(async_ret != 0); + } else { + g_assert(async_ret == 0); + if (pattern) { + g_assert(memcmp(pattern_buf + pattern_offset, + cmp_buf, pattern_count) <= 0); + } + } + + g_free(pattern_buf); + g_free(cmp_buf); + qemu_iovec_destroy(&qiov); +} + +static void test_blk_write(BlockBackend *blk, long pattern, int64_t offset, + int64_t count, bool expect_failed) +{ + void *pattern_buf = NULL; + QEMUIOVector qiov; + int async_ret = NOT_DONE; + + pattern_buf = g_malloc(count); + if (pattern) { + memset(pattern_buf, pattern, count); + } else { + memset(pattern_buf, 0x00, count); + } + + qemu_iovec_init(&qiov, 1); + qemu_iovec_add(&qiov, pattern_buf, count); + + blk_aio_pwritev(blk, offset, &qiov, 0, blk_rw_done, &async_ret); + while (async_ret == NOT_DONE) { + main_loop_wait(false); + } + + if (expect_failed) { + g_assert(async_ret != 0); + } else { + g_assert(async_ret == 0); + } + + g_free(pattern_buf); + qemu_iovec_destroy(&qiov); +} + +/* + * Create a uniquely-named empty temporary file. + */ +static void make_temp(char *template) +{ + int fd; + + fd = mkstemp(template); + g_assert(fd >= 0); + close(fd); +} + +static void prepare_imgs(void) +{ + make_temp(p_local_disk); + make_temp(s_local_disk); + make_temp(s_active_disk); + make_temp(s_hidden_disk); + + /* Primary */ + bdrv_img_create(p_local_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE, + BDRV_O_RDWR, true, &error_abort); + + /* Secondary */ + bdrv_img_create(s_local_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE, + BDRV_O_RDWR, true, &error_abort); + bdrv_img_create(s_active_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE, + BDRV_O_RDWR, true, &error_abort); + bdrv_img_create(s_hidden_disk, "qcow2", NULL, NULL, NULL, IMG_SIZE, + BDRV_O_RDWR, true, &error_abort); +} + +static void cleanup_imgs(void) +{ + /* Primary */ + unlink(p_local_disk); + + /* Secondary */ + unlink(s_local_disk); + unlink(s_active_disk); + unlink(s_hidden_disk); +} + +static BlockBackend *start_primary(void) +{ + BlockBackend *blk; + QemuOpts *opts; + QDict *qdict; + char *cmdline; + + cmdline = g_strdup_printf("driver=replication,mode=primary,node-name=xxx," + "file.driver=qcow2,file.file.filename=%s," + "file.file.locking=off" + , p_local_disk); + opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false); + g_free(cmdline); + + qdict = qemu_opts_to_qdict(opts, NULL); + qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); + qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); + + blk = blk_new_open(NULL, NULL, qdict, BDRV_O_RDWR, &error_abort); + g_assert(blk); + + monitor_add_blk(blk, P_ID, &error_abort); + + qemu_opts_del(opts); + + return blk; +} + +static void teardown_primary(void) +{ + BlockBackend *blk; + AioContext *ctx; + + /* remove P_ID */ + blk = blk_by_name(P_ID); + assert(blk); + + ctx = blk_get_aio_context(blk); + aio_context_acquire(ctx); + monitor_remove_blk(blk); + blk_unref(blk); + aio_context_release(ctx); +} + +static void test_primary_read(void) +{ + BlockBackend *blk; + + blk = start_primary(); + + /* read from 0 to IMG_SIZE */ + test_blk_read(blk, 0, 0, IMG_SIZE, 0, IMG_SIZE, true); + + teardown_primary(); +} + +static void test_primary_write(void) +{ + BlockBackend *blk; + + blk = start_primary(); + + /* write from 0 to IMG_SIZE */ + test_blk_write(blk, 0, 0, IMG_SIZE, true); + + teardown_primary(); +} + +static void test_primary_start(void) +{ + BlockBackend *blk = NULL; + + blk = start_primary(); + + replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); + + /* read from 0 to IMG_SIZE */ + test_blk_read(blk, 0, 0, IMG_SIZE, 0, IMG_SIZE, true); + + /* write 0x22 from 0 to IMG_SIZE */ + test_blk_write(blk, 0x22, 0, IMG_SIZE, false); + + teardown_primary(); +} + +static void test_primary_stop(void) +{ + bool failover = true; + + start_primary(); + + replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); + + replication_stop_all(failover, &error_abort); + + teardown_primary(); +} + +static void test_primary_do_checkpoint(void) +{ + start_primary(); + + replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); + + replication_do_checkpoint_all(&error_abort); + + teardown_primary(); +} + +static void test_primary_get_error_all(void) +{ + start_primary(); + + replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); + + replication_get_error_all(&error_abort); + + teardown_primary(); +} + +static BlockBackend *start_secondary(void) +{ + QemuOpts *opts; + QDict *qdict; + BlockBackend *blk; + char *cmdline; + + /* add s_local_disk and forge S_LOCAL_DISK_ID */ + cmdline = g_strdup_printf("file.filename=%s,driver=qcow2," + "file.locking=off", + s_local_disk); + opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false); + g_free(cmdline); + + qdict = qemu_opts_to_qdict(opts, NULL); + qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); + qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); + + blk = blk_new_open(NULL, NULL, qdict, BDRV_O_RDWR, &error_abort); + assert(blk); + monitor_add_blk(blk, S_LOCAL_DISK_ID, &error_abort); + + /* format s_local_disk with pattern "0x11" */ + test_blk_write(blk, 0x11, 0, IMG_SIZE, false); + + qemu_opts_del(opts); + + /* add S_(ACTIVE/HIDDEN)_DISK and forge S_ID */ + cmdline = g_strdup_printf("driver=replication,mode=secondary,top-id=%s," + "file.driver=qcow2,file.file.filename=%s," + "file.file.locking=off," + "file.backing.driver=qcow2," + "file.backing.file.filename=%s," + "file.backing.file.locking=off," + "file.backing.backing=%s" + , S_ID, s_active_disk, s_hidden_disk + , S_LOCAL_DISK_ID); + opts = qemu_opts_parse_noisily(&qemu_drive_opts, cmdline, false); + g_free(cmdline); + + qdict = qemu_opts_to_qdict(opts, NULL); + qdict_set_default_str(qdict, BDRV_OPT_CACHE_DIRECT, "off"); + qdict_set_default_str(qdict, BDRV_OPT_CACHE_NO_FLUSH, "off"); + + blk = blk_new_open(NULL, NULL, qdict, BDRV_O_RDWR, &error_abort); + assert(blk); + monitor_add_blk(blk, S_ID, &error_abort); + + qemu_opts_del(opts); + + return blk; +} + +static void teardown_secondary(void) +{ + /* only need to destroy two BBs */ + BlockBackend *blk; + AioContext *ctx; + + /* remove S_LOCAL_DISK_ID */ + blk = blk_by_name(S_LOCAL_DISK_ID); + assert(blk); + + ctx = blk_get_aio_context(blk); + aio_context_acquire(ctx); + monitor_remove_blk(blk); + blk_unref(blk); + aio_context_release(ctx); + + /* remove S_ID */ + blk = blk_by_name(S_ID); + assert(blk); + + ctx = blk_get_aio_context(blk); + aio_context_acquire(ctx); + monitor_remove_blk(blk); + blk_unref(blk); + aio_context_release(ctx); +} + +static void test_secondary_read(void) +{ + BlockBackend *blk; + + blk = start_secondary(); + + /* read from 0 to IMG_SIZE */ + test_blk_read(blk, 0, 0, IMG_SIZE, 0, IMG_SIZE, true); + + teardown_secondary(); +} + +static void test_secondary_write(void) +{ + BlockBackend *blk; + + blk = start_secondary(); + + /* write from 0 to IMG_SIZE */ + test_blk_write(blk, 0, 0, IMG_SIZE, true); + + teardown_secondary(); +} + +static void test_secondary_start(void) +{ + BlockBackend *top_blk, *local_blk; + bool failover = true; + + top_blk = start_secondary(); + replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); + + /* read from s_local_disk (0, IMG_SIZE) */ + test_blk_read(top_blk, 0x11, 0, IMG_SIZE, 0, IMG_SIZE, false); + + /* write 0x22 to s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ + local_blk = blk_by_name(S_LOCAL_DISK_ID); + test_blk_write(local_blk, 0x22, IMG_SIZE / 2, IMG_SIZE / 2, false); + + /* replication will backup s_local_disk to s_hidden_disk */ + test_blk_read(top_blk, 0x11, IMG_SIZE / 2, + IMG_SIZE / 2, 0, IMG_SIZE, false); + + /* write 0x33 to s_active_disk (0, IMG_SIZE / 2) */ + test_blk_write(top_blk, 0x33, 0, IMG_SIZE / 2, false); + + /* read from s_active_disk (0, IMG_SIZE/2) */ + test_blk_read(top_blk, 0x33, 0, IMG_SIZE / 2, + 0, IMG_SIZE / 2, false); + + /* unblock top_bs */ + replication_stop_all(failover, &error_abort); + + teardown_secondary(); +} + + +static void test_secondary_stop(void) +{ + BlockBackend *top_blk, *local_blk; + bool failover = true; + + top_blk = start_secondary(); + replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); + + /* write 0x22 to s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ + local_blk = blk_by_name(S_LOCAL_DISK_ID); + test_blk_write(local_blk, 0x22, IMG_SIZE / 2, IMG_SIZE / 2, false); + + /* replication will backup s_local_disk to s_hidden_disk */ + test_blk_read(top_blk, 0x11, IMG_SIZE / 2, + IMG_SIZE / 2, 0, IMG_SIZE, false); + + /* write 0x33 to s_active_disk (0, IMG_SIZE / 2) */ + test_blk_write(top_blk, 0x33, 0, IMG_SIZE / 2, false); + + /* do active commit */ + replication_stop_all(failover, &error_abort); + + /* read from s_local_disk (0, IMG_SIZE / 2) */ + test_blk_read(top_blk, 0x33, 0, IMG_SIZE / 2, + 0, IMG_SIZE / 2, false); + + + /* read from s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ + test_blk_read(top_blk, 0x22, IMG_SIZE / 2, + IMG_SIZE / 2, 0, IMG_SIZE, false); + + teardown_secondary(); +} + +static void test_secondary_continuous_replication(void) +{ + BlockBackend *top_blk, *local_blk; + + top_blk = start_secondary(); + replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); + + /* write 0x22 to s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ + local_blk = blk_by_name(S_LOCAL_DISK_ID); + test_blk_write(local_blk, 0x22, IMG_SIZE / 2, IMG_SIZE / 2, false); + + /* replication will backup s_local_disk to s_hidden_disk */ + test_blk_read(top_blk, 0x11, IMG_SIZE / 2, + IMG_SIZE / 2, 0, IMG_SIZE, false); + + /* write 0x33 to s_active_disk (0, IMG_SIZE / 2) */ + test_blk_write(top_blk, 0x33, 0, IMG_SIZE / 2, false); + + /* do failover (active commit) */ + replication_stop_all(true, &error_abort); + + /* it should ignore all requests from now on */ + + /* start after failover */ + replication_start_all(REPLICATION_MODE_PRIMARY, &error_abort); + + /* checkpoint */ + replication_do_checkpoint_all(&error_abort); + + /* stop */ + replication_stop_all(true, &error_abort); + + /* read from s_local_disk (0, IMG_SIZE / 2) */ + test_blk_read(top_blk, 0x33, 0, IMG_SIZE / 2, + 0, IMG_SIZE / 2, false); + + + /* read from s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ + test_blk_read(top_blk, 0x22, IMG_SIZE / 2, + IMG_SIZE / 2, 0, IMG_SIZE, false); + + teardown_secondary(); +} + +static void test_secondary_do_checkpoint(void) +{ + BlockBackend *top_blk, *local_blk; + bool failover = true; + + top_blk = start_secondary(); + replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); + + /* write 0x22 to s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ + local_blk = blk_by_name(S_LOCAL_DISK_ID); + test_blk_write(local_blk, 0x22, IMG_SIZE / 2, + IMG_SIZE / 2, false); + + /* replication will backup s_local_disk to s_hidden_disk */ + test_blk_read(top_blk, 0x11, IMG_SIZE / 2, + IMG_SIZE / 2, 0, IMG_SIZE, false); + + replication_do_checkpoint_all(&error_abort); + + /* after checkpoint, read pattern 0x22 from s_local_disk */ + test_blk_read(top_blk, 0x22, IMG_SIZE / 2, + IMG_SIZE / 2, 0, IMG_SIZE, false); + + /* unblock top_bs */ + replication_stop_all(failover, &error_abort); + + teardown_secondary(); +} + +static void test_secondary_get_error_all(void) +{ + bool failover = true; + + start_secondary(); + replication_start_all(REPLICATION_MODE_SECONDARY, &error_abort); + + replication_get_error_all(&error_abort); + + /* unblock top_bs */ + replication_stop_all(failover, &error_abort); + + teardown_secondary(); +} + +static void sigabrt_handler(int signo) +{ + cleanup_imgs(); +} + +static void setup_sigabrt_handler(void) +{ +#ifdef _WIN32 + signal(SIGABRT, sigabrt_handler); +#else + struct sigaction sigact; + + sigact = (struct sigaction) { + .sa_handler = sigabrt_handler, + .sa_flags = SA_RESETHAND, + }; + sigemptyset(&sigact.sa_mask); + sigaction(SIGABRT, &sigact, NULL); +#endif +} + +int main(int argc, char **argv) +{ + int ret; + qemu_init_main_loop(&error_fatal); + bdrv_init(); + + g_test_init(&argc, &argv, NULL); + setup_sigabrt_handler(); + + prepare_imgs(); + + /* Primary */ + g_test_add_func("/replication/primary/read", test_primary_read); + g_test_add_func("/replication/primary/write", test_primary_write); + g_test_add_func("/replication/primary/start", test_primary_start); + g_test_add_func("/replication/primary/stop", test_primary_stop); + g_test_add_func("/replication/primary/do_checkpoint", + test_primary_do_checkpoint); + g_test_add_func("/replication/primary/get_error_all", + test_primary_get_error_all); + + /* Secondary */ + g_test_add_func("/replication/secondary/read", test_secondary_read); + g_test_add_func("/replication/secondary/write", test_secondary_write); + g_test_add_func("/replication/secondary/start", test_secondary_start); + g_test_add_func("/replication/secondary/stop", test_secondary_stop); + g_test_add_func("/replication/secondary/continuous_replication", + test_secondary_continuous_replication); + g_test_add_func("/replication/secondary/do_checkpoint", + test_secondary_do_checkpoint); + g_test_add_func("/replication/secondary/get_error_all", + test_secondary_get_error_all); + + ret = g_test_run(); + + cleanup_imgs(); + + return ret; +} From patchwork Thu Sep 3 07:43:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?572X5YuH5YiaKFlvbmdnYW5nIEx1byk=?= X-Patchwork-Id: 274732 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6A95C433E2 for ; Thu, 3 Sep 2020 07:44:44 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8F0FB2071B for ; Thu, 3 Sep 2020 07:44:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wtw9iMxi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F0FB2071B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDjvH-0001iq-Mm for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 03:44:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDjuN-0008NA-He for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:43:47 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:39091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDjuK-0003s7-QL for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:43:47 -0400 Received: by mail-pj1-x1043.google.com with SMTP id s2so1058091pjr.4 for ; Thu, 03 Sep 2020 00:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=voK9C8LiSWL+Sm9aw369V+YjsDRfz05KST8rSNgg5Yw=; b=Wtw9iMxic1Ytac8zBMJ7f/CHaZshDu3ZqMq47D6EUzzhUYVfqHl7rGJ/X4ElpjHRWq ixHVi/MSzOhxC9uOLEEHBHDzskxkktNiwE8mdF0C4sGsyF/67hzRVC5r5FV3pOJHWccV C4DarvGRDWF2vpp74iqPpDx8Utw9Sqe2lA5bfCAW4mfhVA5HJwiTWE9wHGw2lc5HVOUV CMYz6RWPpTR5b1uJAn+X0PuK4NwwSJ5zXXJaTERlX2yrpz+SzS3O6UG8uzTnieGQd1SN J/N3DvoeltfQn9ugT9I/7vpfK4fql23xBiOSe5nbFhbR/usxsaVcsZbMKiCkThxKKtPc Q1ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=voK9C8LiSWL+Sm9aw369V+YjsDRfz05KST8rSNgg5Yw=; b=S7uUdibuMR2tweyXGg54V1nFWAf8FImkvJwrE1BVhtPfTZXKeiFNeu5ScAMtBAWhHX FiNYaY/xF14kM636ukUgPjVEHavt0Nc6E7bSWIEPhgyv4MRNwuTnrS9ACxCKzyP5RpxQ vZPlSFeVYA/rG+yHTOR7W7sb/GkO+ZwJWUy6+EzkIwrBut+ZMQYiyvmyWwjXgmsMyt4w qqVDxgfEYDB5t4R+FkoAFTURUjrCYTqQHtUkHwurv1dSm8LlZ7BgOp1gOi5V99iL8npG Q4Y/MDI7aSbF/DTBv0vbzCQfHXYcc3Kl6q55Z+ukpn1sDzTZ0ljYj1BZoB5Wc59k8ZHx BCuQ== X-Gm-Message-State: AOAM5335FPg6De3B2F9O2lnLEg1PK+Ia0I8Ol3STjXuzOnJtdyzY2MDM PG9cuOHYSDToESOxNrUaksfuV/H2A7ost4ql X-Google-Smtp-Source: ABdhPJz1l9nhz2Wbj2PvRbYYT9YZDSyA6eizKIlyrEz9+0WqEFy4/VAazPMFK7GX4zTgVJCBxhQFaw== X-Received: by 2002:a17:90a:fa8b:: with SMTP id cu11mr743957pjb.10.1599119022978; Thu, 03 Sep 2020 00:43:42 -0700 (PDT) Received: from localhost.localdomain ([222.95.248.6]) by smtp.googlemail.com with ESMTPSA id o6sm1512472pju.25.2020.09.03.00.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 00:43:42 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v3 05/12] configure: Fix include and linkage issue on msys2 Date: Thu, 3 Sep 2020 15:43:06 +0800 Message-Id: <20200903074313.1498-6-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200903074313.1498-1-luoyonggang@gmail.com> References: <20200903074313.1498-1-luoyonggang@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=luoyonggang@gmail.com; helo=mail-pj1-x1043.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Yonggang Luo Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On msys2, the -I/e/path/to/qemu -L/e/path/to/qemu are not recognized by the compiler Cause $PWD are result posix style path such as /e/path/to/qemu that can not be recognized by mingw gcc, and `pwd -W` are result Windows style path such as E:/path/to/qemu that can be recognized by the mingw gcc. So we replace all $PWD with $build_path that can building qemu under msys2/mingw environment. Signed-off-by: Yonggang Luo --- configure | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/configure b/configure index 30f8c4db29..5f2bcc4b57 100755 --- a/configure +++ b/configure @@ -13,8 +13,13 @@ export CCACHE_RECACHE=yes # make source path absolute source_path=$(cd "$(dirname -- "$0")"; pwd) +build_path=$PWD +if [ "$MSYSTEM" = "MINGW64" -o "$MSYSTEM" = "MINGW32" ]; then +source_path=$(cd "$(dirname -- "$0")"; pwd -W) +build_path=`pwd -W` +fi -if test "$PWD" = "$source_path" +if test "$build_path" = "$source_path" then echo "Using './build' as the directory for build output" @@ -346,7 +351,12 @@ ld_has() { $ld --help 2>/dev/null | grep ".$1" >/dev/null 2>&1 } -if printf %s\\n "$source_path" "$PWD" | grep -q "[[:space:]:]"; +check_valid_build_path="[[:space:]:]" +if [ "$MSYSTEM" = "MINGW64" -o "$MSYSTEM" = "MINGW32" ]; then +check_valid_build_path="[[:space:]]" +fi + +if printf %s\\n "$source_path" "$build_path" | grep -q "$check_valid_build_path"; then error_exit "main directory cannot contain spaces nor colons" fi @@ -943,7 +953,7 @@ Linux) linux="yes" linux_user="yes" kvm="yes" - QEMU_INCLUDES="-isystem ${source_path}/linux-headers -I$PWD/linux-headers $QEMU_INCLUDES" + QEMU_INCLUDES="-isystem ${source_path}/linux-headers -I${build_path}/linux-headers $QEMU_INCLUDES" libudev="yes" ;; esac @@ -4259,7 +4269,7 @@ EOF fdt=git mkdir -p dtc fdt_cflags="-I${source_path}/dtc/libfdt" - fdt_ldflags="-L$PWD/dtc/libfdt" + fdt_ldflags="-L${build_path}/dtc/libfdt" fdt_libs="$fdt_libs" elif test "$fdt" = "yes" ; then # Not a git build & no libfdt found, prompt for system install @@ -5244,7 +5254,7 @@ case "$capstone" in else LIBCAPSTONE=libcapstone.a fi - capstone_libs="-L$PWD/capstone -lcapstone" + capstone_libs="-L${build_path}/capstone -lcapstone" capstone_cflags="-I${source_path}/capstone/include" ;; @@ -6244,8 +6254,8 @@ case "$slirp" in git_submodules="${git_submodules} slirp" fi mkdir -p slirp - slirp_cflags="-I${source_path}/slirp/src -I$PWD/slirp/src" - slirp_libs="-L$PWD/slirp -lslirp" + slirp_cflags="-I${source_path}/slirp/src -I${build_path}/slirp/src" + slirp_libs="-L${build_path}/slirp -lslirp" if test "$mingw32" = "yes" ; then slirp_libs="$slirp_libs -lws2_32 -liphlpapi" fi @@ -8190,7 +8200,7 @@ fi mv $cross config-meson.cross rm -rf meson-private meson-info meson-logs -NINJA=${ninja:-$PWD/ninjatool} $meson setup \ +NINJA=${ninja:-${build_path}/ninjatool} $meson setup \ --prefix "${pre_prefix}$prefix" \ --libdir "${pre_prefix}$libdir" \ --libexecdir "${pre_prefix}$libexecdir" \ @@ -8212,7 +8222,7 @@ NINJA=${ninja:-$PWD/ninjatool} $meson setup \ -Dvnc=$vnc -Dvnc_sasl=$vnc_sasl -Dvnc_jpeg=$vnc_jpeg -Dvnc_png=$vnc_png \ -Dgettext=$gettext -Dxkbcommon=$xkbcommon -Du2f=$u2f\ $cross_arg \ - "$PWD" "$source_path" + "$build_path" "$source_path" if test "$?" -ne 0 ; then error_exit "meson setup failed" From patchwork Thu Sep 3 07:43:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?572X5YuH5YiaKFlvbmdnYW5nIEx1byk=?= X-Patchwork-Id: 274731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 027A6C433E7 for ; Thu, 3 Sep 2020 07:46:04 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 7775F206C0 for ; Thu, 3 Sep 2020 07:46:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MgGhlS/p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7775F206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDjwY-0004M9-IZ for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 03:46:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDjuS-00006I-Kp for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:43:52 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:32781) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDjuO-0003sL-CU for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:43:52 -0400 Received: by mail-pg1-x532.google.com with SMTP id e33so1464308pgm.0 for ; Thu, 03 Sep 2020 00:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H8XrF8Pb9GWB51Qq/Erw8qteOrJrg0KP5nGwFRkDrXA=; b=MgGhlS/pEz0BkLa5HNQZumnxoFHs2L91ynvwZ/aWelU62FuTrzy9DpAGI+FuttUe2B 8G0PFkzsqF/tUNefYKi5zHm0S5nQopxwtEoLoQLXfFZSGa0dgHCnOKxXtcgWf1dAOH7e SPc9kEml2JZMy84d/g3IRiEiLtBqrKgV9vZibihswQleFOEnP50c3KsGtDpAYgpDvQVa e0e50yPxCEAysbb3L8lliIhXEIBsi5RqnKAFPDjGKIy8oZUgcK5rt8+7FEXZWl6oJbbh 3d10rlO5UCOcdAxDvvwIZr6RqRCLrx6iTt5yPfy0nE01Sr6NLNP1T3vuLZFgb2A9VKKW bRTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H8XrF8Pb9GWB51Qq/Erw8qteOrJrg0KP5nGwFRkDrXA=; b=VsiFdsVh+0SRX4Jaa7nvdQyD2Ei2Hs3haesOcR9NIYRl3s+dlNe4o83rCMtlEx4gLi h6OR2jmYge6LUkGD1XcUAWGrvemWE4hL4ao0ZUphHNp+CAW0IDB7h1qqDAccGivW2m5s iMlIKB/ctcM/YJLG80mcpWCzKlJkU6+wkJPAju7QXv56sASyWD5L4hDW8ihNOMViw4Mf kgzIjSjeY3yWnTdSyR2xgMxTUgIwCH0JZcU7430N5aSMNBsEiL1qMAiEySs/1txxWafM HggTPJrd9B1JBLnbxZVE0MY5p7VfESUCYz35HZr/HrBkFNPde6OrTEF3+JGeUFOczaQH BU0g== X-Gm-Message-State: AOAM533csRUHbkfFomjBTGjs8CBNtTunfGhjO8N1yzbm5z1LVHAlXuAg nLhQpNviNJfxIQW/qCengz7SszOxEJnOmQEo X-Google-Smtp-Source: ABdhPJxsbsX/06Oq+q7KLJH29b+x81/h7UNM6zh0A5N/X4tpFbMm18fLDZojvmJBw8J56nxl1TL1cg== X-Received: by 2002:a62:d44e:0:b029:13c:1611:652f with SMTP id u14-20020a62d44e0000b029013c1611652fmr911552pfl.15.1599119025539; Thu, 03 Sep 2020 00:43:45 -0700 (PDT) Received: from localhost.localdomain ([222.95.248.6]) by smtp.googlemail.com with ESMTPSA id o6sm1512472pju.25.2020.09.03.00.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 00:43:44 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v3 06/12] block: Fixes nfs on msys2/mingw Date: Thu, 3 Sep 2020 15:43:07 +0800 Message-Id: <20200903074313.1498-7-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200903074313.1498-1-luoyonggang@gmail.com> References: <20200903074313.1498-1-luoyonggang@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=luoyonggang@gmail.com; helo=mail-pg1-x532.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Yonggang Luo Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Yonggang Luo --- block/nfs.c | 1812 ++++++++++++++++++++++++++------------------------- 1 file changed, 910 insertions(+), 902 deletions(-) diff --git a/block/nfs.c b/block/nfs.c index 61a249a9fc..34b2cd5708 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -1,902 +1,910 @@ -/* - * QEMU Block driver for native access to files on NFS shares - * - * Copyright (c) 2014-2017 Peter Lieven - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "qemu/osdep.h" - -#include -#include "qemu/config-file.h" -#include "qemu/error-report.h" -#include "qapi/error.h" -#include "block/block_int.h" -#include "block/qdict.h" -#include "trace.h" -#include "qemu/iov.h" -#include "qemu/main-loop.h" -#include "qemu/module.h" -#include "qemu/option.h" -#include "qemu/uri.h" -#include "qemu/cutils.h" -#include "sysemu/sysemu.h" -#include "sysemu/replay.h" -#include "qapi/qapi-visit-block-core.h" -#include "qapi/qmp/qdict.h" -#include "qapi/qmp/qstring.h" -#include "qapi/qobject-input-visitor.h" -#include "qapi/qobject-output-visitor.h" -#include - - -#define QEMU_NFS_MAX_READAHEAD_SIZE 1048576 -#define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE) -#define QEMU_NFS_MAX_DEBUG_LEVEL 2 - -typedef struct NFSClient { - struct nfs_context *context; - struct nfsfh *fh; - int events; - bool has_zero_init; - AioContext *aio_context; - QemuMutex mutex; - blkcnt_t st_blocks; - bool cache_used; - NFSServer *server; - char *path; - int64_t uid, gid, tcp_syncnt, readahead, pagecache, debug; -} NFSClient; - -typedef struct NFSRPC { - BlockDriverState *bs; - int ret; - int complete; - QEMUIOVector *iov; - struct stat *st; - Coroutine *co; - NFSClient *client; -} NFSRPC; - -static int nfs_parse_uri(const char *filename, QDict *options, Error **errp) -{ - URI *uri = NULL; - QueryParams *qp = NULL; - int ret = -EINVAL, i; - - uri = uri_parse(filename); - if (!uri) { - error_setg(errp, "Invalid URI specified"); - goto out; - } - if (g_strcmp0(uri->scheme, "nfs") != 0) { - error_setg(errp, "URI scheme must be 'nfs'"); - goto out; - } - - if (!uri->server) { - error_setg(errp, "missing hostname in URI"); - goto out; - } - - if (!uri->path) { - error_setg(errp, "missing file path in URI"); - goto out; - } - - qp = query_params_parse(uri->query); - if (!qp) { - error_setg(errp, "could not parse query parameters"); - goto out; - } - - qdict_put_str(options, "server.host", uri->server); - qdict_put_str(options, "server.type", "inet"); - qdict_put_str(options, "path", uri->path); - - for (i = 0; i < qp->n; i++) { - unsigned long long val; - if (!qp->p[i].value) { - error_setg(errp, "Value for NFS parameter expected: %s", - qp->p[i].name); - goto out; - } - if (parse_uint_full(qp->p[i].value, &val, 0)) { - error_setg(errp, "Illegal value for NFS parameter: %s", - qp->p[i].name); - goto out; - } - if (!strcmp(qp->p[i].name, "uid")) { - qdict_put_str(options, "user", qp->p[i].value); - } else if (!strcmp(qp->p[i].name, "gid")) { - qdict_put_str(options, "group", qp->p[i].value); - } else if (!strcmp(qp->p[i].name, "tcp-syncnt")) { - qdict_put_str(options, "tcp-syn-count", qp->p[i].value); - } else if (!strcmp(qp->p[i].name, "readahead")) { - qdict_put_str(options, "readahead-size", qp->p[i].value); - } else if (!strcmp(qp->p[i].name, "pagecache")) { - qdict_put_str(options, "page-cache-size", qp->p[i].value); - } else if (!strcmp(qp->p[i].name, "debug")) { - qdict_put_str(options, "debug", qp->p[i].value); - } else { - error_setg(errp, "Unknown NFS parameter name: %s", - qp->p[i].name); - goto out; - } - } - ret = 0; -out: - if (qp) { - query_params_free(qp); - } - if (uri) { - uri_free(uri); - } - return ret; -} - -static bool nfs_has_filename_options_conflict(QDict *options, Error **errp) -{ - const QDictEntry *qe; - - for (qe = qdict_first(options); qe; qe = qdict_next(options, qe)) { - if (!strcmp(qe->key, "host") || - !strcmp(qe->key, "path") || - !strcmp(qe->key, "user") || - !strcmp(qe->key, "group") || - !strcmp(qe->key, "tcp-syn-count") || - !strcmp(qe->key, "readahead-size") || - !strcmp(qe->key, "page-cache-size") || - !strcmp(qe->key, "debug") || - strstart(qe->key, "server.", NULL)) - { - error_setg(errp, "Option %s cannot be used with a filename", - qe->key); - return true; - } - } - - return false; -} - -static void nfs_parse_filename(const char *filename, QDict *options, - Error **errp) -{ - if (nfs_has_filename_options_conflict(options, errp)) { - return; - } - - nfs_parse_uri(filename, options, errp); -} - -static void nfs_process_read(void *arg); -static void nfs_process_write(void *arg); - -/* Called with QemuMutex held. */ -static void nfs_set_events(NFSClient *client) -{ - int ev = nfs_which_events(client->context); - if (ev != client->events) { - aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), - false, - (ev & POLLIN) ? nfs_process_read : NULL, - (ev & POLLOUT) ? nfs_process_write : NULL, - NULL, client); - - } - client->events = ev; -} - -static void nfs_process_read(void *arg) -{ - NFSClient *client = arg; - - qemu_mutex_lock(&client->mutex); - nfs_service(client->context, POLLIN); - nfs_set_events(client); - qemu_mutex_unlock(&client->mutex); -} - -static void nfs_process_write(void *arg) -{ - NFSClient *client = arg; - - qemu_mutex_lock(&client->mutex); - nfs_service(client->context, POLLOUT); - nfs_set_events(client); - qemu_mutex_unlock(&client->mutex); -} - -static void nfs_co_init_task(BlockDriverState *bs, NFSRPC *task) -{ - *task = (NFSRPC) { - .co = qemu_coroutine_self(), - .bs = bs, - .client = bs->opaque, - }; -} - -static void nfs_co_generic_bh_cb(void *opaque) -{ - NFSRPC *task = opaque; - - task->complete = 1; - aio_co_wake(task->co); -} - -/* Called (via nfs_service) with QemuMutex held. */ -static void -nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data, - void *private_data) -{ - NFSRPC *task = private_data; - task->ret = ret; - assert(!task->st); - if (task->ret > 0 && task->iov) { - if (task->ret <= task->iov->size) { - qemu_iovec_from_buf(task->iov, 0, data, task->ret); - } else { - task->ret = -EIO; - } - } - if (task->ret < 0) { - error_report("NFS Error: %s", nfs_get_error(nfs)); - } - replay_bh_schedule_oneshot_event(task->client->aio_context, - nfs_co_generic_bh_cb, task); -} - -static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offset, - uint64_t bytes, QEMUIOVector *iov, - int flags) -{ - NFSClient *client = bs->opaque; - NFSRPC task; - - nfs_co_init_task(bs, &task); - task.iov = iov; - - WITH_QEMU_LOCK_GUARD(&client->mutex) { - if (nfs_pread_async(client->context, client->fh, - offset, bytes, nfs_co_generic_cb, &task) != 0) { - return -ENOMEM; - } - - nfs_set_events(client); - } - while (!task.complete) { - qemu_coroutine_yield(); - } - - if (task.ret < 0) { - return task.ret; - } - - /* zero pad short reads */ - if (task.ret < iov->size) { - qemu_iovec_memset(iov, task.ret, 0, iov->size - task.ret); - } - - return 0; -} - -static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, uint64_t offset, - uint64_t bytes, QEMUIOVector *iov, - int flags) -{ - NFSClient *client = bs->opaque; - NFSRPC task; - char *buf = NULL; - bool my_buffer = false; - - nfs_co_init_task(bs, &task); - - if (iov->niov != 1) { - buf = g_try_malloc(bytes); - if (bytes && buf == NULL) { - return -ENOMEM; - } - qemu_iovec_to_buf(iov, 0, buf, bytes); - my_buffer = true; - } else { - buf = iov->iov[0].iov_base; - } - - WITH_QEMU_LOCK_GUARD(&client->mutex) { - if (nfs_pwrite_async(client->context, client->fh, - offset, bytes, buf, - nfs_co_generic_cb, &task) != 0) { - if (my_buffer) { - g_free(buf); - } - return -ENOMEM; - } - - nfs_set_events(client); - } - while (!task.complete) { - qemu_coroutine_yield(); - } - - if (my_buffer) { - g_free(buf); - } - - if (task.ret != bytes) { - return task.ret < 0 ? task.ret : -EIO; - } - - return 0; -} - -static int coroutine_fn nfs_co_flush(BlockDriverState *bs) -{ - NFSClient *client = bs->opaque; - NFSRPC task; - - nfs_co_init_task(bs, &task); - - WITH_QEMU_LOCK_GUARD(&client->mutex) { - if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb, - &task) != 0) { - return -ENOMEM; - } - - nfs_set_events(client); - } - while (!task.complete) { - qemu_coroutine_yield(); - } - - return task.ret; -} - -static void nfs_detach_aio_context(BlockDriverState *bs) -{ - NFSClient *client = bs->opaque; - - aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), - false, NULL, NULL, NULL, NULL); - client->events = 0; -} - -static void nfs_attach_aio_context(BlockDriverState *bs, - AioContext *new_context) -{ - NFSClient *client = bs->opaque; - - client->aio_context = new_context; - nfs_set_events(client); -} - -static void nfs_client_close(NFSClient *client) -{ - if (client->context) { - qemu_mutex_lock(&client->mutex); - aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), - false, NULL, NULL, NULL, NULL); - qemu_mutex_unlock(&client->mutex); - if (client->fh) { - nfs_close(client->context, client->fh); - client->fh = NULL; - } -#ifdef LIBNFS_FEATURE_UMOUNT - nfs_umount(client->context); -#endif - nfs_destroy_context(client->context); - client->context = NULL; - } - g_free(client->path); - qemu_mutex_destroy(&client->mutex); - qapi_free_NFSServer(client->server); - client->server = NULL; -} - -static void nfs_file_close(BlockDriverState *bs) -{ - NFSClient *client = bs->opaque; - nfs_client_close(client); -} - -static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts, - int flags, int open_flags, Error **errp) -{ - int64_t ret = -EINVAL; - struct stat st; - char *file = NULL, *strp = NULL; - - qemu_mutex_init(&client->mutex); - - client->path = g_strdup(opts->path); - - strp = strrchr(client->path, '/'); - if (strp == NULL) { - error_setg(errp, "Invalid URL specified"); - goto fail; - } - file = g_strdup(strp); - *strp = 0; - - /* Steal the NFSServer object from opts; set the original pointer to NULL - * to avoid use after free and double free. */ - client->server = opts->server; - opts->server = NULL; - - client->context = nfs_init_context(); - if (client->context == NULL) { - error_setg(errp, "Failed to init NFS context"); - goto fail; - } - - if (opts->has_user) { - client->uid = opts->user; - nfs_set_uid(client->context, client->uid); - } - - if (opts->has_group) { - client->gid = opts->group; - nfs_set_gid(client->context, client->gid); - } - - if (opts->has_tcp_syn_count) { - client->tcp_syncnt = opts->tcp_syn_count; - nfs_set_tcp_syncnt(client->context, client->tcp_syncnt); - } - -#ifdef LIBNFS_FEATURE_READAHEAD - if (opts->has_readahead_size) { - if (open_flags & BDRV_O_NOCACHE) { - error_setg(errp, "Cannot enable NFS readahead " - "if cache.direct = on"); - goto fail; - } - client->readahead = opts->readahead_size; - if (client->readahead > QEMU_NFS_MAX_READAHEAD_SIZE) { - warn_report("Truncating NFS readahead size to %d", - QEMU_NFS_MAX_READAHEAD_SIZE); - client->readahead = QEMU_NFS_MAX_READAHEAD_SIZE; - } - nfs_set_readahead(client->context, client->readahead); -#ifdef LIBNFS_FEATURE_PAGECACHE - nfs_set_pagecache_ttl(client->context, 0); -#endif - client->cache_used = true; - } -#endif - -#ifdef LIBNFS_FEATURE_PAGECACHE - if (opts->has_page_cache_size) { - if (open_flags & BDRV_O_NOCACHE) { - error_setg(errp, "Cannot enable NFS pagecache " - "if cache.direct = on"); - goto fail; - } - client->pagecache = opts->page_cache_size; - if (client->pagecache > QEMU_NFS_MAX_PAGECACHE_SIZE) { - warn_report("Truncating NFS pagecache size to %d pages", - QEMU_NFS_MAX_PAGECACHE_SIZE); - client->pagecache = QEMU_NFS_MAX_PAGECACHE_SIZE; - } - nfs_set_pagecache(client->context, client->pagecache); - nfs_set_pagecache_ttl(client->context, 0); - client->cache_used = true; - } -#endif - -#ifdef LIBNFS_FEATURE_DEBUG - if (opts->has_debug) { - client->debug = opts->debug; - /* limit the maximum debug level to avoid potential flooding - * of our log files. */ - if (client->debug > QEMU_NFS_MAX_DEBUG_LEVEL) { - warn_report("Limiting NFS debug level to %d", - QEMU_NFS_MAX_DEBUG_LEVEL); - client->debug = QEMU_NFS_MAX_DEBUG_LEVEL; - } - nfs_set_debug(client->context, client->debug); - } -#endif - - ret = nfs_mount(client->context, client->server->host, client->path); - if (ret < 0) { - error_setg(errp, "Failed to mount nfs share: %s", - nfs_get_error(client->context)); - goto fail; - } - - if (flags & O_CREAT) { - ret = nfs_creat(client->context, file, 0600, &client->fh); - if (ret < 0) { - error_setg(errp, "Failed to create file: %s", - nfs_get_error(client->context)); - goto fail; - } - } else { - ret = nfs_open(client->context, file, flags, &client->fh); - if (ret < 0) { - error_setg(errp, "Failed to open file : %s", - nfs_get_error(client->context)); - goto fail; - } - } - - ret = nfs_fstat(client->context, client->fh, &st); - if (ret < 0) { - error_setg(errp, "Failed to fstat file: %s", - nfs_get_error(client->context)); - goto fail; - } - - ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE); - client->st_blocks = st.st_blocks; - client->has_zero_init = S_ISREG(st.st_mode); - *strp = '/'; - goto out; - -fail: - nfs_client_close(client); -out: - g_free(file); - return ret; -} - -static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options, - Error **errp) -{ - BlockdevOptionsNfs *opts = NULL; - Visitor *v; - const QDictEntry *e; - - v = qobject_input_visitor_new_flat_confused(options, errp); - if (!v) { - return NULL; - } - - visit_type_BlockdevOptionsNfs(v, NULL, &opts, errp); - visit_free(v); - if (!opts) { - return NULL; - } - - /* Remove the processed options from the QDict (the visitor processes - * _all_ options in the QDict) */ - while ((e = qdict_first(options))) { - qdict_del(options, e->key); - } - - return opts; -} - -static int64_t nfs_client_open_qdict(NFSClient *client, QDict *options, - int flags, int open_flags, Error **errp) -{ - BlockdevOptionsNfs *opts; - int ret; - - opts = nfs_options_qdict_to_qapi(options, errp); - if (opts == NULL) { - ret = -EINVAL; - goto fail; - } - - ret = nfs_client_open(client, opts, flags, open_flags, errp); -fail: - qapi_free_BlockdevOptionsNfs(opts); - return ret; -} - -static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags, - Error **errp) { - NFSClient *client = bs->opaque; - int64_t ret; - - client->aio_context = bdrv_get_aio_context(bs); - - ret = nfs_client_open_qdict(client, options, - (flags & BDRV_O_RDWR) ? O_RDWR : O_RDONLY, - bs->open_flags, errp); - if (ret < 0) { - return ret; - } - - bs->total_sectors = ret; - if (client->has_zero_init) { - bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE; - } - return 0; -} - -static QemuOptsList nfs_create_opts = { - .name = "nfs-create-opts", - .head = QTAILQ_HEAD_INITIALIZER(nfs_create_opts.head), - .desc = { - { - .name = BLOCK_OPT_SIZE, - .type = QEMU_OPT_SIZE, - .help = "Virtual disk size" - }, - { /* end of list */ } - } -}; - -static int nfs_file_co_create(BlockdevCreateOptions *options, Error **errp) -{ - BlockdevCreateOptionsNfs *opts = &options->u.nfs; - NFSClient *client = g_new0(NFSClient, 1); - int ret; - - assert(options->driver == BLOCKDEV_DRIVER_NFS); - - client->aio_context = qemu_get_aio_context(); - - ret = nfs_client_open(client, opts->location, O_CREAT, 0, errp); - if (ret < 0) { - goto out; - } - ret = nfs_ftruncate(client->context, client->fh, opts->size); - nfs_client_close(client); - -out: - g_free(client); - return ret; -} - -static int coroutine_fn nfs_file_co_create_opts(BlockDriver *drv, - const char *url, - QemuOpts *opts, - Error **errp) -{ - BlockdevCreateOptions *create_options; - BlockdevCreateOptionsNfs *nfs_opts; - QDict *options; - int ret; - - create_options = g_new0(BlockdevCreateOptions, 1); - create_options->driver = BLOCKDEV_DRIVER_NFS; - nfs_opts = &create_options->u.nfs; - - /* Read out options */ - nfs_opts->size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), - BDRV_SECTOR_SIZE); - - options = qdict_new(); - ret = nfs_parse_uri(url, options, errp); - if (ret < 0) { - goto out; - } - - nfs_opts->location = nfs_options_qdict_to_qapi(options, errp); - if (nfs_opts->location == NULL) { - ret = -EINVAL; - goto out; - } - - ret = nfs_file_co_create(create_options, errp); - if (ret < 0) { - goto out; - } - - ret = 0; -out: - qobject_unref(options); - qapi_free_BlockdevCreateOptions(create_options); - return ret; -} - -static int nfs_has_zero_init(BlockDriverState *bs) -{ - NFSClient *client = bs->opaque; - return client->has_zero_init; -} - -/* Called (via nfs_service) with QemuMutex held. */ -static void -nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data, - void *private_data) -{ - NFSRPC *task = private_data; - task->ret = ret; - if (task->ret == 0) { - memcpy(task->st, data, sizeof(struct stat)); - } - if (task->ret < 0) { - error_report("NFS Error: %s", nfs_get_error(nfs)); - } - - /* Set task->complete before reading bs->wakeup. */ - atomic_mb_set(&task->complete, 1); - bdrv_wakeup(task->bs); -} - -static int64_t nfs_get_allocated_file_size(BlockDriverState *bs) -{ - NFSClient *client = bs->opaque; - NFSRPC task = {0}; - struct stat st; - - if (bdrv_is_read_only(bs) && - !(bs->open_flags & BDRV_O_NOCACHE)) { - return client->st_blocks * 512; - } - - task.bs = bs; - task.st = &st; - if (nfs_fstat_async(client->context, client->fh, nfs_get_allocated_file_size_cb, - &task) != 0) { - return -ENOMEM; - } - - nfs_set_events(client); - BDRV_POLL_WHILE(bs, !task.complete); - - return (task.ret < 0 ? task.ret : st.st_blocks * 512); -} - -static int coroutine_fn -nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, - PreallocMode prealloc, BdrvRequestFlags flags, - Error **errp) -{ - NFSClient *client = bs->opaque; - int ret; - - if (prealloc != PREALLOC_MODE_OFF) { - error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_str(prealloc)); - return -ENOTSUP; - } - - ret = nfs_ftruncate(client->context, client->fh, offset); - if (ret < 0) { - error_setg_errno(errp, -ret, "Failed to truncate file"); - return ret; - } - - return 0; -} - -/* Note that this will not re-establish a connection with the NFS server - * - it is effectively a NOP. */ -static int nfs_reopen_prepare(BDRVReopenState *state, - BlockReopenQueue *queue, Error **errp) -{ - NFSClient *client = state->bs->opaque; - struct stat st; - int ret = 0; - - if (state->flags & BDRV_O_RDWR && bdrv_is_read_only(state->bs)) { - error_setg(errp, "Cannot open a read-only mount as read-write"); - return -EACCES; - } - - if ((state->flags & BDRV_O_NOCACHE) && client->cache_used) { - error_setg(errp, "Cannot disable cache if libnfs readahead or" - " pagecache is enabled"); - return -EINVAL; - } - - /* Update cache for read-only reopens */ - if (!(state->flags & BDRV_O_RDWR)) { - ret = nfs_fstat(client->context, client->fh, &st); - if (ret < 0) { - error_setg(errp, "Failed to fstat file: %s", - nfs_get_error(client->context)); - return ret; - } - client->st_blocks = st.st_blocks; - } - - return 0; -} - -static void nfs_refresh_filename(BlockDriverState *bs) -{ - NFSClient *client = bs->opaque; - - if (client->uid && !client->gid) { - snprintf(bs->exact_filename, sizeof(bs->exact_filename), - "nfs://%s%s?uid=%" PRId64, client->server->host, client->path, - client->uid); - } else if (!client->uid && client->gid) { - snprintf(bs->exact_filename, sizeof(bs->exact_filename), - "nfs://%s%s?gid=%" PRId64, client->server->host, client->path, - client->gid); - } else if (client->uid && client->gid) { - snprintf(bs->exact_filename, sizeof(bs->exact_filename), - "nfs://%s%s?uid=%" PRId64 "&gid=%" PRId64, - client->server->host, client->path, client->uid, client->gid); - } else { - snprintf(bs->exact_filename, sizeof(bs->exact_filename), - "nfs://%s%s", client->server->host, client->path); - } -} - -static char *nfs_dirname(BlockDriverState *bs, Error **errp) -{ - NFSClient *client = bs->opaque; - - if (client->uid || client->gid) { - bdrv_refresh_filename(bs); - error_setg(errp, "Cannot generate a base directory for NFS node '%s'", - bs->filename); - return NULL; - } - - return g_strdup_printf("nfs://%s%s/", client->server->host, client->path); -} - -#ifdef LIBNFS_FEATURE_PAGECACHE -static void coroutine_fn nfs_co_invalidate_cache(BlockDriverState *bs, - Error **errp) -{ - NFSClient *client = bs->opaque; - nfs_pagecache_invalidate(client->context, client->fh); -} -#endif - -static const char *nfs_strong_runtime_opts[] = { - "path", - "user", - "group", - "server.", - - NULL -}; - -static BlockDriver bdrv_nfs = { - .format_name = "nfs", - .protocol_name = "nfs", - - .instance_size = sizeof(NFSClient), - .bdrv_parse_filename = nfs_parse_filename, - .create_opts = &nfs_create_opts, - - .bdrv_has_zero_init = nfs_has_zero_init, - .bdrv_get_allocated_file_size = nfs_get_allocated_file_size, - .bdrv_co_truncate = nfs_file_co_truncate, - - .bdrv_file_open = nfs_file_open, - .bdrv_close = nfs_file_close, - .bdrv_co_create = nfs_file_co_create, - .bdrv_co_create_opts = nfs_file_co_create_opts, - .bdrv_reopen_prepare = nfs_reopen_prepare, - - .bdrv_co_preadv = nfs_co_preadv, - .bdrv_co_pwritev = nfs_co_pwritev, - .bdrv_co_flush_to_disk = nfs_co_flush, - - .bdrv_detach_aio_context = nfs_detach_aio_context, - .bdrv_attach_aio_context = nfs_attach_aio_context, - .bdrv_refresh_filename = nfs_refresh_filename, - .bdrv_dirname = nfs_dirname, - - .strong_runtime_opts = nfs_strong_runtime_opts, - -#ifdef LIBNFS_FEATURE_PAGECACHE - .bdrv_co_invalidate_cache = nfs_co_invalidate_cache, -#endif -}; - -static void nfs_block_init(void) -{ - bdrv_register(&bdrv_nfs); -} - -block_init(nfs_block_init); +/* + * QEMU Block driver for native access to files on NFS shares + * + * Copyright (c) 2014-2017 Peter Lieven + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" + +#if !defined(_WIN32) +#include +#endif +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "qapi/error.h" +#include "block/block_int.h" +#include "block/qdict.h" +#include "trace.h" +#include "qemu/iov.h" +#include "qemu/main-loop.h" +#include "qemu/module.h" +#include "qemu/option.h" +#include "qemu/uri.h" +#include "qemu/cutils.h" +#include "sysemu/sysemu.h" +#include "sysemu/replay.h" +#include "qapi/qapi-visit-block-core.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi/qobject-output-visitor.h" +#include + + +#define QEMU_NFS_MAX_READAHEAD_SIZE 1048576 +#define QEMU_NFS_MAX_PAGECACHE_SIZE (8388608 / NFS_BLKSIZE) +#define QEMU_NFS_MAX_DEBUG_LEVEL 2 + +#if defined (_WIN32) +#define nfs_stat __stat64 +#else +#define nfs_stat stat +#endif + +typedef struct NFSClient { + struct nfs_context *context; + struct nfsfh *fh; + int events; + bool has_zero_init; + AioContext *aio_context; + QemuMutex mutex; + int64_t st_size; + bool cache_used; + NFSServer *server; + char *path; + int64_t uid, gid, tcp_syncnt, readahead, pagecache, debug; +} NFSClient; + +typedef struct NFSRPC { + BlockDriverState *bs; + int ret; + int complete; + QEMUIOVector *iov; + struct nfs_stat *st; + Coroutine *co; + NFSClient *client; +} NFSRPC; + +static int nfs_parse_uri(const char *filename, QDict *options, Error **errp) +{ + URI *uri = NULL; + QueryParams *qp = NULL; + int ret = -EINVAL, i; + + uri = uri_parse(filename); + if (!uri) { + error_setg(errp, "Invalid URI specified"); + goto out; + } + if (g_strcmp0(uri->scheme, "nfs") != 0) { + error_setg(errp, "URI scheme must be 'nfs'"); + goto out; + } + + if (!uri->server) { + error_setg(errp, "missing hostname in URI"); + goto out; + } + + if (!uri->path) { + error_setg(errp, "missing file path in URI"); + goto out; + } + + qp = query_params_parse(uri->query); + if (!qp) { + error_setg(errp, "could not parse query parameters"); + goto out; + } + + qdict_put_str(options, "server.host", uri->server); + qdict_put_str(options, "server.type", "inet"); + qdict_put_str(options, "path", uri->path); + + for (i = 0; i < qp->n; i++) { + unsigned long long val; + if (!qp->p[i].value) { + error_setg(errp, "Value for NFS parameter expected: %s", + qp->p[i].name); + goto out; + } + if (parse_uint_full(qp->p[i].value, &val, 0)) { + error_setg(errp, "Illegal value for NFS parameter: %s", + qp->p[i].name); + goto out; + } + if (!strcmp(qp->p[i].name, "uid")) { + qdict_put_str(options, "user", qp->p[i].value); + } else if (!strcmp(qp->p[i].name, "gid")) { + qdict_put_str(options, "group", qp->p[i].value); + } else if (!strcmp(qp->p[i].name, "tcp-syncnt")) { + qdict_put_str(options, "tcp-syn-count", qp->p[i].value); + } else if (!strcmp(qp->p[i].name, "readahead")) { + qdict_put_str(options, "readahead-size", qp->p[i].value); + } else if (!strcmp(qp->p[i].name, "pagecache")) { + qdict_put_str(options, "page-cache-size", qp->p[i].value); + } else if (!strcmp(qp->p[i].name, "debug")) { + qdict_put_str(options, "debug", qp->p[i].value); + } else { + error_setg(errp, "Unknown NFS parameter name: %s", + qp->p[i].name); + goto out; + } + } + ret = 0; +out: + if (qp) { + query_params_free(qp); + } + if (uri) { + uri_free(uri); + } + return ret; +} + +static bool nfs_has_filename_options_conflict(QDict *options, Error **errp) +{ + const QDictEntry *qe; + + for (qe = qdict_first(options); qe; qe = qdict_next(options, qe)) { + if (!strcmp(qe->key, "host") || + !strcmp(qe->key, "path") || + !strcmp(qe->key, "user") || + !strcmp(qe->key, "group") || + !strcmp(qe->key, "tcp-syn-count") || + !strcmp(qe->key, "readahead-size") || + !strcmp(qe->key, "page-cache-size") || + !strcmp(qe->key, "debug") || + strstart(qe->key, "server.", NULL)) + { + error_setg(errp, "Option %s cannot be used with a filename", + qe->key); + return true; + } + } + + return false; +} + +static void nfs_parse_filename(const char *filename, QDict *options, + Error **errp) +{ + if (nfs_has_filename_options_conflict(options, errp)) { + return; + } + + nfs_parse_uri(filename, options, errp); +} + +static void nfs_process_read(void *arg); +static void nfs_process_write(void *arg); + +/* Called with QemuMutex held. */ +static void nfs_set_events(NFSClient *client) +{ + int ev = nfs_which_events(client->context); + if (ev != client->events) { + aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), + false, + (ev & POLLIN) ? nfs_process_read : NULL, + (ev & POLLOUT) ? nfs_process_write : NULL, + NULL, client); + + } + client->events = ev; +} + +static void nfs_process_read(void *arg) +{ + NFSClient *client = arg; + + qemu_mutex_lock(&client->mutex); + nfs_service(client->context, POLLIN); + nfs_set_events(client); + qemu_mutex_unlock(&client->mutex); +} + +static void nfs_process_write(void *arg) +{ + NFSClient *client = arg; + + qemu_mutex_lock(&client->mutex); + nfs_service(client->context, POLLOUT); + nfs_set_events(client); + qemu_mutex_unlock(&client->mutex); +} + +static void nfs_co_init_task(BlockDriverState *bs, NFSRPC *task) +{ + *task = (NFSRPC) { + .co = qemu_coroutine_self(), + .bs = bs, + .client = bs->opaque, + }; +} + +static void nfs_co_generic_bh_cb(void *opaque) +{ + NFSRPC *task = opaque; + + task->complete = 1; + aio_co_wake(task->co); +} + +/* Called (via nfs_service) with QemuMutex held. */ +static void +nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data, + void *private_data) +{ + NFSRPC *task = private_data; + task->ret = ret; + assert(!task->st); + if (task->ret > 0 && task->iov) { + if (task->ret <= task->iov->size) { + qemu_iovec_from_buf(task->iov, 0, data, task->ret); + } else { + task->ret = -EIO; + } + } + if (task->ret < 0) { + error_report("NFS Error: %s", nfs_get_error(nfs)); + } + replay_bh_schedule_oneshot_event(task->client->aio_context, + nfs_co_generic_bh_cb, task); +} + +static int coroutine_fn nfs_co_preadv(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, QEMUIOVector *iov, + int flags) +{ + NFSClient *client = bs->opaque; + NFSRPC task; + + nfs_co_init_task(bs, &task); + task.iov = iov; + + WITH_QEMU_LOCK_GUARD(&client->mutex) { + if (nfs_pread_async(client->context, client->fh, + offset, bytes, nfs_co_generic_cb, &task) != 0) { + return -ENOMEM; + } + + nfs_set_events(client); + } + while (!task.complete) { + qemu_coroutine_yield(); + } + + if (task.ret < 0) { + return task.ret; + } + + /* zero pad short reads */ + if (task.ret < iov->size) { + qemu_iovec_memset(iov, task.ret, 0, iov->size - task.ret); + } + + return 0; +} + +static int coroutine_fn nfs_co_pwritev(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, QEMUIOVector *iov, + int flags) +{ + NFSClient *client = bs->opaque; + NFSRPC task; + char *buf = NULL; + bool my_buffer = false; + + nfs_co_init_task(bs, &task); + + if (iov->niov != 1) { + buf = g_try_malloc(bytes); + if (bytes && buf == NULL) { + return -ENOMEM; + } + qemu_iovec_to_buf(iov, 0, buf, bytes); + my_buffer = true; + } else { + buf = iov->iov[0].iov_base; + } + + WITH_QEMU_LOCK_GUARD(&client->mutex) { + if (nfs_pwrite_async(client->context, client->fh, + offset, bytes, buf, + nfs_co_generic_cb, &task) != 0) { + if (my_buffer) { + g_free(buf); + } + return -ENOMEM; + } + + nfs_set_events(client); + } + while (!task.complete) { + qemu_coroutine_yield(); + } + + if (my_buffer) { + g_free(buf); + } + + if (task.ret != bytes) { + return task.ret < 0 ? task.ret : -EIO; + } + + return 0; +} + +static int coroutine_fn nfs_co_flush(BlockDriverState *bs) +{ + NFSClient *client = bs->opaque; + NFSRPC task; + + nfs_co_init_task(bs, &task); + + WITH_QEMU_LOCK_GUARD(&client->mutex) { + if (nfs_fsync_async(client->context, client->fh, nfs_co_generic_cb, + &task) != 0) { + return -ENOMEM; + } + + nfs_set_events(client); + } + while (!task.complete) { + qemu_coroutine_yield(); + } + + return task.ret; +} + +static void nfs_detach_aio_context(BlockDriverState *bs) +{ + NFSClient *client = bs->opaque; + + aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), + false, NULL, NULL, NULL, NULL); + client->events = 0; +} + +static void nfs_attach_aio_context(BlockDriverState *bs, + AioContext *new_context) +{ + NFSClient *client = bs->opaque; + + client->aio_context = new_context; + nfs_set_events(client); +} + +static void nfs_client_close(NFSClient *client) +{ + if (client->context) { + qemu_mutex_lock(&client->mutex); + aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context), + false, NULL, NULL, NULL, NULL); + qemu_mutex_unlock(&client->mutex); + if (client->fh) { + nfs_close(client->context, client->fh); + client->fh = NULL; + } +#ifdef LIBNFS_FEATURE_UMOUNT + nfs_umount(client->context); +#endif + nfs_destroy_context(client->context); + client->context = NULL; + } + g_free(client->path); + qemu_mutex_destroy(&client->mutex); + qapi_free_NFSServer(client->server); + client->server = NULL; +} + +static void nfs_file_close(BlockDriverState *bs) +{ + NFSClient *client = bs->opaque; + nfs_client_close(client); +} + +static int64_t nfs_client_open(NFSClient *client, BlockdevOptionsNfs *opts, + int flags, int open_flags, Error **errp) +{ + int64_t ret = -EINVAL; + struct nfs_stat st; + char *file = NULL, *strp = NULL; + + qemu_mutex_init(&client->mutex); + + client->path = g_strdup(opts->path); + + strp = strrchr(client->path, '/'); + if (strp == NULL) { + error_setg(errp, "Invalid URL specified"); + goto fail; + } + file = g_strdup(strp); + *strp = 0; + + /* Steal the NFSServer object from opts; set the original pointer to NULL + * to avoid use after free and double free. */ + client->server = opts->server; + opts->server = NULL; + + client->context = nfs_init_context(); + if (client->context == NULL) { + error_setg(errp, "Failed to init NFS context"); + goto fail; + } + + if (opts->has_user) { + client->uid = opts->user; + nfs_set_uid(client->context, client->uid); + } + + if (opts->has_group) { + client->gid = opts->group; + nfs_set_gid(client->context, client->gid); + } + + if (opts->has_tcp_syn_count) { + client->tcp_syncnt = opts->tcp_syn_count; + nfs_set_tcp_syncnt(client->context, client->tcp_syncnt); + } + +#ifdef LIBNFS_FEATURE_READAHEAD + if (opts->has_readahead_size) { + if (open_flags & BDRV_O_NOCACHE) { + error_setg(errp, "Cannot enable NFS readahead " + "if cache.direct = on"); + goto fail; + } + client->readahead = opts->readahead_size; + if (client->readahead > QEMU_NFS_MAX_READAHEAD_SIZE) { + warn_report("Truncating NFS readahead size to %d", + QEMU_NFS_MAX_READAHEAD_SIZE); + client->readahead = QEMU_NFS_MAX_READAHEAD_SIZE; + } + nfs_set_readahead(client->context, client->readahead); +#ifdef LIBNFS_FEATURE_PAGECACHE + nfs_set_pagecache_ttl(client->context, 0); +#endif + client->cache_used = true; + } +#endif + +#ifdef LIBNFS_FEATURE_PAGECACHE + if (opts->has_page_cache_size) { + if (open_flags & BDRV_O_NOCACHE) { + error_setg(errp, "Cannot enable NFS pagecache " + "if cache.direct = on"); + goto fail; + } + client->pagecache = opts->page_cache_size; + if (client->pagecache > QEMU_NFS_MAX_PAGECACHE_SIZE) { + warn_report("Truncating NFS pagecache size to %d pages", + QEMU_NFS_MAX_PAGECACHE_SIZE); + client->pagecache = QEMU_NFS_MAX_PAGECACHE_SIZE; + } + nfs_set_pagecache(client->context, client->pagecache); + nfs_set_pagecache_ttl(client->context, 0); + client->cache_used = true; + } +#endif + +#ifdef LIBNFS_FEATURE_DEBUG + if (opts->has_debug) { + client->debug = opts->debug; + /* limit the maximum debug level to avoid potential flooding + * of our log files. */ + if (client->debug > QEMU_NFS_MAX_DEBUG_LEVEL) { + warn_report("Limiting NFS debug level to %d", + QEMU_NFS_MAX_DEBUG_LEVEL); + client->debug = QEMU_NFS_MAX_DEBUG_LEVEL; + } + nfs_set_debug(client->context, client->debug); + } +#endif + + ret = nfs_mount(client->context, client->server->host, client->path); + if (ret < 0) { + error_setg(errp, "Failed to mount nfs share: %s", + nfs_get_error(client->context)); + goto fail; + } + + if (flags & O_CREAT) { + ret = nfs_creat(client->context, file, 0600, &client->fh); + if (ret < 0) { + error_setg(errp, "Failed to create file: %s", + nfs_get_error(client->context)); + goto fail; + } + } else { + ret = nfs_open(client->context, file, flags, &client->fh); + if (ret < 0) { + error_setg(errp, "Failed to open file : %s", + nfs_get_error(client->context)); + goto fail; + } + } + + ret = nfs_fstat(client->context, client->fh, &st); + if (ret < 0) { + error_setg(errp, "Failed to fstat file: %s", + nfs_get_error(client->context)); + goto fail; + } + + ret = DIV_ROUND_UP(st.st_size, BDRV_SECTOR_SIZE); + client->st_size = st.st_size; + client->has_zero_init = S_ISREG(st.st_mode); + *strp = '/'; + goto out; + +fail: + nfs_client_close(client); +out: + g_free(file); + return ret; +} + +static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options, + Error **errp) +{ + BlockdevOptionsNfs *opts = NULL; + Visitor *v; + const QDictEntry *e; + + v = qobject_input_visitor_new_flat_confused(options, errp); + if (!v) { + return NULL; + } + + visit_type_BlockdevOptionsNfs(v, NULL, &opts, errp); + visit_free(v); + if (!opts) { + return NULL; + } + + /* Remove the processed options from the QDict (the visitor processes + * _all_ options in the QDict) */ + while ((e = qdict_first(options))) { + qdict_del(options, e->key); + } + + return opts; +} + +static int64_t nfs_client_open_qdict(NFSClient *client, QDict *options, + int flags, int open_flags, Error **errp) +{ + BlockdevOptionsNfs *opts; + int ret; + + opts = nfs_options_qdict_to_qapi(options, errp); + if (opts == NULL) { + ret = -EINVAL; + goto fail; + } + + ret = nfs_client_open(client, opts, flags, open_flags, errp); +fail: + qapi_free_BlockdevOptionsNfs(opts); + return ret; +} + +static int nfs_file_open(BlockDriverState *bs, QDict *options, int flags, + Error **errp) { + NFSClient *client = bs->opaque; + int64_t ret; + + client->aio_context = bdrv_get_aio_context(bs); + + ret = nfs_client_open_qdict(client, options, + (flags & BDRV_O_RDWR) ? O_RDWR : O_RDONLY, + bs->open_flags, errp); + if (ret < 0) { + return ret; + } + + bs->total_sectors = ret; + if (client->has_zero_init) { + bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE; + } + return 0; +} + +static QemuOptsList nfs_create_opts = { + .name = "nfs-create-opts", + .head = QTAILQ_HEAD_INITIALIZER(nfs_create_opts.head), + .desc = { + { + .name = BLOCK_OPT_SIZE, + .type = QEMU_OPT_SIZE, + .help = "Virtual disk size" + }, + { /* end of list */ } + } +}; + +static int nfs_file_co_create(BlockdevCreateOptions *options, Error **errp) +{ + BlockdevCreateOptionsNfs *opts = &options->u.nfs; + NFSClient *client = g_new0(NFSClient, 1); + int ret; + + assert(options->driver == BLOCKDEV_DRIVER_NFS); + + client->aio_context = qemu_get_aio_context(); + + ret = nfs_client_open(client, opts->location, O_CREAT, 0, errp); + if (ret < 0) { + goto out; + } + ret = nfs_ftruncate(client->context, client->fh, opts->size); + nfs_client_close(client); + +out: + g_free(client); + return ret; +} + +static int coroutine_fn nfs_file_co_create_opts(BlockDriver *drv, + const char *url, + QemuOpts *opts, + Error **errp) +{ + BlockdevCreateOptions *create_options; + BlockdevCreateOptionsNfs *nfs_opts; + QDict *options; + int ret; + + create_options = g_new0(BlockdevCreateOptions, 1); + create_options->driver = BLOCKDEV_DRIVER_NFS; + nfs_opts = &create_options->u.nfs; + + /* Read out options */ + nfs_opts->size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), + BDRV_SECTOR_SIZE); + + options = qdict_new(); + ret = nfs_parse_uri(url, options, errp); + if (ret < 0) { + goto out; + } + + nfs_opts->location = nfs_options_qdict_to_qapi(options, errp); + if (nfs_opts->location == NULL) { + ret = -EINVAL; + goto out; + } + + ret = nfs_file_co_create(create_options, errp); + if (ret < 0) { + goto out; + } + + ret = 0; +out: + qobject_unref(options); + qapi_free_BlockdevCreateOptions(create_options); + return ret; +} + +static int nfs_has_zero_init(BlockDriverState *bs) +{ + NFSClient *client = bs->opaque; + return client->has_zero_init; +} + +/* Called (via nfs_service) with QemuMutex held. */ +static void +nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data, + void *private_data) +{ + NFSRPC *task = private_data; + task->ret = ret; + if (task->ret == 0) { + memcpy(task->st, data, sizeof(struct stat)); + } + if (task->ret < 0) { + error_report("NFS Error: %s", nfs_get_error(nfs)); + } + + /* Set task->complete before reading bs->wakeup. */ + atomic_mb_set(&task->complete, 1); + bdrv_wakeup(task->bs); +} + +static int64_t nfs_get_allocated_file_size(BlockDriverState *bs) +{ + NFSClient *client = bs->opaque; + NFSRPC task = {0}; + struct nfs_stat st; + + if (bdrv_is_read_only(bs) && + !(bs->open_flags & BDRV_O_NOCACHE)) { + return client->st_size; + } + + task.bs = bs; + task.st = &st; + if (nfs_fstat_async(client->context, client->fh, nfs_get_allocated_file_size_cb, + &task) != 0) { + return -ENOMEM; + } + + nfs_set_events(client); + BDRV_POLL_WHILE(bs, !task.complete); + + return (task.ret < 0 ? task.ret : st.st_size); +} + +static int coroutine_fn +nfs_file_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, + Error **errp) +{ + NFSClient *client = bs->opaque; + int ret; + + if (prealloc != PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_str(prealloc)); + return -ENOTSUP; + } + + ret = nfs_ftruncate(client->context, client->fh, offset); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to truncate file"); + return ret; + } + + return 0; +} + +/* Note that this will not re-establish a connection with the NFS server + * - it is effectively a NOP. */ +static int nfs_reopen_prepare(BDRVReopenState *state, + BlockReopenQueue *queue, Error **errp) +{ + NFSClient *client = state->bs->opaque; + struct nfs_stat st; + int ret = 0; + + if (state->flags & BDRV_O_RDWR && bdrv_is_read_only(state->bs)) { + error_setg(errp, "Cannot open a read-only mount as read-write"); + return -EACCES; + } + + if ((state->flags & BDRV_O_NOCACHE) && client->cache_used) { + error_setg(errp, "Cannot disable cache if libnfs readahead or" + " pagecache is enabled"); + return -EINVAL; + } + + /* Update cache for read-only reopens */ + if (!(state->flags & BDRV_O_RDWR)) { + ret = nfs_fstat(client->context, client->fh, &st); + if (ret < 0) { + error_setg(errp, "Failed to fstat file: %s", + nfs_get_error(client->context)); + return ret; + } + client->st_size = st.st_size; + } + + return 0; +} + +static void nfs_refresh_filename(BlockDriverState *bs) +{ + NFSClient *client = bs->opaque; + + if (client->uid && !client->gid) { + snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "nfs://%s%s?uid=%" PRId64, client->server->host, client->path, + client->uid); + } else if (!client->uid && client->gid) { + snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "nfs://%s%s?gid=%" PRId64, client->server->host, client->path, + client->gid); + } else if (client->uid && client->gid) { + snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "nfs://%s%s?uid=%" PRId64 "&gid=%" PRId64, + client->server->host, client->path, client->uid, client->gid); + } else { + snprintf(bs->exact_filename, sizeof(bs->exact_filename), + "nfs://%s%s", client->server->host, client->path); + } +} + +static char *nfs_dirname(BlockDriverState *bs, Error **errp) +{ + NFSClient *client = bs->opaque; + + if (client->uid || client->gid) { + bdrv_refresh_filename(bs); + error_setg(errp, "Cannot generate a base directory for NFS node '%s'", + bs->filename); + return NULL; + } + + return g_strdup_printf("nfs://%s%s/", client->server->host, client->path); +} + +#ifdef LIBNFS_FEATURE_PAGECACHE +static void coroutine_fn nfs_co_invalidate_cache(BlockDriverState *bs, + Error **errp) +{ + NFSClient *client = bs->opaque; + nfs_pagecache_invalidate(client->context, client->fh); +} +#endif + +static const char *nfs_strong_runtime_opts[] = { + "path", + "user", + "group", + "server.", + + NULL +}; + +static BlockDriver bdrv_nfs = { + .format_name = "nfs", + .protocol_name = "nfs", + + .instance_size = sizeof(NFSClient), + .bdrv_parse_filename = nfs_parse_filename, + .create_opts = &nfs_create_opts, + + .bdrv_has_zero_init = nfs_has_zero_init, + .bdrv_get_allocated_file_size = nfs_get_allocated_file_size, + .bdrv_co_truncate = nfs_file_co_truncate, + + .bdrv_file_open = nfs_file_open, + .bdrv_close = nfs_file_close, + .bdrv_co_create = nfs_file_co_create, + .bdrv_co_create_opts = nfs_file_co_create_opts, + .bdrv_reopen_prepare = nfs_reopen_prepare, + + .bdrv_co_preadv = nfs_co_preadv, + .bdrv_co_pwritev = nfs_co_pwritev, + .bdrv_co_flush_to_disk = nfs_co_flush, + + .bdrv_detach_aio_context = nfs_detach_aio_context, + .bdrv_attach_aio_context = nfs_attach_aio_context, + .bdrv_refresh_filename = nfs_refresh_filename, + .bdrv_dirname = nfs_dirname, + + .strong_runtime_opts = nfs_strong_runtime_opts, + +#ifdef LIBNFS_FEATURE_PAGECACHE + .bdrv_co_invalidate_cache = nfs_co_invalidate_cache, +#endif +}; + +static void nfs_block_init(void) +{ + bdrv_register(&bdrv_nfs); +} + +block_init(nfs_block_init); From patchwork Thu Sep 3 07:43:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?572X5YuH5YiaKFlvbmdnYW5nIEx1byk=?= X-Patchwork-Id: 274729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F16EFC433E2 for ; Thu, 3 Sep 2020 07:48:59 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A7814206C0 for ; Thu, 3 Sep 2020 07:48:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V+ZGx1cU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7814206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDjzO-0008FI-Q6 for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 03:48:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDjuZ-0000Pk-T0 for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:43:59 -0400 Received: from mail-pj1-x1043.google.com ([2607:f8b0:4864:20::1043]:37570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDjuY-0003uI-86 for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:43:59 -0400 Received: by mail-pj1-x1043.google.com with SMTP id mw10so1063515pjb.2 for ; Thu, 03 Sep 2020 00:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iUIJV0NrJHasWSyZnY8jh25seOv6g5EICBiDlFuRKr4=; b=V+ZGx1cU4OTfefyAApcuukQl4R7vN5YN202dFspHVkDeN4atRmT84tPnUf4xeYAAIa I+mVUzMGV0w3qTrNFn4JwaDQeBLInW2k07SzNOt3jAh0KWui0iqXy7clGiTj6Hd9ysEA EDhuZ9DV6Zlbyo+PcUVhiR/cspXLwAQwYWfXIK7i4VNwaAZs6EZk0FU5Iryi/GtxsI5c eTbi0s9UpJZqhBqnGvXMZwetX2ALCzcRdQJPOlOm419DnNOiqFTE2nT51n7K/A2yYHrb jPXF6yr0+2v7EKieQzK5frmTuDmqeXnRGErolA3Zfsjzxzg1/Pe+YjO1NxxsPRD800i6 Hh+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iUIJV0NrJHasWSyZnY8jh25seOv6g5EICBiDlFuRKr4=; b=NJ54UvRL7bi9gkbi+wNg14MtTbRtSi0q7875lt65fK6ky8jdewnwwo7cbX5alw6dz9 8EDw1Z1Du7g1SJXcl3JM9+ufO7ew6/Q1ZT3qT+EoylKSmjI5jqwVQvJBCuOvqhSYmrEe syUBv3WCR59RHZ76ifak8oVqW+qgFLIZeL77ez6cPTUYwwqo7ytVKkve+c+NAizMRYOJ ggFmQF/V83TA16U1pDmPK9kJxq+gVz9DiEJyd1y+Qy1dne+oODNgdESzdfzqyHsTE4Q9 MqI2PSFpcMoMR1yeJqdkO4DCgSypm2Lk6eI3kVI3Cd8f6XHy88db/6e1LslYCAyWOx81 QlaA== X-Gm-Message-State: AOAM533jFGZWRACIpB2Lpz4vLnKBCYdBkIJgF4YGi1SLreRtfewyv5gc lxF37vJN0/6HxzQ5OsLeq/piw/2XPyfKle2n X-Google-Smtp-Source: ABdhPJyieuTP3xXoHaWWtLkYgv+toiYfOcMJ/F2wZzEn5itdl2Rkpwy6TLkWSE5O5ma8hcEs733b5A== X-Received: by 2002:a17:90a:c255:: with SMTP id d21mr2126386pjx.212.1599119036513; Thu, 03 Sep 2020 00:43:56 -0700 (PDT) Received: from localhost.localdomain ([222.95.248.6]) by smtp.googlemail.com with ESMTPSA id o6sm1512472pju.25.2020.09.03.00.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 00:43:55 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v3 09/12] stubs: qemu_notify_event have no need to stub Date: Thu, 3 Sep 2020 15:43:10 +0800 Message-Id: <20200903074313.1498-10-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200903074313.1498-1-luoyonggang@gmail.com> References: <20200903074313.1498-1-luoyonggang@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1043; envelope-from=luoyonggang@gmail.com; helo=mail-pj1-x1043.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Yonggang Luo Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" LINK tests/test-qdev-global-props.exe LINK tests/test-timed-average.exe C:/CI-Tools/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: libqemuutil.a(util_main-loop.c.obj): in function `qemu_notify_event': C:\work\xemu\qemu-build/../qemu/util/main-loop.c:139: multiple definition of `qemu_notify_event'; libqemuutil.a(stubs_notify-event.c.obj):C:\work\xemu\qemu-build/../qemu/stubs/notify-event.c:6: first defined here collect2.exe: error: ld returned 1 exit status make: *** [C:/work/xemu/qemu/rules.mak:88:tests/test-timed-average.exe] 错误 1 Signed-off-by: Yonggang Luo --- stubs/notify-event.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/stubs/notify-event.c b/stubs/notify-event.c index 827bb52d1a..59935db11e 100644 --- a/stubs/notify-event.c +++ b/stubs/notify-event.c @@ -1,6 +1,2 @@ -#include "qemu/osdep.h" -#include "qemu/main-loop.h" - -void qemu_notify_event(void) -{ -} +#include "qemu/osdep.h" +#include "qemu/main-loop.h" From patchwork Thu Sep 3 07:43:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?572X5YuH5YiaKFlvbmdnYW5nIEx1byk=?= X-Patchwork-Id: 274727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35E70C433E7 for ; Thu, 3 Sep 2020 07:53:04 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B8A4320775 for ; Thu, 3 Sep 2020 07:53:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uR8f6+8w" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8A4320775 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDk3K-0004Bl-Lr for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 03:53:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43486) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDjuk-0000rh-DJ for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:44:10 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:42721) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDjuf-0003uu-GO for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:44:10 -0400 Received: by mail-pf1-x444.google.com with SMTP id 17so1603923pfw.9 for ; Thu, 03 Sep 2020 00:44:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J7jnwobGRIDUa/em/2YcJoKe5IITUTAYh0YoCe/oM4I=; b=uR8f6+8wxQiGuKMusQHfs3q1NgCVppHtYIUFOl5Zu77r16bQ6nTuLTcF4LbIqSr0j0 lYtvzIVps59TwS23a3V0u16vxf4uezmOSohKYXOJi+OtMG23iXJXVOBOFAtBf7wFkvzc ty2F03Msk4Yd+E8A7txfI8VQMNiEj4HC6rGnSvuiY2qHZvBZA1MD8m/sAT5K9gahcOUZ 0LRDX9HyUsIumkgWZm5Czm4Fbin2vA9D1630Cl+6bxnaSx9BcdRh38O9Iuz86DYqPHJK zR5rb0d8kFOqOc3OQZcy3g8h7XMiaeuB/L1YQQhZsRTbJY23kXezlz25Qhf5WYnEXVZ8 S96w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J7jnwobGRIDUa/em/2YcJoKe5IITUTAYh0YoCe/oM4I=; b=rDwoIwBWsMSju6b28gnLw52jsoSwSNhROGASZHKrah9PLW+333DWo1CWxGPWXaC6Ge EZ3LI2WMF+IX0GfSWiNe9zrr0lG2O8ESkGMSP5Eu+RPsy5AniO6BVY66NHg19om60+LJ LCdwHrqUMV6BQry+ZiXEz0Fm9hgDWcJ6yI+ZzUvmwN1ii0NrbIbeUV30oY9UK78gORTb f6wD4yuwovnpBgU3Qk4p1mEL7HWe/mlbFCpZuqQGRxRh7l7uSZ2SrccTRTzyDuSuisum fu6E0ENTI4QdbET6sFgY2QTeAaOHHxkQlvgDa1qmhvoldfplCKeuv/ekufpgnl5cZdLm Mhtw== X-Gm-Message-State: AOAM530phdNVkupwwMocPsGgBmG9M1oqf+Xpj2ldml7mcLhUho1JEb0x q3gS+o8UeDHOOZnnTpzJ8vLZcZYZlLiT8IVn X-Google-Smtp-Source: ABdhPJzaJVwJVMkVpCrTVXmdc4w6tnDyJND6q4wPE1faO9V/tRjsoO+pAuXRRcFGGTlTLenoZq4kpg== X-Received: by 2002:a65:66c4:: with SMTP id c4mr1991372pgw.442.1599119042329; Thu, 03 Sep 2020 00:44:02 -0700 (PDT) Received: from localhost.localdomain ([222.95.248.6]) by smtp.googlemail.com with ESMTPSA id o6sm1512472pju.25.2020.09.03.00.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 00:44:01 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v3 11/12] tests: Disable test-image-locking that not works under Win32 Date: Thu, 3 Sep 2020 15:43:12 +0800 Message-Id: <20200903074313.1498-12-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200903074313.1498-1-luoyonggang@gmail.com> References: <20200903074313.1498-1-luoyonggang@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::444; envelope-from=luoyonggang@gmail.com; helo=mail-pf1-x444.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Yonggang Luo Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Yonggang Luo --- tests/Makefile.include | 1086 ++++++++++++++++++++-------------------- 1 file changed, 544 insertions(+), 542 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 9ac8f5b86a..497f1f21ff 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -1,542 +1,544 @@ -# -*- Mode: makefile -*- - -.PHONY: check-help -check-help: - @echo "Regression testing targets:" - @echo - @echo " $(MAKE) check Run block, qapi-schema, unit, softfloat, qtest and decodetree tests" - @echo - @echo " $(MAKE) check-qtest-TARGET Run qtest tests for given target" - @echo " $(MAKE) check-qtest Run qtest tests" - @echo " $(MAKE) check-unit Run qobject tests" - @echo " $(MAKE) check-speed Run qobject speed tests" - @echo " $(MAKE) check-qapi-schema Run QAPI schema tests" - @echo " $(MAKE) check-block Run block tests" -ifeq ($(CONFIG_TCG),y) - @echo " $(MAKE) check-tcg Run TCG tests" - @echo " $(MAKE) check-softfloat Run FPU emulation tests" -endif - @echo " $(MAKE) check-acceptance Run all acceptance (functional) tests" - @echo - @echo " $(MAKE) check-report.tap Generates an aggregated TAP test report" - @echo " $(MAKE) check-venv Creates a Python venv for tests" - @echo " $(MAKE) check-clean Clean the tests and related data" - @echo - @echo "The following are useful for CI builds" - @echo " $(MAKE) check-build Build most test binaris" - @echo " $(MAKE) get-vm-images Downloads all images used by acceptance tests, according to configured targets (~350 MB each, 1.5 GB max)" - @echo - @echo - @echo "The variable SPEED can be set to control the gtester speed setting." - @echo "Default options are -k and (for $(MAKE) V=1) --verbose; they can be" - @echo "changed with variable GTESTER_OPTIONS." - -ifneq ($(wildcard config-host.mak),) -export SRC_PATH - -# TODO don't duplicate $(SRC_PATH)/Makefile's qapi-py here -qapi-py = $(SRC_PATH)/scripts/qapi/__init__.py \ -$(SRC_PATH)/scripts/qapi/commands.py \ -$(SRC_PATH)/scripts/qapi/common.py \ -$(SRC_PATH)/scripts/qapi/doc.py \ -$(SRC_PATH)/scripts/qapi/error.py \ -$(SRC_PATH)/scripts/qapi/events.py \ -$(SRC_PATH)/scripts/qapi/expr.py \ -$(SRC_PATH)/scripts/qapi/gen.py \ -$(SRC_PATH)/scripts/qapi/introspect.py \ -$(SRC_PATH)/scripts/qapi/parser.py \ -$(SRC_PATH)/scripts/qapi/schema.py \ -$(SRC_PATH)/scripts/qapi/source.py \ -$(SRC_PATH)/scripts/qapi/types.py \ -$(SRC_PATH)/scripts/qapi/visit.py \ -$(SRC_PATH)/scripts/qapi-gen.py - -# Get the list of all supported sysemu targets -SYSEMU_TARGET_LIST := $(subst -softmmu.mak,,$(notdir \ - $(wildcard $(SRC_PATH)/default-configs/*-softmmu.mak))) - -check-unit-y += tests/check-qdict$(EXESUF) -check-unit-y += tests/check-block-qdict$(EXESUF) -check-unit-y += tests/check-qnum$(EXESUF) -check-unit-y += tests/check-qstring$(EXESUF) -check-unit-y += tests/check-qlist$(EXESUF) -check-unit-y += tests/check-qnull$(EXESUF) -check-unit-y += tests/check-qobject$(EXESUF) -check-unit-y += tests/check-qjson$(EXESUF) -check-unit-y += tests/check-qlit$(EXESUF) -check-unit-y += tests/test-qobject-output-visitor$(EXESUF) -check-unit-y += tests/test-clone-visitor$(EXESUF) -check-unit-y += tests/test-qobject-input-visitor$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) += tests/test-qmp-cmds$(EXESUF) -check-unit-y += tests/test-string-input-visitor$(EXESUF) -check-unit-y += tests/test-string-output-visitor$(EXESUF) -check-unit-y += tests/test-qmp-event$(EXESUF) -check-unit-y += tests/test-opts-visitor$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-coroutine$(EXESUF) -check-unit-y += tests/test-visitor-serialization$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) += tests/test-iov$(EXESUF) -check-unit-y += tests/test-bitmap$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-aio$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-aio-multithread$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-throttle$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-thread-pool$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-hbitmap$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-bdrv-drain$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-bdrv-graph-mod$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-blockjob$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-blockjob-txn$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-block-backend$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-block-iothread$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-image-locking$(EXESUF) -check-unit-y += tests/test-x86-cpuid$(EXESUF) -# all code tested by test-x86-cpuid is inside topology.h -ifeq ($(CONFIG_SOFTMMU),y) -check-unit-y += tests/test-xbzrle$(EXESUF) -check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF) -endif -check-unit-y += tests/test-cutils$(EXESUF) -check-unit-y += tests/test-shift128$(EXESUF) -check-unit-y += tests/test-mul64$(EXESUF) -check-unit-y += tests/test-int128$(EXESUF) -# all code tested by test-int128 is inside int128.h -check-unit-y += tests/rcutorture$(EXESUF) -check-unit-y += tests/test-rcu-list$(EXESUF) -check-unit-y += tests/test-rcu-simpleq$(EXESUF) -check-unit-y += tests/test-rcu-tailq$(EXESUF) -check-unit-y += tests/test-rcu-slist$(EXESUF) -check-unit-y += tests/test-qdist$(EXESUF) -check-unit-y += tests/test-qht$(EXESUF) -check-unit-y += tests/test-qht-par$(EXESUF) -check-unit-y += tests/test-bitops$(EXESUF) -check-unit-y += tests/test-bitcnt$(EXESUF) -check-unit-y += tests/test-qgraph$(EXESUF) -check-unit-y += tests/check-qom-interface$(EXESUF) -check-unit-y += tests/check-qom-proplist$(EXESUF) -check-unit-y += tests/test-qemu-opts$(EXESUF) -check-unit-y += tests/test-keyval$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-write-threshold$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-crypto-hash$(EXESUF) -check-speed-$(CONFIG_BLOCK) += tests/benchmark-crypto-hash$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-crypto-hmac$(EXESUF) -check-speed-$(CONFIG_BLOCK) += tests/benchmark-crypto-hmac$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-crypto-cipher$(EXESUF) -check-speed-$(CONFIG_BLOCK) += tests/benchmark-crypto-cipher$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-crypto-secret$(EXESUF) -check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) += tests/test-crypto-tlscredsx509$(EXESUF) -check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) += tests/test-crypto-tlssession$(EXESUF) -ifndef CONFIG_TSAN -# Some tests: test-char, test-qdev-global-props, and test-qga, -# are not runnable under TSan due to a known issue. -# https://github.com/google/sanitizers/issues/1116 -check-unit-$(CONFIG_SOFTMMU) += tests/test-char$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) += tests/test-qdev-global-props$(EXESUF) -ifeq ($(CONFIG_GUEST_AGENT),y) -check-unit-$(call land,$(CONFIG_LINUX),$(CONFIG_VIRTIO_SERIAL)) += tests/test-qga$(EXESUF) -endif -endif -check-unit-$(CONFIG_SOFTMMU) += tests/test-timed-average$(EXESUF) -check-unit-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_INOTIFY1)) += tests/test-util-filemonitor$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) += tests/test-util-sockets$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-authz-simple$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-authz-list$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-authz-listfile$(EXESUF) -check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_AUTH_PAM)) += tests/test-authz-pam$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-io-task$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-io-channel-socket$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-io-channel-file$(EXESUF) -check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) += tests/test-io-channel-tls$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-io-channel-command$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-io-channel-buffer$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) += tests/test-base64$(EXESUF) -check-unit-$(call land,$(CONFIG_BLOCK),$(if $(CONFIG_NETTLE),y,$(CONFIG_GCRYPT))) += tests/test-crypto-pbkdf$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-crypto-ivgen$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-crypto-afsplit$(EXESUF) -check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_QEMU_PRIVATE_XTS)) += tests/test-crypto-xts$(EXESUF) -check-unit-$(CONFIG_BLOCK) += tests/test-crypto-block$(EXESUF) -check-unit-y += tests/test-logging$(EXESUF) -check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_REPLICATION)) += tests/test-replication$(EXESUF) -check-unit-$(CONFIG_SOFTMMU) += tests/test-bufferiszero$(EXESUF) -check-unit-y += tests/test-uuid$(EXESUF) -check-unit-y += tests/ptimer-test$(EXESUF) -check-unit-y += tests/test-qapi-util$(EXESUF) - -generated-files-y += tests/test-qapi-types.h -generated-files-y += tests/include/test-qapi-types-sub-module.h -generated-files-y += tests/test-qapi-types-sub-sub-module.h -generated-files-y += tests/test-qapi-visit.h -generated-files-y += tests/include/test-qapi-visit-sub-module.h -generated-files-y += tests/test-qapi-visit-sub-sub-module.h -generated-files-y += tests/test-qapi-commands.h -generated-files-y += tests/test-qapi-init-commands.h -generated-files-y += tests/include/test-qapi-commands-sub-module.h -generated-files-y += tests/test-qapi-commands-sub-sub-module.h -generated-files-y += tests/test-qapi-emit-events.h -generated-files-y += tests/test-qapi-events.h -generated-files-y += tests/include/test-qapi-events-sub-module.h -generated-files-y += tests/test-qapi-events-sub-sub-module.h -generated-files-y += tests/test-qapi-introspect.h - -QEMU_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest - - -# Deps that are common to various different sets of tests below -test-util-obj-y = libqemuutil.a -test-qom-obj-y = $(qom-obj-y) $(test-util-obj-y) -test-qapi-obj-y = tests/test-qapi-types.o \ - tests/include/test-qapi-types-sub-module.o \ - tests/test-qapi-types-sub-sub-module.o \ - tests/test-qapi-visit.o \ - tests/include/test-qapi-visit-sub-module.o \ - tests/test-qapi-visit-sub-sub-module.o \ - tests/test-qapi-introspect.o \ - $(test-qom-obj-y) -benchmark-crypto-obj-$(CONFIG_BLOCK) = $(authz-obj-y) $(crypto-obj-y) $(test-qom-obj-y) -test-crypto-obj-$(CONFIG_BLOCK) = $(authz-obj-y) $(crypto-obj-y) $(test-qom-obj-y) -test-io-obj-$(CONFIG_BLOCK) = $(io-obj-y) $(test-crypto-obj-y) -test-authz-obj-$(CONFIG_BLOCK) = $(test-qom-obj-y) $(authz-obj-y) -test-block-obj-$(CONFIG_BLOCK) = $(block-obj-y) $(test-io-obj-y) tests/iothread.o - -tests/check-qnum$(EXESUF): tests/check-qnum.o $(test-util-obj-y) -tests/check-qstring$(EXESUF): tests/check-qstring.o $(test-util-obj-y) -tests/check-qdict$(EXESUF): tests/check-qdict.o $(test-util-obj-y) -tests/check-block-qdict$(EXESUF): tests/check-block-qdict.o $(test-util-obj-y) -tests/check-qlist$(EXESUF): tests/check-qlist.o $(test-util-obj-y) -tests/check-qnull$(EXESUF): tests/check-qnull.o $(test-util-obj-y) -tests/check-qobject$(EXESUF): tests/check-qobject.o $(test-util-obj-y) -tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) -tests/check-qlit$(EXESUF): tests/check-qlit.o $(test-util-obj-y) -tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y) -tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y) - -tests/test-char$(EXESUF): tests/test-char.o $(test-util-obj-y) $(test-io-obj-y) $(chardev-obj-y) tests/socket-helpers.o -tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y) -tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y) -tests/test-aio-multithread$(EXESUF): tests/test-aio-multithread.o $(test-block-obj-y) -tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y) -tests/test-bdrv-drain$(EXESUF): tests/test-bdrv-drain.o $(test-block-obj-y) $(test-util-obj-y) -tests/test-bdrv-graph-mod$(EXESUF): tests/test-bdrv-graph-mod.o $(test-block-obj-y) $(test-util-obj-y) -tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(test-block-obj-y) $(test-util-obj-y) -tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-obj-y) $(test-util-obj-y) -tests/test-block-backend$(EXESUF): tests/test-block-backend.o $(test-block-obj-y) $(test-util-obj-y) -tests/test-block-iothread$(EXESUF): tests/test-block-iothread.o $(test-block-obj-y) $(test-util-obj-y) -tests/test-image-locking$(EXESUF): tests/test-image-locking.o $(test-block-obj-y) $(test-util-obj-y) -tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj-y) -tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y) -tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) $(test-crypto-obj-y) -tests/test-bitmap$(EXESUF): tests/test-bitmap.o $(test-util-obj-y) -tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o -tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/libmigration.fa $(test-util-obj-y) \ - $(test-io-obj-y) -tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o $(test-util-obj-y) -tests/test-int128$(EXESUF): tests/test-int128.o -tests/rcutorture$(EXESUF): tests/rcutorture.o $(test-util-obj-y) -tests/test-rcu-list$(EXESUF): tests/test-rcu-list.o $(test-util-obj-y) -tests/test-rcu-simpleq$(EXESUF): tests/test-rcu-simpleq.o $(test-util-obj-y) -tests/test-rcu-tailq$(EXESUF): tests/test-rcu-tailq.o $(test-util-obj-y) -tests/test-rcu-slist$(EXESUF): tests/test-rcu-slist.o $(test-util-obj-y) -tests/test-qdist$(EXESUF): tests/test-qdist.o $(test-util-obj-y) -tests/test-qht$(EXESUF): tests/test-qht.o $(test-util-obj-y) -tests/test-qht-par$(EXESUF): tests/test-qht-par.o tests/qht-bench$(EXESUF) $(test-util-obj-y) -tests/qht-bench$(EXESUF): tests/qht-bench.o $(test-util-obj-y) -tests/test-bufferiszero$(EXESUF): tests/test-bufferiszero.o $(test-util-obj-y) -tests/atomic_add-bench$(EXESUF): tests/atomic_add-bench.o $(test-util-obj-y) -tests/atomic64-bench$(EXESUF): tests/atomic64-bench.o $(test-util-obj-y) - -tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o hw/core/libhwcore.fa \ - $(test-qapi-obj-y) -tests/test-vmstate$(EXESUF): tests/test-vmstate.o migration/libmigration.fa \ - $(test-io-obj-y) -tests/test-timed-average$(EXESUF): tests/test-timed-average.o $(test-util-obj-y) -tests/test-base64$(EXESUF): tests/test-base64.o $(test-util-obj-y) -tests/ptimer-test$(EXESUF): tests/ptimer-test.o tests/ptimer-test-stubs.o hw/core/ptimer.o -tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) -tests/test-keyval$(EXESUF): tests/test-keyval.o $(test-util-obj-y) $(test-qapi-obj-y) -tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y) -tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) -tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y) - -tests/test-logging$(EXESUF): tests/test-logging.o $(test-util-obj-y) - -tests/test-replication$(EXESUF): tests/test-replication.o $(test-util-obj-y) \ - $(test-block-obj-y) - -tests/test-qapi-types.c tests/test-qapi-types.h \ -tests/include/test-qapi-types-sub-module.c \ -tests/include/test-qapi-types-sub-module.h \ -tests/test-qapi-types-sub-sub-module.c \ -tests/test-qapi-types-sub-sub-module.h \ -tests/test-qapi-visit.c tests/test-qapi-visit.h \ -tests/include/test-qapi-visit-sub-module.c \ -tests/include/test-qapi-visit-sub-module.h \ -tests/test-qapi-visit-sub-sub-module.c \ -tests/test-qapi-visit-sub-sub-module.h \ -tests/test-qapi-commands.h tests/test-qapi-commands.c \ -tests/include/test-qapi-commands-sub-module.h \ -tests/include/test-qapi-commands-sub-module.c \ -tests/test-qapi-commands-sub-sub-module.h \ -tests/test-qapi-commands-sub-sub-module.c \ -tests/test-qapi-emit-events.c tests/test-qapi-emit-events.h \ -tests/test-qapi-events.c tests/test-qapi-events.h \ -tests/test-qapi-init-commands.c \ -tests/test-qapi-init-commands.h \ -tests/include/test-qapi-events-sub-module.c \ -tests/include/test-qapi-events-sub-module.h \ -tests/test-qapi-events-sub-sub-module.c \ -tests/test-qapi-events-sub-sub-module.h \ -tests/test-qapi-introspect.c tests/test-qapi-introspect.h: \ -tests/test-qapi-gen-timestamp ; -tests/test-qapi-gen-timestamp: \ - $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json \ - $(SRC_PATH)/tests/qapi-schema/include/sub-module.json \ - $(SRC_PATH)/tests/qapi-schema/sub-sub-module.json \ - $(qapi-py) - $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-gen.py \ - -o tests -p "test-" $<, \ - "GEN","$(@:%-timestamp=%)") - @rm -f tests/test-qapi-doc.texi - @>$@ - -tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y) -tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(test-qapi-obj-y) -tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) tests/test-qapi-emit-events.o tests/test-qapi-events.o -tests/test-qobject-output-visitor$(EXESUF): tests/test-qobject-output-visitor.o $(test-qapi-obj-y) -tests/test-clone-visitor$(EXESUF): tests/test-clone-visitor.o $(test-qapi-obj-y) -tests/test-qobject-input-visitor$(EXESUF): tests/test-qobject-input-visitor.o $(test-qapi-obj-y) -tests/test-qmp-cmds$(EXESUF): tests/test-qmp-cmds.o tests/test-qapi-commands.o tests/test-qapi-init-commands.o $(test-qapi-obj-y) -tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) -tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y) - -tests/test-shift128$(EXESUF): tests/test-shift128.o $(test-util-obj-y) -tests/test-mul64$(EXESUF): tests/test-mul64.o $(test-util-obj-y) -tests/test-bitops$(EXESUF): tests/test-bitops.o $(test-util-obj-y) -tests/test-bitcnt$(EXESUF): tests/test-bitcnt.o $(test-util-obj-y) -tests/test-qgraph$(EXESUF): tests/test-qgraph.o tests/qtest/libqos/qgraph.o $(test-util-obj-y) -tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-crypto-obj-y) -tests/benchmark-crypto-hash$(EXESUF): tests/benchmark-crypto-hash.o $(test-crypto-obj-y) -tests/test-crypto-hmac$(EXESUF): tests/test-crypto-hmac.o $(test-crypto-obj-y) -tests/benchmark-crypto-hmac$(EXESUF): tests/benchmark-crypto-hmac.o $(test-crypto-obj-y) -tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o $(test-crypto-obj-y) -tests/benchmark-crypto-cipher$(EXESUF): tests/benchmark-crypto-cipher.o $(test-crypto-obj-y) -tests/test-crypto-secret$(EXESUF): tests/test-crypto-secret.o $(test-crypto-obj-y) -tests/test-crypto-xts$(EXESUF): tests/test-crypto-xts.o $(test-crypto-obj-y) - -ifeq ($(CONFIG_TEST_SECRET_KEYRING),y) -tests/test-crypto-secret.o-libs := -lkeyutils -endif - -tests/crypto-tls-x509-helpers.o-cflags := $(TASN1_CFLAGS) -tests/crypto-tls-x509-helpers.o-libs := $(TASN1_LIBS) -tests/pkix_asn1_tab.o-cflags := $(TASN1_CFLAGS) - -tests/test-crypto-tlscredsx509.o-cflags := $(TASN1_CFLAGS) -tests/test-crypto-tlscredsx509$(EXESUF): tests/test-crypto-tlscredsx509.o \ - tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o $(test-crypto-obj-y) - -tests/test-crypto-tlssession.o-cflags := $(TASN1_CFLAGS) -tests/test-crypto-tlssession$(EXESUF): tests/test-crypto-tlssession.o \ - tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o \ - tests/crypto-tls-psk-helpers.o \ - $(test-crypto-obj-y) -tests/test-util-filemonitor$(EXESUF): tests/test-util-filemonitor.o \ - $(test-util-obj-y) -tests/test-util-sockets$(EXESUF): tests/test-util-sockets.o \ - tests/socket-helpers.o $(test-util-obj-y) -tests/test-authz-simple$(EXESUF): tests/test-authz-simple.o $(test-authz-obj-y) -tests/test-authz-list$(EXESUF): tests/test-authz-list.o $(test-authz-obj-y) -tests/test-authz-listfile$(EXESUF): tests/test-authz-listfile.o $(test-authz-obj-y) -tests/test-authz-pam$(EXESUF): tests/test-authz-pam.o $(test-authz-obj-y) -tests/test-io-task$(EXESUF): tests/test-io-task.o $(test-io-obj-y) -tests/test-io-channel-socket$(EXESUF): tests/test-io-channel-socket.o \ - tests/io-channel-helpers.o tests/socket-helpers.o $(test-io-obj-y) -tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \ - tests/io-channel-helpers.o $(test-io-obj-y) -tests/test-io-channel-tls$(EXESUF): tests/test-io-channel-tls.o \ - tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o \ - tests/io-channel-helpers.o $(test-io-obj-y) -tests/test-io-channel-command$(EXESUF): tests/test-io-channel-command.o \ - tests/io-channel-helpers.o $(test-io-obj-y) -tests/test-io-channel-buffer$(EXESUF): tests/test-io-channel-buffer.o \ - tests/io-channel-helpers.o $(test-io-obj-y) -tests/test-crypto-pbkdf$(EXESUF): tests/test-crypto-pbkdf.o $(test-crypto-obj-y) -tests/test-crypto-ivgen$(EXESUF): tests/test-crypto-ivgen.o $(test-crypto-obj-y) -tests/test-crypto-afsplit$(EXESUF): tests/test-crypto-afsplit.o $(test-crypto-obj-y) -tests/test-crypto-block$(EXESUF): tests/test-crypto-block.o $(test-crypto-obj-y) - -tests/migration/stress$(EXESUF): tests/migration/stress.o - $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@") - -INITRD_WORK_DIR=tests/migration/initrd - -tests/migration/initrd-stress.img: tests/migration/stress$(EXESUF) - mkdir -p $(INITRD_WORK_DIR) - cp $< $(INITRD_WORK_DIR)/init - (cd $(INITRD_WORK_DIR) && (find | cpio --quiet -o -H newc | gzip -9)) > $@ - rm $(INITRD_WORK_DIR)/init - rmdir $(INITRD_WORK_DIR) - -tests/test-qga$(EXESUF): qga/qemu-ga$(EXESUF) -tests/test-qga$(EXESUF): tests/test-qga.o tests/qtest/libqtest.o $(test-util-obj-y) -tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o $(test-util-obj-y) libvhost-user.a -tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o - -SPEED = quick - -# gtester tests, possibly with verbose output -# do_test_tap runs all tests, even if some of them fail, while do_test_human -# stops at the first failure unless -k is given on the command line - -define do_test_human_k - $(quiet-@)rc=0; $(foreach COMMAND, $1, \ - $(call quiet-command-run, \ - export MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} $2; \ - $(COMMAND) -m=$(SPEED) -k --tap < /dev/null \ - | ./scripts/tap-driver.pl --test-name="$(notdir $(COMMAND))" $(if $(V),, --show-failures-only) \ - || rc=$$?;, "TEST", "$@: $(COMMAND)")) exit $$rc -endef -define do_test_human_no_k - $(foreach COMMAND, $1, \ - $(call quiet-command, \ - MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} $2 \ - $(COMMAND) -m=$(SPEED) -k --tap < /dev/null \ - | ./scripts/tap-driver.pl --test-name="$(notdir $(COMMAND))" $(if $(V),, --show-failures-only), \ - "TEST", "$@: $(COMMAND)") -) -endef -do_test_human = \ - $(if $(findstring k, $(MAKEFLAGS)), $(do_test_human_k), $(do_test_human_no_k)) - -define do_test_tap - $(call quiet-command, \ - { export MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} $2; \ - $(foreach COMMAND, $1, \ - $(COMMAND) -m=$(SPEED) -k --tap < /dev/null \ - | sed "s/^\(not \)\?ok [0-9]* /&$(notdir $(COMMAND)) /" || true; ) } \ - | ./scripts/tap-merge.pl | tee "$@" \ - | ./scripts/tap-driver.pl $(if $(V),, --show-failures-only), \ - "TAP","$@") -endef - -build-unit: $(check-unit-y) - -check-unit: $(check-unit-y) - $(call do_test_human, $^) - -check-speed: $(check-speed-y) - $(call do_test_human, $^) - -# gtester tests with TAP output - -check-report-unit.tap: $(check-unit-y) - $(call do_test_tap,$^) - -# Per guest TCG tests - -BUILD_TCG_TARGET_RULES=$(patsubst %,build-tcg-tests-%, $(TARGET_DIRS)) -CLEAN_TCG_TARGET_RULES=$(patsubst %,clean-tcg-tests-%, $(TARGET_DIRS)) -RUN_TCG_TARGET_RULES=$(patsubst %,run-tcg-tests-%, $(TARGET_DIRS)) - -# Probe for the Docker Builds needed for each build -$(foreach PROBE_TARGET,$(TARGET_DIRS), \ - $(eval -include $(SRC_PATH)/tests/tcg/Makefile.prereqs)) - -build-tcg-tests-%: $(if $(CONFIG_PLUGIN),plugins) - $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) \ - -f $(SRC_PATH)/tests/tcg/Makefile.qemu \ - SRC_PATH=$(SRC_PATH) \ - V="$(V)" TARGET="$*" guest-tests, \ - "BUILD", "TCG tests for $*") - -run-tcg-tests-%: build-tcg-tests-% all - $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) \ - -f $(SRC_PATH)/tests/tcg/Makefile.qemu \ - SRC_PATH=$(SRC_PATH) SPEED="$(SPEED)" \ - V="$(V)" TARGET="$*" run-guest-tests, \ - "RUN", "TCG tests for $*") - -clean-tcg-tests-%: - $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) \ - -f $(SRC_PATH)/tests/tcg/Makefile.qemu \ - SRC_PATH=$(SRC_PATH) TARGET="$*" clean-guest-tests, \ - "CLEAN", "TCG tests for $*") - -.PHONY: build-tcg -build-tcg: $(BUILD_TCG_TARGET_RULES) - -.PHONY: check-tcg -check-tcg: $(RUN_TCG_TARGET_RULES) - -.PHONY: clean-tcg -clean-tcg: $(CLEAN_TCG_TARGET_RULES) - - -# Python venv for running tests - -.PHONY: check-venv check-acceptance - -TESTS_VENV_DIR=$(BUILD_DIR)/tests/venv -TESTS_VENV_REQ=$(SRC_PATH)/tests/requirements.txt -TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/results -# Controls the output generated by Avocado when running tests. -# Any number of command separated loggers are accepted. For more -# information please refer to "avocado --help". -AVOCADO_SHOW=app -AVOCADO_TAGS=$(patsubst %-softmmu,-t arch:%, $(filter %-softmmu,$(TARGET_DIRS))) - -$(TESTS_VENV_DIR): $(TESTS_VENV_REQ) - $(call quiet-command, \ - $(PYTHON) -m venv --system-site-packages $@, \ - VENV, $@) - $(call quiet-command, \ - $(TESTS_VENV_DIR)/bin/python -m pip -q install -r $(TESTS_VENV_REQ), \ - PIP, $(TESTS_VENV_REQ)) - $(call quiet-command, touch $@) - -$(TESTS_RESULTS_DIR): - $(call quiet-command, mkdir -p $@, \ - MKDIR, $@) - -check-venv: $(TESTS_VENV_DIR) - -FEDORA_31_ARCHES_CANDIDATES=$(patsubst ppc64,ppc64le,$(TARGETS)) -FEDORA_31_ARCHES := x86_64 aarch64 ppc64le s390x -FEDORA_31_DOWNLOAD=$(filter $(FEDORA_31_ARCHES),$(FEDORA_31_ARCHES_CANDIDATES)) - -# download one specific Fedora 31 image -get-vm-image-fedora-31-%: check-venv - $(call quiet-command, \ - $(TESTS_VENV_DIR)/bin/python -m avocado vmimage get \ - --distro=fedora --distro-version=31 --arch=$*, \ - "AVOCADO", "Downloading acceptance tests VM image for $*") - -# download all vm images, according to defined targets -get-vm-images: check-venv $(patsubst %,get-vm-image-fedora-31-%, $(FEDORA_31_DOWNLOAD)) - -check-acceptance: check-venv $(TESTS_RESULTS_DIR) get-vm-images - $(call quiet-command, \ - $(TESTS_VENV_DIR)/bin/python -m avocado \ - --show=$(AVOCADO_SHOW) run --job-results-dir=$(TESTS_RESULTS_DIR) \ - --filter-by-tags-include-empty --filter-by-tags-include-empty-key \ - $(AVOCADO_TAGS) \ - $(if $(GITLAB_CI),,--failfast=on) tests/acceptance, \ - "AVOCADO", "tests/acceptance") - -# Consolidated targets - -.PHONY: check-block check-unit check check-clean get-vm-images -check-block: -check-build: build-unit - -check-clean: - rm -rf $(check-unit-y) tests/*.o tests/*/*.o $(QEMU_IOTESTS_HELPERS-y) - rm -f tests/test-qapi-gen-timestamp - rm -rf $(TESTS_VENV_DIR) $(TESTS_RESULTS_DIR) - -check: check-unit - -clean: check-clean - -# Build the help program automatically - --include $(wildcard tests/*.d) - -endif +# -*- Mode: makefile -*- + +.PHONY: check-help +check-help: + @echo "Regression testing targets:" + @echo + @echo " $(MAKE) check Run block, qapi-schema, unit, softfloat, qtest and decodetree tests" + @echo + @echo " $(MAKE) check-qtest-TARGET Run qtest tests for given target" + @echo " $(MAKE) check-qtest Run qtest tests" + @echo " $(MAKE) check-unit Run qobject tests" + @echo " $(MAKE) check-speed Run qobject speed tests" + @echo " $(MAKE) check-qapi-schema Run QAPI schema tests" + @echo " $(MAKE) check-block Run block tests" +ifeq ($(CONFIG_TCG),y) + @echo " $(MAKE) check-tcg Run TCG tests" + @echo " $(MAKE) check-softfloat Run FPU emulation tests" +endif + @echo " $(MAKE) check-acceptance Run all acceptance (functional) tests" + @echo + @echo " $(MAKE) check-report.tap Generates an aggregated TAP test report" + @echo " $(MAKE) check-venv Creates a Python venv for tests" + @echo " $(MAKE) check-clean Clean the tests and related data" + @echo + @echo "The following are useful for CI builds" + @echo " $(MAKE) check-build Build most test binaris" + @echo " $(MAKE) get-vm-images Downloads all images used by acceptance tests, according to configured targets (~350 MB each, 1.5 GB max)" + @echo + @echo + @echo "The variable SPEED can be set to control the gtester speed setting." + @echo "Default options are -k and (for $(MAKE) V=1) --verbose; they can be" + @echo "changed with variable GTESTER_OPTIONS." + +ifneq ($(wildcard config-host.mak),) +export SRC_PATH + +# TODO don't duplicate $(SRC_PATH)/Makefile's qapi-py here +qapi-py = $(SRC_PATH)/scripts/qapi/__init__.py \ +$(SRC_PATH)/scripts/qapi/commands.py \ +$(SRC_PATH)/scripts/qapi/common.py \ +$(SRC_PATH)/scripts/qapi/doc.py \ +$(SRC_PATH)/scripts/qapi/error.py \ +$(SRC_PATH)/scripts/qapi/events.py \ +$(SRC_PATH)/scripts/qapi/expr.py \ +$(SRC_PATH)/scripts/qapi/gen.py \ +$(SRC_PATH)/scripts/qapi/introspect.py \ +$(SRC_PATH)/scripts/qapi/parser.py \ +$(SRC_PATH)/scripts/qapi/schema.py \ +$(SRC_PATH)/scripts/qapi/source.py \ +$(SRC_PATH)/scripts/qapi/types.py \ +$(SRC_PATH)/scripts/qapi/visit.py \ +$(SRC_PATH)/scripts/qapi-gen.py + +# Get the list of all supported sysemu targets +SYSEMU_TARGET_LIST := $(subst -softmmu.mak,,$(notdir \ + $(wildcard $(SRC_PATH)/default-configs/*-softmmu.mak))) + +check-unit-y += tests/check-qdict$(EXESUF) +check-unit-y += tests/check-block-qdict$(EXESUF) +check-unit-y += tests/check-qnum$(EXESUF) +check-unit-y += tests/check-qstring$(EXESUF) +check-unit-y += tests/check-qlist$(EXESUF) +check-unit-y += tests/check-qnull$(EXESUF) +check-unit-y += tests/check-qobject$(EXESUF) +check-unit-y += tests/check-qjson$(EXESUF) +check-unit-y += tests/check-qlit$(EXESUF) +check-unit-y += tests/test-qobject-output-visitor$(EXESUF) +check-unit-y += tests/test-clone-visitor$(EXESUF) +check-unit-y += tests/test-qobject-input-visitor$(EXESUF) +check-unit-$(CONFIG_SOFTMMU) += tests/test-qmp-cmds$(EXESUF) +check-unit-y += tests/test-string-input-visitor$(EXESUF) +check-unit-y += tests/test-string-output-visitor$(EXESUF) +check-unit-y += tests/test-qmp-event$(EXESUF) +check-unit-y += tests/test-opts-visitor$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-coroutine$(EXESUF) +check-unit-y += tests/test-visitor-serialization$(EXESUF) +check-unit-$(CONFIG_SOFTMMU) += tests/test-iov$(EXESUF) +check-unit-y += tests/test-bitmap$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-aio$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-aio-multithread$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-throttle$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-thread-pool$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-hbitmap$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-bdrv-drain$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-bdrv-graph-mod$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-blockjob$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-blockjob-txn$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-block-backend$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-block-iothread$(EXESUF) +ifeq ($(CONFIG_POSIX),y) +check-unit-$(CONFIG_BLOCK) += tests/test-image-locking$(EXESUF) +endif +check-unit-y += tests/test-x86-cpuid$(EXESUF) +# all code tested by test-x86-cpuid is inside topology.h +ifeq ($(CONFIG_SOFTMMU),y) +check-unit-y += tests/test-xbzrle$(EXESUF) +check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF) +endif +check-unit-y += tests/test-cutils$(EXESUF) +check-unit-y += tests/test-shift128$(EXESUF) +check-unit-y += tests/test-mul64$(EXESUF) +check-unit-y += tests/test-int128$(EXESUF) +# all code tested by test-int128 is inside int128.h +check-unit-y += tests/rcutorture$(EXESUF) +check-unit-y += tests/test-rcu-list$(EXESUF) +check-unit-y += tests/test-rcu-simpleq$(EXESUF) +check-unit-y += tests/test-rcu-tailq$(EXESUF) +check-unit-y += tests/test-rcu-slist$(EXESUF) +check-unit-y += tests/test-qdist$(EXESUF) +check-unit-y += tests/test-qht$(EXESUF) +check-unit-y += tests/test-qht-par$(EXESUF) +check-unit-y += tests/test-bitops$(EXESUF) +check-unit-y += tests/test-bitcnt$(EXESUF) +check-unit-y += tests/test-qgraph$(EXESUF) +check-unit-y += tests/check-qom-interface$(EXESUF) +check-unit-y += tests/check-qom-proplist$(EXESUF) +check-unit-y += tests/test-qemu-opts$(EXESUF) +check-unit-y += tests/test-keyval$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-write-threshold$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-crypto-hash$(EXESUF) +check-speed-$(CONFIG_BLOCK) += tests/benchmark-crypto-hash$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-crypto-hmac$(EXESUF) +check-speed-$(CONFIG_BLOCK) += tests/benchmark-crypto-hmac$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-crypto-cipher$(EXESUF) +check-speed-$(CONFIG_BLOCK) += tests/benchmark-crypto-cipher$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-crypto-secret$(EXESUF) +check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) += tests/test-crypto-tlscredsx509$(EXESUF) +check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) += tests/test-crypto-tlssession$(EXESUF) +ifndef CONFIG_TSAN +# Some tests: test-char, test-qdev-global-props, and test-qga, +# are not runnable under TSan due to a known issue. +# https://github.com/google/sanitizers/issues/1116 +check-unit-$(CONFIG_SOFTMMU) += tests/test-char$(EXESUF) +check-unit-$(CONFIG_SOFTMMU) += tests/test-qdev-global-props$(EXESUF) +ifeq ($(CONFIG_GUEST_AGENT),y) +check-unit-$(call land,$(CONFIG_LINUX),$(CONFIG_VIRTIO_SERIAL)) += tests/test-qga$(EXESUF) +endif +endif +check-unit-$(CONFIG_SOFTMMU) += tests/test-timed-average$(EXESUF) +check-unit-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_INOTIFY1)) += tests/test-util-filemonitor$(EXESUF) +check-unit-$(CONFIG_SOFTMMU) += tests/test-util-sockets$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-authz-simple$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-authz-list$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-authz-listfile$(EXESUF) +check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_AUTH_PAM)) += tests/test-authz-pam$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-io-task$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-io-channel-socket$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-io-channel-file$(EXESUF) +check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_GNUTLS)) += tests/test-io-channel-tls$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-io-channel-command$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-io-channel-buffer$(EXESUF) +check-unit-$(CONFIG_SOFTMMU) += tests/test-base64$(EXESUF) +check-unit-$(call land,$(CONFIG_BLOCK),$(if $(CONFIG_NETTLE),y,$(CONFIG_GCRYPT))) += tests/test-crypto-pbkdf$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-crypto-ivgen$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-crypto-afsplit$(EXESUF) +check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_QEMU_PRIVATE_XTS)) += tests/test-crypto-xts$(EXESUF) +check-unit-$(CONFIG_BLOCK) += tests/test-crypto-block$(EXESUF) +check-unit-y += tests/test-logging$(EXESUF) +check-unit-$(call land,$(CONFIG_BLOCK),$(CONFIG_REPLICATION)) += tests/test-replication$(EXESUF) +check-unit-$(CONFIG_SOFTMMU) += tests/test-bufferiszero$(EXESUF) +check-unit-y += tests/test-uuid$(EXESUF) +check-unit-y += tests/ptimer-test$(EXESUF) +check-unit-y += tests/test-qapi-util$(EXESUF) + +generated-files-y += tests/test-qapi-types.h +generated-files-y += tests/include/test-qapi-types-sub-module.h +generated-files-y += tests/test-qapi-types-sub-sub-module.h +generated-files-y += tests/test-qapi-visit.h +generated-files-y += tests/include/test-qapi-visit-sub-module.h +generated-files-y += tests/test-qapi-visit-sub-sub-module.h +generated-files-y += tests/test-qapi-commands.h +generated-files-y += tests/test-qapi-init-commands.h +generated-files-y += tests/include/test-qapi-commands-sub-module.h +generated-files-y += tests/test-qapi-commands-sub-sub-module.h +generated-files-y += tests/test-qapi-emit-events.h +generated-files-y += tests/test-qapi-events.h +generated-files-y += tests/include/test-qapi-events-sub-module.h +generated-files-y += tests/test-qapi-events-sub-sub-module.h +generated-files-y += tests/test-qapi-introspect.h + +QEMU_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest + + +# Deps that are common to various different sets of tests below +test-util-obj-y = libqemuutil.a +test-qom-obj-y = $(qom-obj-y) $(test-util-obj-y) +test-qapi-obj-y = tests/test-qapi-types.o \ + tests/include/test-qapi-types-sub-module.o \ + tests/test-qapi-types-sub-sub-module.o \ + tests/test-qapi-visit.o \ + tests/include/test-qapi-visit-sub-module.o \ + tests/test-qapi-visit-sub-sub-module.o \ + tests/test-qapi-introspect.o \ + $(test-qom-obj-y) +benchmark-crypto-obj-$(CONFIG_BLOCK) = $(authz-obj-y) $(crypto-obj-y) $(test-qom-obj-y) +test-crypto-obj-$(CONFIG_BLOCK) = $(authz-obj-y) $(crypto-obj-y) $(test-qom-obj-y) +test-io-obj-$(CONFIG_BLOCK) = $(io-obj-y) $(test-crypto-obj-y) +test-authz-obj-$(CONFIG_BLOCK) = $(test-qom-obj-y) $(authz-obj-y) +test-block-obj-$(CONFIG_BLOCK) = $(block-obj-y) $(test-io-obj-y) tests/iothread.o + +tests/check-qnum$(EXESUF): tests/check-qnum.o $(test-util-obj-y) +tests/check-qstring$(EXESUF): tests/check-qstring.o $(test-util-obj-y) +tests/check-qdict$(EXESUF): tests/check-qdict.o $(test-util-obj-y) +tests/check-block-qdict$(EXESUF): tests/check-block-qdict.o $(test-util-obj-y) +tests/check-qlist$(EXESUF): tests/check-qlist.o $(test-util-obj-y) +tests/check-qnull$(EXESUF): tests/check-qnull.o $(test-util-obj-y) +tests/check-qobject$(EXESUF): tests/check-qobject.o $(test-util-obj-y) +tests/check-qjson$(EXESUF): tests/check-qjson.o $(test-util-obj-y) +tests/check-qlit$(EXESUF): tests/check-qlit.o $(test-util-obj-y) +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom-obj-y) +tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-obj-y) + +tests/test-char$(EXESUF): tests/test-char.o $(test-util-obj-y) $(test-io-obj-y) $(chardev-obj-y) tests/socket-helpers.o +tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y) +tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y) +tests/test-aio-multithread$(EXESUF): tests/test-aio-multithread.o $(test-block-obj-y) +tests/test-throttle$(EXESUF): tests/test-throttle.o $(test-block-obj-y) +tests/test-bdrv-drain$(EXESUF): tests/test-bdrv-drain.o $(test-block-obj-y) $(test-util-obj-y) +tests/test-bdrv-graph-mod$(EXESUF): tests/test-bdrv-graph-mod.o $(test-block-obj-y) $(test-util-obj-y) +tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(test-block-obj-y) $(test-util-obj-y) +tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-obj-y) $(test-util-obj-y) +tests/test-block-backend$(EXESUF): tests/test-block-backend.o $(test-block-obj-y) $(test-util-obj-y) +tests/test-block-iothread$(EXESUF): tests/test-block-iothread.o $(test-block-obj-y) $(test-util-obj-y) +tests/test-image-locking$(EXESUF): tests/test-image-locking.o $(test-block-obj-y) $(test-util-obj-y) +tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj-y) +tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y) +tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) $(test-crypto-obj-y) +tests/test-bitmap$(EXESUF): tests/test-bitmap.o $(test-util-obj-y) +tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o +tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/libmigration.fa $(test-util-obj-y) \ + $(test-io-obj-y) +tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o $(test-util-obj-y) +tests/test-int128$(EXESUF): tests/test-int128.o +tests/rcutorture$(EXESUF): tests/rcutorture.o $(test-util-obj-y) +tests/test-rcu-list$(EXESUF): tests/test-rcu-list.o $(test-util-obj-y) +tests/test-rcu-simpleq$(EXESUF): tests/test-rcu-simpleq.o $(test-util-obj-y) +tests/test-rcu-tailq$(EXESUF): tests/test-rcu-tailq.o $(test-util-obj-y) +tests/test-rcu-slist$(EXESUF): tests/test-rcu-slist.o $(test-util-obj-y) +tests/test-qdist$(EXESUF): tests/test-qdist.o $(test-util-obj-y) +tests/test-qht$(EXESUF): tests/test-qht.o $(test-util-obj-y) +tests/test-qht-par$(EXESUF): tests/test-qht-par.o tests/qht-bench$(EXESUF) $(test-util-obj-y) +tests/qht-bench$(EXESUF): tests/qht-bench.o $(test-util-obj-y) +tests/test-bufferiszero$(EXESUF): tests/test-bufferiszero.o $(test-util-obj-y) +tests/atomic_add-bench$(EXESUF): tests/atomic_add-bench.o $(test-util-obj-y) +tests/atomic64-bench$(EXESUF): tests/atomic64-bench.o $(test-util-obj-y) + +tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o hw/core/libhwcore.fa \ + $(test-qapi-obj-y) +tests/test-vmstate$(EXESUF): tests/test-vmstate.o migration/libmigration.fa \ + $(test-io-obj-y) +tests/test-timed-average$(EXESUF): tests/test-timed-average.o $(test-util-obj-y) +tests/test-base64$(EXESUF): tests/test-base64.o $(test-util-obj-y) +tests/ptimer-test$(EXESUF): tests/ptimer-test.o tests/ptimer-test-stubs.o hw/core/ptimer.o +tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) +tests/test-keyval$(EXESUF): tests/test-keyval.o $(test-util-obj-y) $(test-qapi-obj-y) +tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-obj-y) +tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y) +tests/test-qapi-util$(EXESUF): tests/test-qapi-util.o $(test-util-obj-y) + +tests/test-logging$(EXESUF): tests/test-logging.o $(test-util-obj-y) + +tests/test-replication$(EXESUF): tests/test-replication.o $(test-util-obj-y) \ + $(test-block-obj-y) + +tests/test-qapi-types.c tests/test-qapi-types.h \ +tests/include/test-qapi-types-sub-module.c \ +tests/include/test-qapi-types-sub-module.h \ +tests/test-qapi-types-sub-sub-module.c \ +tests/test-qapi-types-sub-sub-module.h \ +tests/test-qapi-visit.c tests/test-qapi-visit.h \ +tests/include/test-qapi-visit-sub-module.c \ +tests/include/test-qapi-visit-sub-module.h \ +tests/test-qapi-visit-sub-sub-module.c \ +tests/test-qapi-visit-sub-sub-module.h \ +tests/test-qapi-commands.h tests/test-qapi-commands.c \ +tests/include/test-qapi-commands-sub-module.h \ +tests/include/test-qapi-commands-sub-module.c \ +tests/test-qapi-commands-sub-sub-module.h \ +tests/test-qapi-commands-sub-sub-module.c \ +tests/test-qapi-emit-events.c tests/test-qapi-emit-events.h \ +tests/test-qapi-events.c tests/test-qapi-events.h \ +tests/test-qapi-init-commands.c \ +tests/test-qapi-init-commands.h \ +tests/include/test-qapi-events-sub-module.c \ +tests/include/test-qapi-events-sub-module.h \ +tests/test-qapi-events-sub-sub-module.c \ +tests/test-qapi-events-sub-sub-module.h \ +tests/test-qapi-introspect.c tests/test-qapi-introspect.h: \ +tests/test-qapi-gen-timestamp ; +tests/test-qapi-gen-timestamp: \ + $(SRC_PATH)/tests/qapi-schema/qapi-schema-test.json \ + $(SRC_PATH)/tests/qapi-schema/include/sub-module.json \ + $(SRC_PATH)/tests/qapi-schema/sub-sub-module.json \ + $(qapi-py) + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-gen.py \ + -o tests -p "test-" $<, \ + "GEN","$(@:%-timestamp=%)") + @rm -f tests/test-qapi-doc.texi + @>$@ + +tests/test-string-output-visitor$(EXESUF): tests/test-string-output-visitor.o $(test-qapi-obj-y) +tests/test-string-input-visitor$(EXESUF): tests/test-string-input-visitor.o $(test-qapi-obj-y) +tests/test-qmp-event$(EXESUF): tests/test-qmp-event.o $(test-qapi-obj-y) tests/test-qapi-emit-events.o tests/test-qapi-events.o +tests/test-qobject-output-visitor$(EXESUF): tests/test-qobject-output-visitor.o $(test-qapi-obj-y) +tests/test-clone-visitor$(EXESUF): tests/test-clone-visitor.o $(test-qapi-obj-y) +tests/test-qobject-input-visitor$(EXESUF): tests/test-qobject-input-visitor.o $(test-qapi-obj-y) +tests/test-qmp-cmds$(EXESUF): tests/test-qmp-cmds.o tests/test-qapi-commands.o tests/test-qapi-init-commands.o $(test-qapi-obj-y) +tests/test-visitor-serialization$(EXESUF): tests/test-visitor-serialization.o $(test-qapi-obj-y) +tests/test-opts-visitor$(EXESUF): tests/test-opts-visitor.o $(test-qapi-obj-y) + +tests/test-shift128$(EXESUF): tests/test-shift128.o $(test-util-obj-y) +tests/test-mul64$(EXESUF): tests/test-mul64.o $(test-util-obj-y) +tests/test-bitops$(EXESUF): tests/test-bitops.o $(test-util-obj-y) +tests/test-bitcnt$(EXESUF): tests/test-bitcnt.o $(test-util-obj-y) +tests/test-qgraph$(EXESUF): tests/test-qgraph.o tests/qtest/libqos/qgraph.o $(test-util-obj-y) +tests/test-crypto-hash$(EXESUF): tests/test-crypto-hash.o $(test-crypto-obj-y) +tests/benchmark-crypto-hash$(EXESUF): tests/benchmark-crypto-hash.o $(test-crypto-obj-y) +tests/test-crypto-hmac$(EXESUF): tests/test-crypto-hmac.o $(test-crypto-obj-y) +tests/benchmark-crypto-hmac$(EXESUF): tests/benchmark-crypto-hmac.o $(test-crypto-obj-y) +tests/test-crypto-cipher$(EXESUF): tests/test-crypto-cipher.o $(test-crypto-obj-y) +tests/benchmark-crypto-cipher$(EXESUF): tests/benchmark-crypto-cipher.o $(test-crypto-obj-y) +tests/test-crypto-secret$(EXESUF): tests/test-crypto-secret.o $(test-crypto-obj-y) +tests/test-crypto-xts$(EXESUF): tests/test-crypto-xts.o $(test-crypto-obj-y) + +ifeq ($(CONFIG_TEST_SECRET_KEYRING),y) +tests/test-crypto-secret.o-libs := -lkeyutils +endif + +tests/crypto-tls-x509-helpers.o-cflags := $(TASN1_CFLAGS) +tests/crypto-tls-x509-helpers.o-libs := $(TASN1_LIBS) +tests/pkix_asn1_tab.o-cflags := $(TASN1_CFLAGS) + +tests/test-crypto-tlscredsx509.o-cflags := $(TASN1_CFLAGS) +tests/test-crypto-tlscredsx509$(EXESUF): tests/test-crypto-tlscredsx509.o \ + tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o $(test-crypto-obj-y) + +tests/test-crypto-tlssession.o-cflags := $(TASN1_CFLAGS) +tests/test-crypto-tlssession$(EXESUF): tests/test-crypto-tlssession.o \ + tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o \ + tests/crypto-tls-psk-helpers.o \ + $(test-crypto-obj-y) +tests/test-util-filemonitor$(EXESUF): tests/test-util-filemonitor.o \ + $(test-util-obj-y) +tests/test-util-sockets$(EXESUF): tests/test-util-sockets.o \ + tests/socket-helpers.o $(test-util-obj-y) +tests/test-authz-simple$(EXESUF): tests/test-authz-simple.o $(test-authz-obj-y) +tests/test-authz-list$(EXESUF): tests/test-authz-list.o $(test-authz-obj-y) +tests/test-authz-listfile$(EXESUF): tests/test-authz-listfile.o $(test-authz-obj-y) +tests/test-authz-pam$(EXESUF): tests/test-authz-pam.o $(test-authz-obj-y) +tests/test-io-task$(EXESUF): tests/test-io-task.o $(test-io-obj-y) +tests/test-io-channel-socket$(EXESUF): tests/test-io-channel-socket.o \ + tests/io-channel-helpers.o tests/socket-helpers.o $(test-io-obj-y) +tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \ + tests/io-channel-helpers.o $(test-io-obj-y) +tests/test-io-channel-tls$(EXESUF): tests/test-io-channel-tls.o \ + tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o \ + tests/io-channel-helpers.o $(test-io-obj-y) +tests/test-io-channel-command$(EXESUF): tests/test-io-channel-command.o \ + tests/io-channel-helpers.o $(test-io-obj-y) +tests/test-io-channel-buffer$(EXESUF): tests/test-io-channel-buffer.o \ + tests/io-channel-helpers.o $(test-io-obj-y) +tests/test-crypto-pbkdf$(EXESUF): tests/test-crypto-pbkdf.o $(test-crypto-obj-y) +tests/test-crypto-ivgen$(EXESUF): tests/test-crypto-ivgen.o $(test-crypto-obj-y) +tests/test-crypto-afsplit$(EXESUF): tests/test-crypto-afsplit.o $(test-crypto-obj-y) +tests/test-crypto-block$(EXESUF): tests/test-crypto-block.o $(test-crypto-obj-y) + +tests/migration/stress$(EXESUF): tests/migration/stress.o + $(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"LINK","$(TARGET_DIR)$@") + +INITRD_WORK_DIR=tests/migration/initrd + +tests/migration/initrd-stress.img: tests/migration/stress$(EXESUF) + mkdir -p $(INITRD_WORK_DIR) + cp $< $(INITRD_WORK_DIR)/init + (cd $(INITRD_WORK_DIR) && (find | cpio --quiet -o -H newc | gzip -9)) > $@ + rm $(INITRD_WORK_DIR)/init + rmdir $(INITRD_WORK_DIR) + +tests/test-qga$(EXESUF): qga/qemu-ga$(EXESUF) +tests/test-qga$(EXESUF): tests/test-qga.o tests/qtest/libqtest.o $(test-util-obj-y) +tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o $(test-util-obj-y) libvhost-user.a +tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o + +SPEED = quick + +# gtester tests, possibly with verbose output +# do_test_tap runs all tests, even if some of them fail, while do_test_human +# stops at the first failure unless -k is given on the command line + +define do_test_human_k + $(quiet-@)rc=0; $(foreach COMMAND, $1, \ + $(call quiet-command-run, \ + export MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} $2; \ + $(COMMAND) -m=$(SPEED) -k --tap < /dev/null \ + | ./scripts/tap-driver.pl --test-name="$(notdir $(COMMAND))" $(if $(V),, --show-failures-only) \ + || rc=$$?;, "TEST", "$@: $(COMMAND)")) exit $$rc +endef +define do_test_human_no_k + $(foreach COMMAND, $1, \ + $(call quiet-command, \ + MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} $2 \ + $(COMMAND) -m=$(SPEED) -k --tap < /dev/null \ + | ./scripts/tap-driver.pl --test-name="$(notdir $(COMMAND))" $(if $(V),, --show-failures-only), \ + "TEST", "$@: $(COMMAND)") +) +endef +do_test_human = \ + $(if $(findstring k, $(MAKEFLAGS)), $(do_test_human_k), $(do_test_human_no_k)) + +define do_test_tap + $(call quiet-command, \ + { export MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} $2; \ + $(foreach COMMAND, $1, \ + $(COMMAND) -m=$(SPEED) -k --tap < /dev/null \ + | sed "s/^\(not \)\?ok [0-9]* /&$(notdir $(COMMAND)) /" || true; ) } \ + | ./scripts/tap-merge.pl | tee "$@" \ + | ./scripts/tap-driver.pl $(if $(V),, --show-failures-only), \ + "TAP","$@") +endef + +build-unit: $(check-unit-y) + +check-unit: $(check-unit-y) + $(call do_test_human, $^) + +check-speed: $(check-speed-y) + $(call do_test_human, $^) + +# gtester tests with TAP output + +check-report-unit.tap: $(check-unit-y) + $(call do_test_tap,$^) + +# Per guest TCG tests + +BUILD_TCG_TARGET_RULES=$(patsubst %,build-tcg-tests-%, $(TARGET_DIRS)) +CLEAN_TCG_TARGET_RULES=$(patsubst %,clean-tcg-tests-%, $(TARGET_DIRS)) +RUN_TCG_TARGET_RULES=$(patsubst %,run-tcg-tests-%, $(TARGET_DIRS)) + +# Probe for the Docker Builds needed for each build +$(foreach PROBE_TARGET,$(TARGET_DIRS), \ + $(eval -include $(SRC_PATH)/tests/tcg/Makefile.prereqs)) + +build-tcg-tests-%: $(if $(CONFIG_PLUGIN),plugins) + $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) \ + -f $(SRC_PATH)/tests/tcg/Makefile.qemu \ + SRC_PATH=$(SRC_PATH) \ + V="$(V)" TARGET="$*" guest-tests, \ + "BUILD", "TCG tests for $*") + +run-tcg-tests-%: build-tcg-tests-% all + $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) \ + -f $(SRC_PATH)/tests/tcg/Makefile.qemu \ + SRC_PATH=$(SRC_PATH) SPEED="$(SPEED)" \ + V="$(V)" TARGET="$*" run-guest-tests, \ + "RUN", "TCG tests for $*") + +clean-tcg-tests-%: + $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) \ + -f $(SRC_PATH)/tests/tcg/Makefile.qemu \ + SRC_PATH=$(SRC_PATH) TARGET="$*" clean-guest-tests, \ + "CLEAN", "TCG tests for $*") + +.PHONY: build-tcg +build-tcg: $(BUILD_TCG_TARGET_RULES) + +.PHONY: check-tcg +check-tcg: $(RUN_TCG_TARGET_RULES) + +.PHONY: clean-tcg +clean-tcg: $(CLEAN_TCG_TARGET_RULES) + + +# Python venv for running tests + +.PHONY: check-venv check-acceptance + +TESTS_VENV_DIR=$(BUILD_DIR)/tests/venv +TESTS_VENV_REQ=$(SRC_PATH)/tests/requirements.txt +TESTS_RESULTS_DIR=$(BUILD_DIR)/tests/results +# Controls the output generated by Avocado when running tests. +# Any number of command separated loggers are accepted. For more +# information please refer to "avocado --help". +AVOCADO_SHOW=app +AVOCADO_TAGS=$(patsubst %-softmmu,-t arch:%, $(filter %-softmmu,$(TARGET_DIRS))) + +$(TESTS_VENV_DIR): $(TESTS_VENV_REQ) + $(call quiet-command, \ + $(PYTHON) -m venv --system-site-packages $@, \ + VENV, $@) + $(call quiet-command, \ + $(TESTS_VENV_DIR)/bin/python -m pip -q install -r $(TESTS_VENV_REQ), \ + PIP, $(TESTS_VENV_REQ)) + $(call quiet-command, touch $@) + +$(TESTS_RESULTS_DIR): + $(call quiet-command, mkdir -p $@, \ + MKDIR, $@) + +check-venv: $(TESTS_VENV_DIR) + +FEDORA_31_ARCHES_CANDIDATES=$(patsubst ppc64,ppc64le,$(TARGETS)) +FEDORA_31_ARCHES := x86_64 aarch64 ppc64le s390x +FEDORA_31_DOWNLOAD=$(filter $(FEDORA_31_ARCHES),$(FEDORA_31_ARCHES_CANDIDATES)) + +# download one specific Fedora 31 image +get-vm-image-fedora-31-%: check-venv + $(call quiet-command, \ + $(TESTS_VENV_DIR)/bin/python -m avocado vmimage get \ + --distro=fedora --distro-version=31 --arch=$*, \ + "AVOCADO", "Downloading acceptance tests VM image for $*") + +# download all vm images, according to defined targets +get-vm-images: check-venv $(patsubst %,get-vm-image-fedora-31-%, $(FEDORA_31_DOWNLOAD)) + +check-acceptance: check-venv $(TESTS_RESULTS_DIR) get-vm-images + $(call quiet-command, \ + $(TESTS_VENV_DIR)/bin/python -m avocado \ + --show=$(AVOCADO_SHOW) run --job-results-dir=$(TESTS_RESULTS_DIR) \ + --filter-by-tags-include-empty --filter-by-tags-include-empty-key \ + $(AVOCADO_TAGS) \ + $(if $(GITLAB_CI),,--failfast=on) tests/acceptance, \ + "AVOCADO", "tests/acceptance") + +# Consolidated targets + +.PHONY: check-block check-unit check check-clean get-vm-images +check-block: +check-build: build-unit + +check-clean: + rm -rf $(check-unit-y) tests/*.o tests/*/*.o $(QEMU_IOTESTS_HELPERS-y) + rm -f tests/test-qapi-gen-timestamp + rm -rf $(TESTS_VENV_DIR) $(TESTS_RESULTS_DIR) + +check: check-unit + +clean: check-clean + +# Build the help program automatically + +-include $(wildcard tests/*.d) + +endif From patchwork Thu Sep 3 07:43:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?572X5YuH5YiaKFlvbmdnYW5nIEx1byk=?= X-Patchwork-Id: 274728 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFBE2C433E2 for ; Thu, 3 Sep 2020 07:49:59 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A4F75206C0 for ; Thu, 3 Sep 2020 07:49:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iUfHbyJF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4F75206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDk0M-0001J4-QV for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 03:49:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDjuj-0000oN-4k for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:44:09 -0400 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:34870) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kDjug-0003v6-VB for qemu-devel@nongnu.org; Thu, 03 Sep 2020 03:44:08 -0400 Received: by mail-pj1-x1044.google.com with SMTP id g6so1068250pjl.0 for ; Thu, 03 Sep 2020 00:44:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RPs3RoSh234lXncrsywCpA+V5get783NAhmcnU+hzlo=; b=iUfHbyJFHXe9LOF3xQaeLRQn4G6OacWh0s0spzv8StMBdYin+zMqcZELjT54/WJvMq Ik+H8tbvrDcXzdr6XSvYQcMm/Sq2/zEHVnA28JTjWFWWjiz+H5cCTMqkqPmm/5PLnbTH hDnBIHN4UJhOC5u+jQOEn7al370Oc7RsSdf/R+Tum0mY8cR9iuC33g8Uej9gSf48kZbv OXz47zU6JzsTnW7bEDGrWGUmJPhl8AKBWhiKCHCSGcSqCs6TJBrGhSFBPLF6TbhkL/D1 7pimML4XQXtD4nVzoTNVKlpGK97M7Acy2vLYy+wykYTxrQOpUyuqpqISfClCiZq7E2QZ AE3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RPs3RoSh234lXncrsywCpA+V5get783NAhmcnU+hzlo=; b=bnRovbYHtPDLsI4PU7Y0430qeIALnUh3ZzKP/OTu3l8YmVGUhpkCQMrPAtnK9jBF2K PModdWfvkEzlGmmW0uVvDVf3qwQ6nW90+1lnavXBrkudg9amkvr/gz0QTy2/Gyomwa8a aNfvJi58YBU0xlJ/YVEp8HPmyb/xs8kpbbBckyTxYPXDrgjBsoFgt+tmIkdRujN7XCbq GaASVn5PfmBRvWBrasnpq/kRBcOaXD9UvpwdGeY83A1m6OLfMaB2CblQrR4K1bDrttAp g8jXoOUwKE5PvJG0BinBZp6Mor3ii1vwYvl37iCa0WqBGhGF5J8FwcIxg8rS+86FZ1W5 a0PA== X-Gm-Message-State: AOAM53373l2hu5yqWe+B2je9TQYcByGQWFZfm4iJ/LXXC6/5Z+l9/8Au ZZlOcgfgmLWhoOUD0flAShVzy0c3IxE+oc7g X-Google-Smtp-Source: ABdhPJwaJblHbAYFES+QR4WRfz3ya+TkSfDAneXGmFAaT9gtylJ1ZjpInma0B83+NxkJiMweIwV3tQ== X-Received: by 2002:a17:90a:8589:: with SMTP id m9mr2074589pjn.109.1599119045126; Thu, 03 Sep 2020 00:44:05 -0700 (PDT) Received: from localhost.localdomain ([222.95.248.6]) by smtp.googlemail.com with ESMTPSA id o6sm1512472pju.25.2020.09.03.00.44.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 00:44:03 -0700 (PDT) From: Yonggang Luo To: qemu-devel@nongnu.org Subject: [PATCH v3 12/12] ci: Enable msys2 ci in cirrus Date: Thu, 3 Sep 2020 15:43:13 +0800 Message-Id: <20200903074313.1498-13-luoyonggang@gmail.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20200903074313.1498-1-luoyonggang@gmail.com> References: <20200903074313.1498-1-luoyonggang@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=luoyonggang@gmail.com; helo=mail-pj1-x1044.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Yonggang Luo Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Install msys2 in a proper way refer to https://github.com/cirruslabs/cirrus-ci-docs/issues/699 The https://wiki.qemu.org/Hosts/W32#Native_builds_with_MSYS2 need to be updated. There is no need of --cross-prefix, open mingw64.exe instead of msys2.exe then we don't need the --cross-prefix, besides using ENV MSYS: winsymlinks:nativestrict MSYSTEM: MINGW64 CHERE_INVOKING: 1 to opening mingw64 native shell. Signed-off-by: Yonggang Luo --- .cirrus.yml | 108 +++++++++++++++++----------- scripts/ci/windows/msys2_build.sh | 33 +++++++++ scripts/ci/windows/msys2_install.sh | 31 ++++++++ 3 files changed, 130 insertions(+), 42 deletions(-) create mode 100644 scripts/ci/windows/msys2_build.sh create mode 100644 scripts/ci/windows/msys2_install.sh diff --git a/.cirrus.yml b/.cirrus.yml index f287d23c5b..0bfb465193 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,42 +1,66 @@ -env: - CIRRUS_CLONE_DEPTH: 1 - -freebsd_12_task: - freebsd_instance: - image_family: freebsd-12-1 - cpu: 8 - memory: 8G - install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y - bash curl cyrus-sasl git glib gmake gnutls gsed - nettle perl5 pixman pkgconf png usbredir - script: - - mkdir build - - cd build - - ../configure || { cat config.log; exit 1; } - - gmake -j8 - - gmake V=1 check - -macos_task: - osx_instance: - image: mojave-base - install_script: - - brew install pkg-config python gnu-sed glib pixman make sdl2 bash - script: - - mkdir build - - cd build - - ../configure --python=/usr/local/bin/python3 || { cat config.log; exit 1; } - - gmake -j$(sysctl -n hw.ncpu) - - gmake check - -macos_xcode_task: - osx_instance: - # this is an alias for the latest Xcode - image: mojave-xcode - install_script: - - brew install pkg-config gnu-sed glib pixman make sdl2 bash - script: - - mkdir build - - cd build - - ../configure --cc=clang || { cat config.log; exit 1; } - - gmake -j$(sysctl -n hw.ncpu) - - gmake check +env: + CIRRUS_CLONE_DEPTH: 1 + +freebsd_12_task: + freebsd_instance: + image_family: freebsd-12-1 + cpu: 8 + memory: 8G + install_script: ASSUME_ALWAYS_YES=yes pkg bootstrap -f ; pkg install -y + bash curl cyrus-sasl git glib gmake gnutls gsed + nettle perl5 pixman pkgconf png usbredir + script: + - mkdir build + - cd build + - ../configure || { cat config.log; exit 1; } + - gmake -j8 + - gmake V=1 check + +macos_task: + osx_instance: + image: mojave-base + install_script: + - brew install pkg-config python gnu-sed glib pixman make sdl2 bash + script: + - mkdir build + - cd build + - ../configure --python=/usr/local/bin/python3 || { cat config.log; exit 1; } + - gmake -j$(sysctl -n hw.ncpu) + - gmake check + +macos_xcode_task: + osx_instance: + # this is an alias for the latest Xcode + image: mojave-xcode + install_script: + - brew install pkg-config gnu-sed glib pixman make sdl2 bash + script: + - mkdir build + - cd build + - ../configure --cc=clang || { cat config.log; exit 1; } + - gmake -j$(sysctl -n hw.ncpu) + - gmake check + +windows_msys2_task: + windows_container: + image: cirrusci/windowsservercore:cmake + os_version: 2019 + cpu: 8 + memory: 8G + env: + MSYS: winsymlinks:nativestrict + MSYSTEM: MINGW64 + CHERE_INVOKING: 1 + printenv_script: + - C:\tools\msys64\usr\bin\bash.exe -lc 'printenv' + install_script: + - C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools && curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz" + - C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools && curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig" + - C:\tools\msys64\usr\bin\bash.exe -lc "cd /c/tools && pacman -U --noconfirm msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz" + - C:\tools\msys64\usr\bin\bash.exe -lc "pacman -Sy --noconfirm" + - C:\tools\msys64\usr\bin\bash.exe -lc "pacman --needed --noconfirm -S bash pacman pacman-mirrors msys2-runtime" + - taskkill /F /IM gpg-agent.exe + - C:\tools\msys64\usr\bin\bash.exe -lc "pacman --noconfirm -Su" + - C:\tools\msys64\usr\bin\bash.exe -lc "sh scripts/ci/windows/msys2_install.sh" + script: + - C:\tools\msys64\usr\bin\bash.exe -lc "sh scripts/ci/windows/msys2_build.sh" diff --git a/scripts/ci/windows/msys2_build.sh b/scripts/ci/windows/msys2_build.sh new file mode 100644 index 0000000000..3ba89a4206 --- /dev/null +++ b/scripts/ci/windows/msys2_build.sh @@ -0,0 +1,33 @@ +mkdir build +cd build +../configure \ + --python=python3 \ + --enable-gtk --enable-sdl \ + --enable-capstone=git \ + --enable-stack-protector \ + --ninja=ninja \ + --enable-gnutls \ + --enable-nettle \ + --enable-vnc \ + --enable-vnc-sasl \ + --enable-vnc-jpeg \ + --enable-vnc-png \ + --enable-membarrier \ + --enable-slirp=git \ + --disable-kvm \ + --enable-hax \ + --enable-whpx \ + --disable-spice \ + --enable-lzo \ + --enable-snappy \ + --enable-bzip2 \ + --enable-vdi \ + --enable-qcow1 \ + --enable-tools \ + --enable-libusb \ + --enable-usb-redir \ + --enable-libnfs \ + --enable-libssh \ + --disable-pie +make -j$NUMBER_OF_PROCESSORS +# make check diff --git a/scripts/ci/windows/msys2_install.sh b/scripts/ci/windows/msys2_install.sh new file mode 100644 index 0000000000..ff35b73ef2 --- /dev/null +++ b/scripts/ci/windows/msys2_install.sh @@ -0,0 +1,31 @@ +pacman --noconfirm -S --needed \ +base-devel \ +git \ +mingw-w64-x86_64-python \ +mingw-w64-x86_64-python-setuptools \ +mingw-w64-x86_64-toolchain \ +mingw-w64-x86_64-SDL2 \ +mingw-w64-x86_64-SDL2_image \ +mingw-w64-x86_64-gtk3 \ +mingw-w64-x86_64-ninja \ +mingw-w64-x86_64-make \ +mingw-w64-x86_64-lzo2 \ +mingw-w64-x86_64-libjpeg-turbo \ +mingw-w64-x86_64-pixman \ +mingw-w64-x86_64-libgcrypt \ +mingw-w64-x86_64-capstone \ +mingw-w64-x86_64-libpng \ +mingw-w64-x86_64-libssh \ +mingw-w64-x86_64-libxml2 \ +mingw-w64-x86_64-snappy \ +mingw-w64-x86_64-libusb \ +mingw-w64-x86_64-usbredir \ +mingw-w64-x86_64-libtasn1 \ +mingw-w64-x86_64-libnfs \ +mingw-w64-x86_64-nettle \ +mingw-w64-x86_64-cyrus-sasl \ +mingw-w64-x86_64-curl \ +mingw-w64-x86_64-gnutls \ +mingw-w64-x86_64-zstd \ +mingw-w64-x86_64-glib2 +