]>
git.saurik.com Git - apple/dyld.git/blob - testing/build_tests.py
14 # Scan files in .dtest directory looking for BUILD: or RUN: directives.
15 # Return a dictionary of all directives.
17 def parseDirectives(testCaseSourceDir
):
23 for file in os
.listdir(testCaseSourceDir
):
24 if file.endswith((".c", ".cpp", ".cxx")):
25 with open(testCaseSourceDir
+ "/" + file) as f
:
26 for line
in f
.read().splitlines():
27 buildIndex
= string
.find(line
, "BUILD:")
29 buildLines
.append(line
[buildIndex
+ 6:].lstrip())
30 runIndex
= string
.find(line
, "RUN:")
32 runLines
.append(line
[runIndex
+4:].lstrip())
33 onlyIndex
= string
.find(line
, "BUILD_ONLY:")
35 onlyLines
.append(line
[onlyIndex
+11:].lstrip())
36 minOsIndex
= string
.find(line
, "BUILD_MIN_OS:")
38 minOS
= line
[minOsIndex
+13:].lstrip()
39 timeoutIndex
= string
.find(line
, "RUN_TIMEOUT:")
40 if timeoutIndex
!= -1:
41 timeout
= line
[timeoutIndex
+12:].lstrip()
45 "BUILD_ONLY": onlyLines
,
46 "BUILD_MIN_OS": minOS
,
48 "RUN_TIMEOUT": timeout
53 # Look at directives dictionary to see if this test should be skipped for this platform
55 def useTestCase(testCaseDirectives
, platformName
):
56 onlyLines
= testCaseDirectives
["BUILD_ONLY"]
57 for only
in onlyLines
:
58 if only
== "MacOSX" and platformName
!= "macosx":
60 if only
== "iOS" and platformName
!= "iphoneos":
66 # Use BUILD directives to construct the test case
67 # Use RUN directives to generate a shell script to run test(s)
69 def buildTestCase(testCaseDirectives
, testCaseSourceDir
, toolsDir
, sdkDir
, minOsOptionsName
, defaultMinOS
, archOptions
, testCaseDestDirBuild
, testCaseDestDirRun
):
70 scratchDir
= tempfile
.mkdtemp()
71 if testCaseDirectives
["BUILD_MIN_OS"]:
72 minOS
= testCaseDirectives
["BUILD_MIN_OS"]
75 compilerSearchOptions
= " -isysroot " + sdkDir
+ " -I" + sdkDir
+ "/System/Library/Frameworks/System.framework/PrivateHeaders"
76 if minOsOptionsName
== "mmacosx-version-min":
77 taskForPidCommand
= "touch "
78 envEnableCommand
= "touch "
80 taskForPidCommand
= "codesign --force --sign - --entitlements " + testCaseSourceDir
+ "/../../task_for_pid_entitlement.plist "
81 envEnableCommand
= "codesign --force --sign - --entitlements " + testCaseSourceDir
+ "/../../get_task_allow_entitlement.plist "
83 "CC": toolsDir
+ "/usr/bin/clang " + archOptions
+ " -" + minOsOptionsName
+ "=" + str(minOS
) + compilerSearchOptions
,
84 "CXX": toolsDir
+ "/usr/bin/clang++ " + archOptions
+ " -" + minOsOptionsName
+ "=" + str(minOS
) + compilerSearchOptions
,
85 "BUILD_DIR": testCaseDestDirBuild
,
86 "RUN_DIR": testCaseDestDirRun
,
87 "TEMP_DIR": scratchDir
,
88 "TASK_FOR_PID_ENABLE": taskForPidCommand
,
89 "DYLD_ENV_VARS_ENABLE": envEnableCommand
91 os
.makedirs(testCaseDestDirBuild
)
92 os
.chdir(testCaseSourceDir
)
93 print >> sys
.stderr
, "cd " + testCaseSourceDir
94 for line
in testCaseDirectives
["BUILD"]:
95 cmd
= string
.Template(line
).safe_substitute(buildSubs
)
96 print >> sys
.stderr
, cmd
98 result
= subprocess
.call(cmd
, shell
=True)
101 cmdList
= string
.split(cmd
)
102 result
= subprocess
.call(cmdList
)
105 shutil
.rmtree(scratchDir
, ignore_errors
=True)
107 if minOsOptionsName
== "mmacosx-version-min":
110 "RUN_DIR": testCaseDestDirRun
,
111 "REQUIRE_CRASH": "nocr -require_crash",
114 runFilePath
= testCaseDestDirBuild
+ "/run.sh"
115 with open(runFilePath
, "a") as runFile
:
116 runFile
.write("#!/bin/sh\n")
117 runFile
.write("cd " + testCaseDestDirRun
+ "\n")
118 os
.chmod(runFilePath
, 0755)
119 for runline
in testCaseDirectives
["RUN"]:
120 runFile
.write(string
.Template(runline
).safe_substitute(runSubs
) + "\n")
128 # Use XCode build settings to build all unit tests for specified platform
129 # Generate a .plist for BATS to use to run all tests
131 if __name__
== "__main__":
132 dstDir
= os
.getenv("DSTROOT", "/tmp/dyld_tests/")
133 testsRunDstTopDir
= "/AppleInternal/CoreOS/tests/dyld/"
134 testsBuildDstTopDir
= dstDir
+ testsRunDstTopDir
135 shutil
.rmtree(testsBuildDstTopDir
, ignore_errors
=True)
136 dyldSrcDir
= os
.getenv("SRCROOT", "")
138 dyldSrcDir
= os
.getcwd()
139 testsSrcTopDir
= dyldSrcDir
+ "/testing/test-cases/"
140 sdkDir
= os
.getenv("SDKROOT", "")
142 #sdkDir = subprocess.check_output(["xcrun", "--show-sdk-path"]).rstrip()
143 sdkDir
= "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.Internal.sdk"
144 toolsDir
= os
.getenv("TOOLCHAIN_DIR", "/")
147 minOSOption
= os
.getenv("DEPLOYMENT_TARGET_CLANG_FLAG_NAME", "")
149 minOSVersName
= os
.getenv("DEPLOYMENT_TARGET_CLANG_ENV_NAME", "")
151 minVersNum
= os
.getenv(minOSVersName
, "")
153 minOSOption
= "mmacosx-version-min"
154 platformName
= os
.getenv("PLATFORM_NAME", "osx")
156 archList
= os
.getenv("RC_ARCHS", "")
158 for arch
in string
.split(archList
, " "):
159 archOptions
= archOptions
+ " -arch " + arch
161 archList
= os
.getenv("ARCHS_STANDARD_32_64_BIT", "")
162 if platformName
== "watchos":
163 archOptions
= "-arch armv7k"
164 elif platformName
== "appletvos":
165 archOptions
= "-arch arm64"
168 for arch
in string
.split(archList
, " "):
169 archOptions
= archOptions
+ " -arch " + arch
171 archOptions
= "-arch x86_64"
173 for f
in os
.listdir(testsSrcTopDir
):
174 if f
.endswith(".dtest"):
176 outDirBuild
= testsBuildDstTopDir
+ testName
177 outDirRun
= testsRunDstTopDir
+ testName
178 testCaseDir
= testsSrcTopDir
+ f
179 testCaseDirectives
= parseDirectives(testCaseDir
)
180 if useTestCase(testCaseDirectives
, platformName
):
181 result
= buildTestCase(testCaseDirectives
, testCaseDir
, toolsDir
, sdkDir
, minOSOption
, minVersNum
, archOptions
, outDirBuild
, outDirRun
)
185 mytest
["TestName"] = testName
186 mytest
["Arch"] = "platform-native"
187 mytest
["WorkingDirectory"] = testsRunDstTopDir
+ testName
188 mytest
["Command"] = []
189 mytest
["Command"].append("./run.sh")
190 for runline
in testCaseDirectives
["RUN"]:
191 if "$SUDO" in runline
:
192 mytest
["AsRoot"] = True
193 if testCaseDirectives
["RUN_TIMEOUT"]:
194 mytest
["Timeout"] = testCaseDirectives
["RUN_TIMEOUT"]
195 allTests
.append(mytest
)
196 batsInfo
= { "BATSConfigVersion": "0.1.0",
197 "Project": "dyld_tests",
199 batsFileDir
= dstDir
+ "/AppleInternal/CoreOS/BATS/unit_tests/"
200 shutil
.rmtree(batsFileDir
, ignore_errors
=True)
201 os
.makedirs(batsFileDir
)
202 batsFilePath
= batsFileDir
+ "dyld.plist"
203 with open(batsFilePath
, "w") as batsFile
:
204 batsFile
.write(plistlib
.writePlistToString(batsInfo
))
206 os
.system('plutil -convert binary1 ' + batsFilePath
) # convert the plist in place to binary
207 runHelper
= dstDir
+ "/AppleInternal/CoreOS/tests/dyld/run_all_dyld_tests.sh"
209 with open(runHelper
, "w") as shFile
:
210 shFile
.write("#!/bin/sh\n")
211 for test
in allTests
:
212 shFile
.write(test
["WorkingDirectory"] + "/run.sh\n")
214 os
.chmod(runHelper
, 0755)