Skip to content

Commit 0676aee

Browse files
geerturobherring
authored andcommitted
of: unittest: Cleanup partially-applied overlays
When of_overlay_fdt_apply() fails, the changeset may be partially applied, and the caller is still expected to call of_overlay_remove() to clean up this partial state. However, overlay_17 is the only test that takes care of cleaning up after an (expected) failure. Instead of adding cleanup code to each individual test, extend overlay_info with the optional expected return value of of_overlay_remove(), and handle cleanup in the overlay_data_apply() helper. While at it, simplify the end marker in the overlay_info table. Update the expected error output for errors during the newly cleanup. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Link: https://lore.kernel.org/r/594a6a8934e5569bf96d317a6a3c0a9129a2ae20.1690533838.git.geert+renesas@glider.be [robh: update and fix EXPECT messages] Signed-off-by: Rob Herring <robh@kernel.org>
1 parent b7a46e7 commit 0676aee

1 file changed

Lines changed: 84 additions & 48 deletions

File tree

drivers/of/unittest.c

Lines changed: 84 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,12 +2997,6 @@ static void __init of_unittest_overlay_notify(void)
29972997

29982998
unittest(ovcs_id, "ovcs_id not created for overlay_17\n");
29992999

3000-
if (ovcs_id) {
3001-
ret = of_overlay_remove(&ovcs_id);
3002-
unittest(!ret,
3003-
"overlay_17 of_overlay_remove(), ret = %d\n", ret);
3004-
}
3005-
30063000
/* --- overlay 18 --- */
30073001

