// This has changed over time and that causes new GSI + old vendor images testing to fail. // This parameter doesn't matter on Android, so simply ignore its value for older vendor images. if (android::base::GetIntProperty("ro.product.first_api_level", 0) >= 30) {
EXPECT_STREQ("/bin/sh", pwd->pw_shell);
}
}
TEST(pwd, getpwnam_non_exist) {
expect_no_passwd_id(999); // End of the system reserved range, unallocated.
expect_no_passwd_id(1999); // End of the system reserved range, unallocated.
expect_no_passwd_id(2899); // End of the system reserved range, unallocated.
// These ranges are for GIDs only.
expect_no_passwd_id(20000);
expect_no_passwd_id(30000);
expect_no_passwd_id(40000);
expect_no_passwd_id(50000);
// These should not be parsed as users, only as groups.
expect_no_passwd_name("u0_a9999_cache");
expect_no_passwd_name("u0_a9999_ext");
expect_no_passwd_name("u0_a9999_ext_cache");
expect_no_passwd_name("all_a9999");
}
TEST(pwd, getpwuid_app_id_u1_non_exist) {
expect_no_passwd_id(100000); // There is no 'root' for secondary users.
expect_no_passwd_id(101999); // End of the system reserved range, unallocated.
expect_no_passwd_id(102900); // The OEM ranges were never allocated to secondary users.
expect_no_passwd_id(105000); // The OEM ranges were never allocated to secondary users.
// These ranges are for GIDs only.
expect_no_passwd_id(120000);
expect_no_passwd_id(130000);
expect_no_passwd_id(140000);
expect_no_passwd_id(150000);
}
TEST(pwd, getpwuid_app_id_u31_non_exist) {
expect_no_passwd_id(3100000); // There is no 'root' for secondary users.
expect_no_passwd_id(3101999); // End of the system reserved range, unallocated.
expect_no_passwd_id(3102900); // The OEM ranges were never allocated to secondary users.
expect_no_passwd_id(3105000); // The OEM ranges were never allocated to secondary users.
// These ranges are for GIDs only.
expect_no_passwd_id(3120000);
expect_no_passwd_id(3130000);
expect_no_passwd_id(3140000);
expect_no_passwd_id(3150000);
}
#ifdefined(__BIONIC__) template <typename T> staticvoid expect_ids(T ids, bool is_group) {
std::set<typename T::key_type> expected_ids; // Ensure that all android_ids are iterated through. for (size_t n = 0; n < android_id_count; ++n) {
EXPECT_EQ(1U, ids.count(android_ids[n].aid)) << "android_ids[n].aid: " << android_ids[n].aid;
expected_ids.emplace(android_ids[n].aid);
}
auto expect_range = [&ids, &expected_ids](uid_t start, uid_t end) { for (size_t n = start; n <= end; ++n) {
EXPECT_EQ(1U, ids.count(n)) << "n: " << n;
expected_ids.emplace(n);
}
};
// Ensure that all reserved ranges are iterated through.
expect_range(AID_OEM_RESERVED_START, AID_OEM_RESERVED_END);
expect_range(AID_OEM_RESERVED_2_START, AID_OEM_RESERVED_2_END);
expect_range(AID_APP_START, AID_APP_END); if (is_group) {
expect_range(AID_CACHE_GID_START, AID_CACHE_GID_END);
expect_range(AID_EXT_GID_START, AID_EXT_GID_END);
expect_range(AID_EXT_CACHE_GID_START, AID_EXT_CACHE_GID_END);
expect_range(AID_SHARED_GID_START, AID_SHARED_GID_END);
}
expect_range(AID_ISOLATED_START, AID_ISOLATED_END);
// Prior to R, we didn't have a mechanism to create vendor AIDs in the system or other non-vendor // partitions, therefore we disabled the rest of these checks for older API levels. if (android::base::GetIntProperty("ro.product.first_api_level", 0) <= 29) { return;
}
auto allow_range = [&ids](uid_t start, uid_t end) { for (size_t n = start; n <= end; ++n) {
ids.erase(n);
}
};
// Ensure that no other ids were returned. auto return_differences = [&ids, &expected_ids] {
std::vector<typename T::key_type> missing_from_ids;
std::set_difference(expected_ids.begin(), expected_ids.end(), ids.begin(), ids.end(),
std::inserter(missing_from_ids, missing_from_ids.begin()));
std::vector<typename T::key_type> extra_in_ids;
std::set_difference(ids.begin(), ids.end(), expected_ids.begin(), expected_ids.end(),
std::inserter(extra_in_ids, extra_in_ids.begin()));
std::string result; if (!missing_from_ids.empty()) {
result += "Missing ids from results: " + Join(missing_from_ids, " ");
} if (!extra_in_ids.empty()) { if (!result.empty()) result += ", ";
result += "Extra ids in results: " + Join(extra_in_ids, " ");
} return result;
};
// AID_CROS_EC (1094) was added in API level 36, but "trunk stable" means // that the 2024Q* builds are tested with the _previous_ release's CTS. if (android::base::GetIntProperty("ro.build.version.sdk", 0) == 35) { #if !defined(AID_CROS_EC) #define AID_CROS_EC 1094 #endif
ids.erase(AID_CROS_EC);
expected_ids.erase(AID_CROS_EC); if (getpwuid(AID_CROS_EC)) {
EXPECT_STREQ(getpwuid(AID_CROS_EC)->pw_name, "cros_ec");
}
} // AID_MMD (1095) was added in API level 36, but "trunk stable" means // that the 2024Q* builds are tested with the _previous_ release's CTS. if (android::base::GetIntProperty("ro.build.version.sdk", 0) == 35) { #if !defined(AID_MMD) #define AID_MMD 1095 #endif
ids.erase(AID_MMD);
expected_ids.erase(AID_MMD); if (getpwuid(AID_MMD)) {
EXPECT_STREQ(getpwuid(AID_MMD)->pw_name, "mmd");
}
} // AID_UPDATE_ENGINE_LOG (1096) was added in API level 36, but "trunk stable" means // that the 2024Q* builds are tested with the _previous_ release's CTS. if (android::base::GetIntProperty("ro.build.version.sdk", 0) == 35) { #if !defined(AID_UPDATE_ENGINE_LOG) #define AID_UPDATE_ENGINE_LOG 1096 #endif
ids.erase(AID_UPDATE_ENGINE_LOG);
expected_ids.erase(AID_UPDATE_ENGINE_LOG); if (getpwuid(AID_UPDATE_ENGINE_LOG)) {
EXPECT_STREQ(getpwuid(AID_UPDATE_ENGINE_LOG)->pw_name, "update_engine_log");
}
} // AID_AP_FIRMWARE (1097) was added in API level 37, but "trunk stable" means // that the 2025Q{1,2} builds are tested with the _previous_ release's CTS. if (android::base::GetIntProperty("ro.build.version.sdk", 0) == 36) { #if !defined(AID_AP_FIRMWARE) #define AID_AP_FIRMWARE 1097 #endif
ids.erase(AID_AP_FIRMWARE);
expected_ids.erase(AID_AP_FIRMWARE); if (getpwuid(AID_AP_FIRMWARE)) {
EXPECT_STREQ(getpwuid(AID_AP_FIRMWARE)->pw_name, "ap_firmware");
}
}
// AID_PMGD (1098) was added in API level 37, but "trunk stable" means // that the 2025Q* builds are tested with the _previous_ release's CTS. if (android::base::GetIntProperty("ro.build.version.sdk", 0) == 36) { #if !defined(AID_PMGD) #define AID_PMGD 1098 #endif
ids.erase(AID_PMGD);
expected_ids.erase(AID_PMGD); if (getpwuid(AID_PMGD)) {
EXPECT_STREQ(getpwuid(AID_PMGD)->pw_name, "pmgd");
}
}
// AID_SDV* (1099-1102) was added in API level 37, but "trunk stable" means // that the 2025Q* builds are tested with the _previous_ release's CTS. if (android::base::GetIntProperty("ro.build.version.sdk", 0) == 36) { #if !defined(AID_SDV_SD_AGENT) #define AID_SDV_SD_AGENT 1099 #endif #if !defined(AID_SDV_DT_AGENT) #define AID_SDV_DT_AGENT 1100 #endif #if !defined(AID_SDV_RPC_AGENT) #define AID_SDV_RPC_AGENT 1101 #endif #if !defined(AID_SDV_INIT_OPEN_DICE) #define AID_SDV_INIT_OPEN_DICE 1102 #endif
ids.erase(AID_SDV_SD_AGENT);
expected_ids.erase(AID_SDV_SD_AGENT); if (getpwuid(AID_SDV_SD_AGENT)) {
EXPECT_STREQ(getpwuid(AID_SDV_SD_AGENT)->pw_name, "sdv_sd_agent");
}
ids.erase(AID_SDV_DT_AGENT);
expected_ids.erase(AID_SDV_DT_AGENT); if (getpwuid(AID_SDV_DT_AGENT)) {
EXPECT_STREQ(getpwuid(AID_SDV_DT_AGENT)->pw_name, "sdv_dt_agent");
}
ids.erase(AID_SDV_RPC_AGENT);
expected_ids.erase(AID_SDV_RPC_AGENT); if (getpwuid(AID_SDV_RPC_AGENT)) {
EXPECT_STREQ(getpwuid(AID_SDV_RPC_AGENT)->pw_name, "sdv_rpc_agent");
}
ids.erase(AID_SDV_INIT_OPEN_DICE);
expected_ids.erase(AID_SDV_INIT_OPEN_DICE); if (getpwuid(AID_SDV_INIT_OPEN_DICE)) {
EXPECT_STREQ(getpwuid(AID_SDV_INIT_OPEN_DICE)->pw_name, "sdv_init_open_dice");
}
}
TEST(grp, getgrnam_non_exist) {
expect_no_passwd_id(999); // End of the system reserved range, unallocated.
expect_no_passwd_id(1999); // End of the system reserved range, unallocated.
expect_no_passwd_id(2899); // End of the system reserved range, unallocated.
}
TEST(grp, getgrgid_app_id_u1_non_exist) {
expect_no_group_id(100000); // There is no 'root' for secondary users.
expect_no_group_id(101999); // End of the system reserved range, unallocated.
expect_no_group_id(102900); // The OEM ranges were never allocated to secondary users.
expect_no_group_id(105000); // The OEM ranges were never allocated to secondary users.
// The shared range is shared among users, and therefore doesn't exist for secondary users.
expect_no_group_id(150000);
}
TEST(grp, getgrgid_app_id_u31_non_exist) {
expect_no_group_id(3100000); // There is no 'root' for secondary users.
expect_no_group_id(3101999); // End of the system reserved range, unallocated.
expect_no_group_id(3102900); // The OEM ranges were never allocated to secondary users.
expect_no_group_id(3105000); // The OEM ranges were never allocated to secondary users.
// The shared range is shared among users, and therefore doesn't exist for secondary users.
expect_no_group_id(3150000);
}
TEST(grp, getgrouplist) { #ifdefined(__BIONIC__) // Query the number of groups. int ngroups = 0;
ASSERT_EQ(-1, getgrouplist("root", 123, nullptr, &ngroups));
ASSERT_EQ(1, ngroups);
// Query the specific groups (just the one you pass in on Android).
ngroups = 8;
gid_t groups[ngroups];
ASSERT_EQ(1, getgrouplist("root", 123, groups, &ngroups));
ASSERT_EQ(1, ngroups);
ASSERT_EQ(123u, groups[0]); #else
GTEST_SKIP() << "bionic-only test (groups too unpredictable)"; #endif
}
#ifdefined(__BIONIC__) staticvoid TestAidNamePrefix(const std::string& file_path) {
std::string file_contents; if (!ReadFileToString(file_path, &file_contents)) { // If we cannot read this file, then there are no vendor defind AID names, in which case this // test passes by default. return;
} auto lines = Split(file_contents, "\n"); for (constauto& line : lines) { if (line.empty()) continue; auto name = Split(line, ":")[0];
EXPECT_TRUE(StartsWith(name, "vendor_"));
}
} #endif
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.19Bemerkung:
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.