File: TestUseSourceCache.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (68 lines) | stat: -rw-r--r-- 2,250 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Tests large source files are not locked on Windows when source cache is disabled
"""

import lldb
import os
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil
from shutil import copy


class SettingsUseSourceCacheTestCase(TestBase):
    NO_DEBUG_INFO_TESTCASE = True

    def test_set_use_source_cache_false(self):
        """Test that after 'set use-source-cache false', files are not locked."""
        self.set_use_source_cache_and_test(False)

    @skipIf(hostoslist=no_match(["windows"]))
    @skipIf(oslist=["windows"], archs=["aarch64"])  # Fails on windows 11
    def test_set_use_source_cache_true(self):
        """Test that after 'set use-source-cache false', files are locked."""
        self.set_use_source_cache_and_test(True)

    def set_use_source_cache_and_test(self, is_cache_enabled):
        """Common test for both True/False values of use-source-cache."""
        self.build()

        # Enable/Disable source cache
        self.runCmd(
            "settings set use-source-cache " + ("true" if is_cache_enabled else "false")
        )

        # Get paths for the main source file.
        src = self.getBuildArtifact("main-copy.cpp")
        self.assertTrue(src)

        # Make sure source file is bigger than 16K to trigger memory mapping
        self.assertGreater(os.stat(src).st_size, 4 * 4096)

        target, process, thread, breakpoint = lldbutil.run_to_name_breakpoint(
            self, "calc"
        )

        # Show the source file contents to make sure LLDB loads src file.
        self.runCmd("source list")

        # Try deleting the source file.
        is_file_removed = self.removeFile(src)

        if is_cache_enabled:
            self.assertFalse(
                is_file_removed, "Source cache is enabled, but delete file succeeded"
            )

        if not is_cache_enabled:
            self.assertTrue(
                is_file_removed, "Source cache is disabled, but delete file failed"
            )

    def removeFile(self, src):
        """Remove file and return true iff file was successfully removed."""
        try:
            os.remove(src)
            return True
        except Exception:
            return False