aconfig: create unit test targets for aconfig_protos and
aconfig_storage_file crate

also added a bunch of comments to satisfy android lint requirements

Bug: b/321077378
Test: atest aconfig.test, atest aconfig_protos.test, atest aconfig_storage_files.test
Change-Id: I9bce302ac3bc98c5347e5334d915e77337ee89c4
diff --git a/tools/aconfig/aconfig_protos/Android.bp b/tools/aconfig/aconfig_protos/Android.bp
index 1cc4e41..18c545a 100644
--- a/tools/aconfig/aconfig_protos/Android.bp
+++ b/tools/aconfig/aconfig_protos/Android.bp
@@ -45,12 +45,12 @@
     host_supported: true,
 }
 
-rust_library {
-    name: "libaconfig_protos",
+rust_defaults {
+    name: "aconfig_protos.defaults",
+    edition: "2021",
+    clippy_lints: "android",
+    lints: "android",
     srcs: ["src/lib.rs"],
-    crate_name: "aconfig_protos",
-    host_supported: true,
-    lints: "none",
     rustlibs: [
         "libaconfig_rust_proto",
         "libanyhow",
@@ -60,3 +60,16 @@
         "libpaste",
     ]
 }
+
+rust_library {
+    name: "libaconfig_protos",
+    crate_name: "aconfig_protos",
+    host_supported: true,
+    defaults: ["aconfig_protos.defaults"],
+}
+
+rust_test_host {
+    name: "aconfig_protos.test",
+    test_suites: ["general-tests"],
+    defaults: ["aconfig_protos.defaults"],
+}
diff --git a/tools/aconfig/aconfig_protos/src/lib.rs b/tools/aconfig/aconfig_protos/src/lib.rs
index f0d27d6..ef16e06 100644
--- a/tools/aconfig/aconfig_protos/src/lib.rs
+++ b/tools/aconfig/aconfig_protos/src/lib.rs
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+//! `aconfig_protos` is a crate for the protos defined for aconfig
 // When building with the Android tool-chain
 //
 //   - an external crate `aconfig_protos` will be generated
@@ -68,6 +69,7 @@
 use anyhow::Result;
 use paste::paste;
 
+/// Check if the name identifier is valid
 pub fn is_valid_name_ident(s: &str) -> bool {
     // Identifiers must match [a-z][a-z0-9_]*, except consecutive underscores are not allowed
     if s.contains("__") {
@@ -83,6 +85,7 @@
     chars.all(|ch| ch.is_ascii_lowercase() || ch.is_ascii_digit() || ch == '_')
 }
 
+/// Check if the package identifier is valid
 pub fn is_valid_package_ident(s: &str) -> bool {
     if !s.contains('.') {
         return false;
@@ -90,6 +93,7 @@
     s.split('.').all(is_valid_name_ident)
 }
 
+/// Check if the container identifier is valid
 pub fn is_valid_container_ident(s: &str) -> bool {
     s.split('.').all(is_valid_name_ident)
 }
@@ -111,10 +115,12 @@
     };
 }
 
+/// Utility module for flag_declaration proto
 pub mod flag_declaration {
     use super::*;
     use anyhow::ensure;
 
+    /// Ensure the proto instance is valid by checking its fields
     pub fn verify_fields(pdf: &ProtoFlagDeclaration) -> Result<()> {
         ensure_required_fields!("flag declaration", pdf, "name", "namespace", "description");
 
@@ -127,16 +133,19 @@
     }
 }
 
+/// Utility module for flag_declarations proto
 pub mod flag_declarations {
     use super::*;
     use anyhow::ensure;
 
+    /// Construct a proto instance from a textproto string content
     pub fn try_from_text_proto(s: &str) -> Result<ProtoFlagDeclarations> {
         let pdf: ProtoFlagDeclarations = super::try_from_text_proto(s)?;
         verify_fields(&pdf)?;
         Ok(pdf)
     }
 
+    /// Ensure the proto instance is valid by checking its fields
     pub fn verify_fields(pdf: &ProtoFlagDeclarations) -> Result<()> {
         ensure_required_fields!("flag declarations", pdf, "package");
         // TODO(b/312769710): Make the container field required.
@@ -157,10 +166,12 @@
     }
 }
 
+/// Utility module for flag_value proto
 pub mod flag_value {
     use super::*;
     use anyhow::ensure;
 
+    /// Ensure the proto instance is valid by checking its fields
     pub fn verify_fields(fv: &ProtoFlagValue) -> Result<()> {
         ensure_required_fields!("flag value", fv, "package", "name", "state", "permission");
 
@@ -171,15 +182,18 @@
     }
 }
 
+/// Utility module for flag_values proto
 pub mod flag_values {
     use super::*;
 
+    /// Construct a proto instance from a textproto string content
     pub fn try_from_text_proto(s: &str) -> Result<ProtoFlagValues> {
         let pfv: ProtoFlagValues = super::try_from_text_proto(s)?;
         verify_fields(&pfv)?;
         Ok(pfv)
     }
 
+    /// Ensure the proto instance is valid by checking its fields
     pub fn verify_fields(pfv: &ProtoFlagValues) -> Result<()> {
         for flag_value in pfv.flag_value.iter() {
             super::flag_value::verify_fields(flag_value)?;
@@ -188,10 +202,12 @@
     }
 }
 
+/// Utility module for flag_permission proto enum
 pub mod flag_permission {
     use super::*;
     use anyhow::bail;
 
+    /// Construct a flag permission proto enum from string
     pub fn parse_from_str(permission: &str) -> Result<ProtoFlagPermission> {
         match permission.to_ascii_lowercase().as_str() {
             "read_write" => Ok(ProtoFlagPermission::READ_WRITE),
@@ -200,6 +216,7 @@
         }
     }
 
+    /// Serialize flag permission proto enum to string
     pub fn to_string(permission: &ProtoFlagPermission) -> &str {
         match permission {
             ProtoFlagPermission::READ_WRITE => "read_write",
@@ -208,10 +225,12 @@
     }
 }
 
+/// Utility module for tracepoint proto
 pub mod tracepoint {
     use super::*;
     use anyhow::ensure;
 
+    /// Ensure the proto instance is valid by checking its fields
     pub fn verify_fields(tp: &ProtoTracepoint) -> Result<()> {
         ensure_required_fields!("tracepoint", tp, "source", "state", "permission");
 
@@ -221,10 +240,12 @@
     }
 }
 
+/// Utility module for parsed_flag proto
 pub mod parsed_flag {
     use super::*;
     use anyhow::ensure;
 
+    /// Ensure the proto instance is valid by checking its fields
     pub fn verify_fields(pf: &ProtoParsedFlag) -> Result<()> {
         ensure_required_fields!(
             "parsed flag",
@@ -265,23 +286,27 @@
         Ok(())
     }
 
+    /// Get the file path of the corresponding flag declaration
     pub fn path_to_declaration(pf: &ProtoParsedFlag) -> &str {
         debug_assert!(!pf.trace.is_empty());
         pf.trace[0].source()
     }
 }
 
+/// Utility module for parsed_flags proto
 pub mod parsed_flags {
     use super::*;
     use anyhow::bail;
     use std::cmp::Ordering;
 
+    /// Construct a proto instance from a binary proto bytes
     pub fn try_from_binary_proto(bytes: &[u8]) -> Result<ProtoParsedFlags> {
         let message: ProtoParsedFlags = protobuf::Message::parse_from_bytes(bytes)?;
         verify_fields(&message)?;
         Ok(message)
     }
 
+    /// Ensure the proto instance is valid by checking its fields
     pub fn verify_fields(pf: &ProtoParsedFlags) -> Result<()> {
         use crate::parsed_flag::path_to_declaration;
 
@@ -309,6 +334,7 @@
         Ok(())
     }
 
+    /// Merge multipe parsed_flags proto
     pub fn merge(parsed_flags: Vec<ProtoParsedFlags>, dedup: bool) -> Result<ProtoParsedFlags> {
         let mut merged = ProtoParsedFlags::new();
         for mut pfs in parsed_flags.into_iter() {
@@ -325,6 +351,7 @@
         Ok(merged)
     }
 
+    /// Sort parsed flags
     pub fn sort_parsed_flags(pf: &mut ProtoParsedFlags) {
         pf.parsed_flag.sort_by_key(create_sorting_key);
     }
@@ -334,7 +361,9 @@
     }
 }
 
+/// ParsedFlagExt trait
 pub trait ParsedFlagExt {
+    /// Return the fully qualified name
     fn fully_qualified_name(&self) -> String;
 }