1import contextlib
2import os
3import unittest2
4import lldb
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10def haswell():
11    features = subprocess.check_output(["sysctl", "machdep.cpu"])
12    return "AVX2" in features.decode('utf-8')
13
14
15def apple_silicon():
16    features = subprocess.check_output(["sysctl", "machdep.cpu"])
17    return "Apple M" in features.decode('utf-8')
18
19
20class TestLaunchProcessPosixSpawn(TestBase):
21    NO_DEBUG_INFO_TESTCASE = True
22
23    def no_haswell(self):
24        if not haswell():
25            return "Current CPU is not Haswell"
26        return None
27
28    def no_apple_silicon(self):
29        if not apple_silicon():
30            return "Current CPU is not Apple Silicon"
31        return None
32
33    def run_arch(self, exe, arch):
34        self.runCmd('target create -arch {} {}'.format(arch, exe))
35        self.runCmd('run')
36
37        process = self.dbg.GetSelectedTarget().process
38        self.assertState(process.GetState(), lldb.eStateExited)
39        self.assertIn('slice: {}'.format(arch), process.GetSTDOUT(1000))
40
41    @skipUnlessDarwin
42    @skipIfDarwinEmbedded
43    @skipIfLLVMTargetMissing("AArch64")
44    @skipIfLLVMTargetMissing("X86")
45    @skipTestIfFn(no_haswell)
46    def test_haswell(self):
47        self.build()
48        exe = self.getBuildArtifact("fat.out")
49        self.run_arch(exe, 'x86_64')
50        self.run_arch(exe, 'x86_64h')
51
52    @skipUnlessDarwin
53    @skipIfDarwinEmbedded
54    @skipIfLLVMTargetMissing("AArch64")
55    @skipIfLLVMTargetMissing("X86")
56    @skipTestIfFn(no_apple_silicon)
57    def test_apple_silicon(self):
58        self.build()
59        exe = self.getBuildArtifact("fat.out")
60        self.run_arch(exe, 'x86_64')
61        self.run_arch(exe, 'arm64')
62