Skip to content

Commit db437d2

Browse files
author
Mishal Awadah
committed
Add all existing tests to integration repo
0 parents  commit db437d2

35 files changed

+721
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*~
2+
*.pyc
3+

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Swift Package Tests
2+
===================
3+
4+
Automated tests for validating the downloadable Swift packages behave correctly.
5+
6+
Usage
7+
-----
8+
9+
You are expected to check this repository out as a peer of "llvm" in the
10+
swift-project.
11+
12+
Run the tests using:
13+
14+
./test -sv --param package-path=/path/to/downloadable-package .
15+
16+
where the path is the unarchived package root path.
17+
18+
Tests
19+
-----
20+
21+
Here is a list of tests in the repository:
22+
23+
| Test Name | Functionality |
24+
|--------------------------+------------------------------------------------------------------|
25+
| basic | check output of `swift --version` |
26+
| example-package-dealer | build the example package-dealer package |
27+
| repl | various REPL sanity checks, notably importing Darwin and Glibc |
28+
| swift-build-self-host | Use swift build to build itself |
29+
| swift-compiler | Compile a basic swift file |
30+
| test-c-library-swiftpm | Build a package that links a 3rd party library |
31+
| test-foundation-package | Build a package that imports Foundation |
32+
| test-import-glibc | Compile a source file importing and using Glibc |
33+
| test-multi-compile | Compile multiple source files into an executable |
34+
| test-multi-compile-glibc | Compile multiple source files importing Glibc into an executable |
35+
| test-static-lib | Compile multiple source files into a static library |
36+
| test-xctest-package | Build a package that imports XCTest |
37+

basic.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Basic sanity check.
2+
#
3+
# RUN: %{swiftc} --version > %t.out
4+
# RUN: %{FileCheck} --input-file %t.out %s
5+
#
6+
# CHECK: Swift version

debugging-flags-SR85.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Check that debugging can print variables.
2+
# https://bugs.swift.org/browse/SR-85
3+
#
4+
# Make a sandbox dir.
5+
# RUN: rm -rf %t.dir
6+
# RUN: mkdir -p %t.dir/tool
7+
# RUN: touch %t.dir/tool/Package.swift
8+
# RUN: echo 'let foo = "bar"' > %t.dir/tool/main.swift
9+
# RUN: echo 'print(foo)' >> %t.dir/tool/main.swift
10+
# RUN: %{swift} build --chdir %t.dir/tool -v > %t.build-log
11+
12+
# RUN: echo 'breakpoint set -f main.swift -l 2' > %t.dir/lldb.script
13+
# RUN: echo 'run' >> %t.dir/lldb.script
14+
# RUN: echo 'print foo' >> %t.dir/lldb.script
15+
# RUN: %{lldb} %t.dir/tool/.build/debug/tool --source %t.dir/lldb.script --batch &> %t.lldb.out
16+
# RUN: %{FileCheck} --check-prefix CHECK-LLDB-OUTPUT --input-file %t.lldb.out %s
17+
#
18+
# CHECK-LLDB-OUTPUT: (lldb) print foo
19+
# CHECK-LLDB-OUTPUT-NEXT: (String) $R0 = "bar"

