[fdt][test] Add integration test for libfdt

Bug: 282928116
Test: atest liblibfdt.integration_test
Change-Id: Ic9a59bf4ee4d925e028e7d2043d648fad93aa85d
diff --git a/libs/libfdt/tests/api_test.rs b/libs/libfdt/tests/api_test.rs
new file mode 100644
index 0000000..d0feb98
--- /dev/null
+++ b/libs/libfdt/tests/api_test.rs
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//! Integration tests of the library libfdt.
+
+use libfdt::Fdt;
+use std::fs;
+use std::ops::Range;
+
+const TEST_TREE1_PATH: &str = "data/test_tree1.dtb";
+
+#[test]
+fn parse_well_formed_fdt_successfully() {
+    let data = fs::read(TEST_TREE1_PATH).unwrap();
+    let fdt = Fdt::from_slice(&data).unwrap();
+
+    const EXPECTED_FIRST_MEMORY_RANGE: Range<usize> = 0..256;
+    let mut memory = fdt.memory().unwrap().unwrap();
+    assert_eq!(memory.next(), Some(EXPECTED_FIRST_MEMORY_RANGE));
+}
diff --git a/libs/libfdt/tests/data/test_tree1.dts b/libs/libfdt/tests/data/test_tree1.dts
new file mode 100644
index 0000000..222b0b1
--- /dev/null
+++ b/libs/libfdt/tests/data/test_tree1.dts
@@ -0,0 +1,43 @@
+/dts-v1/;
+
+/memreserve/	0x0000000000000000 0x000000000000000e;
+/ {
+	model = "MyBoardName";
+	compatible = "MyBoardName", "MyBoardFamilyName";
+	#address-cells = <0x1>;
+	#size-cells = <0x1>;
+
+	cpus {
+		linux,phandle = <0x1>;
+		#address-cells = <0x1>;
+		#size-cells = <0x0>;
+
+		PowerPC,970@0 {
+			device_type = "cpu";
+			reg = <0x0>;
+			linux,boot-cpu;
+		};
+
+		PowerPC,970@1 {
+			device_type = "cpu";
+			reg = <0x1>;
+		};
+	};
+
+	randomnode {
+		string = "foo", "stuff";
+		bytes = [61 62 63 64 65];
+		nbytes = [80 ff];
+
+		child {
+		};
+	};
+
+	memory {
+		device_type = "memory";
+		reg = <0x0 0x100>;
+	};
+
+	chosen {
+	};
+};