]>
git.saurik.com Git - apple/dyld.git/blob - testing/build_tests.py
4bb44828dfcc415e14e76206d33a15a90513ef40
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 testsSrcTopDir
= os
.getenv("SRCROOT", "./") + "/testing/test-cases/"
137 sdkDir
= os
.getenv("SDKROOT", "/")
138 toolsDir
= os
.getenv("TOOLCHAIN_DIR", "/")
140 minOSOption
= os
.getenv("DEPLOYMENT_TARGET_CLANG_FLAG_NAME", "")
142 minOSVersName
= os
.getenv("DEPLOYMENT_TARGET_CLANG_ENV_NAME", "")
144 minVersNum
= os
.getenv(minOSVersName
, "")
145 platformName
= os
.getenv("PLATFORM_NAME", "osx")
147 archList
= os
.getenv("RC_ARCHS", "")
149 for arch
in string
.split(archList
, " "):
150 archOptions
= archOptions
+ " -arch " + arch
152 archList
= os
.getenv("ARCHS_STANDARD_32_64_BIT", "")
153 if platformName
== "watchos":
154 archOptions
= "-arch armv7k"
155 elif platformName
== "appletvos":
156 archOptions
= "-arch arm64"
159 for arch
in string
.split(archList
, " "):
160 archOptions
= archOptions
+ " -arch " + arch
162 for f
in os
.listdir(testsSrcTopDir
):
163 if f
.endswith(".dtest"):
165 outDirBuild
= testsBuildDstTopDir
+ testName
166 outDirRun
= testsRunDstTopDir
+ testName
167 testCaseDir
= testsSrcTopDir
+ f
168 testCaseDirectives
= parseDirectives(testCaseDir
)
169 if useTestCase(testCaseDirectives
, platformName
):
170 result
= buildTestCase(testCaseDirectives
, testCaseDir
, toolsDir
, sdkDir
, minOSOption
, minVersNum
, archOptions
, outDirBuild
, outDirRun
)
174 mytest
["TestName"] = testName
175 mytest
["Arch"] = "platform-native"
176 mytest
["WorkingDirectory"] = testsRunDstTopDir
+ testName
177 mytest
["Command"] = []
178 mytest
["Command"].append("./run.sh")
179 for runline
in testCaseDirectives
["RUN"]:
180 if "$SUDO" in runline
:
181 mytest
["AsRoot"] = True
182 if testCaseDirectives
["RUN_TIMEOUT"]:
183 mytest
["Timeout"] = testCaseDirectives
["RUN_TIMEOUT"]
184 allTests
.append(mytest
)
185 batsInfo
= { "BATSConfigVersion": "0.1.0",
186 "Project": "dyld_tests",
188 batsFileDir
= dstDir
+ "/AppleInternal/CoreOS/BATS/unit_tests/"
189 shutil
.rmtree(batsFileDir
, ignore_errors
=True)
190 os
.makedirs(batsFileDir
)
191 batsFilePath
= batsFileDir
+ "dyld.plist"
192 with open(batsFilePath
, "w") as batsFile
:
193 batsFile
.write(plistlib
.writePlistToString(batsInfo
))
195 os
.system('plutil -convert binary1 ' + batsFilePath
) # convert the plist in place to binary
196 runHelper
= dstDir
+ "/AppleInternal/CoreOS/tests/dyld/run_all_dyld_tests.sh"
198 with open(runHelper
, "w") as shFile
:
199 shFile
.write("#!/bin/sh\n")
200 for test
in allTests
:
201 shFile
.write(test
["WorkingDirectory"] + "/run.sh\n")
203 os
.chmod(runHelper
, 0755)