summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/char/misc_minor_kunit.c25
-rw-r--r--init/initramfs_test.c19
2 files changed, 32 insertions, 12 deletions
diff --git a/drivers/char/misc_minor_kunit.c b/drivers/char/misc_minor_kunit.c
index e930c78e1ef9..e85210cbb640 100644
--- a/drivers/char/misc_minor_kunit.c
+++ b/drivers/char/misc_minor_kunit.c
@@ -5,6 +5,7 @@
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include <linux/file.h>
+#include <linux/fs_struct.h>
#include <linux/init_syscalls.h>
/* static minor (LCD_MINOR) */
@@ -160,18 +161,22 @@ static void __init miscdev_test_can_open(struct kunit *test, struct miscdevice *
char *devname;
devname = kasprintf(GFP_KERNEL, "/dev/%s", misc->name);
- ret = init_mknod(devname, S_IFCHR | 0600,
- new_encode_dev(MKDEV(MISC_MAJOR, misc->minor)));
- if (ret != 0)
- KUNIT_FAIL(test, "failed to create node\n");
- filp = filp_open(devname, O_RDONLY, 0);
- if (IS_ERR(filp))
- KUNIT_FAIL(test, "failed to open misc device: %ld\n", PTR_ERR(filp));
- else
- fput(filp);
+ /* Tests run in a nullfs kthread; borrow the init fs to resolve /dev. */
+ scoped_with_init_fs() {
+ ret = init_mknod(devname, S_IFCHR | 0600,
+ new_encode_dev(MKDEV(MISC_MAJOR, misc->minor)));
+ if (ret != 0)
+ KUNIT_FAIL(test, "failed to create node\n");
+
+ filp = filp_open(devname, O_RDONLY, 0);
+ if (IS_ERR(filp))
+ KUNIT_FAIL(test, "failed to open misc device: %ld\n", PTR_ERR(filp));
+ else
+ fput(filp);
- init_unlink(devname);
+ init_unlink(devname);
+ }
kfree(devname);
}
diff --git a/init/initramfs_test.c b/init/initramfs_test.c
index bc55306d226d..9cf316c13ffa 100644
--- a/init/initramfs_test.c
+++ b/init/initramfs_test.c
@@ -3,6 +3,7 @@
#include <linux/fcntl.h>
#include <linux/file.h>
#include <linux/fs.h>
+#include <linux/fs_struct.h>
#include <linux/init.h>
#include <linux/init_syscalls.h>
#include <linux/initrd.h>
@@ -562,7 +563,7 @@ static struct kunit_case __refdata initramfs_test_cases[] = {
{},
};
-static int __init initramfs_test_init(struct kunit_suite *suite)
+static int __init initramfs_suite_init(struct kunit_suite *suite)
{
/*
* unpack_to_rootfs() uses module-static state (victim, byte_count,
@@ -574,9 +575,23 @@ static int __init initramfs_test_init(struct kunit_suite *suite)
return 0;
}
+/* Tests run in a nullfs kthread; always use the init fs for path resolution. */
+static int __init initramfs_test_init(struct kunit *test)
+{
+ test->priv = __override_init_fs();
+ return 0;
+}
+
+static void __init initramfs_test_exit(struct kunit *test)
+{
+ __revert_init_fs(test->priv);
+}
+
static struct kunit_suite __refdata initramfs_test_suite = {
.name = "initramfs",
- .suite_init = initramfs_test_init,
+ .suite_init = initramfs_suite_init,
+ .init = initramfs_test_init,
+ .exit = initramfs_test_exit,
.test_cases = initramfs_test_cases,
};
kunit_test_init_section_suites(&initramfs_test_suite);