Loading tools/aconfig/src/storage/mod.rs +15 −15 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ pub mod flag_table; pub mod package_table; use anyhow::{anyhow, Result}; Loading @@ -23,12 +24,12 @@ use std::path::PathBuf; use crate::commands::OutputFile; use crate::protos::{ProtoParsedFlag, ProtoParsedFlags}; use crate::storage::package_table::PackageTable; use crate::storage::{flag_table::FlagTable, package_table::PackageTable}; pub const FILE_VERSION: u32 = 1; pub const HASH_PRIMES: [u32; 29] = [ 7, 13, 29, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 7, 17, 29, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741, ]; Loading Loading @@ -120,7 +121,13 @@ where let package_table_file = OutputFile { contents: package_table.as_bytes(), path: package_table_file_path }; Ok(vec![package_table_file]) // create and serialize flag map let flag_table = FlagTable::new(container, &packages)?; let flag_table_file_path = PathBuf::from("flag.map"); let flag_table_file = OutputFile { contents: flag_table.as_bytes(), path: flag_table_file_path }; Ok(vec![package_table_file, flag_table_file]) } #[cfg(test)] Loading @@ -147,13 +154,8 @@ mod tests { let aconfig_files = [ ( "com.android.aconfig.storage.test_1", "storage_test_1_part_1.aconfig", include_bytes!("../../tests/storage_test_1_part_1.aconfig").as_slice(), ), ( "com.android.aconfig.storage.test_1", "storage_test_1_part_2.aconfig", include_bytes!("../../tests/storage_test_1_part_2.aconfig").as_slice(), "storage_test_1.aconfig", include_bytes!("../../tests/storage_test_1.aconfig").as_slice(), ), ( "com.android.aconfig.storage.test_2", Loading Loading @@ -204,12 +206,10 @@ mod tests { assert_eq!(packages[0].package_name, "com.android.aconfig.storage.test_1"); assert_eq!(packages[0].package_id, 0); assert_eq!(packages[0].flag_names.len(), 5); assert_eq!(packages[0].flag_names.len(), 3); assert!(packages[0].flag_names.contains("enabled_rw")); assert!(packages[0].flag_names.contains("disabled_rw")); assert!(packages[0].flag_names.contains("enabled_ro")); assert!(packages[0].flag_names.contains("disabled_ro")); assert!(packages[0].flag_names.contains("enabled_fixed_ro")); assert_eq!(packages[0].boolean_offset, 0); assert_eq!(packages[1].package_name, "com.android.aconfig.storage.test_2"); Loading @@ -218,13 +218,13 @@ mod tests { assert!(packages[1].flag_names.contains("enabled_ro")); assert!(packages[1].flag_names.contains("disabled_ro")); assert!(packages[1].flag_names.contains("enabled_fixed_ro")); assert_eq!(packages[1].boolean_offset, 10); assert_eq!(packages[1].boolean_offset, 6); assert_eq!(packages[2].package_name, "com.android.aconfig.storage.test_4"); assert_eq!(packages[2].package_id, 2); assert_eq!(packages[2].flag_names.len(), 2); assert!(packages[2].flag_names.contains("enabled_ro")); assert!(packages[2].flag_names.contains("enabled_fixed_ro")); assert_eq!(packages[2].boolean_offset, 16); assert_eq!(packages[2].boolean_offset, 12); } } tools/aconfig/src/storage/package_table.rs +2 −2 Original line number Diff line number Diff line Loading @@ -249,7 +249,7 @@ mod tests { let first_node_expected = PackageTableNode { package_name: String::from("com.android.aconfig.storage.test_2"), package_id: 1, boolean_offset: 10, boolean_offset: 6, next_offset: None, bucket_index: 0, }; Loading @@ -265,7 +265,7 @@ mod tests { let third_node_expected = PackageTableNode { package_name: String::from("com.android.aconfig.storage.test_4"), package_id: 2, boolean_offset: 16, boolean_offset: 12, next_offset: None, bucket_index: 3, }; Loading tools/aconfig/tests/storage_test_1_part_1.aconfig→tools/aconfig/tests/storage_test_1.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -15,3 +15,10 @@ flag { bug: "456" is_exported: true } flag { name: "enabled_ro" namespace: "aconfig_test" description: "This flag is ENABLED + READ_ONLY" bug: "abc" } tools/aconfig/tests/storage_test_1_part_2.aconfigdeleted 100644 → 0 +0 −24 Original line number Diff line number Diff line package: "com.android.aconfig.storage.test_1" container: "system" flag { name: "enabled_ro" namespace: "aconfig_test" description: "This flag is ENABLED + READ_ONLY" bug: "abc" } flag { name: "disabled_ro" namespace: "aconfig_test" description: "This flag is DISABLED + READ_ONLY" bug: "123" } flag { name: "enabled_fixed_ro" namespace: "aconfig_test" description: "This flag is fixed READ_ONLY + ENABLED" bug: "" is_fixed_read_only: true } Loading
tools/aconfig/src/storage/mod.rs +15 −15 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ pub mod flag_table; pub mod package_table; use anyhow::{anyhow, Result}; Loading @@ -23,12 +24,12 @@ use std::path::PathBuf; use crate::commands::OutputFile; use crate::protos::{ProtoParsedFlag, ProtoParsedFlags}; use crate::storage::package_table::PackageTable; use crate::storage::{flag_table::FlagTable, package_table::PackageTable}; pub const FILE_VERSION: u32 = 1; pub const HASH_PRIMES: [u32; 29] = [ 7, 13, 29, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 7, 17, 29, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741, ]; Loading Loading @@ -120,7 +121,13 @@ where let package_table_file = OutputFile { contents: package_table.as_bytes(), path: package_table_file_path }; Ok(vec![package_table_file]) // create and serialize flag map let flag_table = FlagTable::new(container, &packages)?; let flag_table_file_path = PathBuf::from("flag.map"); let flag_table_file = OutputFile { contents: flag_table.as_bytes(), path: flag_table_file_path }; Ok(vec![package_table_file, flag_table_file]) } #[cfg(test)] Loading @@ -147,13 +154,8 @@ mod tests { let aconfig_files = [ ( "com.android.aconfig.storage.test_1", "storage_test_1_part_1.aconfig", include_bytes!("../../tests/storage_test_1_part_1.aconfig").as_slice(), ), ( "com.android.aconfig.storage.test_1", "storage_test_1_part_2.aconfig", include_bytes!("../../tests/storage_test_1_part_2.aconfig").as_slice(), "storage_test_1.aconfig", include_bytes!("../../tests/storage_test_1.aconfig").as_slice(), ), ( "com.android.aconfig.storage.test_2", Loading Loading @@ -204,12 +206,10 @@ mod tests { assert_eq!(packages[0].package_name, "com.android.aconfig.storage.test_1"); assert_eq!(packages[0].package_id, 0); assert_eq!(packages[0].flag_names.len(), 5); assert_eq!(packages[0].flag_names.len(), 3); assert!(packages[0].flag_names.contains("enabled_rw")); assert!(packages[0].flag_names.contains("disabled_rw")); assert!(packages[0].flag_names.contains("enabled_ro")); assert!(packages[0].flag_names.contains("disabled_ro")); assert!(packages[0].flag_names.contains("enabled_fixed_ro")); assert_eq!(packages[0].boolean_offset, 0); assert_eq!(packages[1].package_name, "com.android.aconfig.storage.test_2"); Loading @@ -218,13 +218,13 @@ mod tests { assert!(packages[1].flag_names.contains("enabled_ro")); assert!(packages[1].flag_names.contains("disabled_ro")); assert!(packages[1].flag_names.contains("enabled_fixed_ro")); assert_eq!(packages[1].boolean_offset, 10); assert_eq!(packages[1].boolean_offset, 6); assert_eq!(packages[2].package_name, "com.android.aconfig.storage.test_4"); assert_eq!(packages[2].package_id, 2); assert_eq!(packages[2].flag_names.len(), 2); assert!(packages[2].flag_names.contains("enabled_ro")); assert!(packages[2].flag_names.contains("enabled_fixed_ro")); assert_eq!(packages[2].boolean_offset, 16); assert_eq!(packages[2].boolean_offset, 12); } }
tools/aconfig/src/storage/package_table.rs +2 −2 Original line number Diff line number Diff line Loading @@ -249,7 +249,7 @@ mod tests { let first_node_expected = PackageTableNode { package_name: String::from("com.android.aconfig.storage.test_2"), package_id: 1, boolean_offset: 10, boolean_offset: 6, next_offset: None, bucket_index: 0, }; Loading @@ -265,7 +265,7 @@ mod tests { let third_node_expected = PackageTableNode { package_name: String::from("com.android.aconfig.storage.test_4"), package_id: 2, boolean_offset: 16, boolean_offset: 12, next_offset: None, bucket_index: 3, }; Loading
tools/aconfig/tests/storage_test_1_part_1.aconfig→tools/aconfig/tests/storage_test_1.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -15,3 +15,10 @@ flag { bug: "456" is_exported: true } flag { name: "enabled_ro" namespace: "aconfig_test" description: "This flag is ENABLED + READ_ONLY" bug: "abc" }
tools/aconfig/tests/storage_test_1_part_2.aconfigdeleted 100644 → 0 +0 −24 Original line number Diff line number Diff line package: "com.android.aconfig.storage.test_1" container: "system" flag { name: "enabled_ro" namespace: "aconfig_test" description: "This flag is ENABLED + READ_ONLY" bug: "abc" } flag { name: "disabled_ro" namespace: "aconfig_test" description: "This flag is DISABLED + READ_ONLY" bug: "123" } flag { name: "enabled_fixed_ro" namespace: "aconfig_test" description: "This flag is fixed READ_ONLY + ENABLED" bug: "" is_fixed_read_only: true }