Merge "aconfig: test updates" into main am: d740c50331

Original change: https://android-review.googlesource.com/c/platform/build/+/3021364

Change-Id: I21f0c5acf02227d258a5e12aa0907e552acf638f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Dennis Shen 2024-04-02 18:09:28 +00:00 committed by Automerger Merge Worker
commit 32e7cafcc7
20 changed files with 73 additions and 275 deletions

View file

@ -141,79 +141,18 @@ mod tests {
use super::*;
use crate::storage::{group_flags_by_package, tests::parse_all_test_flags};
// create test baseline, syntactic sugar
fn new_expected_node(
package_id: u32,
flag_name: &str,
flag_type: u16,
flag_id: u16,
next_offset: Option<u32>,
) -> FlagTableNode {
FlagTableNode {
package_id,
flag_name: flag_name.to_string(),
flag_type: StoredFlagType::try_from(flag_type).unwrap(),
flag_id,
next_offset,
}
}
fn create_test_flag_table() -> Result<FlagTable> {
fn create_test_flag_table_from_source() -> Result<FlagTable> {
let caches = parse_all_test_flags();
let packages = group_flags_by_package(caches.iter());
create_flag_table("system", &packages)
create_flag_table("mockup", &packages)
}
#[test]
// this test point locks down the table creation and each field
fn test_table_contents() {
let flag_table = create_test_flag_table();
let flag_table = create_test_flag_table_from_source();
assert!(flag_table.is_ok());
let header: &FlagTableHeader = &flag_table.as_ref().unwrap().header;
let expected_header = FlagTableHeader {
version: FILE_VERSION,
container: String::from("system"),
file_type: StorageFileType::FlagMap as u8,
file_size: 321,
num_flags: 8,
bucket_offset: 31,
node_offset: 99,
};
assert_eq!(header, &expected_header);
let buckets: &Vec<Option<u32>> = &flag_table.as_ref().unwrap().buckets;
let expected_bucket: Vec<Option<u32>> = vec![
Some(99),
Some(125),
None,
None,
None,
Some(178),
None,
Some(204),
None,
Some(262),
None,
None,
None,
None,
None,
Some(294),
None,
];
assert_eq!(buckets, &expected_bucket);
let nodes: &Vec<FlagTableNode> = &flag_table.as_ref().unwrap().nodes;
assert_eq!(nodes.len(), 8);
assert_eq!(nodes[0], new_expected_node(0, "enabled_ro", 1, 1, None));
assert_eq!(nodes[1], new_expected_node(0, "enabled_rw", 0, 2, Some(151)));
assert_eq!(nodes[2], new_expected_node(1, "disabled_ro", 1, 0, None));
assert_eq!(nodes[3], new_expected_node(2, "enabled_ro", 1, 1, None));
assert_eq!(nodes[4], new_expected_node(1, "enabled_fixed_ro", 2, 1, Some(236)));
assert_eq!(nodes[5], new_expected_node(1, "enabled_ro", 1, 2, None));
assert_eq!(nodes[6], new_expected_node(2, "enabled_fixed_ro", 2, 0, None));
assert_eq!(nodes[7], new_expected_node(0, "disabled_rw", 0, 0, None));
let expected_flag_table = aconfig_storage_file::test_utils::create_test_flag_table();
assert_eq!(flag_table.unwrap(), expected_flag_table);
}
}

View file

@ -64,31 +64,19 @@ mod tests {
use super::*;
use crate::storage::{group_flags_by_package, tests::parse_all_test_flags};
pub fn create_test_flag_value_list() -> Result<FlagValueList> {
pub fn create_test_flag_value_list_from_source() -> Result<FlagValueList> {
let caches = parse_all_test_flags();
let packages = group_flags_by_package(caches.iter());
create_flag_value("system", &packages)
create_flag_value("mockup", &packages)
}
#[test]
// this test point locks down the flag value creation and each field
fn test_list_contents() {
let flag_value_list = create_test_flag_value_list();
let flag_value_list = create_test_flag_value_list_from_source();
assert!(flag_value_list.is_ok());
let header: &FlagValueHeader = &flag_value_list.as_ref().unwrap().header;
let expected_header = FlagValueHeader {
version: FILE_VERSION,
container: String::from("system"),
file_type: StorageFileType::FlagVal as u8,
file_size: 35,
num_flags: 8,
boolean_value_offset: 27,
};
assert_eq!(header, &expected_header);
let booleans: &Vec<bool> = &flag_value_list.as_ref().unwrap().booleans;
let expected_booleans: Vec<bool> = vec![false, true, true, false, true, true, true, true];
assert_eq!(booleans, &expected_booleans);
let expected_flag_value_list =
aconfig_storage_file::test_utils::create_test_flag_value_list();
assert_eq!(flag_value_list.unwrap(), expected_flag_value_list);
}
}

View file

@ -109,56 +109,18 @@ mod tests {
use super::*;
use crate::storage::{group_flags_by_package, tests::parse_all_test_flags};
pub fn create_test_package_table() -> Result<PackageTable> {
pub fn create_test_package_table_from_source() -> Result<PackageTable> {
let caches = parse_all_test_flags();
let packages = group_flags_by_package(caches.iter());
create_package_table("system", &packages)
create_package_table("mockup", &packages)
}
#[test]
// this test point locks down the table creation and each field
fn test_table_contents() {
let package_table = create_test_package_table();
let package_table = create_test_package_table_from_source();
assert!(package_table.is_ok());
let header: &PackageTableHeader = &package_table.as_ref().unwrap().header;
let expected_header = PackageTableHeader {
version: FILE_VERSION,
container: String::from("system"),
file_type: StorageFileType::PackageMap as u8,
file_size: 209,
num_packages: 3,
bucket_offset: 31,
node_offset: 59,
};
assert_eq!(header, &expected_header);
let buckets: &Vec<Option<u32>> = &package_table.as_ref().unwrap().buckets;
let expected: Vec<Option<u32>> = vec![Some(59), None, None, Some(109), None, None, None];
assert_eq!(buckets, &expected);
let nodes: &Vec<PackageTableNode> = &package_table.as_ref().unwrap().nodes;
assert_eq!(nodes.len(), 3);
let first_node_expected = PackageTableNode {
package_name: String::from("com.android.aconfig.storage.test_2"),
package_id: 1,
boolean_offset: 3,
next_offset: None,
};
assert_eq!(nodes[0], first_node_expected);
let second_node_expected = PackageTableNode {
package_name: String::from("com.android.aconfig.storage.test_1"),
package_id: 0,
boolean_offset: 0,
next_offset: Some(159),
};
assert_eq!(nodes[1], second_node_expected);
let third_node_expected = PackageTableNode {
package_name: String::from("com.android.aconfig.storage.test_4"),
package_id: 2,
boolean_offset: 6,
next_offset: None,
};
assert_eq!(nodes[2], third_node_expected);
let expected_package_table = aconfig_storage_file::test_utils::create_test_package_table();
assert_eq!(package_table.unwrap(), expected_package_table);
}
}

View file

@ -251,7 +251,7 @@ mod tests {
let bytes = &flag_table.into_bytes();
let mut head = 0;
let version = read_u32_from_bytes(bytes, &mut head).unwrap();
assert_eq!(version, 1234)
assert_eq!(version, 1);
}
#[test]

View file

@ -158,7 +158,7 @@ mod tests {
let bytes = &flag_value_list.into_bytes();
let mut head = 0;
let version = read_u32_from_bytes(bytes, &mut head).unwrap();
assert_eq!(version, 1234)
assert_eq!(version, 1);
}
#[test]

View file

@ -37,9 +37,7 @@ pub mod flag_table;
pub mod flag_value;
pub mod package_table;
pub mod protos;
#[cfg(test)]
mod test_utils;
pub mod test_utils;
use anyhow::anyhow;
use std::collections::hash_map::DefaultHasher;
@ -295,7 +293,7 @@ mod tests {
list_flags(&package_table_path, &flag_table_path, &flag_value_list_path).unwrap();
let expected = [
(String::from("com.android.aconfig.storage.test_1"), String::from("enabled_ro"), true),
(String::from("com.android.aconfig.storage.test_1"), String::from("enabled_rw"), false),
(String::from("com.android.aconfig.storage.test_1"), String::from("enabled_rw"), true),
(
String::from("com.android.aconfig.storage.test_1"),
String::from("disabled_rw"),
@ -316,7 +314,7 @@ mod tests {
(
String::from("com.android.aconfig.storage.test_4"),
String::from("enabled_fixed_ro"),
false,
true,
),
];
assert_eq!(flags, expected);

View file

@ -250,7 +250,7 @@ mod tests {
let bytes = &package_table.into_bytes();
let mut head = 0;
let version = read_u32_from_bytes(bytes, &mut head).unwrap();
assert_eq!(version, 1234)
assert_eq!(version, 1);
}
#[test]

View file

@ -24,10 +24,10 @@ use anyhow::anyhow;
use std::io::Write;
use tempfile::NamedTempFile;
pub(crate) fn create_test_package_table() -> PackageTable {
pub fn create_test_package_table() -> PackageTable {
let header = PackageTableHeader {
version: 1234,
container: String::from("system"),
version: 1,
container: String::from("mockup"),
file_type: StorageFileType::PackageMap as u8,
file_size: 209,
num_packages: 3,
@ -76,10 +76,10 @@ impl FlagTableNode {
}
}
pub(crate) fn create_test_flag_table() -> FlagTable {
pub fn create_test_flag_table() -> FlagTable {
let header = FlagTableHeader {
version: 1234,
container: String::from("system"),
version: 1,
container: String::from("mockup"),
file_type: StorageFileType::FlagMap as u8,
file_size: 321,
num_flags: 8,
@ -107,34 +107,34 @@ pub(crate) fn create_test_flag_table() -> FlagTable {
];
let nodes = vec![
FlagTableNode::new_expected(0, "enabled_ro", 1, 1, None),
FlagTableNode::new_expected(0, "enabled_rw", 1, 2, Some(151)),
FlagTableNode::new_expected(0, "enabled_rw", 0, 2, Some(151)),
FlagTableNode::new_expected(1, "disabled_ro", 1, 0, None),
FlagTableNode::new_expected(2, "enabled_ro", 1, 1, None),
FlagTableNode::new_expected(1, "enabled_fixed_ro", 1, 1, Some(236)),
FlagTableNode::new_expected(1, "enabled_fixed_ro", 2, 1, Some(236)),
FlagTableNode::new_expected(1, "enabled_ro", 1, 2, None),
FlagTableNode::new_expected(2, "enabled_fixed_ro", 1, 0, None),
FlagTableNode::new_expected(0, "disabled_rw", 1, 0, None),
FlagTableNode::new_expected(2, "enabled_fixed_ro", 2, 0, None),
FlagTableNode::new_expected(0, "disabled_rw", 0, 0, None),
];
FlagTable { header, buckets, nodes }
}
pub(crate) fn create_test_flag_value_list() -> FlagValueList {
pub fn create_test_flag_value_list() -> FlagValueList {
let header = FlagValueHeader {
version: 1234,
container: String::from("system"),
version: 1,
container: String::from("mockup"),
file_type: StorageFileType::FlagVal as u8,
file_size: 35,
num_flags: 8,
boolean_value_offset: 27,
};
let booleans: Vec<bool> = vec![false, true, false, false, true, true, false, true];
let booleans: Vec<bool> = vec![false, true, true, false, true, true, true, true];
FlagValueList { header, booleans }
}
pub(crate) fn create_test_flag_info_list() -> FlagInfoList {
pub fn create_test_flag_info_list() -> FlagInfoList {
let header = FlagInfoHeader {
version: 1234,
container: String::from("system"),
container: String::from("mockup"),
file_type: StorageFileType::FlagInfo as u8,
file_size: 35,
num_flags: 8,
@ -144,7 +144,7 @@ pub(crate) fn create_test_flag_info_list() -> FlagInfoList {
FlagInfoList { header, nodes }
}
pub(crate) fn write_bytes_to_temp_file(bytes: &[u8]) -> Result<NamedTempFile, AconfigStorageError> {
pub fn write_bytes_to_temp_file(bytes: &[u8]) -> Result<NamedTempFile, AconfigStorageError> {
let mut file = NamedTempFile::new().map_err(|_| {
AconfigStorageError::FileCreationFail(anyhow!("Failed to create temp file"))
})?;

View file

@ -65,66 +65,7 @@ pub fn find_flag_offset(
#[cfg(test)]
mod tests {
use super::*;
use aconfig_storage_file::{FlagTable, StorageFileType, StoredFlagType};
// create test baseline, syntactic sugar
fn new_expected_node(
package_id: u32,
flag_name: &str,
flag_type: u16,
flag_id: u16,
next_offset: Option<u32>,
) -> FlagTableNode {
FlagTableNode {
package_id,
flag_name: flag_name.to_string(),
flag_type: StoredFlagType::try_from(flag_type).unwrap(),
flag_id,
next_offset,
}
}
pub fn create_test_flag_table() -> FlagTable {
let header = FlagTableHeader {
version: crate::FILE_VERSION,
container: String::from("system"),
file_type: StorageFileType::FlagMap as u8,
file_size: 321,
num_flags: 8,
bucket_offset: 31,
node_offset: 99,
};
let buckets: Vec<Option<u32>> = vec![
Some(99),
Some(125),
None,
None,
None,
Some(178),
None,
Some(204),
None,
Some(262),
None,
None,
None,
None,
None,
Some(294),
None,
];
let nodes = vec![
new_expected_node(0, "enabled_ro", 1, 1, None),
new_expected_node(0, "enabled_rw", 1, 2, Some(151)),
new_expected_node(1, "disabled_ro", 1, 0, None),
new_expected_node(2, "enabled_ro", 1, 1, None),
new_expected_node(1, "enabled_fixed_ro", 1, 1, Some(236)),
new_expected_node(1, "enabled_ro", 1, 2, None),
new_expected_node(2, "enabled_fixed_ro", 1, 0, None),
new_expected_node(0, "disabled_rw", 1, 0, None),
];
FlagTable { header, buckets, nodes }
}
use aconfig_storage_file::test_utils::create_test_flag_table;
#[test]
// this test point locks down table query

View file

@ -326,7 +326,7 @@ mod tests {
r#"
files {{
version: 0
container: "system"
container: "mockup"
package_map: "{}"
flag_map: "{}"
flag_val: "{}"
@ -347,7 +347,7 @@ files {{
let [_package_map, _flag_map, _flag_val, pb_file] = create_test_storage_files();
let pb_file_path = pb_file.path().display().to_string();
let package_mapped_file = unsafe {
get_mapped_file(&pb_file_path, "system", StorageFileType::PackageMap).unwrap()
get_mapped_file(&pb_file_path, "mockup", StorageFileType::PackageMap).unwrap()
};
let package_offset =
@ -378,7 +378,7 @@ files {{
let [_package_map, _flag_map, _flag_val, pb_file] = create_test_storage_files();
let pb_file_path = pb_file.path().display().to_string();
let flag_mapped_file =
unsafe { get_mapped_file(&pb_file_path, "system", StorageFileType::FlagMap).unwrap() };
unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagMap).unwrap() };
let baseline = vec![
(0, "enabled_ro", 1u16),
@ -403,8 +403,8 @@ files {{
let [_package_map, _flag_map, _flag_val, pb_file] = create_test_storage_files();
let pb_file_path = pb_file.path().display().to_string();
let flag_value_file =
unsafe { get_mapped_file(&pb_file_path, "system", StorageFileType::FlagVal).unwrap() };
let baseline: Vec<bool> = vec![false; 8];
unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagVal).unwrap() };
let baseline: Vec<bool> = vec![false, true, true, false, true, true, true, true];
for (offset, expected_value) in baseline.into_iter().enumerate() {
let flag_value = get_boolean_flag_value(&flag_value_file, offset as u32).unwrap();
assert_eq!(flag_value, expected_value);

View file

@ -72,40 +72,7 @@ pub fn find_package_offset(
#[cfg(test)]
mod tests {
use super::*;
use aconfig_storage_file::{PackageTable, StorageFileType};
pub fn create_test_package_table() -> PackageTable {
let header = PackageTableHeader {
version: crate::FILE_VERSION,
container: String::from("system"),
file_type: StorageFileType::PackageMap as u8,
file_size: 209,
num_packages: 3,
bucket_offset: 31,
node_offset: 59,
};
let buckets: Vec<Option<u32>> = vec![Some(59), None, None, Some(109), None, None, None];
let first_node = PackageTableNode {
package_name: String::from("com.android.aconfig.storage.test_2"),
package_id: 1,
boolean_offset: 3,
next_offset: None,
};
let second_node = PackageTableNode {
package_name: String::from("com.android.aconfig.storage.test_1"),
package_id: 0,
boolean_offset: 0,
next_offset: Some(159),
};
let third_node = PackageTableNode {
package_name: String::from("com.android.aconfig.storage.test_4"),
package_id: 2,
boolean_offset: 6,
next_offset: None,
};
let nodes = vec![first_node, second_node, third_node];
PackageTable { header, buckets, nodes }
}
use aconfig_storage_file::test_utils::create_test_package_table;
#[test]
// this test point locks down table query

View file

@ -52,7 +52,7 @@ class AconfigStorageTest : public ::testing::Test {
auto proto = storage_files();
auto* info = proto.add_files();
info->set_version(0);
info->set_container("system");
info->set_container("mockup");
info->set_package_map(package_map);
info->set_flag_map(flag_map);
info->set_flag_val(flag_val);
@ -113,7 +113,7 @@ TEST_F(AconfigStorageTest, test_none_exist_storage_file_mapping) {
/// Test to lock down storage package offset query api
TEST_F(AconfigStorageTest, test_package_offset_query) {
auto mapped_file = private_api::get_mapped_file_impl(
storage_record_pb, "system", api::StorageFileType::package_map);
storage_record_pb, "mockup", api::StorageFileType::package_map);
ASSERT_TRUE(mapped_file.ok());
auto offset = api::get_package_offset(
@ -141,7 +141,7 @@ TEST_F(AconfigStorageTest, test_package_offset_query) {
/// Test to lock down when querying none exist package
TEST_F(AconfigStorageTest, test_none_existent_package_offset_query) {
auto mapped_file = private_api::get_mapped_file_impl(
storage_record_pb, "system", api::StorageFileType::package_map);
storage_record_pb, "mockup", api::StorageFileType::package_map);
ASSERT_TRUE(mapped_file.ok());
auto offset = api::get_package_offset(
@ -153,7 +153,7 @@ TEST_F(AconfigStorageTest, test_none_existent_package_offset_query) {
/// Test to lock down storage flag offset query api
TEST_F(AconfigStorageTest, test_flag_offset_query) {
auto mapped_file = private_api::get_mapped_file_impl(
storage_record_pb, "system", api::StorageFileType::flag_map);
storage_record_pb, "mockup", api::StorageFileType::flag_map);
ASSERT_TRUE(mapped_file.ok());
auto baseline = std::vector<std::tuple<int, std::string, int>>{
@ -177,7 +177,7 @@ TEST_F(AconfigStorageTest, test_flag_offset_query) {
/// Test to lock down when querying none exist flag
TEST_F(AconfigStorageTest, test_none_existent_flag_offset_query) {
auto mapped_file = private_api::get_mapped_file_impl(
storage_record_pb, "system", api::StorageFileType::flag_map);
storage_record_pb, "mockup", api::StorageFileType::flag_map);
ASSERT_TRUE(mapped_file.ok());
auto offset = api::get_flag_offset(*mapped_file, 0, "none_exist");
@ -192,20 +192,22 @@ TEST_F(AconfigStorageTest, test_none_existent_flag_offset_query) {
/// Test to lock down storage flag value query api
TEST_F(AconfigStorageTest, test_boolean_flag_value_query) {
auto mapped_file = private_api::get_mapped_file_impl(
storage_record_pb, "system", api::StorageFileType::flag_val);
storage_record_pb, "mockup", api::StorageFileType::flag_val);
ASSERT_TRUE(mapped_file.ok());
auto expected_value = std::vector<bool>{
false, true, true, false, true, true, true, true};
for (int offset = 0; offset < 8; ++offset) {
auto value = api::get_boolean_flag_value(*mapped_file, offset);
ASSERT_TRUE(value.ok());
ASSERT_FALSE(*value);
ASSERT_EQ(*value, expected_value[offset]);
}
}
/// Negative test to lock down the error when querying flag value out of range
TEST_F(AconfigStorageTest, test_invalid_boolean_flag_value_query) {
auto mapped_file = private_api::get_mapped_file_impl(
storage_record_pb, "system", api::StorageFileType::flag_val);
storage_record_pb, "mockup", api::StorageFileType::flag_val);
ASSERT_TRUE(mapped_file.ok());
auto value = api::get_boolean_flag_value(*mapped_file, 8);

View file

@ -24,7 +24,7 @@ mod aconfig_storage_rust_test {
r#"
files {{
version: 0
container: "system"
container: "mockup"
package_map: "{}"
flag_map: "{}"
flag_val: "{}"
@ -61,7 +61,7 @@ files {{
// SAFETY:
// The safety here is ensured as the test process will not write to temp storage file
let package_mapped_file = unsafe {
get_mapped_file(&pb_file_path, "system", StorageFileType::PackageMap).unwrap()
get_mapped_file(&pb_file_path, "mockup", StorageFileType::PackageMap).unwrap()
};
let package_offset =
@ -93,7 +93,7 @@ files {{
// SAFETY:
// The safety here is ensured as the test process will not write to temp storage file
let package_mapped_file = unsafe {
get_mapped_file(&pb_file_path, "system", StorageFileType::PackageMap).unwrap()
get_mapped_file(&pb_file_path, "mockup", StorageFileType::PackageMap).unwrap()
};
let package_offset_option =
@ -108,7 +108,7 @@ files {{
// SAFETY:
// The safety here is ensured as the test process will not write to temp storage file
let flag_mapped_file =
unsafe { get_mapped_file(&pb_file_path, "system", StorageFileType::FlagMap).unwrap() };
unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagMap).unwrap() };
let baseline = vec![
(0, "enabled_ro", 1u16),
@ -134,7 +134,7 @@ files {{
// SAFETY:
// The safety here is ensured as the test process will not write to temp storage file
let flag_mapped_file =
unsafe { get_mapped_file(&pb_file_path, "system", StorageFileType::FlagMap).unwrap() };
unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagMap).unwrap() };
let flag_offset_option = get_flag_offset(&flag_mapped_file, 0, "none_exist").unwrap();
assert_eq!(flag_offset_option, None);
@ -149,8 +149,8 @@ files {{
// SAFETY:
// The safety here is ensured as the test process will not write to temp storage file
let flag_value_file =
unsafe { get_mapped_file(&pb_file_path, "system", StorageFileType::FlagVal).unwrap() };
let baseline: Vec<bool> = vec![false; 8];
unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagVal).unwrap() };
let baseline: Vec<bool> = vec![false, true, true, false, true, true, true, true];
for (offset, expected_value) in baseline.into_iter().enumerate() {
let flag_value = get_boolean_flag_value(&flag_value_file, offset as u32).unwrap();
assert_eq!(flag_value, expected_value);
@ -164,7 +164,7 @@ files {{
// SAFETY:
// The safety here is ensured as the test process will not write to temp storage file
let flag_value_file =
unsafe { get_mapped_file(&pb_file_path, "system", StorageFileType::FlagVal).unwrap() };
unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagVal).unwrap() };
let err = get_boolean_flag_value(&flag_value_file, 8u32).unwrap_err();
assert_eq!(
format!("{:?}", err),

View file

@ -62,7 +62,7 @@ static Result<MappedFlagValueFile> map_storage_file(std::string const& file) {
}
if ((file_stat.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0) {
return ErrnoError() << "cannot map nonwriteable file";
return Error() << "cannot map nonwriteable file";
}
size_t file_size = file_stat.st_size;

View file

@ -55,7 +55,7 @@ class AconfigStorageTest : public ::testing::Test {
auto proto = storage_files();
auto* info = proto.add_files();
info->set_version(0);
info->set_container("system");
info->set_container("mockup");
info->set_package_map("some_package.map");
info->set_flag_map("some_flag.map");
info->set_flag_val(flag_val);
@ -97,15 +97,16 @@ TEST_F(AconfigStorageTest, test_none_exist_storage_file_mapping) {
TEST_F(AconfigStorageTest, test_non_writable_storage_file_mapping) {
ASSERT_TRUE(chmod(flag_val.c_str(), S_IRUSR | S_IRGRP | S_IROTH) != -1);
auto mapped_file_result = private_api::get_mapped_flag_value_file_impl(
storage_record_pb, "system");
storage_record_pb, "mockup");
ASSERT_FALSE(mapped_file_result.ok());
ASSERT_EQ(mapped_file_result.error().message(), "cannot map nonwriteable file");
auto it = mapped_file_result.error().message().find("cannot map nonwriteable file");
ASSERT_TRUE(it != std::string::npos) << mapped_file_result.error().message();
}
/// Test to lock down storage flag value update api
TEST_F(AconfigStorageTest, test_boolean_flag_value_update) {
auto mapped_file_result = private_api::get_mapped_flag_value_file_impl(
storage_record_pb, "system");
storage_record_pb, "mockup");
ASSERT_TRUE(mapped_file_result.ok());
auto mapped_file = *mapped_file_result;
@ -124,7 +125,7 @@ TEST_F(AconfigStorageTest, test_boolean_flag_value_update) {
/// Negative test to lock down the error when querying flag value out of range
TEST_F(AconfigStorageTest, test_invalid_boolean_flag_value_update) {
auto mapped_file_result = private_api::get_mapped_flag_value_file_impl(
storage_record_pb, "system");
storage_record_pb, "mockup");
ASSERT_TRUE(mapped_file_result.ok());
auto mapped_file = *mapped_file_result;
auto update_result = api::set_boolean_flag_value(mapped_file, 8, true);

View file

@ -15,7 +15,7 @@ mod aconfig_storage_write_api_test {
r#"
files {{
version: 0
container: "system"
container: "mockup"
package_map: "some_package_map"
flag_map: "some_flag_map"
flag_val: "{}"
@ -59,7 +59,7 @@ files {{
// SAFETY:
// The safety here is ensured as only this single threaded test process will
// write to this file
let mut file = unsafe { get_mapped_file(&record_pb_path, "system").unwrap() };
let mut file = unsafe { get_mapped_file(&record_pb_path, "mockup").unwrap() };
for i in 0..8 {
set_boolean_flag_value(&mut file, i, true).unwrap();
let value = get_boolean_flag_value_at_offset(&flag_value_path, i);