summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/component/imgdiff_test.cpp14
-rw-r--r--tests/component/sideload_test.cpp70
2 files changed, 75 insertions, 9 deletions
diff --git a/tests/component/imgdiff_test.cpp b/tests/component/imgdiff_test.cpp
index 6de804e06..728b6cc76 100644
--- a/tests/component/imgdiff_test.cpp
+++ b/tests/component/imgdiff_test.cpp
@@ -657,19 +657,23 @@ static void construct_deflate_entry(const std::vector<std::tuple<std::string, si
}
}
-// Look for the generated source and patch pieces in the debug_dir and generate the target on
-// each pair. Concatenate the split target and match against the orignal one.
+// Look for the source and patch pieces in debug_dir. Generate a target piece from each pair.
+// Concatenate all the target pieces and match against the orignal one. Used pieces in debug_dir
+// will be cleaned up.
static void GenerateAndCheckSplitTarget(const std::string& debug_dir, size_t count,
const std::string& tgt) {
std::string patched;
for (size_t i = 0; i < count; i++) {
std::string split_src_path = android::base::StringPrintf("%s/src-%zu", debug_dir.c_str(), i);
- std::string split_patch_path = android::base::StringPrintf("%s/patch-%zu", debug_dir.c_str(), i);
-
std::string split_src;
- std::string split_patch;
ASSERT_TRUE(android::base::ReadFileToString(split_src_path, &split_src));
+ ASSERT_EQ(0, unlink(split_src_path.c_str()));
+
+ std::string split_patch_path =
+ android::base::StringPrintf("%s/patch-%zu", debug_dir.c_str(), i);
+ std::string split_patch;
ASSERT_TRUE(android::base::ReadFileToString(split_patch_path, &split_patch));
+ ASSERT_EQ(0, unlink(split_patch_path.c_str()));
std::string split_tgt;
GenerateTarget(split_src, split_patch, &split_tgt);
diff --git a/tests/component/sideload_test.cpp b/tests/component/sideload_test.cpp
index 40cfc6975..b7109fcc2 100644
--- a/tests/component/sideload_test.cpp
+++ b/tests/component/sideload_test.cpp
@@ -16,6 +16,12 @@
#include <unistd.h>
+#include <string>
+#include <vector>
+
+#include <android-base/file.h>
+#include <android-base/strings.h>
+#include <android-base/test_utils.h>
#include <gtest/gtest.h>
#include "fuse_sideload.h"
@@ -26,11 +32,67 @@ TEST(SideloadTest, fuse_device) {
TEST(SideloadTest, run_fuse_sideload_wrong_parameters) {
provider_vtab vtab;
- vtab.close = [](void*) {};
+ vtab.close = [](void) {};
- ASSERT_EQ(-1, run_fuse_sideload(&vtab, nullptr, 4096, 4095));
- ASSERT_EQ(-1, run_fuse_sideload(&vtab, nullptr, 4096, (1 << 22) + 1));
+ ASSERT_EQ(-1, run_fuse_sideload(vtab, 4096, 4095));
+ ASSERT_EQ(-1, run_fuse_sideload(vtab, 4096, (1 << 22) + 1));
// Too many blocks.
- ASSERT_EQ(-1, run_fuse_sideload(&vtab, nullptr, ((1 << 18) + 1) * 4096, 4096));
+ ASSERT_EQ(-1, run_fuse_sideload(vtab, ((1 << 18) + 1) * 4096, 4096));
+}
+
+TEST(SideloadTest, run_fuse_sideload) {
+ const std::vector<std::string> blocks = {
+ std::string(2048, 'a') + std::string(2048, 'b'),
+ std::string(2048, 'c') + std::string(2048, 'd'),
+ std::string(2048, 'e') + std::string(2048, 'f'),
+ std::string(2048, 'g') + std::string(2048, 'h'),
+ };
+ const std::string content = android::base::Join(blocks, "");
+ ASSERT_EQ(16384U, content.size());
+
+ provider_vtab vtab;
+ vtab.close = [](void) {};
+ vtab.read_block = [&blocks](uint32_t block, uint8_t* buffer, uint32_t fetch_size) {
+ if (block >= 4) return -1;
+ blocks[block].copy(reinterpret_cast<char*>(buffer), fetch_size);
+ return 0;
+ };
+
+ TemporaryDir mount_point;
+ pid_t pid = fork();
+ if (pid == 0) {
+ ASSERT_EQ(0, run_fuse_sideload(vtab, 16384, 4096, mount_point.path));
+ _exit(EXIT_SUCCESS);
+ }
+
+ std::string package = std::string(mount_point.path) + "/" + FUSE_SIDELOAD_HOST_FILENAME;
+ int status;
+ static constexpr int kSideloadInstallTimeout = 10;
+ for (int i = 0; i < kSideloadInstallTimeout; ++i) {
+ ASSERT_NE(-1, waitpid(pid, &status, WNOHANG));
+
+ struct stat sb;
+ if (stat(package.c_str(), &sb) == 0) {
+ break;
+ }
+
+ if (errno == ENOENT && i < kSideloadInstallTimeout - 1) {
+ sleep(1);
+ continue;
+ }
+ FAIL() << "Timed out waiting for the fuse-provided package.";
+ }
+
+ std::string content_via_fuse;
+ ASSERT_TRUE(android::base::ReadFileToString(package, &content_via_fuse));
+ ASSERT_EQ(content, content_via_fuse);
+
+ std::string exit_flag = std::string(mount_point.path) + "/" + FUSE_SIDELOAD_HOST_EXIT_FLAG;
+ struct stat sb;
+ ASSERT_EQ(0, stat(exit_flag.c_str(), &sb));
+
+ waitpid(pid, &status, 0);
+ ASSERT_EQ(0, WEXITSTATUS(status));
+ ASSERT_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
}