30083002
unittest(overlay_data_apply("overlay_18", &ovcs_id),
@@ -3292,17 +3286,19 @@ static void __init of_unittest_lifecycle(void)
32923286
extern uint8_t __dtbo_##overlay_name##_begin[]; \
32933287
extern uint8_t __dtbo_##overlay_name##_end[]
32943288

3295-
#define OVERLAY_INFO(overlay_name, expected) \
3296-
{ .dtbo_begin = __dtbo_##overlay_name##_begin, \
3297-
.dtbo_end = __dtbo_##overlay_name##_end, \
3298-
.expected_result = expected, \
3299-
.name = #overlay_name, \
3289+
#define OVERLAY_INFO(overlay_name, expected, expected_remove) \
3290+
{ .dtbo_begin = __dtbo_##overlay_name##_begin, \
3291+
.dtbo_end = __dtbo_##overlay_name##_end, \
3292+
.expected_result = expected, \
3293+
.expected_result_remove = expected_remove, \
3294+
.name = #overlay_name, \
33003295
}
33013296

33023297
struct overlay_info {
33033298
uint8_t *dtbo_begin;
33043299
uint8_t *dtbo_end;
33053300
int expected_result;
3301+
int expected_result_remove; /* if apply failed */
33063302
int ovcs_id;
33073303
char *name;
33083304
};
@@ -3343,41 +3339,41 @@ OVERLAY_INFO_EXTERN(overlay_bad_symbol);
33433339

33443340
/* entries found by name */
33453341
static struct overlay_info overlays[] = {
3346-
OVERLAY_INFO(overlay_base, -9999),
3347-
OVERLAY_INFO(overlay, 0),
3348-
OVERLAY_INFO(overlay_0, 0),
3349-
OVERLAY_INFO(overlay_1, 0),
3350-
OVERLAY_INFO(overlay_2, 0),
3351-
OVERLAY_INFO(overlay_3, 0),
3352-
OVERLAY_INFO(overlay_4, 0),
3353-
OVERLAY_INFO(overlay_5, 0),
3354-
OVERLAY_INFO(overlay_6, 0),
3355-
OVERLAY_INFO(overlay_7, 0),
3356-
OVERLAY_INFO(overlay_8, 0),
3357-
OVERLAY_INFO(overlay_9, 0),
3358-
OVERLAY_INFO(overlay_10, 0),
3359-
OVERLAY_INFO(overlay_11, 0),
3360-
OVERLAY_INFO(overlay_12, 0),
3361-
OVERLAY_INFO(overlay_13, 0),
3362-
OVERLAY_INFO(overlay_15, 0),
3363-
OVERLAY_INFO(overlay_16, -EBUSY),
3364-
OVERLAY_INFO(overlay_17, -EEXIST),
3365-
OVERLAY_INFO(overlay_18, 0),
3366-
OVERLAY_INFO(overlay_19, 0),
3367-
OVERLAY_INFO(overlay_20, 0),
3368-
OVERLAY_INFO(overlay_gpio_01, 0),
3369-
OVERLAY_INFO(overlay_gpio_02a, 0),
3370-
OVERLAY_INFO(overlay_gpio_02b, 0),
3371-
OVERLAY_INFO(overlay_gpio_03, 0),
3372-
OVERLAY_INFO(overlay_gpio_04a, 0),
3373-
OVERLAY_INFO(overlay_gpio_04b, 0),
3374-
OVERLAY_INFO(overlay_pci_node, 0),
3375-
OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL),
3376-
OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL),
3377-
OVERLAY_INFO(overlay_bad_phandle, -EINVAL),
3378-
OVERLAY_INFO(overlay_bad_symbol, -EINVAL),
3342+
OVERLAY_INFO(overlay_base, -9999, 0),
3343+
OVERLAY_INFO(overlay, 0, 0),
3344+
OVERLAY_INFO(overlay_0, 0, 0),
3345+
OVERLAY_INFO(overlay_1, 0, 0),
3346+
OVERLAY_INFO(overlay_2, 0, 0),
3347+
OVERLAY_INFO(overlay_3, 0, 0),
3348+
OVERLAY_INFO(overlay_4, 0, 0),
3349+
OVERLAY_INFO(overlay_5, 0, 0),
3350+
OVERLAY_INFO(overlay_6, 0, 0),
3351+
OVERLAY_INFO(overlay_7, 0, 0),
3352+
OVERLAY_INFO(overlay_8, 0, 0),
3353+
OVERLAY_INFO(overlay_9, 0, 0),
3354+
OVERLAY_INFO(overlay_10, 0, 0),
3355+
OVERLAY_INFO(overlay_11, 0, 0),
3356+
OVERLAY_INFO(overlay_12, 0, 0),
3357+
OVERLAY_INFO(overlay_13, 0, 0),
3358+
OVERLAY_INFO(overlay_15, 0, 0),
3359+
OVERLAY_INFO(overlay_16, -EBUSY, 0),
3360+
OVERLAY_INFO(overlay_17, -EEXIST, 0),
3361+
OVERLAY_INFO(overlay_18, 0, 0),
3362+
OVERLAY_INFO(overlay_19, 0, 0),
3363+
OVERLAY_INFO(overlay_20, 0, 0),
3364+
OVERLAY_INFO(overlay_gpio_01, 0, 0),
3365+
OVERLAY_INFO(overlay_gpio_02a, 0, 0),
3366+
OVERLAY_INFO(overlay_gpio_02b, 0, 0),
3367+
OVERLAY_INFO(overlay_gpio_03, 0, 0),
3368+
OVERLAY_INFO(overlay_gpio_04a, 0, 0),
3369+
OVERLAY_INFO(overlay_gpio_04b, 0, 0),
3370+
OVERLAY_INFO(overlay_pci_node, 0, 0),
3371+
OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL, -ENODEV),
3372+
OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL, -ENODEV),
3373+
OVERLAY_INFO(overlay_bad_phandle, -EINVAL, 0),
3374+
OVERLAY_INFO(overlay_bad_symbol, -EINVAL, -ENODEV),
33793375
/* end marker */
3380-
{.dtbo_begin = NULL, .dtbo_end = NULL, .expected_result = 0, .name = NULL}
3376+
{ }
33813377
};
33823378

