]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
meta-selftest: add test kernel module recipe
authorAdrian Freihofer <adrian.freihofer@siemens.com>
Mon, 23 Feb 2026 21:06:39 +0000 (22:06 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 5 Mar 2026 11:18:56 +0000 (11:18 +0000)
Add a minimal out-of-tree kernel module and corresponding recipe under
meta-selftest for devtool ide-sdk test coverage.

This provides a simple module source and Makefile that can be built via
the module class in selftest scenarios.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta-selftest/recipes-test/selftest-kmodule/files/Makefile [new file with mode: 0644]
meta-selftest/recipes-test/selftest-kmodule/files/selftest-kmodule.c [new file with mode: 0644]
meta-selftest/recipes-test/selftest-kmodule/selftest-kmodule.bb [new file with mode: 0644]

diff --git a/meta-selftest/recipes-test/selftest-kmodule/files/Makefile b/meta-selftest/recipes-test/selftest-kmodule/files/Makefile
new file mode 100644 (file)
index 0000000..9a26462
--- /dev/null
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: MIT
+
+obj-m := selftest-kmodule.o
+
+SRC := $(shell pwd)
+
+all:
+       $(MAKE) -C $(KERNEL_SRC) M=$(SRC)
+
+modules_install:
+       $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install
+
+clean:
+       rm -f *.o *~ core .depend .*.cmd *.ko *.mod.c
+       rm -f Module.markers Module.symvers modules.order
+       rm -rf .tmp_versions Modules.symvers
diff --git a/meta-selftest/recipes-test/selftest-kmodule/files/selftest-kmodule.c b/meta-selftest/recipes-test/selftest-kmodule/files/selftest-kmodule.c
new file mode 100644 (file)
index 0000000..a72e0a9
--- /dev/null
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: GPL-2.0-only
+ * A simple test kernel module with sysfs interface for devtool ide-sdk testing
+ *
+ * Usage:
+ *   cat /sys/kernel/selftest_kmodule/magic
+ *   Hello from selftest-kmodule
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/kobject.h>
+#include <linux/sysfs.h>
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("OpenEmbedded Contributors");
+MODULE_DESCRIPTION("A simple test kernel module with sysfs interface for devtool ide-sdk testing");
+
+/* Change this string to verify the modify/rebuild/redeploy workflow */
+#define SELFTEST_MAGIC_STRING "Hello from selftest-kmodule"
+
+static struct kobject *selftest_kobj;
+
+static ssize_t magic_show(struct kobject *kobj, struct kobj_attribute *attr,
+                         char *buf)
+{
+       return sysfs_emit(buf, "%s\n", SELFTEST_MAGIC_STRING);
+}
+
+static struct kobj_attribute magic_attr = __ATTR_RO(magic);
+
+static int __init selftest_kmodule_init(void)
+{
+       int ret;
+
+       selftest_kobj = kobject_create_and_add("selftest_kmodule", kernel_kobj);
+       if (!selftest_kobj)
+               return -ENOMEM;
+
+       ret = sysfs_create_file(selftest_kobj, &magic_attr.attr);
+       if (ret)
+               kobject_put(selftest_kobj);
+
+       pr_info("selftest-kmodule: loaded\n");
+       return ret;
+}
+
+static void __exit selftest_kmodule_exit(void)
+{
+       sysfs_remove_file(selftest_kobj, &magic_attr.attr);
+       kobject_put(selftest_kobj);
+       pr_info("selftest-kmodule: unloaded\n");
+}
+
+module_init(selftest_kmodule_init);
+module_exit(selftest_kmodule_exit);
diff --git a/meta-selftest/recipes-test/selftest-kmodule/selftest-kmodule.bb b/meta-selftest/recipes-test/selftest-kmodule/selftest-kmodule.bb
new file mode 100644 (file)
index 0000000..5b3f00c
--- /dev/null
@@ -0,0 +1,18 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+SUMMARY = "A simple kernel module for testing devtool ide-sdk"
+LICENSE = "GPL-2.0-only"
+LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6"
+
+inherit module
+
+SRC_URI = "\
+    file://selftest-kmodule.c \
+    file://Makefile \
+"
+
+S = "${UNPACKDIR}"