1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2023 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import XCTest
@testable import NIOCore
class LinuxTest: XCTestCase {
func testCoreCountQuota() throws {
#if os(Linux) || os(Android)
try [
("50000", "100000", 1),
("100000", "100000", 1),
("100000\n", "100000", 1),
("100000", "100000\n", 1),
("150000", "100000", 2),
("200000", "100000", 2),
("-1", "100000", nil),
("100000", "-1", nil),
("", "100000", nil),
("100000", "", nil),
("100000", "0", nil)
].forEach { quota, period, count in
try withTemporaryFile(content: quota) { (_, quotaPath) -> Void in
try withTemporaryFile(content: period) { (_, periodPath) -> Void in
XCTAssertEqual(Linux.coreCountCgroup1Restriction(quota: quotaPath, period: periodPath), count)
}
}
}
#endif
}
func testCoreCountCpuset() throws {
#if os(Linux) || os(Android)
try [
("0", 1),
("0,3", 2),
("0-3", 4),
("0-3,7", 5),
("0-3,7\n", 5),
("0,2-4,6,7,9-11", 9),
("", nil)
].forEach { cpuset, count in
try withTemporaryFile(content: cpuset) { (_, path) -> Void in
XCTAssertEqual(Linux.coreCount(cpuset: path), count)
}
}
#endif
}
func testCoreCountCgoup2() throws {
#if os(Linux) || os(Android)
try [
("max 100000", nil),
("75000 100000", 1),
("200000 100000", 2)
].forEach { (content, count) in
try withTemporaryFile(content: content) { (_, path) in
XCTAssertEqual(Linux.coreCountCgroup2Restriction(cpuMaxPath: path), count)
}
}
#endif
}
}
|