From: Bernhard Beschow <shentey@gmail.com>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>,
Eduardo Habkost <eduardo@habkost.net>,
John Snow <jsnow@redhat.com>, Fabiano Rosas <farosas@suse.de>,
Laurent Vivier <laurent@vivier.eu>,
kvm@vger.kernel.org, Zhao Liu <zhao1.liu@intel.com>,
qemu-trivial@nongnu.org,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Sunil Muthuswamy <sunilmut@microsoft.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Michael Tokarev <mjt@tls.msk.ru>,
Richard Henderson <richard.henderson@linaro.org>,
qemu-block@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Bernhard Beschow <shentey@gmail.com>
Subject: [PATCH 8/8] tests/qtest/ds1338-test: Reuse from_bcd()
Date: Fri, 17 Oct 2025 13:33:38 +0200 [thread overview]
Message-ID: <20251017113338.7953-9-shentey@gmail.com> (raw)
In-Reply-To: <20251017113338.7953-1-shentey@gmail.com>
from_bcd() is a public API function which can be unit-tested. Reuse it to avoid
code duplication.
Signed-off-by: Bernhard Beschow <shentey@gmail.com>
---
tests/qtest/ds1338-test.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/tests/qtest/ds1338-test.c b/tests/qtest/ds1338-test.c
index d12424d27f..b8d0e65ec4 100644
--- a/tests/qtest/ds1338-test.c
+++ b/tests/qtest/ds1338-test.c
@@ -18,16 +18,12 @@
*/
#include "qemu/osdep.h"
+#include "qemu/bcd.h"
#include "libqtest.h"
#include "libqos/i2c.h"
#define DS1338_ADDR 0x68
-static inline uint8_t bcd2bin(uint8_t x)
-{
- return ((x) & 0x0f) + ((x) >> 4) * 10;
-}
-
static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
{
QI2CDevice *i2cdev = (QI2CDevice *)obj;
@@ -39,9 +35,9 @@ static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc)
i2c_read_block(i2cdev, 0, resp, sizeof(resp));
/* check retrieved time against local time */
- g_assert_cmpuint(bcd2bin(resp[4]), == , tm_ptr->tm_mday);
- g_assert_cmpuint(bcd2bin(resp[5]), == , 1 + tm_ptr->tm_mon);
- g_assert_cmpuint(2000 + bcd2bin(resp[6]), == , 1900 + tm_ptr->tm_year);
+ g_assert_cmpuint(from_bcd(resp[4]), == , tm_ptr->tm_mday);
+ g_assert_cmpuint(from_bcd(resp[5]), == , 1 + tm_ptr->tm_mon);
+ g_assert_cmpuint(2000 + from_bcd(resp[6]), == , 1900 + tm_ptr->tm_year);
}
static void ds1338_register_nodes(void)
--
2.51.1.dirty
next prev parent reply other threads:[~2025-10-17 11:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-17 11:33 [PATCH 0/8] Trivial patches, mostly PC-related Bernhard Beschow
2025-10-17 11:33 ` [PATCH 1/8] hw/timer/i8254: Add I/O trace events Bernhard Beschow
2025-10-17 11:33 ` [PATCH 2/8] hw/audio/pcspk: " Bernhard Beschow
2025-10-17 11:33 ` [PATCH 3/8] hw/rtc/mc146818rtc: Convert CMOS_DPRINTF() into " Bernhard Beschow
2025-10-17 11:33 ` [PATCH 4/8] hw/rtc/mc146818rtc: Use ARRAY_SIZE macro Bernhard Beschow
2025-10-17 11:33 ` [PATCH 5/8] hw/rtc/mc146818rtc: Assert correct usage of mc146818rtc_set_cmos_data() Bernhard Beschow
2025-10-17 11:33 ` [PATCH 6/8] hw/i386/apic: Prefer APICCommonState over DeviceState Bernhard Beschow
2025-10-17 11:33 ` [PATCH 7/8] hw/ide/ide-internal: Move dma_buf_commit() into ide "namespace" Bernhard Beschow
2025-10-17 11:33 ` Bernhard Beschow [this message]
2025-10-21 20:57 ` [PATCH 8/8] tests/qtest/ds1338-test: Reuse from_bcd() Fabiano Rosas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251017113338.7953-9-shentey@gmail.com \
--to=shentey@gmail.com \
--cc=eduardo@habkost.net \
--cc=farosas@suse.de \
--cc=jsnow@redhat.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=laurent@vivier.eu \
--cc=lvivier@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mjt@tls.msk.ru \
--cc=mst@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sunilmut@microsoft.com \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).