example-package-dealer.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Test the open source example packages.
2+
#
3+
# REQUIRES: have-network
4+
#
5+
# Make a sandbox dir. If you want to experiment with this test without waiting
6+
# for the clone, disable the first three lines here.
7+
#
8+
# RUN: rm -rf %t.dir
9+
# RUN: mkdir -p %t.dir/
10+
# RUN: git clone https://github.com/apple/example-package-dealer %t.dir/dealer
11+
12+
# RUN: rm -rf %t.dir/dealer/.build
13+
# RUN: %{swift} build --chdir %t.dir/dealer > %t.build-log
14+
15+
# Check the build log.
16+
#
17+
# RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
18+
#
19+
# CHECK-BUILD-LOG: Compiling Swift Module 'FisherYates'
20+
# CHECK-BUILD-LOG: Compiling Swift Module 'Dealer'
21+
22+
# Verify that the build worked.
23+
#
24+
# RUN: test -x %t.dir/dealer/.build/debug/Dealer
25+
# RUN: %t.dir/dealer/.build/debug/Dealer > %t.out
26+
# RUN: %{FileCheck} --check-prefix CHECK-TOOL-OUTPUT --input-file %t.out %s
27+
#
28+
# We should get an example that is easier to test.
29+
#
30+
# CHECK-TOOL-OUTPUT: {{♡|♠|♢|♣}}{{[0-9JQKA]|10}}
31+
32+
# Verify that the 'git status' is clean after a build.
33+
#
34+
# RUN: cd %t.dir/dealer && git status > %t.out
35+
# RUN: %{FileCheck} --check-prefix CHECK-GIT-STATUS --input-file %t.out %s
36+
#
37+
# CHECK-GIT-STATUS: nothing to commit, working directory clean
38+
39+
# Verify that another 'swift build' does nothing.
40+
#
41+
# RUN: %{swift} build --chdir %t.dir/dealer > %t.rebuild-log
42+
# RUN: echo END-OF-INPUT >> %t.rebuild-log
43+
# RUN: %{FileCheck} --check-prefix CHECK-BUILD-LOG --input-file %t.build-log %s
44+
#
45+
# CHECK-REBUILD-LOG-NOT: Compiling

lit.cfg

