Fix tests for 32-bit platforms, tested for Android armv7 (#1877)

Motivation:

Get the tests passing on 32-bit platforms again.

Modifications:

- Change the way _UInt56.max is initialized.
- Set the proper max capacity for AdaptiveRecvByteBufferAllocator
  and change the test to match it.
- Add a cmsghdrExample for Android armv7.

Result:

All the same tests pass on Android armv7 as Android AArch64.
This commit is contained in:
buttaface authored and GitHub committed 2021-06-11 12:20:19 +01:00
1 parent 67f0843653
commit a1f405285a
4 files changed
+26 -9

No files matched your search

+2 -1
View File
@@ -75,7 +75,8 @@ struct _UInt56 {
static let bitWidth: Int = 56
static let max: _UInt56 = .init((1 << 56) - 1)
private static let initializeUInt64 : UInt64 = (1 << 56) - 1
static let max: _UInt56 = .init(initializeUInt64)
static let min: _UInt56 = .init(0)
}
+4 -3
View File
@@ -55,7 +55,7 @@ public struct AdaptiveRecvByteBufferAllocator: RecvByteBufferAllocator {
private var nextReceiveBufferSize: Int
private var decreaseNow: Bool
private static let maximumAllocationSize = 1 << 31
private static let maximumAllocationSize = 1 << 30
public init() {
self.init(minimum: 64, initial: 2048, maximum: 65536)
@@ -93,7 +93,7 @@ public struct AdaptiveRecvByteBufferAllocator: RecvByteBufferAllocator {
// Here we need to be careful with 32-bit systems: if maximum is too large then any shift or multiply will overflow, which
// we don't want. Instead we check, and clamp to this current value if we overflow.
let upperBoundCandidate = Int(truncatingIfNeeded: Int64(self.nextReceiveBufferSize) &<< 1)
let upperBound = upperBoundCandidate == 0 ? self.nextReceiveBufferSize : upperBoundCandidate
let upperBound = upperBoundCandidate <= 0 ? self.nextReceiveBufferSize : upperBoundCandidate
if actualReadBytes <= lowerBound && lowerBound >= self.minimum {
if self.decreaseNow {
@@ -102,7 +102,8 @@ public struct AdaptiveRecvByteBufferAllocator: RecvByteBufferAllocator {
} else {
self.decreaseNow = true
}
} else if actualReadBytes >= self.nextReceiveBufferSize && upperBound <= self.maximum {
} else if actualReadBytes >= self.nextReceiveBufferSize && upperBound <= self.maximum &&
self.nextReceiveBufferSize != upperBound {
self.nextReceiveBufferSize = upperBound
self.decreaseNow = false
mayGrow = true
@@ -117,8 +117,8 @@ final class AdaptiveRecvByteBufferAllocatorTest: XCTestCase {
}
let buffer = self.adaptive.buffer(allocator: self.allocator)
XCTAssertEqual(buffer.capacity, 1 << 31)
XCTAssertEqual(self.adaptive.maximum, 1 << 31)
XCTAssertEqual(buffer.capacity, 1 << 30)
XCTAssertEqual(self.adaptive.maximum, 1 << 30)
XCTAssertEqual(self.adaptive.minimum, 0)
}
@@ -136,8 +136,8 @@ final class AdaptiveRecvByteBufferAllocatorTest: XCTestCase {
}
let adaptive = AdaptiveRecvByteBufferAllocator(minimum: targetValue, initial: targetValue + 1, maximum: targetValue + 2)
XCTAssertEqual(adaptive.minimum, 1 << 31)
XCTAssertEqual(adaptive.maximum, 1 << 31)
XCTAssertEqual(adaptive.initial, 1 << 31)
XCTAssertEqual(adaptive.minimum, 1 << 30)
XCTAssertEqual(adaptive.maximum, 1 << 30)
XCTAssertEqual(adaptive.initial, 1 << 30)
}
}
+15
View File
@@ -62,6 +62,21 @@ class SystemTest: XCTestCase {
private static let cmsghdr_secondDataCount = 1
private static let cmsghdr_firstType = IP_RECVDSTADDR
private static let cmsghdr_secondType = IP_RECVTOS
#elseif os(Android) && arch(arm)
private static let cmsghdrExample: [UInt8] = [0x10, 0x00, 0x00, 0x00, // Length 16 including header
0x00, 0x00, 0x00, 0x00, // IPPROTO_IP
0x08, 0x00, 0x00, 0x00, // IP_PKTINFO
0x7F, 0x00, 0x00, 0x01, // 127.0.0.1
0x0D, 0x00, 0x00, 0x00, // Length 13 including header
0x00, 0x00, 0x00, 0x00, // IPPROTO_IP
0x01, 0x00, 0x00, 0x00, // IP_TOS
0x01, 0x00, 0x00, 0x00] // ECT-1 (1 byte)
private static let cmsghdr_secondStartPosition = 16
private static let cmsghdr_firstDataStart = 12
private static let cmsghdr_firstDataCount = 4
private static let cmsghdr_secondDataCount = 1
private static let cmsghdr_firstType = IP_PKTINFO
private static let cmsghdr_secondType = IP_TOS
#elseif os(Linux) || os(Android)
// Example twin data options captured on Linux
private static let cmsghdrExample: [UInt8] = [