aboutsummaryrefslogtreecommitdiff
path: root/tests/get_phandle.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/get_phandle.c')
-rw-r--r--tests/get_phandle.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/get_phandle.c b/tests/get_phandle.c
index 6973ee4..e97b49c 100644
--- a/tests/get_phandle.c
+++ b/tests/get_phandle.c
@@ -17,6 +17,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -42,9 +43,30 @@ static void check_phandle(void *fdt, const char *path, uint32_t checkhandle)
path, phandle, checkhandle);
}
+static void check_phandle_unique(const void *fdt, uint32_t checkhandle)
+{
+ uint32_t phandle;
+ int offset = -1;
+
+ while (true) {
+ offset = fdt_next_node(fdt, offset, NULL);
+ if (offset < 0) {
+ if (offset == -FDT_ERR_NOTFOUND)
+ break;
+
+ FAIL("error looking for phandle %#x", checkhandle);
+ }
+
+ phandle = fdt_get_phandle(fdt, offset);
+
+ if (phandle == checkhandle)
+ FAIL("generated phandle already exists");
+ }
+}
+
int main(int argc, char *argv[])
{
- uint32_t max;
+ uint32_t max, phandle;
void *fdt;
int err;
@@ -68,5 +90,11 @@ int main(int argc, char *argv[])
FAIL("fdt_get_max_phandle returned 0x%x instead of 0x%x\n",
max, PHANDLE_2);
+ err = fdt_generate_phandle(fdt, &phandle);
+ if (err < 0)
+ FAIL("failed to generate phandle: %d", err);
+
+ check_phandle_unique(fdt, phandle);
+
PASS();
}