• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright 2024 The ChromiumOS Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Tests for clean_up_old_llvm_patches"""
7
8from pathlib import Path
9import shutil
10import tempfile
11import unittest
12
13import clean_up_old_llvm_patches
14
15
16ANDROID_VERSION_PY_EXAMPLE = """
17def get_svn_revision():
18    return "r654321"
19"""
20
21
22class Test(unittest.TestCase):
23    """Tests for clean_up_old_llvm_patches"""
24
25    def make_tempdir(self) -> Path:
26        tmpdir = Path(tempfile.mkdtemp(prefix="patch_utils_unittest"))
27        self.addCleanup(shutil.rmtree, tmpdir)
28        return tmpdir
29
30    def test_android_version_autodetection(self):
31        android_root = self.make_tempdir()
32        android_version_py = (
33            android_root / "toolchain" / "llvm_android" / "android_version.py"
34        )
35        android_version_py.parent.mkdir(parents=True)
36        android_version_py.write_text(
37            ANDROID_VERSION_PY_EXAMPLE, encoding="utf-8"
38        )
39
40        self.assertEqual(
41            clean_up_old_llvm_patches.find_android_llvm_version(android_root),
42            654321,
43        )
44
45    def test_chromeos_version_autodetection(self):
46        chromiumos_overlay = self.make_tempdir()
47        llvm = chromiumos_overlay / "sys-devel" / "llvm"
48        llvm.mkdir(parents=True)
49
50        file_names = (
51            "Manifest",
52            "llvm-12.0-r1.ebuild",
53            "llvm-18.0_pre123456-r90.ebuild",
54            "llvm-9999.ebuild",
55        )
56        for f in file_names:
57            (llvm / f).touch()
58
59        self.assertEqual(
60            clean_up_old_llvm_patches.find_chromeos_llvm_version(
61                chromiumos_overlay
62            ),
63            123456,
64        )
65
66
67if __name__ == "__main__":
68    unittest.main()
69