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