+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# -*- Python -*-
2+
3+
import platform
4+
import os
5+
import subprocess
6+
7+
import lit.formats
8+
9+
# Configuration file for the 'lit' test runner.
10+
11+
def which(command, paths = None):
12+
"""which(command, [paths]) - Look up the given command in the paths string
13+
(or the PATH environment variable, if unspecified)."""
14+
15+
if paths is None:
16+
paths = os.environ.get('PATH','')
17+
18+
# Check for absolute match first.
19+
if os.path.exists(command):
20+
return command
21+
22+
# Would be nice if Python had a lib function for this.
23+
if not paths:
24+
paths = os.defpath
25+
26+
# Get suffixes to search.
27+
pathext = os.environ.get('PATHEXT', '').split(os.pathsep)
28+
29+
# Search the paths...
30+
for path in paths.split(os.pathsep):
31+
for ext in pathext:
32+
p = os.path.join(path, command + ext)
33+
if os.path.exists(p):
34+
return p
35+
36+
return None
37+
38+
###
39+
# Retrieve expected values from lit.site.cfg
40+
41+
srcroot = os.path.dirname(os.path.abspath(__file__))
42+
srcroot = os.path.normpath(srcroot)
43+
44+
###
45+
# Basic Configuration Parameters
46+
47+
# name: The name of this test suite.
48+
config.name = 'swift-package-tests'
49+
50+
# testFormat: The test format to use to interpret tests.
51+
config.test_format = lit.formats.ShTest(execute_external = False)
52+
53+
# suffixes: A list of file extensions to treat as test files.
54+
#
55+
# We override this in specific subdirectories to change what we test.
56+
config.suffixes = [".txt", ".py"]
57+
58+
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
59+
# subdirectories contain auxiliary inputs for various tests in their parent
60+
# directories.
61+
config.excludes = ['Inputs']
62+
63+
# test_source_root: The root path where tests are located.
64+
config.test_source_root = os.path.join(srcroot)
65+
66+
# test_source_root: The root path where tests are executing.
67+
config.test_exec_root = "/tmp/swift-package-tests"
68+
69+
# We don't make use of this yet.
70+
#
71+
# FIXME: This is pretty compiler specific and probably should just be ripped out
72+
# of lit.
73+
config.target_triple = None
74+
75+
# On Darwin, always push SDKROOT in the environment.
76+
#
77+
# FIXME: Eventually, when we use xcrun to launch the toolchain items, this
78+
# should go away.
79+
if platform.system() == "Darwin":
80+
config.environment["SDKROOT"] = subprocess.check_output(
81+
["xcrun", "--sdk", "macosx", "--show-sdk-path"]).strip()
82+
83+
###
84+
85+
# Use features like this in lit:
86+
# # REQUIRES: platform=<platform>
87+
# where <platform> is Linux or Darwin
88+
# Add a platform feature.
89+
config.available_features.add("platform="+platform.system())
90+
91+
# Check if 'pexpect' is available.
92+
have_pexpect = False
93+
try:
94+
import pexpect
95+
have_pexpect = True
96+
except ImportError as e:
97+
pass
98+
if have_pexpect:
99+
config.available_features.add("have-pexpect")
100+
else:
101+
lit_config.note("'pexpect' module unavailable, skipping related tests")
102+
103+
# For tests that need access to the outside world, let them know if
104+
# that's possible
105+
if lit_config.params.get("have-network"):
106+
config.available_features.add("have-network")
107+
108+
###
109+
110+
# Get the package path.
111+
package_path = lit_config.params.get("package-path")
112+
if package_path is None:
113+
lit_config.fatal("'--param package-path=PATH' is required")
114+
package_path = os.path.abspath(package_path)
115+
# if platform.system() == "Darwin":
116+
# package_path = os.path.join(package_path, "Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain")
117+
lit_config.note("testing package: %r" % (package_path,))
118+
119+
# Find the path to FileCheck. We just pick any one out of the build directory.
120+
swift_build_path = os.path.join(srcroot, "..", "build")
121+
filecheck_path = lit_config.params.get("filecheck")
122+
if filecheck_path is None:
123+
for variant in os.listdir(swift_build_path):
124+
variant_path = os.path.join(swift_build_path, variant)
125+
for tree in os.listdir(variant_path):
126+
if tree.startswith("llvm-"):
127+
path = os.path.join(variant_path, tree, "bin", "FileCheck")
128+
if os.path.exists(path):
129+
filecheck_path = path
130+
break
131+
if filecheck_path is None:
132+
lit_config.fatal("unable to locate FileCheck, '--param filecheck=PATH' is required")
133+
134+
# Use the default Swift src layout if swiftpm is not provided as a
135+
# param
136+
swiftpm_srcdir = lit_config.params.get("swiftpm-srcdir")
137+
if swiftpm_srcdir is None:
138+
swiftpm_srcdir = os.path.join(srcroot, "..", "swiftpm")
139+
if os.path.exists(swiftpm_srcdir):
140+
config.available_features.add("have-swiftpm")
141+
config.substitutions.append( ('%{swiftpm_srcdir}', swiftpm_srcdir) )
142+
143+
# Find the tools we need.
144+
lit_config.note("testing using 'FileCheck': %r" % (filecheck_path,))
145+
146+
swift_path = os.path.join(package_path, "usr", "bin", "swift")
147+
lit_config.note("testing using 'swift': %r" % (swift_path,))
148+
149+
swiftc_path = os.path.join(package_path, "usr", "bin", "swiftc")
150+
lit_config.note("testing using 'swiftc': %r" % (swiftc_path,))
151+
152+
lldb_path = os.path.join(package_path, "usr", "bin", "lldb")
153+
lit_config.note("testing using 'lldb': {}".format(lldb_path))
154+
155+
# Verify they exist.
156+
if not os.path.exists(swift_path):
157+
lit_config.fatal("swift does not exist!")
158+
if not os.path.exists(swiftc_path):
159+
lit_config.fatal("swiftc does not exist!")
160+
if not os.path.exists(filecheck_path):
161+
lit_config.fatal("filecheck does not exist!")
162+
if not os.path.exists(lldb_path):
163+
lit_config.fatal("lldb does not exist!")
164+
165+
# Define our supported substitutions.
166+
config.substitutions.append( ('%{lldb}', lldb_path) )
167+
config.substitutions.append( ('%{swift}', swift_path) )
168+
config.substitutions.append( ('%{swiftc}', swiftc_path) )
169+
config.substitutions.append( ('%{FileCheck}', filecheck_path) )
170+
171+
###
172+
173+
# Protected against unquoted use of substitutions.
174+
for name in ('swift-build', 'FileCheck'):
175+
config.substitutions.append((' {0} '.format(name),
176+
' unquoted-command-name-{0} '.format(name)))

