xref: /aosp_15_r20/build/soong/scripts/uffd_gc_utils_test.py (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1*333d2b36SAndroid Build Coastguard Worker#!/usr/bin/env python
2*333d2b36SAndroid Build Coastguard Worker#
3*333d2b36SAndroid Build Coastguard Worker# Copyright (C) 2024 The Android Open Source Project
4*333d2b36SAndroid Build Coastguard Worker#
5*333d2b36SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*333d2b36SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*333d2b36SAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*333d2b36SAndroid Build Coastguard Worker#
9*333d2b36SAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
10*333d2b36SAndroid Build Coastguard Worker#
11*333d2b36SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*333d2b36SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*333d2b36SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*333d2b36SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*333d2b36SAndroid Build Coastguard Worker# limitations under the License.
16*333d2b36SAndroid Build Coastguard Worker#
17*333d2b36SAndroid Build Coastguard Worker"""Unit tests for uffd_gc_utils.py."""
18*333d2b36SAndroid Build Coastguard Worker
19*333d2b36SAndroid Build Coastguard Workerimport unittest
20*333d2b36SAndroid Build Coastguard Worker
21*333d2b36SAndroid Build Coastguard Workerfrom uffd_gc_utils import should_enable_uffd_gc_impl
22*333d2b36SAndroid Build Coastguard Worker
23*333d2b36SAndroid Build Coastguard Worker
24*333d2b36SAndroid Build Coastguard Workerclass UffdGcUtilsTest(unittest.TestCase):
25*333d2b36SAndroid Build Coastguard Worker  def test_should_enable_uffd_gc_impl(self):
26*333d2b36SAndroid Build Coastguard Worker    # GKI kernels in new format.
27*333d2b36SAndroid Build Coastguard Worker    self.assertTrue(should_enable_uffd_gc_impl(
28*333d2b36SAndroid Build Coastguard Worker        "6.1.25-android14-11-g34fde9ec08a3-ab10675345"))
29*333d2b36SAndroid Build Coastguard Worker    self.assertTrue(should_enable_uffd_gc_impl(
30*333d2b36SAndroid Build Coastguard Worker        "5.4.42-android12-0-something"))
31*333d2b36SAndroid Build Coastguard Worker    self.assertFalse(should_enable_uffd_gc_impl(
32*333d2b36SAndroid Build Coastguard Worker        "5.4.42-android11-0-something"))
33*333d2b36SAndroid Build Coastguard Worker    # GKI kernels in old format.
34*333d2b36SAndroid Build Coastguard Worker    self.assertFalse(should_enable_uffd_gc_impl(
35*333d2b36SAndroid Build Coastguard Worker        "4.19.282-g4b749a433956-ab10893502"))
36*333d2b36SAndroid Build Coastguard Worker    # Non GKI kernels.
37*333d2b36SAndroid Build Coastguard Worker    self.assertTrue(should_enable_uffd_gc_impl(
38*333d2b36SAndroid Build Coastguard Worker        "6.1.25-foo"))
39*333d2b36SAndroid Build Coastguard Worker    self.assertTrue(should_enable_uffd_gc_impl(
40*333d2b36SAndroid Build Coastguard Worker        "6.1.25"))
41*333d2b36SAndroid Build Coastguard Worker    self.assertTrue(should_enable_uffd_gc_impl(
42*333d2b36SAndroid Build Coastguard Worker        "5.10.19-foo"))
43*333d2b36SAndroid Build Coastguard Worker    self.assertTrue(should_enable_uffd_gc_impl(
44*333d2b36SAndroid Build Coastguard Worker        "5.10.19"))
45*333d2b36SAndroid Build Coastguard Worker    with self.assertRaises(SystemExit):
46*333d2b36SAndroid Build Coastguard Worker        should_enable_uffd_gc_impl("5.4.42-foo")
47*333d2b36SAndroid Build Coastguard Worker    with self.assertRaises(SystemExit):
48*333d2b36SAndroid Build Coastguard Worker        should_enable_uffd_gc_impl("5.4.42")
49*333d2b36SAndroid Build Coastguard Worker    self.assertFalse(should_enable_uffd_gc_impl(
50*333d2b36SAndroid Build Coastguard Worker        "4.19.282-foo"))
51*333d2b36SAndroid Build Coastguard Worker    self.assertFalse(should_enable_uffd_gc_impl(
52*333d2b36SAndroid Build Coastguard Worker        "4.19.282"))
53*333d2b36SAndroid Build Coastguard Worker    with self.assertRaises(SystemExit):
54*333d2b36SAndroid Build Coastguard Worker        should_enable_uffd_gc_impl("foo")
55*333d2b36SAndroid Build Coastguard Worker    # No kernel.
56*333d2b36SAndroid Build Coastguard Worker    self.assertTrue(should_enable_uffd_gc_impl(
57*333d2b36SAndroid Build Coastguard Worker        "<unknown-kernel>"))
58*333d2b36SAndroid Build Coastguard Worker
59*333d2b36SAndroid Build Coastguard Worker
60*333d2b36SAndroid Build Coastguard Workerif __name__ == '__main__':
61*333d2b36SAndroid Build Coastguard Worker  unittest.main(verbosity=2)
62