From nobody Wed Nov 27 13:05:52 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1699271486; cv=none; d=zohomail.com; s=zohoarc; b=n8ysrFqyo/UvmXB2DJJvrPY/5XquwBgfqtF0YLZP3whZ3NdWvCnTb0bs6SjBrGBUMZA1D/tXDNmVYvqEZp3kzowbyBuW9cFMh9yHLZlzPHuQLG7CxyGQQjP7ehC/IZYhbcRGtxYQKBZsfJuT4rniJRInbk2767t8vrAoqNqsxDk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699271486; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7zBtay+FXHfC62zOoHOvwVv9aq/hIRy7K1YGyquZqPM=; b=O4y0IGQiibIY+5PtrWUTSkpsUKgwdlI9mGVyfc86Uz8GGqDTRAKn2Kp3VQxsAkxVA6+0eMNxYvKwyAMB28BgR/jo/IZamhV1OcC35M4d3+9jHX3Cby5b0hAUPIGLzHD7v2BjN8dKg6KyKNU3lBUukmsKYTQjh0nhmFl8pSuZmtE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699271486258887.9661771406143; Mon, 6 Nov 2023 03:51:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qzxuG-0003Ue-3n; Mon, 06 Nov 2023 06:36:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qzxuE-0003TH-TQ for qemu-devel@nongnu.org; Mon, 06 Nov 2023 06:36:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qzxuD-0003OU-7y for qemu-devel@nongnu.org; Mon, 06 Nov 2023 06:36:34 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-178-S2YWS4NqMumuYrT-d6SS8g-1; Mon, 06 Nov 2023 06:36:31 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D36B528B730A; Mon, 6 Nov 2023 11:36:30 +0000 (UTC) Received: from localhost (unknown [10.39.208.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CC981C060B1; Mon, 6 Nov 2023 11:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699270592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7zBtay+FXHfC62zOoHOvwVv9aq/hIRy7K1YGyquZqPM=; b=XT+EDaqikpvUBN6PzGtjrqpsqQk90BDSDEtGgOrokwO0oswDfeaYwcRMrruUQo1OYikHFf OuOeGwJ3SKtObiF6r0StvyMNsQiLo+AzO68k1CVN799KTwe7867vKr+gIhr5aeiD5PimHZ me+0FbvCE65Y8Aqt/Z2YlL1EfJLR+Uw= X-MC-Unique: S2YWS4NqMumuYrT-d6SS8g-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Peter Xu , Samuel Thibault , Kevin Wolf , Juan Quintela , Fabiano Rosas , "Michael S. Tsirkin" , Leonardo Bras , qemu-block@nongnu.org, Hanna Reitz , Jason Wang , John Snow , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v3 5/6] test-vmstate: add some subsection tests Date: Mon, 6 Nov 2023 15:35:59 +0400 Message-ID: <20231106113601.2052601-6-marcandre.lureau@redhat.com> In-Reply-To: <20231106113601.2052601-1-marcandre.lureau@redhat.com> References: <20231106113601.2052601-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1699271487057100001 From: Marc-Andr=C3=A9 Lureau Check subsection support, and optional handling. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Juan Quintela --- tests/unit/test-vmstate.c | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c index 0b7d5ecd68..d60457486c 100644 --- a/tests/unit/test-vmstate.c +++ b/tests/unit/test-vmstate.c @@ -1479,6 +1479,118 @@ static void test_tmp_struct(void) g_assert_cmpint(obj.f, =3D=3D, 8); /* From the child->parent */ } =20 +static bool sub_optional_needed =3D true; + +static bool sub_optional_needed_cb(void *opaque) +{ + return sub_optional_needed; +} + +static const VMStateDescription vmstate_sub_optional_a =3D { + .name =3D "sub/optional/a", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D sub_optional_needed_cb, + .fields =3D (VMStateField[]) { + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_sub_optional =3D { + .name =3D "sub/optional", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_END_OF_LIST() + }, + .subsections =3D (const VMStateDescription * []) { + &vmstate_sub_optional_a, + } +}; + +static uint8_t wire_sub_optional[] =3D { + QEMU_VM_SUBSECTION, + 14, + 's', 'u', 'b', '/', 'o', 'p', 't', 'i', 'o', 'n', 'a', 'l', '/', 'a', + 0x0, 0x0, 0x0, 1, + QEMU_VM_EOF, +}; + +static uint8_t wire_sub_optional_missing[] =3D { + QEMU_VM_EOF, +}; + +static void test_sub_optional_needed(void) +{ + sub_optional_needed =3D true; + save_vmstate(&vmstate_sub_optional, NULL); + + compare_vmstate(wire_sub_optional, sizeof(wire_sub_optional)); + + SUCCESS(load_vmstate_one(&vmstate_sub_optional, NULL, + 1, wire_sub_optional, + sizeof(wire_sub_optional))); + + /* this will print an error, but succeed nonetheless */ + load_vmstate_one(&vmstate_sub_optional, NULL, + 1, wire_sub_optional_missing, + sizeof(wire_sub_optional_missing)); +} + +static void test_sub_optional_missing(void) +{ + sub_optional_needed =3D false; + save_vmstate(&vmstate_sub_optional, NULL); + + compare_vmstate(wire_sub_optional_missing, sizeof(wire_sub_optional_mi= ssing)); + + SUCCESS(load_vmstate_one(&vmstate_sub_optional, NULL, + 1, wire_sub_optional, + sizeof(wire_sub_optional))); + + SUCCESS(load_vmstate_one(&vmstate_sub_optional, NULL, + 1, wire_sub_optional_missing, + sizeof(wire_sub_optional_missing))); +} + +static uint8_t wire_sub_dup[] =3D { + QEMU_VM_SUBSECTION, + 14, + 's', 'u', 'b', '/', 'o', 'p', 't', 'i', 'o', 'n', 'a', 'l', '/', 'a', + 0x0, 0x0, 0x0, 1, + QEMU_VM_SUBSECTION, + 14, + 's', 'u', 'b', '/', 'o', 'p', 't', 'i', 'o', 'n', 'a', 'l', '/', 'a', + 0x0, 0x0, 0x0, 1, + QEMU_VM_EOF, +}; + +static void test_sub_optional_dup(void) +{ + sub_optional_needed =3D false; + + FAILURE(load_vmstate_one(&vmstate_sub_optional, NULL, + 1, wire_sub_dup, + sizeof(wire_sub_dup))); +} + +static uint8_t wire_sub_unknown[] =3D { + QEMU_VM_SUBSECTION, + 14, + 's', 'u', 'b', '/', 'o', 'p', 't', 'i', 'o', 'n', 'a', 'l', '/', 'b', + 0x0, 0x0, 0x0, 1, + QEMU_VM_EOF, +}; + +static void test_sub_optional_unknown(void) +{ + sub_optional_needed =3D false; + + FAILURE(load_vmstate_one(&vmstate_sub_optional, NULL, + 1, wire_sub_unknown, + sizeof(wire_sub_unknown))); +} + int main(int argc, char **argv) { g_autofree char *temp_file =3D g_strdup_printf("%s/vmst.test.XXXXXX", @@ -1519,6 +1631,10 @@ int main(int argc, char **argv) g_test_add_func("/vmstate/qlist/save/saveqlist", test_save_qlist); g_test_add_func("/vmstate/qlist/load/loadqlist", test_load_qlist); g_test_add_func("/vmstate/tmp_struct", test_tmp_struct); + g_test_add_func("/vmstate/subsection/needed", test_sub_optional_needed= ); + g_test_add_func("/vmstate/subsection/missing", test_sub_optional_missi= ng); + g_test_add_func("/vmstate/subsection/dup", test_sub_optional_dup); + g_test_add_func("/vmstate/subsection/unknown", test_sub_optional_unkno= wn); g_test_run(); =20 close(temp_fd); --=20 2.41.0