aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTao Bao2017-05-01 17:57:38 -0500
committerTao Bao2017-11-03 20:30:41 -0500
commit91a7aa4577feb5f80038a30d15765e8b79845cf1 (patch)
tree9ecb91bec8c5ad34382a5b3d24f36274e9be7aaa /tests
parent0da645fefa55d7cb067b76820c620939d02f106a (diff)
downloadplatform-bootable-recovery-91a7aa4577feb5f80038a30d15765e8b79845cf1.tar.gz
platform-bootable-recovery-91a7aa4577feb5f80038a30d15765e8b79845cf1.tar.xz
platform-bootable-recovery-91a7aa4577feb5f80038a30d15765e8b79845cf1.zip
Clean up fuse_sideload and add a testcase.
This CL mainly changes: a) moving the interface in struct provider_vtab to std::function; b) code cleanup, such as moving the declaration closer to the uses, using explicit type conversion. Test: recovery_component_test Test: minadbd_test Test: Sideload a package on marlin. Change-Id: Id0e3c70f1ada54a4cd985b54c84438c23ed4687e
Diffstat (limited to 'tests')
-rw-r--r--tests/component/sideload_test.cpp70
1 files changed, 66 insertions, 4 deletions
diff --git a/tests/component/sideload_test.cpp b/tests/component/sideload_test.cpp
index 40cfc697..b7109fcc 100644
--- a/tests/component/sideload_test.cpp
+++ b/tests/component/sideload_test.cpp
@@ -16,6 +16,12 @@
16 16
17#include <unistd.h> 17#include <unistd.h>
18 18
19#include <string>
20#include <vector>
21
22#include <android-base/file.h>
23#include <android-base/strings.h>
24#include <android-base/test_utils.h>
19#include <gtest/gtest.h> 25#include <gtest/gtest.h>
20 26
21#include "fuse_sideload.h" 27#include "fuse_sideload.h"
@@ -26,11 +32,67 @@ TEST(SideloadTest, fuse_device) {
26 32
27TEST(SideloadTest, run_fuse_sideload_wrong_parameters) { 33TEST(SideloadTest, run_fuse_sideload_wrong_parameters) {
28 provider_vtab vtab; 34 provider_vtab vtab;
29 vtab.close = [](void*) {}; 35 vtab.close = [](void) {};
30 36
31 ASSERT_EQ(-1, run_fuse_sideload(&vtab, nullptr, 4096, 4095)); 37 ASSERT_EQ(-1, run_fuse_sideload(vtab, 4096, 4095));
32 ASSERT_EQ(-1, run_fuse_sideload(&vtab, nullptr, 4096, (1 << 22) + 1)); 38 ASSERT_EQ(-1, run_fuse_sideload(vtab, 4096, (1 << 22) + 1));
33 39
34 // Too many blocks. 40 // Too many blocks.
35 ASSERT_EQ(-1, run_fuse_sideload(&vtab, nullptr, ((1 << 18) + 1) * 4096, 4096)); 41 ASSERT_EQ(-1, run_fuse_sideload(vtab, ((1 << 18) + 1) * 4096, 4096));
42}
43
44TEST(SideloadTest, run_fuse_sideload) {
45 const std::vector<std::string> blocks = {
46 std::string(2048, 'a') + std::string(2048, 'b'),
47 std::string(2048, 'c') + std::string(2048, 'd'),
48 std::string(2048, 'e') + std::string(2048, 'f'),
49 std::string(2048, 'g') + std::string(2048, 'h'),
50 };
51 const std::string content = android::base::Join(blocks, "");
52 ASSERT_EQ(16384U, content.size());
53
54 provider_vtab vtab;
55 vtab.close = [](void) {};
56 vtab.read_block = [&blocks](uint32_t block, uint8_t* buffer, uint32_t fetch_size) {
57 if (block >= 4) return -1;
58 blocks[block].copy(reinterpret_cast<char*>(buffer), fetch_size);
59 return 0;
60 };
61
62 TemporaryDir mount_point;
63 pid_t pid = fork();
64 if (pid == 0) {
65 ASSERT_EQ(0, run_fuse_sideload(vtab, 16384, 4096, mount_point.path));
66 _exit(EXIT_SUCCESS);
67 }
68
69 std::string package = std::string(mount_point.path) + "/" + FUSE_SIDELOAD_HOST_FILENAME;
70 int status;
71 static constexpr int kSideloadInstallTimeout = 10;
72 for (int i = 0; i < kSideloadInstallTimeout; ++i) {
73 ASSERT_NE(-1, waitpid(pid, &status, WNOHANG));
74
75 struct stat sb;
76 if (stat(package.c_str(), &sb) == 0) {
77 break;
78 }
79
80 if (errno == ENOENT && i < kSideloadInstallTimeout - 1) {
81 sleep(1);
82 continue;
83 }
84 FAIL() << "Timed out waiting for the fuse-provided package.";
85 }
86
87 std::string content_via_fuse;
88 ASSERT_TRUE(android::base::ReadFileToString(package, &content_via_fuse));
89 ASSERT_EQ(content, content_via_fuse);
90
91 std::string exit_flag = std::string(mount_point.path) + "/" + FUSE_SIDELOAD_HOST_EXIT_FLAG;
92 struct stat sb;
93 ASSERT_EQ(0, stat(exit_flag.c_str(), &sb));
94
95 waitpid(pid, &status, 0);
96 ASSERT_EQ(0, WEXITSTATUS(status));
97 ASSERT_EQ(EXIT_SUCCESS, WEXITSTATUS(status));
36} 98}