aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPantelis Antoniou <pantelis.antoniou@konsulko.com>2015-04-07 15:23:49 -0400
committerRob Herring <robh@kernel.org>2015-04-14 20:35:46 -0400
commit492a22aceb75e34e7b1c1b300ecc8bef2a2f42dc (patch)
treec2cd43434e59fcbded15c4b5958d8ed9af46638d
parent05f4647b10233dd2e18106abb16ff7fb68abbd08 (diff)
of: unittest: overlay: Keep track of created overlays
During the course of the overlay selftests some of them remain applied. While this does not pose a real problem, make sure you track them and destroy them at the end of the test. Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com> Signed-off-by: Rob Herring <robh@kernel.org>
-rw-r--r--drivers/of/unittest.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index fdb597766be9..995cc73ed630 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -23,6 +23,8 @@
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/i2c-mux.h> 24#include <linux/i2c-mux.h>
25 25
26#include <linux/bitops.h>
27
26#include "of_private.h" 28#include "of_private.h"
27 29
28static struct unittest_results { 30static struct unittest_results {
@@ -1095,6 +1097,59 @@ static const char *overlay_path(int nr)
1095 1097
1096static const char *bus_path = "/testcase-data/overlay-node/test-bus"; 1098static const char *bus_path = "/testcase-data/overlay-node/test-bus";
1097 1099
1100/* it is guaranteed that overlay ids are assigned in sequence */
1101#define MAX_UNITTEST_OVERLAYS 256
1102static unsigned long overlay_id_bits[BITS_TO_LONGS(MAX_UNITTEST_OVERLAYS)];
1103static int overlay_first_id = -1;
1104
1105static void of_unittest_track_overlay(int id)
1106{
1107 if (overlay_first_id < 0)
1108 overlay_first_id = id;
1109 id -= overlay_first_id;
1110
1111 /* we shouldn't need that many */
1112 BUG_ON(id >= MAX_UNITTEST_OVERLAYS);
1113 overlay_id_bits[BIT_WORD(id)] |= BIT_MASK(id);
1114}
1115
1116static void of_unittest_untrack_overlay(int id)
1117{
1118 if (overlay_first_id < 0)
1119 return;
1120 id -= overlay_first_id;
1121 BUG_ON(id >= MAX_UNITTEST_OVERLAYS);
1122 overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id);
1123}
1124
1125static void of_unittest_destroy_tracked_overlays(void)
1126{
1127 int id, ret, defers;
1128
1129 if (overlay_first_id < 0)
1130 return;
1131
1132 /* try until no defers */
1133 do {
1134 defers = 0;
1135 /* remove in reverse order */
1136 for (id = MAX_UNITTEST_OVERLAYS - 1; id >= 0; id--) {
1137 if (!(overlay_id_bits[BIT_WORD(id)] & BIT_MASK(id)))
1138 continue;
1139
1140 ret = of_overlay_destroy(id + overlay_first_id);
1141 if (ret != 0) {
1142 defers++;
1143 pr_warn("%s: overlay destroy failed for #%d\n",
1144 __func__, id + overlay_first_id);
1145 continue;
1146 }
1147
1148 overlay_id_bits[BIT_WORD(id)] &= ~BIT_MASK(id);
1149 }
1150 } while (defers > 0);
1151}
1152
1098static int of_unittest_apply_overlay(int unittest_nr, int overlay_nr, 1153static int of_unittest_apply_overlay(int unittest_nr, int overlay_nr,
1099 int *overlay_id) 1154 int *overlay_id)
1100{ 1155{
@@ -1116,6 +1171,7 @@ static int of_unittest_apply_overlay(int unittest_nr, int overlay_nr,
1116 goto out; 1171 goto out;
1117 } 1172 }
1118 id = ret; 1173 id = ret;
1174 of_unittest_track_overlay(id);
1119 1175
1120 ret = 0; 1176 ret = 0;
1121 1177
@@ -1329,6 +1385,7 @@ static void of_unittest_overlay_6(void)
1329 return; 1385 return;
1330 } 1386 }
1331 ov_id[i] = ret; 1387 ov_id[i] = ret;
1388 of_unittest_track_overlay(ov_id[i]);
1332 } 1389 }
1333 1390
1334 for (i = 0; i < 2; i++) { 1391 for (i = 0; i < 2; i++) {
@@ -1353,6 +1410,7 @@ static void of_unittest_overlay_6(void)
1353 PDEV_OVERLAY)); 1410 PDEV_OVERLAY));
1354 return; 1411 return;
1355 } 1412 }
1413 of_unittest_untrack_overlay(ov_id[i]);
1356 } 1414 }
1357 1415
1358 for (i = 0; i < 2; i++) { 1416 for (i = 0; i < 2; i++) {
@@ -1397,6 +1455,7 @@ static void of_unittest_overlay_8(void)
1397 return; 1455 return;
1398 } 1456 }
1399 ov_id[i] = ret; 1457 ov_id[i] = ret;
1458 of_unittest_track_overlay(ov_id[i]);
1400 } 1459 }
1401 1460
1402 /* now try to remove first overlay (it should fail) */ 1461 /* now try to remove first overlay (it should fail) */
@@ -1419,6 +1478,7 @@ static void of_unittest_overlay_8(void)
1419 PDEV_OVERLAY)); 1478 PDEV_OVERLAY));
1420 return; 1479 return;
1421 } 1480 }
1481 of_unittest_untrack_overlay(ov_id[i]);
1422 } 1482 }
1423 1483
1424 unittest(1, "overlay test %d passed\n", 8); 1484 unittest(1, "overlay test %d passed\n", 8);
@@ -1841,6 +1901,8 @@ static void __init of_unittest_overlay(void)
1841 of_unittest_overlay_i2c_cleanup(); 1901 of_unittest_overlay_i2c_cleanup();
1842#endif 1902#endif
1843 1903
1904 of_unittest_destroy_tracked_overlays();
1905
1844out: 1906out:
1845 of_node_put(bus_np); 1907 of_node_put(bus_np);
1846} 1908}