diff mbox series

[meta-oe] memtool: Add recipe

Message ID 20240725113135.55806-1-mark.jonas@de.bosch.com
State Accepted
Headers show
Series [meta-oe] memtool: Add recipe | expand

Commit Message

Jonas Mark (BT-FS/ENG1-GRB) July 25, 2024, 11:31 a.m. UTC
From: Ricardo Simoes <ricardo.simoes@pt.bosch.com>

memtool is a program that allows to access memory mapped registers.
This is useful to inspect and modify registers from the command line.
memtool can also operate on plain files, and access PHY registers.

Signed-off-by: Ricardo Simoes <ricardo.simoes@pt.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
---
 .../memtool/memtool/run-ptest                 | 27 ++++++++
 .../memtool/test_read_write_plainfiles.sh     | 69 +++++++++++++++++++
 .../memtool/memtool_2018.03.0.bb              | 31 +++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 meta-oe/recipes-devtools/memtool/memtool/run-ptest
 create mode 100644 meta-oe/recipes-devtools/memtool/memtool/test_read_write_plainfiles.sh
 create mode 100644 meta-oe/recipes-devtools/memtool/memtool_2018.03.0.bb
diff mbox series

Patch

diff --git a/meta-oe/recipes-devtools/memtool/memtool/run-ptest b/meta-oe/recipes-devtools/memtool/memtool/run-ptest
new file mode 100644
index 000000000..865da9f69
--- /dev/null
+++ b/meta-oe/recipes-devtools/memtool/memtool/run-ptest
@@ -0,0 +1,27 @@ 
+#!/bin/sh
+
+# SPDX-FileCopyrightText: 2024 Bosch Sicherheitssysteme GmbH
+#
+# SPDX-License-Identifier: MIT
+
+fail_count=0
+all_count=0
+
+for test_suite in tests/test_*
+do
+    if "./$test_suite"
+    then
+        echo "PASS: $test_suite"
+    else
+        echo "FAIL: $test_suite"
+        fail_count=$((fail_count + 1))
+    fi
+    all_count=$((all_count + 1))
+done
+
+if [ $fail_count -eq 0 ]
+then
+    echo "PASS: All $all_count tests passed"
+else
+    echo "FAIL: $fail_count of $all_count tests failed"
+fi
diff --git a/meta-oe/recipes-devtools/memtool/memtool/test_read_write_plainfiles.sh b/meta-oe/recipes-devtools/memtool/memtool/test_read_write_plainfiles.sh
new file mode 100644
index 000000000..a74975d39
--- /dev/null
+++ b/meta-oe/recipes-devtools/memtool/memtool/test_read_write_plainfiles.sh
@@ -0,0 +1,69 @@ 
+#!/bin/bash
+
+# SPDX-FileCopyrightText: 2024 Bosch Sicherheitssysteme GmbH
+#
+# SPDX-License-Identifier: MIT
+
+# This script verifies the behavior of memtool against plain files.
+
+readonly PLAIN_FILE=$(mktemp)
+FAIL_COUNT=0
+
+setup() {
+	echo "Hello World!" >"$PLAIN_FILE"
+}
+
+teardown() {
+	rm "$PLAIN_FILE"
+}
+
+verify() {
+	ACTUAL=$1
+	EXPECTED=$2
+	TEST_NAME=$3
+
+	if [ "$ACTUAL" = "$EXPECTED" ]; then
+		echo "pass: $TEST_NAME"
+	else
+		echo "FAIL: $TEST_NAME"
+		echo "  Expected: $EXPECTED"
+		echo "  Actual: $ACTUAL"
+		FAIL_COUNT=$((FAIL_COUNT + 1))
+	fi
+}
+
+# Test Case: Verifies that the expected string of bytes is read from a plain file starting from
+# the offset 6 and reading 6 bytes.
+test_memtool_read() {
+	EXPECTED="00000006: 57 6f 72 6c 64 21                                  World!"
+	ACTUAL=$(memtool md -s "$PLAIN_FILE" -b 0x6+6)
+	verify "$ACTUAL" "$EXPECTED" "memtool read from plain file"
+}
+
+# Test Case 2: Verifies that the expected string of bytes is written to a plain file starting from
+# and then read the result.
+test_memtool_write() {
+	# Usage of 'od' ensures correct endianess.
+	readonly replace_str_bytes=$(echo "Yocto!" | od -t d4 -A n)
+
+	# shellcheck disable=SC2086 # We want to pass the bytes as separate arguments.
+	memtool mw -d "$PLAIN_FILE" 0x6+6 $replace_str_bytes
+
+	EXPECTED="00000006: 59 6f 63 74 6f 21                                  Yocto!"
+	ACTUAL=$(memtool md -s "$PLAIN_FILE" -b 0x6+6)
+	verify "$ACTUAL" "$EXPECTED" "memtool write to plain file"
+}
+
+for test_case in $(declare -F | grep test_memtool_ | cut -f 3 -d ' '); do
+	setup
+	$test_case
+	teardown
+done
+
+if [ $FAIL_COUNT -eq 0 ]; then
+	echo "Test Passed: memtool plain file read/write functionality is correct."
+	exit 0
+else
+	echo "Test FAILED: memtool plain file read/write functionality is incorrect. Check the logs."
+	exit 1
+fi
diff --git a/meta-oe/recipes-devtools/memtool/memtool_2018.03.0.bb b/meta-oe/recipes-devtools/memtool/memtool_2018.03.0.bb
new file mode 100644
index 000000000..1e2e93bcd
--- /dev/null
+++ b/meta-oe/recipes-devtools/memtool/memtool_2018.03.0.bb
@@ -0,0 +1,31 @@ 
+# SPDX-FileCopyrightText: 2024 Bosch Sicherheitssysteme GmbH
+#
+# SPDX-License-Identifier: MIT
+
+SUMMARY = "A tool to manipulate and read memory mapped registers"
+DESCRIPTION = "memtool is a program that allows to access memory mapped registers. This is useful \
+to inspect and modify registers from the command line. memtool can also operate on plain files, \
+and access PHY registers."
+HOMEPAGE = "https://github.com/pengutronix/memtool"
+BUGTRACKER = "https://github.com/pengutronix/memtool/issues"
+SECTION = "devtool"
+
+LICENSE = "GPL-2.0-only"
+LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263"
+
+SRC_URI = " \
+    http://www.pengutronix.de/software/memtool/downloads/memtool-${PV}.tar.xz \
+    file://run-ptest \
+    file://test_read_write_plainfiles.sh \
+"
+
+SRC_URI[sha256sum] = "87cb7175266ff3a00a9c1f541c4c6c93693ffbe8dcc0d97a60d13c45ff860900"
+
+inherit autotools ptest
+
+do_install_ptest () {
+    install -d ${D}${PTEST_PATH}/tests
+    install -m 0755 ${UNPACKDIR}/test_* ${D}${PTEST_PATH}/tests
+}
+
+RDEPENDS:${PN}-ptest += "bash coreutils"