[test] Add API test target for libbssl

And checks the function hmac_sha256.

Bug: 301068421
Test: atest libbssl_avf_nostd.test
Change-Id: I3b4ebc9d9bd473b79103038181e2310a523f29a6
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 171389b..adf6309 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -72,6 +72,9 @@
       "path": "packages/modules/Virtualization/libs/avb"
     },
     {
+      "path": "packages/modules/Virtualization/libs/bssl"
+    },
+    {
       "path": "packages/modules/Virtualization/libs/capabilities"
     },
     {
diff --git a/libs/bssl/Android.bp b/libs/bssl/Android.bp
index 5cc2125..9b464c6 100644
--- a/libs/bssl/Android.bp
+++ b/libs/bssl/Android.bp
@@ -27,3 +27,21 @@
         "libzeroize_nostd",
     ],
 }
+
+rust_defaults {
+    name: "libbssl_avf_test_defaults",
+    crate_name: "bssl_avf_test",
+    srcs: ["tests/*.rs"],
+    test_suites: ["general-tests"],
+    static_libs: [
+        "libcrypto_baremetal",
+    ],
+}
+
+rust_test {
+    name: "libbssl_avf_nostd.test",
+    defaults: ["libbssl_avf_test_defaults"],
+    rustlibs: [
+        "libbssl_avf_nostd",
+    ],
+}
diff --git a/libs/bssl/TEST_MAPPING b/libs/bssl/TEST_MAPPING
new file mode 100644
index 0000000..a91e8c5
--- /dev/null
+++ b/libs/bssl/TEST_MAPPING
@@ -0,0 +1,9 @@
+// When adding or removing tests here, don't forget to amend _all_modules list in
+// wireless/android/busytown/ath_config/configs/prod/avf/tests.gcl
+{
+  "avf-presubmit" : [
+    {
+      "name" : "libbssl_avf_nostd.test"
+    }
+  ]
+}
\ No newline at end of file
diff --git a/libs/bssl/tests/api_test.rs b/libs/bssl/tests/api_test.rs
new file mode 100644
index 0000000..25aaf04
--- /dev/null
+++ b/libs/bssl/tests/api_test.rs
@@ -0,0 +1,40 @@
+// Copyright 2023, The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+use bssl_avf::{hmac_sha256, Result};
+
+const DATA1: [u8; 32] = [
+    0xdb, 0x16, 0xcc, 0xbf, 0xf0, 0xc4, 0xbc, 0x93, 0xc3, 0x5f, 0x11, 0xc5, 0xfa, 0xae, 0x03, 0x6c,
+    0x75, 0x40, 0x1f, 0x60, 0xb6, 0x3e, 0xb9, 0x2a, 0x6c, 0x84, 0x06, 0x4b, 0x36, 0x7f, 0xed, 0xdb,
+];
+const DATA2: [u8; 32] = [
+    0xaa, 0x57, 0x7a, 0x1a, 0x8b, 0xa2, 0x59, 0x3b, 0xad, 0x5f, 0x4d, 0x29, 0xe1, 0x0c, 0xaa, 0x85,
+    0xde, 0xf9, 0xad, 0xad, 0x8c, 0x11, 0x0c, 0x2e, 0x13, 0x43, 0xd7, 0xdf, 0x2a, 0x43, 0xb9, 0xdd,
+];
+
+#[test]
+fn hmac_sha256_returns_correct_result() -> Result<()> {
+    // The EXPECTED_HMAC can by computed with python:
+    // ```
+    // import hashlib; import base64; import hmac;
+    // print(hmac.new(bytes(DATA1), bytes(DATA2), hashlib.sha256).hexdigest())
+    // ```
+    const EXPECTED_HMAC: [u8; 32] = [
+        0xe9, 0x0d, 0x40, 0x9a, 0xef, 0x0d, 0xb1, 0x0b, 0x57, 0x82, 0xc4, 0x95, 0x6b, 0x4d, 0x54,
+        0x38, 0xa9, 0x41, 0xb0, 0xc9, 0xe2, 0x15, 0x59, 0x72, 0xb1, 0x0b, 0x0a, 0x03, 0xe1, 0x38,
+        0x8d, 0x07,
+    ];
+    assert_eq!(EXPECTED_HMAC, hmac_sha256(&DATA1, &DATA2)?);
+    Ok(())
+}