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
17 #include <linux/fs.h>
18 #include <mntent.h>
19
20 #include <algorithm>
21 #include <iterator>
22 #include <set>
23 #include <string>
24 #include <utility>
25 #include <vector>
26
27 #include <android-base/file.h>
28 #include <android-base/properties.h>
29 #include <android-base/strings.h>
30 #include <fs_mgr.h>
31 #include <fstab/fstab.h>
32 #include <gtest/gtest.h>
33
34 #include "../fs_mgr_priv_boot_config.h"
35
36 using namespace android::fs_mgr;
37
38 namespace {
39
40 const std::string cmdline =
41 "rcupdate.rcu_expedited=1 rootwait ro "
42 "init=/init androidboot.bootdevice=1d84000.ufshc "
43 "androidboot.baseband=sdy androidboot.keymaster=1 skip_initramfs "
44 "androidboot.serialno=BLAHBLAHBLAH androidboot.slot_suffix=_a "
45 "androidboot.hardware.platform=sdw813 androidboot.hardware=foo "
46 "androidboot.revision=EVT1.0 androidboot.bootloader=burp-0.1-7521 "
47 "androidboot.hardware.sku=mary androidboot.hardware.radio.subtype=0 "
48 "androidboot.dtbo_idx=2 androidboot.mode=normal "
49 "androidboot.hardware.ddr=1GB,combuchi,LPDDR4X "
50 "androidboot.ddr_info=combuchiandroidboot.ddr_size=2GB "
51 "androidboot.hardware.ufs=2GB,combushi "
52 "androidboot.boottime=0BLE:58,1BLL:22,1BLE:571,2BLL:105,ODT:0,AVB:123 "
53 "androidboot.ramdump=disabled "
54 "dm=\"1 vroot none ro 1,0 10416 verity 1 624684 fec_start 624684\" "
55 "root=/dev/dm-0 "
56 "androidboot.vbmeta.device=PARTUUID=aa08f1a4-c7c9-402e-9a66-9707cafa9ceb "
57 "androidboot.vbmeta.avb_version=\"1.1\" "
58 "androidboot.vbmeta.device_state=unlocked "
59 "androidboot.vbmeta.hash_alg=sha256 androidboot.vbmeta.size=5248 "
60 "androidboot.vbmeta.digest="
61 "ac13147e959861c20f2a6da97d25fe79e60e902c022a371c5c039d31e7c68860 "
62 "androidboot.vbmeta.invalidate_on_error=yes "
63 "androidboot.veritymode=enforcing androidboot.verifiedbootstate=orange "
64 "androidboot.space=\"sha256 5248 androidboot.nospace=nope\" "
65 "printk.devkmsg=on msm_rtb.filter=0x237 ehci-hcd.park=3 "
66 "\"string =\"\"string '\" "
67 "service_locator.enable=1 firmware_class.path=/vendor/firmware "
68 "cgroup.memory=nokmem lpm_levels.sleep_disabled=1 "
69 "buildvariant=userdebug console=null "
70 "terminator=\"truncated";
71
72 const std::vector<std::pair<std::string, std::string>> result_space = {
73 {"rcupdate.rcu_expedited", "1"},
74 {"rootwait", ""},
75 {"ro", ""},
76 {"init", "/init"},
77 {"androidboot.bootdevice", "1d84000.ufshc"},
78 {"androidboot.baseband", "sdy"},
79 {"androidboot.keymaster", "1"},
80 {"skip_initramfs", ""},
81 {"androidboot.serialno", "BLAHBLAHBLAH"},
82 {"androidboot.slot_suffix", "_a"},
83 {"androidboot.hardware.platform", "sdw813"},
84 {"androidboot.hardware", "foo"},
85 {"androidboot.revision", "EVT1.0"},
86 {"androidboot.bootloader", "burp-0.1-7521"},
87 {"androidboot.hardware.sku", "mary"},
88 {"androidboot.hardware.radio.subtype", "0"},
89 {"androidboot.dtbo_idx", "2"},
90 {"androidboot.mode", "normal"},
91 {"androidboot.hardware.ddr", "1GB,combuchi,LPDDR4X"},
92 {"androidboot.ddr_info", "combuchiandroidboot.ddr_size=2GB"},
93 {"androidboot.hardware.ufs", "2GB,combushi"},
94 {"androidboot.boottime", "0BLE:58,1BLL:22,1BLE:571,2BLL:105,ODT:0,AVB:123"},
95 {"androidboot.ramdump", "disabled"},
96 {"dm", "1 vroot none ro 1,0 10416 verity 1 624684 fec_start 624684"},
97 {"root", "/dev/dm-0"},
98 {"androidboot.vbmeta.device", "PARTUUID=aa08f1a4-c7c9-402e-9a66-9707cafa9ceb"},
99 {"androidboot.vbmeta.avb_version", "1.1"},
100 {"androidboot.vbmeta.device_state", "unlocked"},
101 {"androidboot.vbmeta.hash_alg", "sha256"},
102 {"androidboot.vbmeta.size", "5248"},
103 {"androidboot.vbmeta.digest",
104 "ac13147e959861c20f2a6da97d25fe79e60e902c022a371c5c039d31e7c68860"},
105 {"androidboot.vbmeta.invalidate_on_error", "yes"},
106 {"androidboot.veritymode", "enforcing"},
107 {"androidboot.verifiedbootstate", "orange"},
108 {"androidboot.space", "sha256 5248 androidboot.nospace=nope"},
109 {"printk.devkmsg", "on"},
110 {"msm_rtb.filter", "0x237"},
111 {"ehci-hcd.park", "3"},
112 {"string ", "string '"},
113 {"service_locator.enable", "1"},
114 {"firmware_class.path", "/vendor/firmware"},
115 {"cgroup.memory", "nokmem"},
116 {"lpm_levels.sleep_disabled", "1"},
117 {"buildvariant", "userdebug"},
118 {"console", "null"},
119 {"terminator", "truncated"},
120 };
121
122 } // namespace
123
TEST(fs_mgr,fs_mgr_parse_boot_config)124 TEST(fs_mgr, fs_mgr_parse_boot_config) {
125 EXPECT_EQ(result_space, fs_mgr_parse_boot_config(cmdline));
126 }
127
TEST(fs_mgr,fs_mgr_get_boot_config_from_kernel_cmdline)128 TEST(fs_mgr, fs_mgr_get_boot_config_from_kernel_cmdline) {
129 std::string content;
130 for (const auto& entry : result_space) {
131 static constexpr char androidboot[] = "androidboot.";
132 if (!android::base::StartsWith(entry.first, androidboot)) continue;
133 auto key = entry.first.substr(strlen(androidboot));
134 EXPECT_TRUE(fs_mgr_get_boot_config_from_kernel(cmdline, key, &content)) << " for " << key;
135 EXPECT_EQ(entry.second, content);
136 }
137 EXPECT_FALSE(fs_mgr_get_boot_config_from_kernel(cmdline, "vbmeta.avb_versio", &content));
138 EXPECT_TRUE(content.empty()) << content;
139 EXPECT_FALSE(fs_mgr_get_boot_config_from_kernel(cmdline, "nospace", &content));
140 EXPECT_TRUE(content.empty()) << content;
141 }
142
TEST(fs_mgr,fs_mgr_read_fstab_file_proc_mounts)143 TEST(fs_mgr, fs_mgr_read_fstab_file_proc_mounts) {
144 Fstab fstab;
145 ASSERT_TRUE(ReadFstabFromFile("/proc/mounts", &fstab));
146
147 std::unique_ptr<std::FILE, int (*)(std::FILE*)> mounts(setmntent("/proc/mounts", "re"),
148 endmntent);
149 ASSERT_NE(mounts, nullptr);
150
151 mntent* mentry;
152 size_t i = 0;
153 while ((mentry = getmntent(mounts.get())) != nullptr) {
154 ASSERT_LT(i, fstab.size());
155 auto& entry = fstab[i];
156
157 EXPECT_EQ(mentry->mnt_fsname, entry.blk_device);
158 EXPECT_EQ(mentry->mnt_dir, entry.mount_point);
159 EXPECT_EQ(mentry->mnt_type, entry.fs_type);
160
161 std::set<std::string> mnt_opts;
162 for (auto& s : android::base::Split(mentry->mnt_opts, ",")) {
163 mnt_opts.emplace(s);
164 }
165 std::set<std::string> fs_options;
166 if (!entry.fs_options.empty()) {
167 for (auto& s : android::base::Split(entry.fs_options, ",")) {
168 fs_options.emplace(s);
169 }
170 }
171 // matches private content in fs_mgr_fstab.c
172 static struct flag_list {
173 const char* name;
174 unsigned int flag;
175 } mount_flags[] = {
176 {"noatime", MS_NOATIME},
177 {"noexec", MS_NOEXEC},
178 {"nosuid", MS_NOSUID},
179 {"nodev", MS_NODEV},
180 {"nodiratime", MS_NODIRATIME},
181 {"ro", MS_RDONLY},
182 {"rw", 0},
183 {"sync", MS_SYNCHRONOUS},
184 {"remount", MS_REMOUNT},
185 {"bind", MS_BIND},
186 {"rec", MS_REC},
187 {"unbindable", MS_UNBINDABLE},
188 {"private", MS_PRIVATE},
189 {"slave", MS_SLAVE},
190 {"shared", MS_SHARED},
191 {"defaults", 0},
192 {0, 0},
193 };
194 for (auto f = 0; mount_flags[f].name; ++f) {
195 if (mount_flags[f].flag & entry.flags) {
196 fs_options.emplace(mount_flags[f].name);
197 }
198 }
199 if (!(entry.flags & MS_RDONLY)) {
200 fs_options.emplace("rw");
201 }
202 EXPECT_EQ(mnt_opts, fs_options) << "At line " << i;
203 ++i;
204 }
205 EXPECT_EQ(i, fstab.size());
206 }
207
208 // TODO(124837435): enable it later when it can pass TreeHugger.
TEST(fs_mgr,DISABLED_ReadFstabFromFile_MountOptions)209 TEST(fs_mgr, DISABLED_ReadFstabFromFile_MountOptions) {
210 TemporaryFile tf;
211 ASSERT_TRUE(tf.fd != -1);
212 std::string fstab_contents = R"fs(
213 source / ext4 ro,barrier=1 wait,slotselect,avb
214 source /metadata ext4 noatime,nosuid,nodev,discard wait,formattable
215
216 source /data f2fs noatime,nosuid,nodev,discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier latemount,wait,check,fileencryption=ice,keydirectory=/metadata/vold/metadata_encryption,quota,formattable,sysfs_path=/sys/devices/platform/soc/1d84000.ufshc,reservedsize=128M
217
218 source /misc emmc defaults defaults
219
220 source /vendor/firmware_mnt vfat ro,shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337,context=u:object_r:firmware_file:s0 wait,slotselect
221
222 source auto vfat defaults voldmanaged=usb:auto
223 source none swap defaults zramsize=1073741824,max_comp_streams=8
224 source none2 swap nodiratime,remount,bind zramsize=1073741824,max_comp_streams=8
225 source none3 swap unbindable,private,slave zramsize=1073741824,max_comp_streams=8
226 source none4 swap noexec,shared,rec zramsize=1073741824,max_comp_streams=8
227 source none5 swap rw zramsize=1073741824,max_comp_streams=8
228 )fs";
229 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
230
231 Fstab fstab;
232 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
233 ASSERT_EQ(11U, fstab.size());
234
235 EXPECT_EQ("/", fstab[0].mount_point);
236 EXPECT_EQ(static_cast<unsigned long>(MS_RDONLY), fstab[0].flags);
237 EXPECT_EQ("barrier=1", fstab[0].fs_options);
238
239 EXPECT_EQ("/metadata", fstab[1].mount_point);
240 EXPECT_EQ(static_cast<unsigned long>(MS_NOATIME | MS_NOSUID | MS_NODEV), fstab[1].flags);
241 EXPECT_EQ("discard", fstab[1].fs_options);
242
243 EXPECT_EQ("/data", fstab[2].mount_point);
244 EXPECT_EQ(static_cast<unsigned long>(MS_NOATIME | MS_NOSUID | MS_NODEV), fstab[2].flags);
245 EXPECT_EQ("discard,reserve_root=32768,resgid=1065,fsync_mode=nobarrier", fstab[2].fs_options);
246
247 EXPECT_EQ("/misc", fstab[3].mount_point);
248 EXPECT_EQ(0U, fstab[3].flags);
249 EXPECT_EQ("", fstab[3].fs_options);
250
251 EXPECT_EQ("/vendor/firmware_mnt", fstab[4].mount_point);
252 EXPECT_EQ(static_cast<unsigned long>(MS_RDONLY), fstab[4].flags);
253 EXPECT_EQ(
254 "shortname=lower,uid=1000,gid=1000,dmask=227,fmask=337,"
255 "context=u:object_r:firmware_file:s0",
256 fstab[4].fs_options);
257
258 EXPECT_EQ("auto", fstab[5].mount_point);
259 EXPECT_EQ(0U, fstab[5].flags);
260 EXPECT_EQ("", fstab[5].fs_options);
261
262 EXPECT_EQ("none", fstab[6].mount_point);
263 EXPECT_EQ(0U, fstab[6].flags);
264 EXPECT_EQ("", fstab[6].fs_options);
265
266 EXPECT_EQ("none2", fstab[7].mount_point);
267 EXPECT_EQ(static_cast<unsigned long>(MS_NODIRATIME | MS_REMOUNT | MS_BIND), fstab[7].flags);
268 EXPECT_EQ("", fstab[7].fs_options);
269
270 EXPECT_EQ("none3", fstab[8].mount_point);
271 EXPECT_EQ(static_cast<unsigned long>(MS_UNBINDABLE | MS_PRIVATE | MS_SLAVE), fstab[8].flags);
272 EXPECT_EQ("", fstab[8].fs_options);
273
274 EXPECT_EQ("none4", fstab[9].mount_point);
275 EXPECT_EQ(static_cast<unsigned long>(MS_NOEXEC | MS_SHARED | MS_REC), fstab[9].flags);
276 EXPECT_EQ("", fstab[9].fs_options);
277
278 EXPECT_EQ("none5", fstab[10].mount_point);
279 EXPECT_EQ(0U, fstab[10].flags); // rw is the same as defaults
280 EXPECT_EQ("", fstab[10].fs_options);
281 }
282
CompareFlags(FstabEntry::FsMgrFlags & lhs,FstabEntry::FsMgrFlags & rhs)283 static bool CompareFlags(FstabEntry::FsMgrFlags& lhs, FstabEntry::FsMgrFlags& rhs) {
284 // clang-format off
285 return lhs.wait == rhs.wait &&
286 lhs.check == rhs.check &&
287 lhs.crypt == rhs.crypt &&
288 lhs.nonremovable == rhs.nonremovable &&
289 lhs.vold_managed == rhs.vold_managed &&
290 lhs.recovery_only == rhs.recovery_only &&
291 lhs.verify == rhs.verify &&
292 lhs.force_crypt == rhs.force_crypt &&
293 lhs.no_emulated_sd == rhs.no_emulated_sd &&
294 lhs.no_trim == rhs.no_trim &&
295 lhs.file_encryption == rhs.file_encryption &&
296 lhs.formattable == rhs.formattable &&
297 lhs.slot_select == rhs.slot_select &&
298 lhs.force_fde_or_fbe == rhs.force_fde_or_fbe &&
299 lhs.late_mount == rhs.late_mount &&
300 lhs.no_fail == rhs.no_fail &&
301 lhs.verify_at_boot == rhs.verify_at_boot &&
302 lhs.quota == rhs.quota &&
303 lhs.avb == rhs.avb &&
304 lhs.logical == rhs.logical &&
305 lhs.checkpoint_blk == rhs.checkpoint_blk &&
306 lhs.checkpoint_fs == rhs.checkpoint_fs &&
307 lhs.first_stage_mount == rhs.first_stage_mount &&
308 lhs.slot_select_other == rhs.slot_select_other &&
309 lhs.fs_verity == rhs.fs_verity;
310 // clang-format on
311 }
312
313 // TODO(124837435): enable it later when it can pass TreeHugger.
TEST(fs_mgr,DISABLED_ReadFstabFromFile_FsMgrFlags)314 TEST(fs_mgr, DISABLED_ReadFstabFromFile_FsMgrFlags) {
315 TemporaryFile tf;
316 ASSERT_TRUE(tf.fd != -1);
317 std::string fstab_contents = R"fs(
318 source none0 swap defaults wait,check,nonremovable,recoveryonly,verifyatboot,verify
319 source none1 swap defaults avb,noemulatedsd,notrim,formattable,slotselect,nofail
320 source none2 swap defaults first_stage_mount,latemount,quota,logical,slotselect_other
321 source none3 swap defaults checkpoint=block
322 source none4 swap defaults checkpoint=fs
323 source none5 swap defaults defaults
324 )fs";
325 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
326
327 Fstab fstab;
328 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
329 ASSERT_EQ(6U, fstab.size());
330
331 auto entry = fstab.begin();
332 EXPECT_EQ("none0", entry->mount_point);
333 {
334 FstabEntry::FsMgrFlags flags = {};
335 flags.wait = true;
336 flags.check = true;
337 flags.nonremovable = true;
338 flags.recovery_only = true;
339 flags.verify_at_boot = true;
340 flags.verify = true;
341 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
342 }
343 entry++;
344
345 EXPECT_EQ("none1", entry->mount_point);
346 {
347 FstabEntry::FsMgrFlags flags = {};
348 flags.avb = true;
349 flags.no_emulated_sd = true;
350 flags.no_trim = true;
351 flags.formattable = true;
352 flags.slot_select = true;
353 flags.no_fail = true;
354 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
355 }
356 entry++;
357
358 EXPECT_EQ("none2", entry->mount_point);
359 {
360 FstabEntry::FsMgrFlags flags = {};
361 flags.first_stage_mount = true;
362 flags.late_mount = true;
363 flags.quota = true;
364 flags.logical = true;
365 flags.slot_select_other = true;
366 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
367 }
368 entry++;
369
370 EXPECT_EQ("none3", entry->mount_point);
371 {
372 FstabEntry::FsMgrFlags flags = {};
373 flags.checkpoint_blk = true;
374 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
375 }
376 entry++;
377
378 EXPECT_EQ("none4", entry->mount_point);
379 {
380 FstabEntry::FsMgrFlags flags = {};
381 flags.checkpoint_fs = true;
382 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
383 }
384 entry++;
385
386 EXPECT_EQ("none5", entry->mount_point);
387 {
388 FstabEntry::FsMgrFlags flags = {};
389 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
390 }
391 }
392
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_AllBad)393 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_AllBad) {
394 TemporaryFile tf;
395 ASSERT_TRUE(tf.fd != -1);
396 std::string fstab_contents = R"fs(
397 source none0 swap defaults encryptable,forceencrypt,fileencryption,forcefdeorfbe,keydirectory,length,swapprio,zramsize,max_comp_streams,reservedsize,eraseblk,logicalblk,sysfs_path,zram_loopback_path,zram_loopback_size,zram_backing_dev_path
398
399 source none1 swap defaults encryptable=,forceencrypt=,fileencryption=,keydirectory=,length=,swapprio=,zramsize=,max_comp_streams=,avb=,reservedsize=,eraseblk=,logicalblk=,sysfs_path=,zram_loopback_path=,zram_loopback_size=,zram_backing_dev_path=
400
401 source none2 swap defaults forcefdeorfbe=
402
403 )fs";
404 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
405
406 Fstab fstab;
407 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
408 ASSERT_EQ(3U, fstab.size());
409
410 auto entry = fstab.begin();
411 EXPECT_EQ("none0", entry->mount_point);
412 {
413 FstabEntry::FsMgrFlags flags = {};
414 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
415 }
416 EXPECT_EQ("", entry->key_loc);
417 EXPECT_EQ("", entry->metadata_key_dir);
418 EXPECT_EQ(0, entry->length);
419 EXPECT_EQ("", entry->label);
420 EXPECT_EQ(-1, entry->partnum);
421 EXPECT_EQ(-1, entry->swap_prio);
422 EXPECT_EQ(0, entry->max_comp_streams);
423 EXPECT_EQ(0, entry->zram_size);
424 EXPECT_EQ(0, entry->reserved_size);
425 EXPECT_EQ("", entry->encryption_options);
426 EXPECT_EQ(0, entry->erase_blk_size);
427 EXPECT_EQ(0, entry->logical_blk_size);
428 EXPECT_EQ("", entry->sysfs_path);
429 EXPECT_EQ("", entry->zram_loopback_path);
430 EXPECT_EQ(512U * 1024U * 1024U, entry->zram_loopback_size);
431 EXPECT_EQ("", entry->zram_backing_dev_path);
432 entry++;
433
434 EXPECT_EQ("none1", entry->mount_point);
435 {
436 FstabEntry::FsMgrFlags flags = {};
437 flags.crypt = true;
438 flags.force_crypt = true;
439 flags.file_encryption = true;
440 flags.avb = true;
441 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
442 }
443 EXPECT_EQ("", entry->key_loc);
444 EXPECT_EQ("", entry->metadata_key_dir);
445 EXPECT_EQ(0, entry->length);
446 EXPECT_EQ("", entry->label);
447 EXPECT_EQ(-1, entry->partnum);
448 EXPECT_EQ(-1, entry->swap_prio);
449 EXPECT_EQ(0, entry->max_comp_streams);
450 EXPECT_EQ(0, entry->zram_size);
451 EXPECT_EQ(0, entry->reserved_size);
452 EXPECT_EQ("", entry->encryption_options);
453 EXPECT_EQ(0, entry->erase_blk_size);
454 EXPECT_EQ(0, entry->logical_blk_size);
455 EXPECT_EQ("", entry->sysfs_path);
456 EXPECT_EQ("", entry->zram_loopback_path);
457 EXPECT_EQ(512U * 1024U * 1024U, entry->zram_loopback_size);
458 EXPECT_EQ("", entry->zram_backing_dev_path);
459 entry++;
460
461 // forcefdeorfbe has its own encryption_options defaults, so test it separately.
462 EXPECT_EQ("none2", entry->mount_point);
463 {
464 FstabEntry::FsMgrFlags flags = {};
465 flags.force_fde_or_fbe = true;
466 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
467 }
468 EXPECT_EQ("aes-256-xts:aes-256-cts", entry->encryption_options);
469 EXPECT_EQ("", entry->key_loc);
470 }
471
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_Encryptable)472 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_Encryptable) {
473 TemporaryFile tf;
474 ASSERT_TRUE(tf.fd != -1);
475 std::string fstab_contents = R"fs(
476 source none0 swap defaults encryptable=/dir/key
477 )fs";
478 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
479
480 Fstab fstab;
481 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
482 ASSERT_EQ(1U, fstab.size());
483
484 FstabEntry::FsMgrFlags flags = {};
485 flags.crypt = true;
486
487 auto entry = fstab.begin();
488 EXPECT_EQ("none0", entry->mount_point);
489 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
490 EXPECT_EQ("/dir/key", entry->key_loc);
491 }
492
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_VoldManaged)493 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_VoldManaged) {
494 TemporaryFile tf;
495 ASSERT_TRUE(tf.fd != -1);
496 std::string fstab_contents = R"fs(
497 source none0 swap defaults voldmanaged=:
498 source none1 swap defaults voldmanaged=sdcard
499 source none2 swap defaults voldmanaged=sdcard:3
500 source none3 swap defaults voldmanaged=sdcard:auto
501 )fs";
502 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
503
504 Fstab fstab;
505 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
506 ASSERT_EQ(4U, fstab.size());
507
508 FstabEntry::FsMgrFlags flags = {};
509 flags.vold_managed = true;
510
511 auto entry = fstab.begin();
512 EXPECT_EQ("none0", entry->mount_point);
513 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
514 EXPECT_TRUE(entry->label.empty());
515 EXPECT_EQ(-1, entry->partnum);
516 entry++;
517
518 EXPECT_EQ("none1", entry->mount_point);
519 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
520 EXPECT_TRUE(entry->label.empty());
521 EXPECT_EQ(-1, entry->partnum);
522 entry++;
523
524 EXPECT_EQ("none2", entry->mount_point);
525 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
526 EXPECT_EQ("sdcard", entry->label);
527 EXPECT_EQ(3, entry->partnum);
528 entry++;
529
530 EXPECT_EQ("none3", entry->mount_point);
531 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
532 EXPECT_EQ("sdcard", entry->label);
533 EXPECT_EQ(-1, entry->partnum);
534 }
535
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_Length)536 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_Length) {
537 TemporaryFile tf;
538 ASSERT_TRUE(tf.fd != -1);
539 std::string fstab_contents = R"fs(
540 source none0 swap defaults length=blah
541 source none1 swap defaults length=123456
542 )fs";
543 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
544
545 Fstab fstab;
546 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
547 ASSERT_EQ(2U, fstab.size());
548
549 FstabEntry::FsMgrFlags flags = {};
550
551 auto entry = fstab.begin();
552 EXPECT_EQ("none0", entry->mount_point);
553 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
554 EXPECT_EQ(0, entry->length);
555 entry++;
556
557 EXPECT_EQ("none1", entry->mount_point);
558 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
559 EXPECT_EQ(123456, entry->length);
560 }
561
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_Swapprio)562 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_Swapprio) {
563 TemporaryFile tf;
564 ASSERT_TRUE(tf.fd != -1);
565 std::string fstab_contents = R"fs(
566 source none0 swap defaults swapprio=blah
567 source none1 swap defaults swapprio=123456
568 )fs";
569 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
570
571 Fstab fstab;
572 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
573 ASSERT_EQ(2U, fstab.size());
574
575 FstabEntry::FsMgrFlags flags = {};
576
577 auto entry = fstab.begin();
578 EXPECT_EQ("none0", entry->mount_point);
579 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
580 EXPECT_EQ(-1, entry->swap_prio);
581 entry++;
582
583 EXPECT_EQ("none1", entry->mount_point);
584 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
585 EXPECT_EQ(123456, entry->swap_prio);
586 }
587
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_ZramSize)588 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_ZramSize) {
589 TemporaryFile tf;
590 ASSERT_TRUE(tf.fd != -1);
591 std::string fstab_contents = R"fs(
592 source none0 swap defaults zramsize=blah
593 source none1 swap defaults zramsize=123456
594 source none2 swap defaults zramsize=blah%
595 source none3 swap defaults zramsize=5%
596 source none4 swap defaults zramsize=105%
597 source none5 swap defaults zramsize=%
598 )fs";
599 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
600
601 Fstab fstab;
602 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
603 ASSERT_EQ(6U, fstab.size());
604
605 FstabEntry::FsMgrFlags flags = {};
606
607 auto entry = fstab.begin();
608 EXPECT_EQ("none0", entry->mount_point);
609 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
610 EXPECT_EQ(0, entry->zram_size);
611 entry++;
612
613 EXPECT_EQ("none1", entry->mount_point);
614 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
615 EXPECT_EQ(123456, entry->zram_size);
616 entry++;
617
618 EXPECT_EQ("none2", entry->mount_point);
619 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
620 EXPECT_EQ(0, entry->zram_size);
621 entry++;
622
623 EXPECT_EQ("none3", entry->mount_point);
624 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
625 EXPECT_NE(0, entry->zram_size);
626 entry++;
627
628 EXPECT_EQ("none4", entry->mount_point);
629 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
630 EXPECT_EQ(0, entry->zram_size);
631 entry++;
632
633 EXPECT_EQ("none5", entry->mount_point);
634 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
635 EXPECT_EQ(0, entry->zram_size);
636 }
637
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_ForceEncrypt)638 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_ForceEncrypt) {
639 TemporaryFile tf;
640 ASSERT_TRUE(tf.fd != -1);
641 std::string fstab_contents = R"fs(
642 source none0 swap defaults forceencrypt=/dir/key
643 )fs";
644
645 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
646
647 Fstab fstab;
648 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
649 ASSERT_EQ(1U, fstab.size());
650
651 auto entry = fstab.begin();
652 EXPECT_EQ("none0", entry->mount_point);
653
654 FstabEntry::FsMgrFlags flags = {};
655 flags.force_crypt = true;
656 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
657
658 EXPECT_EQ("/dir/key", entry->key_loc);
659 }
660
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_ForceFdeOrFbe)661 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_ForceFdeOrFbe) {
662 TemporaryFile tf;
663 ASSERT_TRUE(tf.fd != -1);
664 std::string fstab_contents = R"fs(
665 source none0 swap defaults forcefdeorfbe=/dir/key
666 )fs";
667
668 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
669
670 Fstab fstab;
671 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
672 ASSERT_EQ(1U, fstab.size());
673
674 auto entry = fstab.begin();
675 EXPECT_EQ("none0", entry->mount_point);
676
677 FstabEntry::FsMgrFlags flags = {};
678 flags.force_fde_or_fbe = true;
679 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
680
681 EXPECT_EQ("/dir/key", entry->key_loc);
682 EXPECT_EQ("aes-256-xts:aes-256-cts", entry->encryption_options);
683 }
684
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_FileEncryption)685 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_FileEncryption) {
686 TemporaryFile tf;
687 ASSERT_TRUE(tf.fd != -1);
688 std::string fstab_contents = R"fs(
689 source none0 swap defaults fileencryption=aes-256-xts:aes-256-cts:v1
690 )fs";
691
692 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
693
694 Fstab fstab;
695 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
696 ASSERT_EQ(1U, fstab.size());
697
698 FstabEntry::FsMgrFlags flags = {};
699 flags.file_encryption = true;
700
701 auto entry = fstab.begin();
702 EXPECT_EQ("none0", entry->mount_point);
703 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
704 EXPECT_EQ("aes-256-xts:aes-256-cts:v1", entry->encryption_options);
705 }
706
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_MaxCompStreams)707 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_MaxCompStreams) {
708 TemporaryFile tf;
709 ASSERT_TRUE(tf.fd != -1);
710 std::string fstab_contents = R"fs(
711 source none0 swap defaults max_comp_streams=blah
712 source none1 swap defaults max_comp_streams=123456
713 )fs";
714 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
715
716 Fstab fstab;
717 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
718 ASSERT_EQ(2U, fstab.size());
719
720 FstabEntry::FsMgrFlags flags = {};
721
722 auto entry = fstab.begin();
723 EXPECT_EQ("none0", entry->mount_point);
724 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
725 EXPECT_EQ(0, entry->max_comp_streams);
726 entry++;
727
728 EXPECT_EQ("none1", entry->mount_point);
729 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
730 EXPECT_EQ(123456, entry->max_comp_streams);
731 }
732
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_ReservedSize)733 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_ReservedSize) {
734 TemporaryFile tf;
735 ASSERT_TRUE(tf.fd != -1);
736 std::string fstab_contents = R"fs(
737 source none0 swap defaults reservedsize=blah
738 source none1 swap defaults reservedsize=2
739 source none2 swap defaults reservedsize=1K
740 source none3 swap defaults reservedsize=2m
741 )fs";
742 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
743
744 Fstab fstab;
745 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
746 ASSERT_EQ(4U, fstab.size());
747
748 FstabEntry::FsMgrFlags flags = {};
749
750 auto entry = fstab.begin();
751 EXPECT_EQ("none0", entry->mount_point);
752 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
753 EXPECT_EQ(0, entry->reserved_size);
754 entry++;
755
756 EXPECT_EQ("none1", entry->mount_point);
757 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
758 EXPECT_EQ(2, entry->reserved_size);
759 entry++;
760
761 EXPECT_EQ("none2", entry->mount_point);
762 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
763 EXPECT_EQ(1024, entry->reserved_size);
764 entry++;
765
766 EXPECT_EQ("none3", entry->mount_point);
767 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
768 EXPECT_EQ(2 * 1024 * 1024, entry->reserved_size);
769 }
770
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_EraseBlk)771 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_EraseBlk) {
772 TemporaryFile tf;
773 ASSERT_TRUE(tf.fd != -1);
774 std::string fstab_contents = R"fs(
775 source none0 swap defaults eraseblk=blah
776 source none1 swap defaults eraseblk=4000
777 source none2 swap defaults eraseblk=5000
778 source none3 swap defaults eraseblk=8192
779 )fs";
780 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
781
782 Fstab fstab;
783 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
784 ASSERT_EQ(4U, fstab.size());
785
786 FstabEntry::FsMgrFlags flags = {};
787
788 auto entry = fstab.begin();
789 EXPECT_EQ("none0", entry->mount_point);
790 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
791 EXPECT_EQ(0, entry->erase_blk_size);
792 entry++;
793
794 EXPECT_EQ("none1", entry->mount_point);
795 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
796 EXPECT_EQ(0, entry->erase_blk_size);
797 entry++;
798
799 EXPECT_EQ("none2", entry->mount_point);
800 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
801 EXPECT_EQ(0, entry->erase_blk_size);
802 entry++;
803
804 EXPECT_EQ("none3", entry->mount_point);
805 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
806 EXPECT_EQ(8192, entry->erase_blk_size);
807 }
808
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_Logicalblk)809 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_Logicalblk) {
810 TemporaryFile tf;
811 ASSERT_TRUE(tf.fd != -1);
812 std::string fstab_contents = R"fs(
813 source none0 swap defaults logicalblk=blah
814 source none1 swap defaults logicalblk=4000
815 source none2 swap defaults logicalblk=5000
816 source none3 swap defaults logicalblk=8192
817 )fs";
818 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
819
820 Fstab fstab;
821 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
822 ASSERT_EQ(4U, fstab.size());
823
824 FstabEntry::FsMgrFlags flags = {};
825
826 auto entry = fstab.begin();
827 EXPECT_EQ("none0", entry->mount_point);
828 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
829 EXPECT_EQ(0, entry->logical_blk_size);
830 entry++;
831
832 EXPECT_EQ("none1", entry->mount_point);
833 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
834 EXPECT_EQ(0, entry->logical_blk_size);
835 entry++;
836
837 EXPECT_EQ("none2", entry->mount_point);
838 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
839 EXPECT_EQ(0, entry->logical_blk_size);
840 entry++;
841
842 EXPECT_EQ("none3", entry->mount_point);
843 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
844 EXPECT_EQ(8192, entry->logical_blk_size);
845 }
846
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_Avb)847 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_Avb) {
848 TemporaryFile tf;
849 ASSERT_TRUE(tf.fd != -1);
850 std::string fstab_contents = R"fs(
851 source none0 swap defaults avb=vbmeta_partition
852 source none1 swap defaults avb_keys=/path/to/test.avbpubkey
853 )fs";
854
855 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
856
857 Fstab fstab;
858 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
859 ASSERT_EQ(2U, fstab.size());
860
861 auto entry = fstab.begin();
862 EXPECT_EQ("none0", entry->mount_point);
863
864 FstabEntry::FsMgrFlags flags = {};
865 flags.avb = true;
866 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
867
868 EXPECT_EQ("vbmeta_partition", entry->vbmeta_partition);
869 entry++;
870
871 EXPECT_EQ("none1", entry->mount_point);
872 FstabEntry::FsMgrFlags empty_flags = {}; // no flags should be set for avb_keys.
873 EXPECT_TRUE(CompareFlags(empty_flags, entry->fs_mgr_flags));
874 EXPECT_EQ("/path/to/test.avbpubkey", entry->avb_keys);
875 }
876
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_KeyDirectory)877 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_KeyDirectory) {
878 TemporaryFile tf;
879 ASSERT_TRUE(tf.fd != -1);
880 std::string fstab_contents = R"fs(
881 source none0 swap defaults keydirectory=/dir/key
882 )fs";
883
884 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
885
886 Fstab fstab;
887 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
888 ASSERT_EQ(1U, fstab.size());
889
890 auto entry = fstab.begin();
891 EXPECT_EQ("none0", entry->mount_point);
892
893 FstabEntry::FsMgrFlags flags = {};
894 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
895
896 EXPECT_EQ("/dir/key", entry->metadata_key_dir);
897 }
898
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_MetadataEncryption)899 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_MetadataEncryption) {
900 TemporaryFile tf;
901 ASSERT_TRUE(tf.fd != -1);
902 std::string fstab_contents = R"fs(
903 source none0 swap defaults keydirectory=/dir/key,metadata_encryption=adiantum
904 )fs";
905
906 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
907
908 Fstab fstab;
909 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
910 ASSERT_EQ(1U, fstab.size());
911
912 auto entry = fstab.begin();
913 EXPECT_EQ("adiantum", entry->metadata_encryption);
914 }
915
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_MetadataEncryption_WrappedKey)916 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_MetadataEncryption_WrappedKey) {
917 TemporaryFile tf;
918 ASSERT_TRUE(tf.fd != -1);
919 std::string fstab_contents = R"fs(
920 source none0 swap defaults keydirectory=/dir/key,metadata_encryption=aes-256-xts:wrappedkey_v0
921 )fs";
922
923 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
924
925 Fstab fstab;
926 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
927 ASSERT_EQ(1U, fstab.size());
928
929 auto entry = fstab.begin();
930 EXPECT_EQ("aes-256-xts:wrappedkey_v0", entry->metadata_encryption);
931 auto parts = android::base::Split(entry->metadata_encryption, ":");
932 EXPECT_EQ(2U, parts.size());
933 EXPECT_EQ("aes-256-xts", parts[0]);
934 EXPECT_EQ("wrappedkey_v0", parts[1]);
935 }
936
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_SysfsPath)937 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_SysfsPath) {
938 TemporaryFile tf;
939 ASSERT_TRUE(tf.fd != -1);
940 std::string fstab_contents = R"fs(
941 source none0 swap defaults sysfs_path=/sys/device
942 )fs";
943
944 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
945
946 Fstab fstab;
947 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
948 ASSERT_EQ(1U, fstab.size());
949
950 auto entry = fstab.begin();
951 EXPECT_EQ("none0", entry->mount_point);
952
953 FstabEntry::FsMgrFlags flags = {};
954 EXPECT_TRUE(CompareFlags(flags, entry->fs_mgr_flags));
955
956 EXPECT_EQ("/sys/device", entry->sysfs_path);
957 }
958
TEST(fs_mgr,ReadFstabFromFile_FsMgrOptions_Zram)959 TEST(fs_mgr, ReadFstabFromFile_FsMgrOptions_Zram) {
960 TemporaryFile tf;
961 ASSERT_TRUE(tf.fd != -1);
962 std::string fstab_contents = R"fs(
963 source none0 swap defaults zram_loopback_path=/dev/path
964
965 source none1 swap defaults zram_loopback_size=blah
966 source none2 swap defaults zram_loopback_size=2
967 source none3 swap defaults zram_loopback_size=1K
968 source none4 swap defaults zram_loopback_size=2m
969
970 source none5 swap defaults zram_backing_dev_path=/dev/path2
971
972 )fs";
973
974 ASSERT_TRUE(android::base::WriteStringToFile(fstab_contents, tf.path));
975
976 Fstab fstab;
977 EXPECT_TRUE(ReadFstabFromFile(tf.path, &fstab));
978 ASSERT_EQ(6U, fstab.size());
979
980 auto entry = fstab.begin();
981 EXPECT_EQ("none0", entry->mount_point);
982 EXPECT_EQ("/dev/path", entry->zram_loopback_path);
983 entry++;
984
985 EXPECT_EQ("none1", entry->mount_point);
986 EXPECT_EQ(512U * 1024U * 1024U, entry->zram_loopback_size);
987 entry++;
988
989 EXPECT_EQ("none2", entry->mount_point);
990 EXPECT_EQ(2U, entry->zram_loopback_size);
991 entry++;
992
993 EXPECT_EQ("none3", entry->mount_point);
994 EXPECT_EQ(1024U, entry->zram_loopback_size);
995 entry++;
996
997 EXPECT_EQ("none4", entry->mount_point);
998 EXPECT_EQ(2U * 1024U * 1024U, entry->zram_loopback_size);
999 entry++;
1000
1001 EXPECT_EQ("none5", entry->mount_point);
1002 EXPECT_EQ("/dev/path2", entry->zram_backing_dev_path);
1003 }
1004
TEST(fs_mgr,DefaultFstabContainsUserdata)1005 TEST(fs_mgr, DefaultFstabContainsUserdata) {
1006 Fstab fstab;
1007 ASSERT_TRUE(ReadDefaultFstab(&fstab)) << "Failed to read default fstab";
1008 ASSERT_NE(nullptr, GetEntryForMountPoint(&fstab, "/data"))
1009 << "Default fstab doesn't contain /data entry";
1010 }
1011
TEST(fs_mgr,UserdataMountedFromDefaultFstab)1012 TEST(fs_mgr, UserdataMountedFromDefaultFstab) {
1013 if (getuid() != 0) {
1014 GTEST_SKIP() << "Must be run as root.";
1015 return;
1016 }
1017 Fstab fstab;
1018 ASSERT_TRUE(ReadDefaultFstab(&fstab)) << "Failed to read default fstab";
1019 Fstab proc_mounts;
1020 ASSERT_TRUE(ReadFstabFromFile("/proc/mounts", &proc_mounts)) << "Failed to read /proc/mounts";
1021 auto mounted_entry = GetEntryForMountPoint(&proc_mounts, "/data");
1022 ASSERT_NE(mounted_entry, nullptr) << "/data is not mounted";
1023 std::string block_device;
1024 ASSERT_TRUE(android::base::Realpath(mounted_entry->blk_device, &block_device));
1025 ASSERT_NE(nullptr, fs_mgr_get_mounted_entry_for_userdata(&fstab, block_device))
1026 << "/data wasn't mounted from default fstab";
1027 }
1028