[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));
+}