diff --git a/tools/aconfig/aconfig_storage_read_api/aconfig_storage_read_api.cpp b/tools/aconfig/aconfig_storage_read_api/aconfig_storage_read_api.cpp index 39f1840856..ff2f38e765 100644 --- a/tools/aconfig/aconfig_storage_read_api/aconfig_storage_read_api.cpp +++ b/tools/aconfig/aconfig_storage_read_api/aconfig_storage_read_api.cpp @@ -106,6 +106,19 @@ Result get_mapped_file_impl( } // namespace private internal api +/// Map from StoredFlagType to FlagValueType +android::base::Result map_to_flag_value_type( + StoredFlagType stored_type) { + switch (stored_type) { + case StoredFlagType::ReadWriteBoolean: + case StoredFlagType::ReadOnlyBoolean: + case StoredFlagType::FixedReadOnlyBoolean: + return FlagValueType::Boolean; + default: + return Error() << "Unsupported stored flag type"; + } +} + /// Get mapped storage file Result get_mapped_file( std::string const& container, @@ -178,12 +191,14 @@ Result get_boolean_flag_value( } /// Get boolean flag attribute -Result get_boolean_flag_attribute( +Result get_flag_attribute( MappedStorageFile const& file, + FlagValueType value_type, uint32_t index) { auto content = rust::Slice( static_cast(file.file_ptr), file.file_size); - auto info_cxx = get_boolean_flag_attribute_cxx(content, index); + auto info_cxx = get_flag_attribute_cxx( + content, static_cast(value_type), index); if (info_cxx.query_success) { return info_cxx.flag_attribute; } else { diff --git a/tools/aconfig/aconfig_storage_read_api/include/aconfig_storage/aconfig_storage_read_api.hpp b/tools/aconfig/aconfig_storage_read_api/include/aconfig_storage/aconfig_storage_read_api.hpp index 45552074fc..7c63ef2a89 100644 --- a/tools/aconfig/aconfig_storage_read_api/include/aconfig_storage/aconfig_storage_read_api.hpp +++ b/tools/aconfig/aconfig_storage_read_api/include/aconfig_storage/aconfig_storage_read_api.hpp @@ -37,7 +37,6 @@ enum FlagInfoBit { HasOverride = 1<<2, }; - /// Mapped storage file struct MappedStorageFile { void* file_ptr; @@ -68,6 +67,12 @@ android::base::Result get_mapped_file_impl( } // namespace private_internal_api +/// Map from StoredFlagType to FlagValueType +/// \input stored_type: stored flag type in the storage file +/// \returns the flag value type enum +android::base::Result map_to_flag_value_type( + StoredFlagType stored_type); + /// Get mapped storage file /// \input container: stoarge container name /// \input file_type: storage file type enum @@ -110,9 +115,11 @@ android::base::Result get_boolean_flag_value( /// Get boolean flag attribute /// \input file: mapped storage file +/// \input value_type: flag value type /// \input index: the boolean flag index in the file /// \returns the boolean flag attribute -android::base::Result get_boolean_flag_attribute( +android::base::Result get_flag_attribute( MappedStorageFile const& file, + FlagValueType value_type, uint32_t index); } // namespace aconfig_storage diff --git a/tools/aconfig/aconfig_storage_read_api/src/flag_info_query.rs b/tools/aconfig/aconfig_storage_read_api/src/flag_info_query.rs index 807da971ed..e593418aec 100644 --- a/tools/aconfig/aconfig_storage_read_api/src/flag_info_query.rs +++ b/tools/aconfig/aconfig_storage_read_api/src/flag_info_query.rs @@ -17,11 +17,15 @@ //! flag value query module defines the flag value file read from mapped bytes use crate::{AconfigStorageError, FILE_VERSION}; -use aconfig_storage_file::{flag_info::FlagInfoHeader, read_u8_from_bytes}; +use aconfig_storage_file::{flag_info::FlagInfoHeader, read_u8_from_bytes, FlagValueType}; use anyhow::anyhow; /// Get flag attribute bitfield -pub fn find_boolean_flag_attribute(buf: &[u8], flag_index: u32) -> Result { +pub fn find_flag_attribute( + buf: &[u8], + flag_type: FlagValueType, + flag_index: u32, +) -> Result { let interpreted_header = FlagInfoHeader::from_bytes(buf)?; if interpreted_header.version > crate::FILE_VERSION { return Err(AconfigStorageError::HigherStorageFileVersion(anyhow!( @@ -31,8 +35,11 @@ pub fn find_boolean_flag_attribute(buf: &[u8], flag_index: u32) -> Result (interpreted_header.boolean_flag_offset + flag_index) as usize, + }; + if head >= interpreted_header.file_size as usize { return Err(AconfigStorageError::InvalidStorageFileOffset(anyhow!( "Flag info offset goes beyond the end of the file." @@ -53,7 +60,8 @@ mod tests { fn test_is_flag_sticky() { let flag_info_list = create_test_flag_info_list().into_bytes(); for offset in 0..8 { - let attribute = find_boolean_flag_attribute(&flag_info_list[..], offset).unwrap(); + let attribute = + find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, offset).unwrap(); assert_eq!((attribute & FlagInfoBit::IsSticky as u8) != 0u8, false); } } @@ -64,7 +72,8 @@ mod tests { let flag_info_list = create_test_flag_info_list().into_bytes(); let baseline: Vec = vec![true, false, true, false, false, false, false, false]; for offset in 0..8 { - let attribute = find_boolean_flag_attribute(&flag_info_list[..], offset).unwrap(); + let attribute = + find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, offset).unwrap(); assert_eq!( (attribute & FlagInfoBit::IsReadWrite as u8) != 0u8, baseline[offset as usize] @@ -77,7 +86,8 @@ mod tests { fn test_flag_has_override() { let flag_info_list = create_test_flag_info_list().into_bytes(); for offset in 0..8 { - let attribute = find_boolean_flag_attribute(&flag_info_list[..], offset).unwrap(); + let attribute = + find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, offset).unwrap(); assert_eq!((attribute & FlagInfoBit::HasOverride as u8) != 0u8, false); } } @@ -86,7 +96,8 @@ mod tests { // this test point locks down query beyond the end of boolean section fn test_boolean_out_of_range() { let flag_info_list = create_test_flag_info_list().into_bytes(); - let error = find_boolean_flag_attribute(&flag_info_list[..], 8).unwrap_err(); + let error = + find_flag_attribute(&flag_info_list[..], FlagValueType::Boolean, 8).unwrap_err(); assert_eq!( format!("{:?}", error), "InvalidStorageFileOffset(Flag info offset goes beyond the end of the file.)" @@ -99,7 +110,7 @@ mod tests { let mut info_list = create_test_flag_info_list(); info_list.header.version = crate::FILE_VERSION + 1; let flag_info = info_list.into_bytes(); - let error = find_boolean_flag_attribute(&flag_info[..], 4).unwrap_err(); + let error = find_flag_attribute(&flag_info[..], FlagValueType::Boolean, 4).unwrap_err(); assert_eq!( format!("{:?}", error), format!( diff --git a/tools/aconfig/aconfig_storage_read_api/src/lib.rs b/tools/aconfig/aconfig_storage_read_api/src/lib.rs index aa0145f71d..bc0911251b 100644 --- a/tools/aconfig/aconfig_storage_read_api/src/lib.rs +++ b/tools/aconfig/aconfig_storage_read_api/src/lib.rs @@ -45,12 +45,12 @@ pub mod package_table_query; #[cfg(test)] mod test_utils; -pub use aconfig_storage_file::{AconfigStorageError, StorageFileType}; +pub use aconfig_storage_file::{AconfigStorageError, FlagValueType, StorageFileType}; pub use flag_table_query::FlagReadContext; pub use package_table_query::PackageReadContext; use aconfig_storage_file::{read_u32_from_bytes, FILE_VERSION}; -use flag_info_query::find_boolean_flag_attribute; +use flag_info_query::find_flag_attribute; use flag_table_query::find_flag_read_context; use flag_value_query::find_boolean_flag_value; use package_table_query::find_package_read_context; @@ -149,16 +149,21 @@ pub fn get_storage_file_version(file_path: &str) -> Result Result { - find_boolean_flag_attribute(file, index) +pub fn get_flag_attribute( + file: &Mmap, + flag_type: FlagValueType, + flag_index: u32, +) -> Result { + find_flag_attribute(file, flag_type, flag_index) } // *************************************** // @@ -201,7 +206,7 @@ mod ffi { } // Flag info query return for cc interlop - pub struct BooleanFlagAttributeQueryCXX { + pub struct FlagAttributeQueryCXX { pub query_success: bool, pub error_message: String, pub flag_attribute: u8, @@ -224,10 +229,11 @@ mod ffi { pub fn get_boolean_flag_value_cxx(file: &[u8], offset: u32) -> BooleanFlagValueQueryCXX; - pub fn get_boolean_flag_attribute_cxx( + pub fn get_flag_attribute_cxx( file: &[u8], - offset: u32, - ) -> BooleanFlagAttributeQueryCXX; + flag_type: u16, + flag_index: u32, + ) -> FlagAttributeQueryCXX; } } @@ -312,7 +318,7 @@ impl ffi::BooleanFlagValueQueryCXX { } /// Implement the flag info interlop return type, create from actual flag info api return type -impl ffi::BooleanFlagAttributeQueryCXX { +impl ffi::FlagAttributeQueryCXX { pub(crate) fn new(info_result: Result) -> Self { match info_result { Ok(info) => { @@ -365,12 +371,18 @@ pub fn get_boolean_flag_value_cxx(file: &[u8], offset: u32) -> ffi::BooleanFlagV ffi::BooleanFlagValueQueryCXX::new(find_boolean_flag_value(file, offset)) } -/// Get boolean flag attribute cc interlop -pub fn get_boolean_flag_attribute_cxx( +/// Get flag attribute cc interlop +pub fn get_flag_attribute_cxx( file: &[u8], - offset: u32, -) -> ffi::BooleanFlagAttributeQueryCXX { - ffi::BooleanFlagAttributeQueryCXX::new(find_boolean_flag_attribute(file, offset)) + flag_type: u16, + flag_index: u32, +) -> ffi::FlagAttributeQueryCXX { + match FlagValueType::try_from(flag_type) { + Ok(value_type) => { + ffi::FlagAttributeQueryCXX::new(find_flag_attribute(file, value_type, flag_index)) + } + Err(errmsg) => ffi::FlagAttributeQueryCXX::new(Err(errmsg)), + } } /// Get storage version number cc interlop @@ -494,7 +506,8 @@ files {{ unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagInfo).unwrap() }; let is_rw: Vec = vec![true, false, true, false, false, false, false, false]; for (offset, expected_value) in is_rw.into_iter().enumerate() { - let attribute = get_boolean_flag_attribute(&flag_info_file, offset as u32).unwrap(); + let attribute = + get_flag_attribute(&flag_info_file, FlagValueType::Boolean, offset as u32).unwrap(); assert!((attribute & FlagInfoBit::IsSticky as u8) == 0u8); assert_eq!((attribute & FlagInfoBit::IsReadWrite as u8) != 0u8, expected_value); assert!((attribute & FlagInfoBit::HasOverride as u8) == 0u8); diff --git a/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.cpp b/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.cpp index 8ed3756e33..10f71a5723 100644 --- a/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.cpp +++ b/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.cpp @@ -234,7 +234,7 @@ TEST_F(AconfigStorageTest, test_boolean_flag_info_query) { auto expected_value = std::vector{ true, false, true, false, false, false, false, false}; for (int index = 0; index < 8; ++index) { - auto attribute = api::get_boolean_flag_attribute(*mapped_file, index); + auto attribute = api::get_flag_attribute(*mapped_file, api::FlagValueType::Boolean, index); ASSERT_TRUE(attribute.ok()); ASSERT_EQ(*attribute & static_cast(api::FlagInfoBit::IsSticky), 0); ASSERT_EQ((*attribute & static_cast(api::FlagInfoBit::IsReadWrite)) != 0, @@ -249,7 +249,7 @@ TEST_F(AconfigStorageTest, test_invalid_boolean_flag_info_query) { storage_record_pb, "mockup", api::StorageFileType::flag_info); ASSERT_TRUE(mapped_file.ok()); - auto attribute = api::get_boolean_flag_attribute(*mapped_file, 8); + auto attribute = api::get_flag_attribute(*mapped_file, api::FlagValueType::Boolean, 8); ASSERT_FALSE(attribute.ok()); ASSERT_EQ(attribute.error().message(), std::string("InvalidStorageFileOffset(Flag info offset goes beyond the end of the file.)")); diff --git a/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.rs b/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.rs index bddb396a95..212f7345ee 100644 --- a/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.rs +++ b/tools/aconfig/aconfig_storage_read_api/tests/storage_read_api_test.rs @@ -1,9 +1,9 @@ #[cfg(not(feature = "cargo"))] mod aconfig_storage_rust_test { use aconfig_storage_file::protos::storage_record_pb::write_proto_to_temp_file; - use aconfig_storage_file::{FlagInfoBit, StorageFileType, StoredFlagType}; + use aconfig_storage_file::{FlagInfoBit, FlagValueType, StorageFileType, StoredFlagType}; use aconfig_storage_read_api::{ - get_boolean_flag_attribute, get_boolean_flag_value, get_flag_read_context, + get_boolean_flag_value, get_flag_attribute, get_flag_read_context, get_package_read_context, get_storage_file_version, mapped_file::get_mapped_file, PackageReadContext, }; @@ -190,7 +190,8 @@ files {{ unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagInfo).unwrap() }; let is_rw: Vec = vec![true, false, true, false, false, false, false, false]; for (offset, expected_value) in is_rw.into_iter().enumerate() { - let attribute = get_boolean_flag_attribute(&flag_info_file, offset as u32).unwrap(); + let attribute = + get_flag_attribute(&flag_info_file, FlagValueType::Boolean, offset as u32).unwrap(); assert!((attribute & FlagInfoBit::IsSticky as u8) == 0u8); assert_eq!((attribute & FlagInfoBit::IsReadWrite as u8) != 0u8, expected_value); assert!((attribute & FlagInfoBit::HasOverride as u8) == 0u8); @@ -205,7 +206,7 @@ files {{ // The safety here is ensured as the test process will not write to temp storage file let flag_info_file = unsafe { get_mapped_file(&pb_file_path, "mockup", StorageFileType::FlagInfo).unwrap() }; - let err = get_boolean_flag_attribute(&flag_info_file, 8u32).unwrap_err(); + let err = get_flag_attribute(&flag_info_file, FlagValueType::Boolean, 8u32).unwrap_err(); assert_eq!( format!("{:?}", err), "InvalidStorageFileOffset(Flag info offset goes beyond the end of the file.)" diff --git a/tools/aconfig/aconfig_storage_write_api/src/flag_info_update.rs b/tools/aconfig/aconfig_storage_write_api/src/flag_info_update.rs index 56e1253c7e..3f38705581 100644 --- a/tools/aconfig/aconfig_storage_write_api/src/flag_info_update.rs +++ b/tools/aconfig/aconfig_storage_write_api/src/flag_info_update.rs @@ -95,7 +95,7 @@ pub fn update_flag_has_override( mod tests { use super::*; use aconfig_storage_file::test_utils::create_test_flag_info_list; - use aconfig_storage_read_api::flag_info_query::find_boolean_flag_attribute; + use aconfig_storage_read_api::flag_info_query::find_flag_attribute; #[test] // this test point locks down is sticky update @@ -104,10 +104,10 @@ mod tests { let mut buf = flag_info_list.into_bytes(); for i in 0..flag_info_list.header.num_flags { update_flag_is_sticky(&mut buf, FlagValueType::Boolean, i, true).unwrap(); - let attribute = find_boolean_flag_attribute(&buf, i).unwrap(); + let attribute = find_flag_attribute(&buf, FlagValueType::Boolean, i).unwrap(); assert!((attribute & (FlagInfoBit::IsSticky as u8)) != 0); update_flag_is_sticky(&mut buf, FlagValueType::Boolean, i, false).unwrap(); - let attribute = find_boolean_flag_attribute(&buf, i).unwrap(); + let attribute = find_flag_attribute(&buf, FlagValueType::Boolean, i).unwrap(); assert!((attribute & (FlagInfoBit::IsSticky as u8)) == 0); } } @@ -119,10 +119,10 @@ mod tests { let mut buf = flag_info_list.into_bytes(); for i in 0..flag_info_list.header.num_flags { update_flag_has_override(&mut buf, FlagValueType::Boolean, i, true).unwrap(); - let attribute = find_boolean_flag_attribute(&buf, i).unwrap(); + let attribute = find_flag_attribute(&buf, FlagValueType::Boolean, i).unwrap(); assert!((attribute & (FlagInfoBit::HasOverride as u8)) != 0); update_flag_has_override(&mut buf, FlagValueType::Boolean, i, false).unwrap(); - let attribute = find_boolean_flag_attribute(&buf, i).unwrap(); + let attribute = find_flag_attribute(&buf, FlagValueType::Boolean, i).unwrap(); assert!((attribute & (FlagInfoBit::HasOverride as u8)) == 0); } } diff --git a/tools/aconfig/aconfig_storage_write_api/src/lib.rs b/tools/aconfig/aconfig_storage_write_api/src/lib.rs index ee08d1651b..8b7e459967 100644 --- a/tools/aconfig/aconfig_storage_write_api/src/lib.rs +++ b/tools/aconfig/aconfig_storage_write_api/src/lib.rs @@ -281,7 +281,7 @@ pub(crate) fn update_flag_is_sticky_cxx( match crate::flag_info_update::update_flag_is_sticky(file, value_type, offset, value) { Ok(()) => ffi::FlagIsStickyUpdateCXX { update_success: true, - error_message: String::from("") + error_message: String::from(""), }, Err(errmsg) => ffi::FlagIsStickyUpdateCXX { update_success: false, @@ -292,7 +292,7 @@ pub(crate) fn update_flag_is_sticky_cxx( Err(errmsg) => ffi::FlagIsStickyUpdateCXX { update_success: false, error_message: format!("{:?}", errmsg), - } + }, } } @@ -304,10 +304,11 @@ pub(crate) fn update_flag_has_override_cxx( ) -> ffi::FlagHasOverrideUpdateCXX { match FlagValueType::try_from(flag_type) { Ok(value_type) => { - match crate::flag_info_update::update_flag_has_override(file, value_type, offset, value) { + match crate::flag_info_update::update_flag_has_override(file, value_type, offset, value) + { Ok(()) => ffi::FlagHasOverrideUpdateCXX { update_success: true, - error_message: String::from("") + error_message: String::from(""), }, Err(errmsg) => ffi::FlagHasOverrideUpdateCXX { update_success: false, @@ -318,7 +319,7 @@ pub(crate) fn update_flag_has_override_cxx( Err(errmsg) => ffi::FlagHasOverrideUpdateCXX { update_success: false, error_message: format!("{:?}", errmsg), - } + }, } } @@ -346,7 +347,7 @@ mod tests { write_bytes_to_temp_file, }; use aconfig_storage_file::FlagInfoBit; - use aconfig_storage_read_api::flag_info_query::find_boolean_flag_attribute; + use aconfig_storage_read_api::flag_info_query::find_flag_attribute; use aconfig_storage_read_api::flag_value_query::find_boolean_flag_value; use std::fs::File; use std::io::Read; @@ -402,11 +403,11 @@ files {{ } } - fn get_flag_attribute_at_offset(file: &str, offset: u32) -> u8 { + fn get_flag_attribute_at_offset(file: &str, value_type: FlagValueType, offset: u32) -> u8 { let mut f = File::open(&file).unwrap(); let mut bytes = Vec::new(); f.read_to_end(&mut bytes).unwrap(); - find_boolean_flag_attribute(&bytes, offset).unwrap() + find_flag_attribute(&bytes, value_type, offset).unwrap() } #[test] @@ -442,10 +443,10 @@ files {{ .unwrap(); for i in 0..8 { set_flag_is_sticky(&mut file, FlagValueType::Boolean, i, true).unwrap(); - let attribute = get_flag_attribute_at_offset(&flag_info_path, i); + let attribute = get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i); assert!((attribute & (FlagInfoBit::IsSticky as u8)) != 0); set_flag_is_sticky(&mut file, FlagValueType::Boolean, i, false).unwrap(); - let attribute = get_flag_attribute_at_offset(&flag_info_path, i); + let attribute = get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i); assert!((attribute & (FlagInfoBit::IsSticky as u8)) == 0); } } @@ -484,10 +485,10 @@ files {{ .unwrap(); for i in 0..8 { set_flag_has_override(&mut file, FlagValueType::Boolean, i, true).unwrap(); - let attribute = get_flag_attribute_at_offset(&flag_info_path, i); + let attribute = get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i); assert!((attribute & (FlagInfoBit::HasOverride as u8)) != 0); set_flag_has_override(&mut file, FlagValueType::Boolean, i, false).unwrap(); - let attribute = get_flag_attribute_at_offset(&flag_info_path, i); + let attribute = get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i); assert!((attribute & (FlagInfoBit::HasOverride as u8)) == 0); } } diff --git a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp index 77664e40a8..6de3327d75 100644 --- a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp +++ b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.cpp @@ -170,7 +170,8 @@ TEST_F(AconfigStorageTest, test_flag_is_sticky_update) { auto ro_mapped_file = api::MappedStorageFile(); ro_mapped_file.file_ptr = mapped_file.file_ptr; ro_mapped_file.file_size = mapped_file.file_size; - auto attribute = api::get_boolean_flag_attribute(ro_mapped_file, offset); + auto attribute = api::get_flag_attribute( + ro_mapped_file, api::FlagValueType::Boolean, offset); ASSERT_TRUE(attribute.ok()); ASSERT_TRUE(*attribute & api::FlagInfoBit::IsSticky); @@ -179,7 +180,8 @@ TEST_F(AconfigStorageTest, test_flag_is_sticky_update) { ASSERT_TRUE(update_result.ok()); ro_mapped_file.file_ptr = mapped_file.file_ptr; ro_mapped_file.file_size = mapped_file.file_size; - attribute = api::get_boolean_flag_attribute(ro_mapped_file, offset); + attribute = api::get_flag_attribute( + ro_mapped_file, api::FlagValueType::Boolean, offset); ASSERT_TRUE(attribute.ok()); ASSERT_FALSE(*attribute & api::FlagInfoBit::IsSticky); } @@ -199,7 +201,8 @@ TEST_F(AconfigStorageTest, test_flag_has_override_update) { auto ro_mapped_file = api::MappedStorageFile(); ro_mapped_file.file_ptr = mapped_file.file_ptr; ro_mapped_file.file_size = mapped_file.file_size; - auto attribute = api::get_boolean_flag_attribute(ro_mapped_file, offset); + auto attribute = api::get_flag_attribute( + ro_mapped_file, api::FlagValueType::Boolean, offset); ASSERT_TRUE(attribute.ok()); ASSERT_TRUE(*attribute & api::FlagInfoBit::HasOverride); @@ -208,7 +211,8 @@ TEST_F(AconfigStorageTest, test_flag_has_override_update) { ASSERT_TRUE(update_result.ok()); ro_mapped_file.file_ptr = mapped_file.file_ptr; ro_mapped_file.file_size = mapped_file.file_size; - attribute = api::get_boolean_flag_attribute(ro_mapped_file, offset); + attribute = api::get_flag_attribute( + ro_mapped_file, api::FlagValueType::Boolean, offset); ASSERT_TRUE(attribute.ok()); ASSERT_FALSE(*attribute & api::FlagInfoBit::HasOverride); } diff --git a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.rs b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.rs index f6a9b2808e..5dd36c43a8 100644 --- a/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.rs +++ b/tools/aconfig/aconfig_storage_write_api/tests/storage_write_api_test.rs @@ -2,7 +2,7 @@ mod aconfig_storage_write_api_test { use aconfig_storage_file::protos::ProtoStorageFiles; use aconfig_storage_file::{FlagInfoBit, FlagValueType, StorageFileType}; - use aconfig_storage_read_api::flag_info_query::find_boolean_flag_attribute; + use aconfig_storage_read_api::flag_info_query::find_flag_attribute; use aconfig_storage_read_api::flag_value_query::find_boolean_flag_value; use aconfig_storage_write_api::{ mapped_file::get_mapped_file, set_boolean_flag_value, set_flag_has_override, @@ -55,11 +55,11 @@ files {{ } /// Get flag attribute at offset - fn get_flag_attribute_at_offset(file: &str, offset: u32) -> u8 { + fn get_flag_attribute_at_offset(file: &str, value_type: FlagValueType, offset: u32) -> u8 { let mut f = File::open(file).unwrap(); let mut bytes = Vec::new(); f.read_to_end(&mut bytes).unwrap(); - find_boolean_flag_attribute(&bytes, offset).unwrap() + find_flag_attribute(&bytes, value_type, offset).unwrap() } #[test] @@ -107,10 +107,12 @@ files {{ }; for i in 0..8 { set_flag_is_sticky(&mut file, FlagValueType::Boolean, i, true).unwrap(); - let attribute = get_flag_attribute_at_offset(&flag_info_path, i); + let attribute = + get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i); assert!((attribute & (FlagInfoBit::IsSticky as u8)) != 0); set_flag_is_sticky(&mut file, FlagValueType::Boolean, i, false).unwrap(); - let attribute = get_flag_attribute_at_offset(&flag_info_path, i); + let attribute = + get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i); assert!((attribute & (FlagInfoBit::IsSticky as u8)) == 0); } } @@ -133,10 +135,12 @@ files {{ }; for i in 0..8 { set_flag_has_override(&mut file, FlagValueType::Boolean, i, true).unwrap(); - let attribute = get_flag_attribute_at_offset(&flag_info_path, i); + let attribute = + get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i); assert!((attribute & (FlagInfoBit::HasOverride as u8)) != 0); set_flag_has_override(&mut file, FlagValueType::Boolean, i, false).unwrap(); - let attribute = get_flag_attribute_at_offset(&flag_info_path, i); + let attribute = + get_flag_attribute_at_offset(&flag_info_path, FlagValueType::Boolean, i); assert!((attribute & (FlagInfoBit::HasOverride as u8)) == 0); } }