repl/test-repl-darwin.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Tests that importing Darwin works on OS X
2+
#
3+
# REQUIRES: magic
4+
# REQUIRES: platform=Darwin
5+
# REQUIRES: have-pexpect
6+
#
7+
# RUN: rm -rf %t.dir
8+
# RUN: mkdir %t.dir
9+
# RUN: python %s %{swift} > %t.dir/output.txt
10+
# RUN: %{FileCheck} --input-file %t.dir/output.txt %s
11+
# CHECK: OK
12+
13+
import pexpect, sys, time
14+
15+
swift = "swift"
16+
if len(sys.argv) > 1:
17+
swift = sys.argv[1]
18+
19+
def debug(p):
20+
print 'before:'
21+
print p.before
22+
print '--'
23+
print 'after:'
24+
print p.after
25+
print '--'
26+
print p.match.groups()
27+
print '--'
28+
29+
repl = pexpect.spawn(swift)
30+
31+
repl.expect('(.*)Welcome to Apple Swift version (.*)\r\n')
32+
repl.sendline('print("hello, world")')
33+
34+
repl.expect('\r\nhello, world.*\r\n')
35+
repl.sendline('import Foundation')
36+
37+
repl.sendline(":type lookup FILE")
38+
try:
39+
repl.expect("init")
40+
except:
41+
debug(repl)
42+
43+
print "OK"

repl/test-repl-glibc.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Tests that importing Glibc works on Linux
2+
#
3+
# REQUIRES: platform=Linux
4+
# REQUIRES: have-pexpect
5+
#
6+
# RUN: rm -rf %t.dir
7+
# RUN: mkdir %t.dir
8+
# RUN: python %s %{swift} > %t.dir/output.txt
9+
# RUN: %{FileCheck} --input-file %t.dir/output.txt %s
10+
# CHECK: OK
11+
12+
import pexpect, sys
13+
14+
swift = "swift"
15+
if len(sys.argv) > 1:
16+
swift = sys.argv[1]
17+
18+
repl = pexpect.spawn(swift)
19+
20+
repl.expect('(.*)Welcome to Swift version (.*)\r\n')
21+
# print 'before (text up to pattern that was matched):'
22+
# print repl.before
23+
# print '--'
24+
# print 'after (what was actually matched by pattern):'
25+
# print repl.after
26+
# print '--'
27+
# print repl.match.groups()
28+
# print '--'
29+
30+
# repl.expect("(.*)1>(.*)")
31+
repl.sendline('print("hello, world")')
32+
33+
repl.expect('\r\nhello, world.*\r\n')
34+
# print 'before:'
35+
# print repl.before
36+
# print '--'
37+
# print 'after:'
38+
# print repl.after
39+
# print '--'
40+
# print repl.match.groups()
41+
# print '--'
42+
43+
# repl.expect("(.*)2>(.*)")
44+
repl.sendline('import Glibc')
45+
46+
# repl.expect("(.*)3>(.*)")
47+
48+
repl.sendline(":type lookup FILE")
49+
repl.expect("init")
50+
# print 'before:'
51+
# print repl.before
52+
# print '--'
53+
# print 'after:'
54+
# print repl.after
55+
# print '--'
56+
# print repl.match.groups()
57+
# print '--'
58+
59+
print "OK"

0 commit comments

Comments
 (0)