Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Geert Uytterhoeven and committed by
Rob Herring
0676aeec b7a46e7b

+84 -48
+84 -48
drivers/of/unittest.c
··· 2997 2997 2998 2998 unittest(ovcs_id, "ovcs_id not created for overlay_17\n"); 2999 2999 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 - 3006 3000 /* --- overlay 18 --- */ 3007 3001 3008 3002 unittest(overlay_data_apply("overlay_18", &ovcs_id), ··· 3286 3292 extern uint8_t __dtbo_##overlay_name##_begin[]; \ 3287 3293 extern uint8_t __dtbo_##overlay_name##_end[] 3288 3294 3289 - #define OVERLAY_INFO(overlay_name, expected) \ 3290 - { .dtbo_begin = __dtbo_##overlay_name##_begin, \ 3291 - .dtbo_end = __dtbo_##overlay_name##_end, \ 3292 - .expected_result = expected, \ 3293 - .name = #overlay_name, \ 3295 + #define OVERLAY_INFO(overlay_name, expected, expected_remove) \ 3296 + { .dtbo_begin = __dtbo_##overlay_name##_begin, \ 3297 + .dtbo_end = __dtbo_##overlay_name##_end, \ 3298 + .expected_result = expected, \ 3299 + .expected_result_remove = expected_remove, \ 3300 + .name = #overlay_name, \ 3294 3301 } 3295 3302 3296 3303 struct overlay_info { 3297 3304 uint8_t *dtbo_begin; 3298 3305 uint8_t *dtbo_end; 3299 3306 int expected_result; 3307 + int expected_result_remove; /* if apply failed */ 3300 3308 int ovcs_id; 3301 3309 char *name; 3302 3310 }; ··· 3339 3343 3340 3344 /* entries found by name */ 3341 3345 static struct overlay_info overlays[] = { 3342 - OVERLAY_INFO(overlay_base, -9999), 3343 - OVERLAY_INFO(overlay, 0), 3344 - OVERLAY_INFO(overlay_0, 0), 3345 - OVERLAY_INFO(overlay_1, 0), 3346 - OVERLAY_INFO(overlay_2, 0), 3347 - OVERLAY_INFO(overlay_3, 0), 3348 - OVERLAY_INFO(overlay_4, 0), 3349 - OVERLAY_INFO(overlay_5, 0), 3350 - OVERLAY_INFO(overlay_6, 0), 3351 - OVERLAY_INFO(overlay_7, 0), 3352 - OVERLAY_INFO(overlay_8, 0), 3353 - OVERLAY_INFO(overlay_9, 0), 3354 - OVERLAY_INFO(overlay_10, 0), 3355 - OVERLAY_INFO(overlay_11, 0), 3356 - OVERLAY_INFO(overlay_12, 0), 3357 - OVERLAY_INFO(overlay_13, 0), 3358 - OVERLAY_INFO(overlay_15, 0), 3359 - OVERLAY_INFO(overlay_16, -EBUSY), 3360 - OVERLAY_INFO(overlay_17, -EEXIST), 3361 - OVERLAY_INFO(overlay_18, 0), 3362 - OVERLAY_INFO(overlay_19, 0), 3363 - OVERLAY_INFO(overlay_20, 0), 3364 - OVERLAY_INFO(overlay_gpio_01, 0), 3365 - OVERLAY_INFO(overlay_gpio_02a, 0), 3366 - OVERLAY_INFO(overlay_gpio_02b, 0), 3367 - OVERLAY_INFO(overlay_gpio_03, 0), 3368 - OVERLAY_INFO(overlay_gpio_04a, 0), 3369 - OVERLAY_INFO(overlay_gpio_04b, 0), 3370 - OVERLAY_INFO(overlay_pci_node, 0), 3371 - OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL), 3372 - OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL), 3373 - OVERLAY_INFO(overlay_bad_phandle, -EINVAL), 3374 - OVERLAY_INFO(overlay_bad_symbol, -EINVAL), 3346 + OVERLAY_INFO(overlay_base, -9999, 0), 3347 + OVERLAY_INFO(overlay, 0, 0), 3348 + OVERLAY_INFO(overlay_0, 0, 0), 3349 + OVERLAY_INFO(overlay_1, 0, 0), 3350 + OVERLAY_INFO(overlay_2, 0, 0), 3351 + OVERLAY_INFO(overlay_3, 0, 0), 3352 + OVERLAY_INFO(overlay_4, 0, 0), 3353 + OVERLAY_INFO(overlay_5, 0, 0), 3354 + OVERLAY_INFO(overlay_6, 0, 0), 3355 + OVERLAY_INFO(overlay_7, 0, 0), 3356 + OVERLAY_INFO(overlay_8, 0, 0), 3357 + OVERLAY_INFO(overlay_9, 0, 0), 3358 + OVERLAY_INFO(overlay_10, 0, 0), 3359 + OVERLAY_INFO(overlay_11, 0, 0), 3360 + OVERLAY_INFO(overlay_12, 0, 0), 3361 + OVERLAY_INFO(overlay_13, 0, 0), 3362 + OVERLAY_INFO(overlay_15, 0, 0), 3363 + OVERLAY_INFO(overlay_16, -EBUSY, 0), 3364 + OVERLAY_INFO(overlay_17, -EEXIST, 0), 3365 + OVERLAY_INFO(overlay_18, 0, 0), 3366 + OVERLAY_INFO(overlay_19, 0, 0), 3367 + OVERLAY_INFO(overlay_20, 0, 0), 3368 + OVERLAY_INFO(overlay_gpio_01, 0, 0), 3369 + OVERLAY_INFO(overlay_gpio_02a, 0, 0), 3370 + OVERLAY_INFO(overlay_gpio_02b, 0, 0), 3371 + OVERLAY_INFO(overlay_gpio_03, 0, 0), 3372 + OVERLAY_INFO(overlay_gpio_04a, 0, 0), 3373 + OVERLAY_INFO(overlay_gpio_04b, 0, 0), 3374 + OVERLAY_INFO(overlay_pci_node, 0, 0), 3375 + OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL, -ENODEV), 3376 + OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL, -ENODEV), 3377 + OVERLAY_INFO(overlay_bad_phandle, -EINVAL, 0), 3378 + OVERLAY_INFO(overlay_bad_symbol, -EINVAL, -ENODEV), 3375 3379 /* end marker */ 3376 - {.dtbo_begin = NULL, .dtbo_end = NULL, .expected_result = 0, .name = NULL} 3380 + { } 3377 3381 }; 3378 3382 3379 3383 static struct device_node *overlay_base_root; ··· 3468 3472 static int __init overlay_data_apply(const char *overlay_name, int *ovcs_id) 3469 3473 { 3470 3474 struct overlay_info *info; 3475 + int passed = 1; 3471 3476 int found = 0; 3472 - int ret; 3477 + int ret, ret2; 3473 3478 u32 size; 3474 3479 3475 3480 for (info = overlays; info && info->name; info++) { ··· 3498 3501 pr_debug("%s applied\n", overlay_name); 3499 3502 3500 3503 out: 3501 - if (ret != info->expected_result) 3504 + if (ret != info->expected_result) { 3502 3505 pr_err("of_overlay_fdt_apply() expected %d, ret=%d, %s\n", 3503 3506 info->expected_result, ret, overlay_name); 3507 + passed = 0; 3508 + } 3504 3509 3505 - return (ret == info->expected_result); 3510 + if (ret < 0) { 3511 + /* changeset may be partially applied */ 3512 + ret2 = of_overlay_remove(&info->ovcs_id); 3513 + if (ret2 != info->expected_result_remove) { 3514 + pr_err("of_overlay_remove() expected %d, ret=%d, %s\n", 3515 + info->expected_result_remove, ret2, 3516 + overlay_name); 3517 + passed = 0; 3518 + } 3519 + } 3520 + 3521 + return passed; 3506 3522 } 3507 3523 3508 3524 /* ··· 3708 3698 "OF: overlay: ERROR: multiple fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller"); 3709 3699 EXPECT_BEGIN(KERN_ERR, 3710 3700 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name"); 3701 + EXPECT_BEGIN(KERN_ERR, 3702 + "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/controller:name"); 3703 + EXPECT_BEGIN(KERN_ERR, 3704 + "OF: Error reverting changeset (-19)"); 3711 3705 3712 3706 unittest(overlay_data_apply("overlay_bad_add_dup_node", NULL), 3713 3707 "Adding overlay 'overlay_bad_add_dup_node' failed\n"); 3714 3708 3709 + EXPECT_END(KERN_ERR, 3710 + "OF: Error reverting changeset (-19)"); 3711 + EXPECT_END(KERN_ERR, 3712 + "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/controller:name"); 3715 3713 EXPECT_END(KERN_ERR, 3716 3714 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/controller/name"); 3717 3715 EXPECT_END(KERN_ERR, ··· 3731 3713 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/rpm_avail"); 3732 3714 EXPECT_BEGIN(KERN_ERR, 3733 3715 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name"); 3716 + EXPECT_BEGIN(KERN_ERR, 3717 + "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/electric:name"); 3718 + EXPECT_BEGIN(KERN_ERR, 3719 + "OF: Error reverting changeset (-19)"); 3734 3720 3735 3721 unittest(overlay_data_apply("overlay_bad_add_dup_prop", NULL), 3736 3722 "Adding overlay 'overlay_bad_add_dup_prop' failed\n"); 3737 3723 3724 + EXPECT_END(KERN_ERR, 3725 + "OF: Error reverting changeset (-19)"); 3726 + EXPECT_END(KERN_ERR, 3727 + "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/motor-1/electric:name"); 3738 3728 EXPECT_END(KERN_ERR, 3739 3729 "OF: overlay: ERROR: multiple fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/electric/name"); 3740 3730 EXPECT_END(KERN_ERR, ··· 3753 3727 unittest(overlay_data_apply("overlay_bad_phandle", NULL), 3754 3728 "Adding overlay 'overlay_bad_phandle' failed\n"); 3755 3729 3730 + EXPECT_BEGIN(KERN_ERR, 3731 + "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/hvac-medium-2:name"); 3732 + EXPECT_BEGIN(KERN_ERR, 3733 + "OF: Error reverting changeset (-19)"); 3734 + 3756 3735 unittest(overlay_data_apply("overlay_bad_symbol", NULL), 3757 3736 "Adding overlay 'overlay_bad_symbol' failed\n"); 3737 + 3738 + EXPECT_END(KERN_ERR, 3739 + "OF: Error reverting changeset (-19)"); 3740 + EXPECT_END(KERN_ERR, 3741 + "OF: changeset: apply failed: REMOVE_PROPERTY /testcase-data-2/substation@100/hvac-medium-2:name"); 3758 3742 3759 3743 return; 3760 3744