From: Vincent Cruz <mooz@blockos.org>
To: buildroot@buildroot.org
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
Vincent Cruz <mooz@blockos.org>
Subject: [Buildroot] [PATCH 2/2] support/testing: add rwmem tests
Date: Wed, 8 Apr 2026 12:04:26 +0200 [thread overview]
Message-ID: <20260408100528.468929-3-mooz@blockos.org> (raw)
In-Reply-To: <20260408100528.468929-1-mooz@blockos.org>
Add a basic runtime test for rwmem package.
This test verifies that `rwmem` package can read register values from
an I2C device and a memory mapped file.
Signed-off-by: Vincent Cruz <mooz@blockos.org>
---
support/testing/tests/package/test_rwmem.py | 72 +++++++++++++++++++
.../package/test_rwmem/linux-rwmem.fragment | 3 +
.../test_rwmem/rootfs-overlay/root/tests.py | 22 ++++++
3 files changed, 97 insertions(+)
create mode 100644 support/testing/tests/package/test_rwmem.py
create mode 100644 support/testing/tests/package/test_rwmem/linux-rwmem.fragment
create mode 100644 support/testing/tests/package/test_rwmem/rootfs-overlay/root/tests.py
diff --git a/support/testing/tests/package/test_rwmem.py b/support/testing/tests/package/test_rwmem.py
new file mode 100644
index 0000000000..15d9fbc8d0
--- /dev/null
+++ b/support/testing/tests/package/test_rwmem.py
@@ -0,0 +1,72 @@
+import os
+
+import infra.basetest
+
+
+class TestRwmem(infra.basetest.BRTest):
+ kernel_fragment = infra.filepath("tests/package/test_rwmem/linux-rwmem.fragment")
+ rootfs_overlay = infra.filepath("tests/package/test_rwmem/rootfs-overlay")
+
+ config = \
+ f"""
+ BR2_arm=y
+ BR2_cortex_a9=y
+ BR2_ARM_ENABLE_NEON=y
+ BR2_ARM_ENABLE_VFP=y
+ BR2_TOOLCHAIN_EXTERNAL=y
+ BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
+ BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV7_EABIHF_GLIBC_STABLE=y
+ BR2_LINUX_KERNEL=y
+ BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
+ BR2_LINUX_KERNEL_DTS_SUPPORT=y
+ BR2_LINUX_KERNEL_INTREE_DTS_NAME="arm/vexpress-v2p-ca9"
+ BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
+ BR2_TARGET_ROOTFS_CPIO=y
+ BR2_LINUX_KERNEL_CONFIG_FRAGMENT_FILES="{kernel_fragment}"
+ BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
+ BR2_PACKAGE_PYTHON3=y
+ BR2_PACKAGE_RWMEM=y
+ BR2_PACKAGE_RWMEM_PYTHON=y
+ # BR2_TARGET_ROOTFS_TAR is not set
+ """
+
+ def test_run(self):
+ img = os.path.join(self.builddir, "images", "rootfs.cpio")
+ kern = os.path.join(self.builddir, "images", "zImage")
+ dtb = os.path.join(self.builddir, "images", "vexpress-v2p-ca9.dtb")
+ self.emulator.boot(arch="armv7",
+ kernel=kern,
+ kernel_cmdline=["console=ttyAMA0"],
+ options=["-M", "vexpress-a9",
+ "-dtb", dtb,
+ "-device", "virtio-rng-device",
+ "-device", "tmp105,address=0x49,id=sensor",
+ "-initrd", img])
+ self.emulator.login()
+
+ self.assertRunOk("i2cset -y 0 0x49 0x02 0x5a 0x80 i")
+
+ out, ret = self.emulator.run("rwmem -S 8 -s 16be --i2c=0:0x49 0x02")
+ self.assertEqual(ret, 0)
+ self.assertIn("0x02 (+0x0) = 0x5a80", out)
+
+ out, ret = self.emulator.run("rwmem -S 8 -s 8 --mmap /etc/os-release 0x6-0xe")
+ self.assertEqual(ret, 0)
+ self.assertEqual(out, [
+ "0x06 (+0x0) = 0x75",
+ "0x07 (+0x1) = 0x69",
+ "0x08 (+0x2) = 0x6c",
+ "0x09 (+0x3) = 0x64",
+ "0x0a (+0x4) = 0x72",
+ "0x0b (+0x5) = 0x6f",
+ "0x0c (+0x6) = 0x6f",
+ "0x0d (+0x7) = 0x74"
+ ])
+
+ self.assertRunOk("i2cset -y 0 0x49 0x02 0x7c 0xa0 i")
+ out, ret = self.emulator.run("python3 /root/tests.py")
+ self.assertEqual(ret, 0)
+ self.assertEqual(out, [
+ "0x7ca0",
+ "0x75696c64726f6f74"
+ ])
diff --git a/support/testing/tests/package/test_rwmem/linux-rwmem.fragment b/support/testing/tests/package/test_rwmem/linux-rwmem.fragment
new file mode 100644
index 0000000000..15d1e73bc8
--- /dev/null
+++ b/support/testing/tests/package/test_rwmem/linux-rwmem.fragment
@@ -0,0 +1,3 @@
+CONFIG_I2C=y
+CONFIG_I2C_CHARDEV=y
+CONFIG_SENSORS_LM75=y
\ No newline at end of file
diff --git a/support/testing/tests/package/test_rwmem/rootfs-overlay/root/tests.py b/support/testing/tests/package/test_rwmem/rootfs-overlay/root/tests.py
new file mode 100644
index 0000000000..f3e094b913
--- /dev/null
+++ b/support/testing/tests/package/test_rwmem/rootfs-overlay/root/tests.py
@@ -0,0 +1,22 @@
+#! /usr/bin/env python3
+# This is the python version of the rwmem cli tests.
+import sys
+
+import rwmem as rw
+
+# rwmem -S 8 -s 16be --i2c=0:0x49 0x02
+map = rw.I2CTarget(i2c_adapter_nr=0, i2c_dev_addr=0x49,
+ offset=0x0, length=16,
+ addr_endianness=rw.Endianness.Big, addr_size=1,
+ data_endianness=rw.Endianness.Big, data_size=2,
+ mode=rw.MapMode.ReadWrite)
+
+out = map.read(0x02)
+print(hex(out))
+
+# rwmem -S 8 -s 8 --mmap /etc/os-release 0x6-0xe
+map = rw.MMapTarget('/etc/os-release', 0, 32, rw.Endianness.Big, 1, rw.MapMode.Read)
+out = map.read(0x6, 8)
+print(hex(out))
+
+sys.exit(0)
--
2.51.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
prev parent reply other threads:[~2026-04-08 10:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-08 10:04 [Buildroot] [PATCH 1/2] package/rwmem: add python module Vincent Cruz
2026-04-08 10:04 ` Vincent Cruz [this message]
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=20260408100528.468929-3-mooz@blockos.org \
--to=mooz@blockos.org \
--cc=buildroot@buildroot.org \
--cc=thomas.petazzoni@bootlin.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