vts_fs_test: checks AVB 1.0 isn't used

AVB 1.0 support in fs_mgr has been removed in commit
Ibfb46aa6c2f761dbb3a9b5f0b16336e510417620.

Adding a VTS test case to ensure the legacy 'verify' fs_mgr
flag isn't used anymore.

Also converting GetFstabPath() to a public API in the fstab.h,
so the test case can read then parse the fstab file.

Bug: 204948957
Test: atest vts_fs_test
Change-Id: Ib6ed7cb8b6ad719b19cd876acf10f4312ecb51b6
This commit is contained in:
Bowgo Tsai 2022-07-15 14:04:05 +08:00
parent 86cc51ae60
commit 80cb505f64
3 changed files with 60 additions and 28 deletions

View file

@ -439,34 +439,6 @@ std::string ReadFstabFromDt() {
return fstab_result;
}
// Return the path to the fstab file. There may be multiple fstab files; the
// one that is returned will be the first that exists of fstab.<fstab_suffix>,
// fstab.<hardware>, and fstab.<hardware.platform>. The fstab is searched for
// in /odm/etc/ and /vendor/etc/, as well as in the locations where it may be in
// the first stage ramdisk during early boot. Previously, the first stage
// ramdisk's copy of the fstab had to be located in the root directory, but now
// the system/etc directory is supported too and is the preferred location.
std::string GetFstabPath() {
for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) {
std::string suffix;
if (!fs_mgr_get_boot_config(prop, &suffix)) continue;
for (const char* prefix : {// late-boot/post-boot locations
"/odm/etc/fstab.", "/vendor/etc/fstab.",
// early boot locations
"/system/etc/fstab.", "/first_stage_ramdisk/system/etc/fstab.",
"/fstab.", "/first_stage_ramdisk/fstab."}) {
std::string fstab_path = prefix + suffix;
if (access(fstab_path.c_str(), F_OK) == 0) {
return fstab_path;
}
}
}
return "";
}
/* Extracts <device>s from the by-name symlinks specified in a fstab:
* /dev/block/<type>/<device>/by-name/<partition>
*
@ -526,6 +498,34 @@ std::vector<FstabEntry*> GetEntriesByPred(Fstab* fstab, const Pred& pred) {
} // namespace
// Return the path to the fstab file. There may be multiple fstab files; the
// one that is returned will be the first that exists of fstab.<fstab_suffix>,
// fstab.<hardware>, and fstab.<hardware.platform>. The fstab is searched for
// in /odm/etc/ and /vendor/etc/, as well as in the locations where it may be in
// the first stage ramdisk during early boot. Previously, the first stage
// ramdisk's copy of the fstab had to be located in the root directory, but now
// the system/etc directory is supported too and is the preferred location.
std::string GetFstabPath() {
for (const char* prop : {"fstab_suffix", "hardware", "hardware.platform"}) {
std::string suffix;
if (!fs_mgr_get_boot_config(prop, &suffix)) continue;
for (const char* prefix : {// late-boot/post-boot locations
"/odm/etc/fstab.", "/vendor/etc/fstab.",
// early boot locations
"/system/etc/fstab.", "/first_stage_ramdisk/system/etc/fstab.",
"/fstab.", "/first_stage_ramdisk/fstab."}) {
std::string fstab_path = prefix + suffix;
if (access(fstab_path.c_str(), F_OK) == 0) {
return fstab_path;
}
}
}
return "";
}
bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out) {
const int expected_fields = proc_mounts ? 4 : 5;

View file

@ -95,6 +95,8 @@ using Fstab = std::vector<FstabEntry>;
// Exported for testability. Regular users should use ReadFstabFromFile().
bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out);
// Exported for testability. Regular users should use ReadDefaultFstab().
std::string GetFstabPath();
bool ReadFstabFromFile(const std::string& path, Fstab* fstab);
bool ReadFstabFromDt(Fstab* fstab, bool verbose = true);

View file

@ -23,6 +23,9 @@
#include <gtest/gtest.h>
#include <libdm/dm.h>
using testing::Contains;
using testing::Not;
static int GetVsrLevel() {
return android::base::GetIntProperty("ro.vendor.api_level", -1);
}
@ -117,3 +120,30 @@ TEST(fs, NoDtFstab) {
android::fs_mgr::Fstab fstab;
EXPECT_FALSE(android::fs_mgr::ReadFstabFromDt(&fstab, false));
}
TEST(fs, NoLegacyVerifiedBoot) {
if (GetVsrLevel() < __ANDROID_API_T__) {
GTEST_SKIP();
}
const auto& default_fstab_path = android::fs_mgr::GetFstabPath();
EXPECT_FALSE(default_fstab_path.empty());
std::string fstab_str;
EXPECT_TRUE(android::base::ReadFileToString(default_fstab_path, &fstab_str,
/* follow_symlinks = */ true));
for (const auto& line : android::base::Split(fstab_str, "\n")) {
auto fields = android::base::Tokenize(line, " \t");
// Ignores empty lines and comments.
if (fields.empty() || android::base::StartsWith(fields.front(), '#')) {
continue;
}
// Each line in a fstab should have at least five entries.
// <src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>
ASSERT_GE(fields.size(), 5);
EXPECT_THAT(android::base::Split(fields[4], ","), Not(Contains("verify")))
<< "AVB 1.0 isn't supported now, but the 'verify' flag is found:\n"
<< " " << line;
}
}