Skip to content

Commit 7ca074b

Browse files
committed
test: port most of the stdlib tests to Windows
This adjusts the standard library test suite to mostly pass on Windows. The remaining failures are due to various cases: - memory corruption (`_swift_stdlib_free` in swiftDemangle) - heap corruption (canGrowUsingRealloc) - withVAList failure (unresolved) - unicode handling on the command line
1 parent f348fb1 commit 7ca074b

20 files changed

+78
-28
lines changed

test/stdlib/CastTraps.swift.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// FIXME: Casting.cpp has dozens of places to fail a cast. This test does not
66
// attempt to enumerate them all.
77

8-
// XFAIL: linux
8+
// REQUIRES: objc_interop
99

1010
import StdlibUnittest
1111

test/stdlib/Error.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift -o %t/Error -DPTR_SIZE_%target-ptrsize -module-name main %s
2+
// RUN: %target-build-swift -o %t/Error -DPTR_SIZE_%target-ptrsize -module-name main %/s
33
// RUN: %target-run %t/Error
44
// REQUIRES: executable_test
55

test/stdlib/FloatConstants.swift

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import Darwin
55
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
66
import Glibc
7+
#elseif os(Windows)
8+
import MSVCRT
79
#endif
810

911
_ = FLT_RADIX // expected-warning {{is deprecated}}

test/stdlib/FloatingPointIR.swift

-15
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
var globalFloat32 : Float32 = 0.0
66
var globalFloat64 : Float64 = 0.0
7-
#if arch(i386) || arch(x86_64)
8-
var globalFloat80 : Float80 = 0.0
9-
#endif
107

