diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-23 00:09:59 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-23 00:09:59 +0000 |
commit | 10b41a934c4eb93fc4712df71f14771ddb1e01ad (patch) | |
tree | c8faaef4211326b843bf0fa8cb3fa63cf5fd1ae2 | |
parent | ba97bd280abda11509ca8d88e8a232a44fe427a4 (diff) | |
parent | e5a18b52cafa9dfa25a2b06e8c200628e34005c7 (diff) | |
download | net-10b41a934c4eb93fc4712df71f14771ddb1e01ad.tar.gz |
Snap for 8754433 from e5a18b52cafa9dfa25a2b06e8c200628e34005c7 to mainline-tethering-releaseaml_tet_330812150
Change-Id: If0b9aebf29afff562ca756eaa7520409437f0ea3
-rw-r--r-- | common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java | 14 | ||||
-rw-r--r-- | common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java | 15 |
2 files changed, 29 insertions, 0 deletions
diff --git a/common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java b/common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java index 6f603d50..e46dd599 100644 --- a/common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java +++ b/common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java @@ -106,4 +106,18 @@ public final class DeviceInfoUtilsTest { assertFalse(v1.isAtLeast(v4)); assertFalse(v1.isAtLeast(v5)); } + + @Test + public void testKernelVersionIsAtLeast() { + // Pick a lower kernel version 4.0 which was released at April 2015, the kernel + // version running on all test devices nowadays should be higher than it. + assertTrue(DeviceInfoUtils.isKernelVersionAtLeast("4.0")); + + // Invalid kernel version. + assertTrue(DeviceInfoUtils.isKernelVersionAtLeast("0.0.0")); + + // Pick a higher kernel version which isn't released yet, comparison should return false. + // Need to update the target version in the future to make sure the test still passes. + assertFalse(DeviceInfoUtils.isKernelVersionAtLeast("20.0.0")); + } } diff --git a/common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java b/common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java index 1925b559..ea89edaa 100644 --- a/common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java +++ b/common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java @@ -16,6 +16,7 @@ package com.android.testutils; +import android.os.VintfRuntimeInfo; import android.text.TextUtils; import android.util.Pair; @@ -157,4 +158,18 @@ public class DeviceInfoUtils { return new KVersion(0, 0, 0); } } + + /** + * Check if the current kernel version is at least satisfied with the given version. + * + * @param version the start version to compare + * @return return true if the current version is at least satisfied with the given version. + * otherwise, return false. + */ + public static boolean isKernelVersionAtLeast(final String version) { + final String kernelVersion = VintfRuntimeInfo.getKernelVersion(); + final KVersion current = DeviceInfoUtils.getMajorMinorSubminorVersion(kernelVersion); + final KVersion from = DeviceInfoUtils.getMajorMinorSubminorVersion(version); + return current.isAtLeast(from); + } } |