VintfObjectRecoveryTest.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <dirent.h>
  17. #include <memory>
  18. #include <android-base/logging.h>
  19. #include <gtest/gtest.h>
  20. #include <vintf/VintfObjectRecovery.h>
  21. namespace android {
  22. namespace vintf {
  23. bool directoryEmpty(const char* path) {
  24. auto dir = std::unique_ptr<DIR, decltype(&closedir)>(opendir(path), &closedir);
  25. if (!dir) return true;
  26. for (struct dirent* dirent; (dirent = readdir(dir.get())) != nullptr;) {
  27. if (strcmp(dirent->d_name, ".") == 0) continue;
  28. if (strcmp(dirent->d_name, "..") == 0) continue;
  29. LOG(ERROR) << "Seen: " << path << "/" << dirent->d_name;
  30. return false;
  31. }
  32. return true;
  33. }
  34. struct VintfObjectRecoveryTest : public ::testing::Test {};
  35. TEST_F(VintfObjectRecoveryTest, LoadAllVintf) {
  36. std::string error;
  37. ASSERT_EQ(COMPATIBLE, VintfObjectRecovery::CheckCompatibility({}, &error)) << error;
  38. EXPECT_TRUE(directoryEmpty("/mnt/system"));
  39. EXPECT_TRUE(directoryEmpty("/mnt/vendor"));
  40. EXPECT_TRUE(directoryEmpty("/mnt/odm"));
  41. ASSERT_EQ(COMPATIBLE, VintfObjectRecovery::CheckCompatibility({}, &error))
  42. << "Second CheckCompatibility call should still be successful because all "
  43. << "partitions should already be unmounted, but error: " << error;
  44. EXPECT_TRUE(directoryEmpty("/mnt/system"));
  45. EXPECT_TRUE(directoryEmpty("/mnt/vendor"));
  46. EXPECT_TRUE(directoryEmpty("/mnt/odm"));
  47. }
  48. } // namespace vintf
  49. } // namespace android
  50. int main(int argc, char** argv) {
  51. // There is no logcat in recovery.
  52. android::base::SetLogger(android::base::StderrLogger);
  53. ::testing::InitGoogleTest(&argc, argv);
  54. return RUN_ALL_TESTS();
  55. }