118
@inline(never)
129
func acceptFloat32(_ a: Float32) {
@@ -18,28 +15,16 @@ func acceptFloat64(_ a: Float64) {
1815
globalFloat64 = a
1916
}
2017

21-
#if arch(i386) || arch(x86_64)
22-
@inline(never)
23-
func acceptFloat80(_ a: Float80) {
24-
globalFloat80 = a
25-
}
26-
#endif
27-
2818
func testConstantFoldFloatLiterals() {
2919
acceptFloat32(1.0)
3020
acceptFloat64(1.0)
31-
#if arch(i386) || arch(x86_64)
32-
acceptFloat80(1.0)
33-
#endif
3421
}
3522

3623
// i386: call swiftcc void @"$s15FloatingPointIR13acceptFloat32yySfF{{.*}}"(float 1.000000e+00)
3724
// i386: call swiftcc void @"$s15FloatingPointIR13acceptFloat64yySdF{{.*}}"(double 1.000000e+00)
38-
// i386: call swiftcc void @"$s15FloatingPointIR13acceptFloat80yys0E0VF{{.*}}"(x86_fp80 0xK3FFF8000000000000000)
3925

4026
// x86_64: call swiftcc void @"$s15FloatingPointIR13acceptFloat32yySfF{{.*}}"(float 1.000000e+00)
4127
// x86_64: call swiftcc void @"$s15FloatingPointIR13acceptFloat64yySdF{{.*}}"(double 1.000000e+00)
42-
// x86_64: call swiftcc void @"$s15FloatingPointIR13acceptFloat80yys0E0VF{{.*}}"(x86_fp80 0xK3FFF8000000000000000)
4328

4429
// armv7: call swiftcc void @"$s15FloatingPointIR13acceptFloat32yySfF{{.*}}"(float 1.000000e+00)
4530
// armv7: call swiftcc void @"$s15FloatingPointIR13acceptFloat64yySdF{{.*}}"(double 1.000000e+00)
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-build-swift -emit-ir %s | %FileCheck -check-prefix=%target-cpu %s
2+
// RUN: %target-build-swift -O -emit-ir %s | %FileCheck -check-prefix=%target-cpu %s
3+
// RUN: %target-build-swift -Ounchecked -emit-ir %s | %FileCheck -check-prefix=%target-cpu %s
4+
5+
// REQUIRES: CPU=i386 || CPU=x86_64
6+
// UNSUPPORTED: OS=windows-msvc
7+
8+
var globalFloat80 : Float80 = 0.0
9+
10+
@inline(never)
11+
func acceptFloat80(_ a: Float80) {
12+
globalFloat80 = a
13+
}
14+
15+
func testConstantFoldFloatLiterals() {
16+
acceptFloat80(1.0)
17+
}
18+
19+
// i386: call swiftcc void @"$s20FloatingPointIR_FP8013acceptFloat80yys0F0VF{{.*}}"(x86_fp80 0xK3FFF8000000000000000)
20+
// x86_64: call swiftcc void @"$s20FloatingPointIR_FP8013acceptFloat80yys0F0VF{{.*}}"(x86_fp80 0xK3FFF8000000000000000)

test/stdlib/MathConstants.swift

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import Darwin
55
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
66
import Glibc
7+
#elseif os(Windows)
8+
import MSVCRT
79
#endif
810

911
_ = M_PI // expected-warning {{is deprecated}}

test/stdlib/Mirror.swift

+2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
// RUN: fi
2222
// RUN: %target-codesign %t/Mirror
2323
// RUN: %target-run %t/Mirror
24+
2425
// REQUIRES: executable_test
26+
// REQUIRES: shell
2527

2628
import StdlibUnittest
2729

test/stdlib/Nil.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// REQUIRES: executable_test
33

44
// FIXME: rdar://problem/19648117 Needs splitting objc parts out
5-
// XFAIL: linux
5+
// REQUIRES: objc_interop
66

77
import Foundation
88

test/stdlib/NumericParsing.swift.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ tests.test("FixedWidthInteger/maxUInt64") {
134134
% for Self in 'Float', 'Double', 'Float80':
135135

136136
% if Self == 'Float80':
137-
#if arch(i386) || arch(x86_64)
137+
#if !os(Windows) && (arch(i386) || arch(x86_64))
138138
% end
139139

140140
tests.test("${Self}/Basics") {

test/stdlib/POSIX.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-run-simple-swift %t
22
// REQUIRES: executable_test
3+
// UNSUPPORTED: OS=windows-msvc
34

45
import StdlibUnittest
56
#if os(Linux) || os(Android)

test/stdlib/PrintFloat.swift.gyb

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import StdlibUnittest
1010
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
1111
import Glibc
12-
#else
12+
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
1313
import Darwin
14+
#elseif os(Windows)
15+
import MSVCRT
1416
#endif
1517

1618
// It takes about an hour to run the Float formatter over all 2 billion

test/stdlib/Runtime.swift.gyb

+17-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import SwiftShims
1414
import Darwin
1515
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
1616
import Glibc
17+
#elseif os(Windows)
18+
import MSVCRT
19+
import WinSDK
1720
#endif
1821

1922
@_silgen_name("swift_demangle")
@@ -566,14 +569,27 @@ Runtime.test("SwiftError layout constants for LLDB") {
566569
#else
567570
_UnimplementedError()
568571
#endif
572+
#elseif os(Windows)
573+
let hStdlibCore: HMODULE = GetModuleHandleA("swiftCore.dll")!
569574
#else
570575
_UnimplementedError()
571576
#endif
572577

578+
#if os(Windows)
579+
let offsetof_SwiftError_typeMetadata: UnsafeRawPointer =
580+
unsafeBitCast(GetProcAddress(hStdlibCore,
581+
"_swift_lldb_offsetof_SwiftError_typeMetadata")!,
582+
to: UnsafeRawPointer.self)
583+
let sizeof_SwiftError: UnsafeRawPointer =
584+
unsafeBitCast(GetProcAddress(hStdlibCore,
585+
"_swift_lldb_sizeof_SwiftError")!,
586+
to: UnsafeRawPointer.self)
587+
#else
573588
let offsetof_SwiftError_typeMetadata =
574589
dlsym(RTLD_DEFAULT, "_swift_lldb_offsetof_SwiftError_typeMetadata")!
575590
let sizeof_SwiftError =
576591
dlsym(RTLD_DEFAULT, "_swift_lldb_sizeof_SwiftError")!
592+
#endif
577593
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
578594
#if arch(i386) || arch(arm)
579595
expectEqual(20, offsetof_SwiftError_typeMetadata.load(as: UInt.self))
@@ -582,7 +598,7 @@ Runtime.test("SwiftError layout constants for LLDB") {
582598
expectEqual(40, offsetof_SwiftError_typeMetadata.load(as: UInt.self))
583599
expectEqual(72, sizeof_SwiftError.load(as: UInt.self))
584600
#endif
585-
#elseif os(Linux) || os(Android)
601+
#elseif os(Linux) || os(Android) || os(Windows)
586602
expectEqual(16, offsetof_SwiftError_typeMetadata.load(as: UInt.self))
587603
expectEqual(32, sizeof_SwiftError.load(as: UInt.self))
588604
#else

test/stdlib/StringDiagnostics.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %target-typecheck-verify-swift
22

3-
// XFAIL: linux
3+
// REQUIRES: objc_interop
44

55
import Foundation
66

test/stdlib/VarArgs.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ import Swift
66
#if _runtime(_ObjC)
77
import Darwin
88
import CoreGraphics
9-
#else
9+
#elseif os(Linux) || os(FreeBSD) || os(Android) || os(Haiku) || os(PS4)
1010
import Glibc
1111
typealias CGFloat = Double
12+
#elseif os(Windows)
13+
import MSVCRT
14+
#if arch(x86_64) || arch(arm64)
15+
typealias CGFloat = Double
16+
#else
17+
typealias CGFloat = Float
18+
#endif
1219
#endif
1320

1421
func my_printf(_ format: String, _ arguments: CVarArg...) {

test/stdlib/WeakMirror.swift

+2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
// RUN: fi
2121
// RUN: %target-codesign %t/Mirror
2222
// RUN: %target-run %t/Mirror
23+
2324
// REQUIRES: executable_test
25+
// REQUIRES: shell
2426

2527
import StdlibUnittest
2628

test/stdlib/mmap.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %target-run-simple-swift %t
22
// REQUIRES: executable_test
3+
// UNSUPPORTED: OS=windows-msvc
34

45
import StdlibUnittest
56
#if os(Linux) || os(Android)

test/stdlib/simd.swift.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// REQUIRES: executable_test
33

44
// FIXME: No simd module on linux rdar://problem/20795411
5-
// XFAIL: linux
5+
// XFAIL: linux, windows
66

77
import simd
88
import StdlibUnittest

test/stdlib/simd_diagnostics.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-typecheck-verify-swift
22

33
// FIXME: No simd module on linux rdar://problem/20795411
4-
// XFAIL: linux
4+
// XFAIL: linux, windows
55

66
import simd
77

test/stdlib/tgmath.swift.gyb

+10-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
// RUN: %line-directive %t/tgmath.swift -- %target-run %t/a.out
1818
// REQUIRES: executable_test
1919

20-
#if canImport(Darwin)
20+
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
2121
import Darwin.C.tgmath
22-
#else
22+
#elseif os(Linux) || os(android) || os(FreeBSD) || os(Haiku) || os(PS4)
2323
import Glibc
24+
#elseif os(Windows)
25+
import MSVCRT
2426
#endif
2527

2628
#if (arch(i386) || arch(x86_64)) && !os(Windows)
@@ -77,7 +79,9 @@ internal protocol TGMath: BinaryFloatingPoint {
7779
%end
7880
static func _remquo(_ x: Self, _ y: Self) -> (Self, Int)
7981
static func _fma(_ x: Self, _ y: Self, _ z: Self) -> Self
82+
#if !os(Windows)
8083
static func _lgamma(_ x: Self) -> (Self, Int)
84+
#endif
8185
static func _modf(_ x: Self) -> (Self, Self)
8286
static func _scalbn(_ x: Self, _ n: Int) -> Self
8387
static func _frexp(_ x: Self) -> (Self, Int)
@@ -116,8 +120,10 @@ internal extension TGMath {
116120
expectEqualWithTolerance(0.4041169094348222983238250859191217675, Self._erf(0.375))
117121
expectEqualWithTolerance(0.5958830905651777016761749140808782324, Self._erfc(0.375))
118122
expectEqualWithTolerance(2.3704361844166009086464735041766525098, Self._tgamma(0.375))
123+
#if !os(Windows)
119124
expectEqualWithTolerance( -0.11775527074107877445136203331798850, Self._lgamma(1.375).0, ulps: 16)
120125
expectEqual(1, Self._lgamma(1.375).1)
126+
#endif
121127
expectEqual(1, Self._ceil(0.375))
122128
expectEqual(0, Self._floor(0.375))
123129
expectEqual(0, Self._nearbyint(0.375))
@@ -181,7 +187,9 @@ extension ${T}: TGMath {
181187
%end
182188
static func _remquo(_ x: ${T}, _ y: ${T}) -> (${T}, Int) { return remquo(x, y) }
183189
static func _fma(_ x: ${T}, _ y: ${T}, _ z: ${T}) -> ${T} { return fma(x, y, z) }
190+
#if !os(Windows)
184191
static func _lgamma(_ x: ${T}) -> (${T}, Int) { return lgamma(x) }
192+
#endif
185193
static func _modf(_ x: ${T}) -> (${T}, ${T}) { return modf(x) }
186194
static func _scalbn(_ x: ${T}, _ n: Int) -> ${T} { return scalbn(x, n) }
187195
static func _frexp(_ x: ${T}) -> (${T}, Int) { return frexp(x) }

test/stdlib/tgmath_optimized.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
#if os(Linux) || os(FreeBSD) || os(PS4) || os(Android)
88
import Glibc
9-
#else
9+
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
1010
import Darwin
11+
#elseif os(Windows)
12+
import MSVCRT
1113
#endif
1214
import StdlibUnittest
1315

0 commit comments

Comments
 (0)