From patchwork Thu Dec 19 13:48:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13915251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1A152E77184 for ; Thu, 19 Dec 2024 16:32:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJGp-0003k5-3s; Thu, 19 Dec 2024 11:21:03 -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 1tOGta-00072n-2G for qemu-devel@nongnu.org; Thu, 19 Dec 2024 08:48:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOGtX-0000yG-BB for qemu-devel@nongnu.org; Thu, 19 Dec 2024 08:48:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734616130; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qn4mquEweZ71Z9jDJcuQq1s3l2ovJcdloeaI6PAZhIY=; b=OBUgyNVZWiKaNlDg6Ev+NjePdWQIaAM+rN2ltZTLVdMcHH7JU3SI/HSyQe9xmO6L4gXvIr +XtXJvVDU7ZChuqzZ7LbMUyQ5hBqHfpiShrBMb8mAWheqMdDDmDzidI6CeaqkHHZ4mTmVn OzlRj5Q3e0NlNPkUPZZCZVc7m+jdFmw= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-a_TJoLt7NOGzlZSuFarY-w-1; Thu, 19 Dec 2024 08:48:49 -0500 X-MC-Unique: a_TJoLt7NOGzlZSuFarY-w-1 X-Mimecast-MFC-AGG-ID: a_TJoLt7NOGzlZSuFarY-w Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-436328fcfeeso6791315e9.1 for ; Thu, 19 Dec 2024 05:48:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734616127; x=1735220927; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qn4mquEweZ71Z9jDJcuQq1s3l2ovJcdloeaI6PAZhIY=; b=Y22LVlu91Oq1pbqTGVYooDLWFkx20fm0X9+kdnp+wKKgGaZeGy4gYCbIzEjuC4Yhe3 UfwpDiLlycbAjrj79Pe+jkG58phcoOuAKebErYXdTyfDgzPmjDj+6q8BwR0gDFIkoHfV OljFAuJH7MSxDhYso+zs3J4tSVnYcSBWtAddpSRHtNWXbi2Cs4uR0z+OCWGAA/r2FyBi pmhjakl2z1SHgn+Df29T3NDYtQlhbcEPdbXYLiuSXuYyj5qzQwLZGw4nnAFrD2+nF2UY KsDTJ649ziyPtAAtgmgdRlPiioHJIctCDvzsaagJDDaABmebPt+1HG7+UFmoVXPrcY5M tcxQ== X-Gm-Message-State: AOJu0Yz8l/3PuiNGppj539q4Psn+QIvbJ8b6Mwk/pDUQ6orKll5X61fO qAksukIpZ9e9ipXgKX/6otr+Sq4HveSAZFkIPPq7cdAJPnB4JUA4qDSV/QhHWh6rf7it3aZO3M9 f9m1LU9HkKbv3QLxlc88KYWwUqLO+t9SeiNoDQWmonC69UyKVg7eYlzaXPL+lrDrV2dRN7pLnm2 LfWPwgsLgdYXEHrTtIjmCojWPL0EMUIWDCEBq8 X-Gm-Gg: ASbGncs34UyqaHASJBd68dtHxp5a5USK8FEJ69eNBgyFbaf3zRNoBOOm94HGQIAugGk z2k6pbAIWi/ecTTiN/wLcxQJB77rXyTc4rkQhRbBoloNDQoMoEt0bWdyZjt+0kINLAx20z8xvHI jdSbmWVQAoQ+k/g60FFGJMvUt0txm2aVnZQ/pIjvEBnz8/wtl6+sE3U4fGDziciBqTUqAkSWKZF H1NUdcCfHwqHrsHk36aQRe28jd2BqGrGReNyAyy9TvRvdljWv3SLZOctG0O X-Received: by 2002:a05:600c:3b23:b0:434:a684:9b1 with SMTP id 5b1f17b1804b1-436553452f9mr63293465e9.4.1734616126782; Thu, 19 Dec 2024 05:48:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmoaepJVMrUu55Nx90MG32ecMysRlQm8k6S6Ohz5xpxYumsO4Sw0un0me9jnRMsTeVZ/PCUg== X-Received: by 2002:a05:600c:3b23:b0:434:a684:9b1 with SMTP id 5b1f17b1804b1-436553452f9mr63293145e9.4.1734616126224; Thu, 19 Dec 2024 05:48:46 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38a1c833155sm1588971f8f.24.2024.12.19.05.48.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 05:48:45 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 29/42] bql: add a "mock" BQL for Rust unit tests Date: Thu, 19 Dec 2024 14:48:42 +0100 Message-ID: <20241219134843.443085-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219134843.443085-1-pbonzini@redhat.com> References: <20241219134843.443085-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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_H2=-1.116, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Right now, the stub BQL in stubs/iothread-lock.c always reports itself as unlocked. However, Rust would like to run its tests in an environment where the BQL *is* locked. Provide an extremely dirty function that flips the return value of bql_is_locked() to true. Signed-off-by: Paolo Bonzini --- include/qemu/main-loop.h | 8 ++++++++ stubs/iothread-lock.c | 8 +++++++- rust/qemu-api/meson.build | 2 +- rust/qemu-api/src/cell.rs | 26 +++++++++++++++++++++++--- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index 646306c272f..3935a573391 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -247,6 +247,14 @@ void event_notifier_set_handler(EventNotifier *e, GSource *iohandler_get_g_source(void); AioContext *iohandler_get_aio_context(void); +/** + * rust_bql_mock_lock: + * + * Called from Rust doctests to make bql_lock() return true. + * Do not touch. + */ +void rust_bql_mock_lock(void); + /** * bql_locked: Return lock status of the Big QEMU Lock (BQL) * diff --git a/stubs/iothread-lock.c b/stubs/iothread-lock.c index 54676598950..6050c081f53 100644 --- a/stubs/iothread-lock.c +++ b/stubs/iothread-lock.c @@ -1,11 +1,17 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" +static bool bql_is_locked = false; static uint32_t bql_unlock_blocked; bool bql_locked(void) { - return false; + return bql_is_locked; +} + +void rust_bql_mock_lock(void) +{ + bql_is_locked = true; } void bql_lock_impl(const char *file, int line) diff --git a/rust/qemu-api/meson.build b/rust/qemu-api/meson.build index 7ff408ad68e..50ec00e128d 100644 --- a/rust/qemu-api/meson.build +++ b/rust/qemu-api/meson.build @@ -60,7 +60,7 @@ test('rust-qemu-api-integration', dependencies: [qemu_api, qemu_api_macros], link_whole: [rust_qemu_api_objs, libqemuutil]), args: [ - '--test', + '--test', '--test-threads', '1', '--format', 'pretty', ], protocol: 'rust', diff --git a/rust/qemu-api/src/cell.rs b/rust/qemu-api/src/cell.rs index 28349de291a..eae4e2ce786 100644 --- a/rust/qemu-api/src/cell.rs +++ b/rust/qemu-api/src/cell.rs @@ -124,9 +124,18 @@ use crate::bindings; -// TODO: When building doctests do not include the actual BQL, because cargo -// does not know how to link them to libqemuutil. This can be fixed by -// running rustdoc from "meson test" instead of relying on cargo. +/// An internal function that is used by doctests. +pub fn bql_start_test() { + if cfg!(MESON) { + // SAFETY: integration tests are run with --test-threads=1, while + // unit tests and doctests are not multithreaded and do not have + // any BQL-protected data. Just set bql_locked to true. + unsafe { + bindings::rust_bql_mock_lock(); + } + } +} + pub fn bql_locked() -> bool { // SAFETY: the function does nothing but return a thread-local bool !cfg!(MESON) || unsafe { bindings::bql_locked() } @@ -220,6 +229,7 @@ impl BqlCell { /// /// ``` /// use qemu_api::cell::BqlCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlCell::new(5); /// ``` @@ -236,6 +246,7 @@ pub const fn new(value: T) -> BqlCell { /// /// ``` /// use qemu_api::cell::BqlCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlCell::new(5); /// @@ -253,6 +264,7 @@ pub fn set(&self, val: T) { /// /// ``` /// use qemu_api::cell::BqlCell; + /// # qemu_api::cell::bql_start_test(); /// /// let cell = BqlCell::new(5); /// assert_eq!(cell.get(), 5); @@ -274,6 +286,7 @@ pub fn replace(&self, val: T) -> T { /// /// ``` /// use qemu_api::cell::BqlCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlCell::new(5); /// let five = c.into_inner(); @@ -293,6 +306,7 @@ impl BqlCell { /// /// ``` /// use qemu_api::cell::BqlCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlCell::new(5); /// @@ -315,6 +329,7 @@ impl BqlCell { /// /// ``` /// use qemu_api::cell::BqlCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlCell::new(5); /// @@ -333,6 +348,7 @@ impl BqlCell { /// /// ``` /// use qemu_api::cell::BqlCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlCell::new(5); /// let five = c.take(); @@ -461,6 +477,7 @@ fn panic_already_borrowed(&self) -> ! { /// /// ``` /// use qemu_api::cell::BqlRefCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlRefCell::new(5); /// @@ -472,6 +489,7 @@ fn panic_already_borrowed(&self) -> ! { /// /// ```should_panic /// use qemu_api::cell::BqlRefCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlRefCell::new(5); /// @@ -513,6 +531,7 @@ pub fn borrow(&self) -> BqlRef<'_, T> { /// /// ``` /// use qemu_api::cell::BqlRefCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlRefCell::new("hello".to_owned()); /// @@ -525,6 +544,7 @@ pub fn borrow(&self) -> BqlRef<'_, T> { /// /// ```should_panic /// use qemu_api::cell::BqlRefCell; + /// # qemu_api::cell::bql_start_test(); /// /// let c = BqlRefCell::new(5); /// let m = c.borrow(); From patchwork Thu Dec 19 13:48:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 13915244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B5DAE7718A for ; Thu, 19 Dec 2024 16:29:00 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOJGx-0004jo-TM; Thu, 19 Dec 2024 11:21:11 -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 1tOGta-000732-Om for qemu-devel@nongnu.org; Thu, 19 Dec 2024 08:48:55 -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 1tOGtZ-0000yU-7k for qemu-devel@nongnu.org; Thu, 19 Dec 2024 08:48:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734616132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b8X5LSjSBtqJTtR/RvJgszEpGhBtRYXHObYm/N1R5ek=; b=aG+MX7sJGjy2PLwk63VYxTUf839apJ6Bj4pKkp6ROW4U5fHSD7mQzSvfsP3L0uE9jny+hb d8VDKCFE8ML4Vndc2qIQs7PmCPN0iaIz9EdAm6iHT+s7dR0VaFFkXaknBI1Bq1lNrIVbWh 2fzJtKbnSb2C49IekDXczqC8Bov7sa8= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-kVW0cuoENuSubvPDxTJf_Q-1; Thu, 19 Dec 2024 08:48:51 -0500 X-MC-Unique: kVW0cuoENuSubvPDxTJf_Q-1 X-Mimecast-MFC-AGG-ID: kVW0cuoENuSubvPDxTJf_Q Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4361eb83f46so6741255e9.3 for ; Thu, 19 Dec 2024 05:48:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734616129; x=1735220929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b8X5LSjSBtqJTtR/RvJgszEpGhBtRYXHObYm/N1R5ek=; b=MRw/oPAImdR7WgFAa3/cChUMxKHVPwWnbJe0QKo5JljEo06QhUGGhgJoukThasB+AG HB+egiesCj92wVxXS9feLdQFPOHmzNWpNEyBiPDkarW784OPJ2ARWamor7pqKk1moT0X DkGdlKw1tQlVJtwPFtVp+JXeJLiMBnhojAQYIzOAcG33fqMtvL/Up8+Oi5VVhOuYsLjb I18AK+HGidufJKLThYK3mIKweUyVulfcsswYUuT32kIgcPzT9I1Uh2+uRw1xS6BjY0DH 58NK+nYTZ9KAOaPeEM4D+5f/ruxZTZraezplhJoFpMowOxbQD++/a7gYDlTzNhcOrkAv 3czA== X-Gm-Message-State: AOJu0YzgdscVyG6Br6djQrGN7fHJFvc0l+qyTYW2wP1gjafV9XnZAgnP 3lhyo7RwSlNR/D05/SXHvX+/ghYc/tAMjfZDuPJeDZMwEZgmGLFCqz8kn91DV576VTFHQM7Kpv8 mb4/rgM2bXsfTPX/EPYejYuYPui/JOBvdw25V1ZjTvEs9OfFqXt+7pzfRa0lzJevzcfRVjkNmmR SMt6po7wiAeiFuPtnAWWkAf7QiPb5eykvYrn8n X-Gm-Gg: ASbGncuNzAyl/r36UU98v24LmoWsbvYKFfD8+ZxBOB3yugehRE4Oe/4NiPYxO6yd8RT CkJIpwQ4PUrgKrkWfuJe7hOLYvxyBFlrEK+mPcDj+CDHg9B8/cDTS9jpu4vMo0NwP7OJzGwrjdC i0BjUaxdoGoQ2tSJ5+O5LOVQM7IPT1dxpYZx44CMZ9wCp6QvP38UKQXuTz9hy8Wiukv2SZObcXH Tq3piS9OFVxwjYUXckB074UVT7ksfqU64hHuL6ptHqvze75Xlu84CXkGVye X-Received: by 2002:a05:6000:4a0e:b0:385:fc70:7eb with SMTP id ffacd0b85a97d-388e4d311e8mr6489673f8f.12.1734616129523; Thu, 19 Dec 2024 05:48:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEcZhSRX3qITHRvqYShHelgbBLPEdillmFV8HI1U4MBSWtynLsmMq7SRbYkADJ+k+52Rsv/ug== X-Received: by 2002:a05:6000:4a0e:b0:385:fc70:7eb with SMTP id ffacd0b85a97d-388e4d311e8mr6489654f8f.12.1734616129109; Thu, 19 Dec 2024 05:48:49 -0800 (PST) Received: from [192.168.10.47] ([151.81.118.45]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4366127c493sm18338905e9.28.2024.12.19.05.48.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Dec 2024 05:48:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 30/42] rust: tests: allow writing more than one test Date: Thu, 19 Dec 2024 14:48:43 +0100 Message-ID: <20241219134843.443085-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241219134843.443085-1-pbonzini@redhat.com> References: <20241219134843.443085-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 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_H2=-1.116, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Paolo Bonzini --- rust/qemu-api/tests/tests.rs | 111 ++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 48 deletions(-) diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs index 68557fb85c7..dc0ed190192 100644 --- a/rust/qemu-api/tests/tests.rs +++ b/rust/qemu-api/tests/tests.rs @@ -6,7 +6,9 @@ use qemu_api::{ bindings::*, - c_str, declare_properties, define_property, + c_str, + cell::{self, BqlCell}, + declare_properties, define_property, prelude::*, qdev::{DeviceImpl, DeviceState, Property}, qom::ObjectImpl, @@ -14,55 +16,68 @@ zeroable::Zeroable, }; +// Test that macros can compile. +pub static VMSTATE: VMStateDescription = VMStateDescription { + name: c_str!("name").as_ptr(), + unmigratable: true, + ..Zeroable::ZERO +}; + +#[derive(qemu_api_macros::offsets)] +#[repr(C)] +#[derive(qemu_api_macros::Object)] +pub struct DummyState { + parent: DeviceState, + migrate_clock: bool, +} + +declare_properties! { + DUMMY_PROPERTIES, + define_property!( + c_str!("migrate-clk"), + DummyState, + migrate_clock, + unsafe { &qdev_prop_bool }, + bool + ), +} + +unsafe impl ObjectType for DummyState { + type Class = ::Class; + const TYPE_NAME: &'static CStr = c_str!("dummy"); +} + +impl ObjectImpl for DummyState { + type ParentType = DeviceState; + const ABSTRACT: bool = false; +} + +impl DeviceImpl for DummyState { + fn properties() -> &'static [Property] { + &DUMMY_PROPERTIES + } + fn vmsd() -> Option<&'static VMStateDescription> { + Some(&VMSTATE) + } +} + +fn init_qom() { + static ONCE: BqlCell = BqlCell::new(false); + + cell::bql_start_test(); + if !ONCE.get() { + unsafe { + module_call_init(module_init_type::MODULE_INIT_QOM); + } + ONCE.set(true); + } +} + #[test] -fn test_device_decl_macros() { - // Test that macros can compile. - pub static VMSTATE: VMStateDescription = VMStateDescription { - name: c_str!("name").as_ptr(), - unmigratable: true, - ..Zeroable::ZERO - }; - - #[derive(qemu_api_macros::offsets)] - #[repr(C)] - #[derive(qemu_api_macros::Object)] - pub struct DummyState { - pub _parent: DeviceState, - pub migrate_clock: bool, - } - - declare_properties! { - DUMMY_PROPERTIES, - define_property!( - c_str!("migrate-clk"), - DummyState, - migrate_clock, - unsafe { &qdev_prop_bool }, - bool - ), - } - - unsafe impl ObjectType for DummyState { - type Class = ::Class; - const TYPE_NAME: &'static CStr = c_str!("dummy"); - } - - impl ObjectImpl for DummyState { - type ParentType = DeviceState; - const ABSTRACT: bool = false; - } - - impl DeviceImpl for DummyState { - fn properties() -> &'static [Property] { - &DUMMY_PROPERTIES - } - fn vmsd() -> Option<&'static VMStateDescription> { - Some(&VMSTATE) - } - } - +/// Create and immediately drop an instance. +fn test_object_new() { + init_qom(); unsafe { - module_call_init(module_init_type::MODULE_INIT_QOM); object_unref(object_new(DummyState::TYPE_NAME.as_ptr()).cast()); } }