33833379
static struct device_node *overlay_base_root;
@@ -3472,8 +3468,9 @@ void __init unittest_unflatten_overlay_base(void)
34723468
static int __init overlay_data_apply(const char *overlay_name, int *ovcs_id)
34733469
{
34743470
struct overlay_info *info;
3471+
int passed = 1;
34753472
int found = 0;
3476-
int ret;
3473+
int ret, ret2;
34773474
u32 size;
34783475

34793476
for (info = overlays; info && info->name; info++) {
@@ -3501,11 +3498,24 @@ static int __init overlay_data_apply(const char *overlay_name, int *ovcs_id)
35013498
pr_debug("%s applied\n", overlay_name);
35023499

35033500
out:
3504-
if (ret != info->expected_result)
3501+
if (ret != info->expected_result) {
35053502
pr_err("of_overlay_fdt_apply() expected %d, ret=%d, %s\n",
35063503
info->expected_result, ret, overlay_name);
3504+
passed = 0;
3505+
}
3506+
3507+
if (ret < 0) {
3508+
/* changeset may be partially applied */
3509+
ret2 = of_overlay_remove(&info->ovcs_id);
3510+
if (ret2 != info->expected_result_remove) {
3511+
pr_err("of_overlay_remove() expected %d, ret=%d, %s\n",
3512+
info->expected_result_remove, ret2,
3513+
overlay_name);
3514+
passed = 0;
3515+
}
3516+
}
35073517

3508-
return (ret == info->expected_result);
3518+
return passed;
35093519
}
35103520

35113521
/*
@@ -3698,10 +3708,18 @@ static __init void of_unittest_overlay_high_level(void)
36983708
"OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller");
36993709
EXPECT_BEGIN(KERN_ERR,
37003710
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
3711+
EXPECT_BEGIN(KERN_ERR,
3712+
"OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/controller:name");
3713+
EXPECT_BEGIN(KERN_ERR,
3714+
"OF: Error reverting changeset (-19)");
37013715

37023716
unittest(overlay_data_apply("overlay_bad_add_dup_node", NULL),
37033717
"Adding overlay 'overlay_bad_add_dup_node' failed\n");
37043718

3719+
EXPECT_END(KERN_ERR,
3720+
"OF: Error reverting changeset (-19)");
3721+
EXPECT_END(KERN_ERR,
3722+
"OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/controller:name");
37053723
EXPECT_END(KERN_ERR,
37063724
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name");
37073725
EXPECT_END(KERN_ERR,
@@ -3713,10 +3731,18 @@ static __init void of_unittest_overlay_high_level(void)
37133731
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail");
37143732
EXPECT_BEGIN(KERN_ERR,
37153733
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
3734+
EXPECT_BEGIN(KERN_ERR,
3735+
"OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/electric:name");
3736+
EXPECT_BEGIN(KERN_ERR,
3737+
"OF: Error reverting changeset (-19)");
37163738

37173739
unittest(overlay_data_apply("overlay_bad_add_dup_prop", NULL),
37183740
"Adding overlay 'overlay_bad_add_dup_prop' failed\n");
37193741

3742+
EXPECT_END(KERN_ERR,
3743+
"OF: Error reverting changeset (-19)");
3744+
EXPECT_END(KERN_ERR,
3745+
"OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/electric:name");
37203746
EXPECT_END(KERN_ERR,
37213747
"OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name");
37223748
EXPECT_END(KERN_ERR,
@@ -3727,9 +3753,19 @@ static __init void of_unittest_overlay_high_level(void)
37273753
unittest(overlay_data_apply("overlay_bad_phandle", NULL),
37283754
"Adding overlay 'overlay_bad_phandle' failed\n");
37293755

3756+
EXPECT_BEGIN(KERN_ERR,
3757+
"OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/hvac-medium-2:name");
3758+
EXPECT_BEGIN(KERN_ERR,
3759+
"OF: Error reverting changeset (-19)");
3760+
37303761
unittest(overlay_data_apply("overlay_bad_symbol", NULL),
37313762
"Adding overlay 'overlay_bad_symbol' failed\n");
37323763

3764+
EXPECT_END(KERN_ERR,
3765+
"OF: Error reverting changeset (-19)");
3766+
EXPECT_END(KERN_ERR,
3767+
"OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/hvac-medium-2:name");
3768+
37333769
return;
37343770

37353771
err_unlock:

0 commit comments

Comments
 (0)