Test for checking persistence of encryptedstore
Test#encryptedStorageIsPersistent creates a VM, writes an example string
into a file backed by encryptedstore. Then it stops the VM, re-runs it
(this will reuse the instance image & backing storage). Then it reads
the file & checks that the content is the same as the string before.
Test: atest MicrodroidTests#encryptedStorageIsPersistent
Bug: 260084116
Change-Id: I9a0694de07175c1a29d37fd16488d1523eb13fed
diff --git a/tests/testapk/src/native/testbinary.cpp b/tests/testapk/src/native/testbinary.cpp
index da408e4..4ba502a 100644
--- a/tests/testapk/src/native/testbinary.cpp
+++ b/tests/testapk/src/native/testbinary.cpp
@@ -232,6 +232,29 @@
return ScopedAStatus::fromServiceSpecificErrorWithMessage(-1, message.c_str());
}
}
+
+ ScopedAStatus writeToFile(const std::string& content, const std::string& path) override {
+ if (!android::base::WriteStringToFile(content, path)) {
+ std::string msg = "Failed to write " + content + " to file " + path +
+ ". Errono: " + std::to_string(errno);
+ return ScopedAStatus::fromExceptionCodeWithMessage(EX_SERVICE_SPECIFIC,
+ msg.c_str());
+ }
+ // TODO(b/264520098): Remove sync() once TestService supports quit() method
+ // and Microdroid manager flushes filesystem caches on shutdown.
+ sync();
+ return ScopedAStatus::ok();
+ }
+
+ ScopedAStatus readFromFile(const std::string& path, std::string* out) override {
+ if (!android::base::ReadFileToString(path, out)) {
+ std::string msg =
+ "Failed to read " + path + " to string. Errono: " + std::to_string(errno);
+ return ScopedAStatus::fromExceptionCodeWithMessage(EX_SERVICE_SPECIFIC,
+ msg.c_str());
+ }
+ return ScopedAStatus::ok();
+ }
};
auto testService = ndk::SharedRefBase::make<TestService>();