Skip to content

Commit 6e0391e

Browse files
bebarinorobherring
authored andcommitted
of: Skip kunit tests when arm64+ACPI doesn't populate root node
A root node is required to apply DT overlays. A root node is usually present after commit 7b937cc ("of: Create of_root if no dtb provided by firmware"), except for on arm64 systems booted with ACPI tables. In that case, the root node is intentionally not populated because it would "allow DT devices to be instantiated atop an ACPI base system"[1]. Introduce an OF function that skips the kunit test if the root node isn't populated. Limit the test to when both CONFIG_ARM64 and CONFIG_ACPI are set, because otherwise the lack of a root node is a bug. Make the function private and take a kunit test parameter so that it can't be abused to test for the presence of the root node in non-test code. Use this function to skip tests that require the root node. Currently that's the DT tests and any tests that apply overlays. Reported-by: Guenter Roeck <[email protected]> Closes: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] [1] Fixes: 893ecc6 ("of: Add KUnit test to confirm DTB is loaded") Signed-off-by: Stephen Boyd <[email protected]> Tested-by: Guenter Roeck <[email protected]> Acked-by: Mark Rutland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent b68694a commit 6e0391e

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

drivers/of/of_kunit_helpers.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010
#include <kunit/test.h>
1111
#include <kunit/resource.h>
1212

13+
#include "of_private.h"
14+
15+
/**
16+
* of_root_kunit_skip() - Skip test if the root node isn't populated
17+
* @test: test to skip if the root node isn't populated
18+
*/
19+
void of_root_kunit_skip(struct kunit *test)
20+
{
21+
if (IS_ENABLED(CONFIG_ARM64) && IS_ENABLED(CONFIG_ACPI) && !of_root)
22+
kunit_skip(test, "arm64+acpi doesn't populate a root node");
23+
}
24+
EXPORT_SYMBOL_GPL(of_root_kunit_skip);
25+
1326
#if defined(CONFIG_OF_OVERLAY) && defined(CONFIG_OF_EARLY_FLATTREE)
1427

1528
static void of_overlay_fdt_apply_kunit_exit(void *ovcs_id)
@@ -36,6 +49,8 @@ int of_overlay_fdt_apply_kunit(struct kunit *test, void *overlay_fdt,
3649
int ret;
3750
int *copy_id;
3851

52+
of_root_kunit_skip(test);
53+
3954
copy_id = kunit_kmalloc(test, sizeof(*copy_id), GFP_KERNEL);
4055
if (!copy_id)
4156
return -ENOMEM;

drivers/of/of_private.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ extern raw_spinlock_t devtree_lock;
4242
extern struct list_head aliases_lookup;
4343
extern struct kset *of_kset;
4444

45+
struct kunit;
46+
extern void of_root_kunit_skip(struct kunit *test);
47+
4548
#if defined(CONFIG_OF_DYNAMIC)
4649
extern int of_property_notify(int action, struct device_node *np,
4750
struct property *prop, struct property *old_prop);

drivers/of/of_test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include <kunit/test.h>
99

10+
#include "of_private.h"
11+
1012
/*
1113
* Test that the root node "/" can be found by path.
1214
*/
@@ -36,6 +38,7 @@ static struct kunit_case of_dtb_test_cases[] = {
3638

3739
static int of_dtb_test_init(struct kunit *test)
3840
{
41+
of_root_kunit_skip(test);
3942
if (!IS_ENABLED(CONFIG_OF_EARLY_FLATTREE))
4043
kunit_skip(test, "requires CONFIG_OF_EARLY_FLATTREE");
4144

drivers/of/overlay_test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <kunit/of.h>
1212
#include <kunit/test.h>
1313

14+
#include "of_private.h"
15+
1416
static const char * const kunit_node_name = "kunit-test";
1517
static const char * const kunit_compatible = "test,empty";
1618

@@ -62,6 +64,7 @@ static void of_overlay_apply_kunit_cleanup(struct kunit *test)
6264
struct device *dev;
6365
struct device_node *np;
6466

67+
of_root_kunit_skip(test);
6568
if (!IS_ENABLED(CONFIG_OF_EARLY_FLATTREE))
6669
kunit_skip(test, "requires CONFIG_OF_EARLY_FLATTREE for root node");
6770

0 commit comments

Comments
 (0)