aboutsummaryrefslogtreecommitdiff
path: root/tools/finalization/finalization-test/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tools/finalization/finalization-test/test.rs')
-rw-r--r--tools/finalization/finalization-test/test.rs130
1 files changed, 130 insertions, 0 deletions
diff --git a/tools/finalization/finalization-test/test.rs b/tools/finalization/finalization-test/test.rs
new file mode 100644
index 0000000000..60a677f597
--- /dev/null
+++ b/tools/finalization/finalization-test/test.rs
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2025 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.
+ */
+
+mod build_flags;
+
+#[cfg(test)]
+mod tests {
+ use crate::build_flags::{ReleaseConfigs, FLAGS_WE_CARE_ABOUT};
+ use std::sync::LazyLock;
+
+ // the subset of build flags relevant for SDK finalization
+ static RELEASE_CONFIGS: LazyLock<ReleaseConfigs> = LazyLock::new(ReleaseConfigs::init);
+
+ fn sdk_version(release_config: &str) -> f32 {
+ // use SDK_INT_FULL if set, otherwise fall back to SDK_INT
+ let s = &RELEASE_CONFIGS.flags[release_config]["RELEASE_PLATFORM_SDK_VERSION_FULL"];
+ if !s.is_empty() {
+ s.parse::<f32>().unwrap_or_else(|_| {
+ panic!(
+ "failed to parse RELEASE_PLATFORM_SDK_VERSION_FULL for {} ({}) as f32",
+ release_config, s
+ )
+ })
+ } else {
+ let s = &RELEASE_CONFIGS.flags[release_config]["RELEASE_PLATFORM_SDK_VERSION"];
+ s.parse::<f32>().unwrap_or_else(|_| {
+ panic!(
+ "failed to parse RELEASE_PLATFORM_SDK_VERSION for {} ({}) as f32",
+ release_config, s
+ )
+ })
+ }
+ }
+
+ #[test]
+ fn test_build_flags_in_trunk_and_trunk_staging_are_equal() {
+ // invariant: the values of the flags (that this test cares about) in RELEASE_CONFIGS.flags are equal
+ // across trunk and trunk_staging release configs
+ //
+ // this means that the rest of the tests can focus on trunk and ignore trunk_staging
+ for flag in FLAGS_WE_CARE_ABOUT {
+ assert_eq!(
+ RELEASE_CONFIGS.flags["trunk"][flag], RELEASE_CONFIGS.flags["trunk_staging"][flag],
+ "flag {} differenct across trunk and trunk_staging",
+ flag,
+ );
+ }
+ }
+
+ #[test]
+ fn test_trunk_is_never_rel() {
+ // invariant: the codename in trunk is never REL: trunk is always bleeding edge and thus
+ // always something later than the latest finalized (REL) platform
+ assert_ne!(RELEASE_CONFIGS.flags["trunk"]["RELEASE_PLATFORM_VERSION_CODENAME"], "REL");
+ }
+
+ #[test]
+ fn test_version_parity_if_next_is_not_rel() {
+ // invariant: the version code of trunk and next are identical, unless next is REL: then
+ // the version in trunk can be one less than the version in next (during the intermediate
+ // state where next is REL but we haven't created prebuilts/sdk/<new-version> yet), or the
+ // version in trunk is identical to the one in next
+ let next = &RELEASE_CONFIGS.next;
+ if RELEASE_CONFIGS.flags[next]["RELEASE_PLATFORM_VERSION_CODENAME"] != "REL" {
+ // expect the versions to be identical
+ assert_eq!(
+ RELEASE_CONFIGS.flags[next]["RELEASE_PLATFORM_SDK_VERSION_FULL"],
+ RELEASE_CONFIGS.flags["trunk"]["RELEASE_PLATFORM_SDK_VERSION_FULL"]
+ );
+ } else {
+ // make sure the version in trunk is less or equal to that of next
+ //
+ // ideally this should check that trunk is at most one version behind next, but we
+ // can't tell what that means, so let's settle for the weaker guarantee of "less or
+ // equal"
+ assert!(sdk_version("trunk") <= sdk_version(next));
+ }
+ }
+
+ #[test]
+ fn test_version_and_version_full_parity() {
+ // invariant: for the release configs that set RELEASE_PLATFORM_SDK_VERSION_FULL:
+ // - the value can be parsed as a float
+ // - the value contains a decimal separator
+ // - the value before the decimal separator is identical to RELEASE_PLATFORM_SDK_VERSION
+ // (e.g. 36.0 and 36)
+ for release_config in RELEASE_CONFIGS.flags.keys() {
+ let version_full =
+ &RELEASE_CONFIGS.flags[release_config]["RELEASE_PLATFORM_SDK_VERSION_FULL"];
+ if version_full.is_empty() {
+ // skip this release config if it doesn't set RELEASE_PLATFORM_SDK_VERSION_FULL
+ continue;
+ }
+ assert!(
+ version_full.parse::<f32>().is_ok(),
+ "failed to convert value ({}) of RELEASE_PLATFORM_SDK_VERSION_FULL for {} to f32",
+ version_full,
+ release_config
+ );
+ let (integer_part, _) = version_full.split_once(".").unwrap_or_else(|| panic!("value of RELEASE_PLATFORM_SDK_VERSION_FULL ({}) for {} doesn't have expected format", version_full, release_config));
+ assert_eq!(
+ integer_part,
+ RELEASE_CONFIGS.flags[release_config]["RELEASE_PLATFORM_SDK_VERSION"]
+ );
+ }
+ }
+
+ #[test]
+ fn test_release_hidden_api_exportable_stubs_is_enabled_in_next() {
+ // invariant: RELEASE_HIDDEN_API_EXPORTABLE_STUBS is set to `true` in `next`, because we'll
+ // cut an Android release from this release config (the flag is too expensive in terms of
+ // build performance to enable everywhere)
+ let next = &RELEASE_CONFIGS.next;
+ let value = &RELEASE_CONFIGS.flags[next]["RELEASE_HIDDEN_API_EXPORTABLE_STUBS"];
+ assert_eq!(value, "true");
+ }
+}