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    mydir = TestBase.compute_mydir(__file__)
23
24    def no_haswell(self):
25        if not haswell():
26            return "Current CPU is not Haswell"
27        return None
28
29    def no_apple_silicon(self):
30        if not apple_silicon():
31            return "Current CPU is not Apple Silicon"
32        return None
33
34    def run_arch(self, exe, arch):
35        self.runCmd('target create -arch {} {}'.format(arch, exe))
36        self.runCmd('run')
37
38        process = self.dbg.GetSelectedTarget().process
39        self.assertEqual(process.GetState(), lldb.eStateExited)
40        self.assertIn('slice: {}'.format(arch), process.GetSTDOUT(1000))
41
42    @skipUnlessDarwin
43    @skipIfDarwinEmbedded
44    @skipIfLLVMTargetMissing("AArch64")
45    @skipIfLLVMTargetMissing("X86")
46    @skipTestIfFn(no_haswell)
47    def test_haswell(self):
48        self.build()
49        exe = self.getBuildArtifact("fat.out")
50        self.run_arch(exe, 'x86_64')
51        self.run_arch(exe, 'x86_64h')
52
53    @skipUnlessDarwin
54    @skipIfDarwinEmbedded
55    @skipIfLLVMTargetMissing("AArch64")
56    @skipIfLLVMTargetMissing("X86")
57    @skipTestIfFn(no_apple_silicon)
58    def test_apple_silicon(self):
59        self.build()
60        exe = self.getBuildArtifact("fat.out")
61        self.run_arch(exe, 'x86_64')
62        self.run_arch(exe, 'arm64')
63