@@ -66,4 +66,53 @@ struct LinuxContainerTests {
6666
6767 #expect( process. arguments == [ " /bin/sh " , " -c " , " echo 'hello' " , " && " , " sleep 10 " ] )
6868 }
69+
70+ @Test func runtimeSpecIncludesConfiguredBlockIO( ) throws {
71+ let blockIO = LinuxBlockIO (
72+ weight: 500 ,
73+ leafWeight: 300 ,
74+ weightDevice: [
75+ LinuxWeightDevice ( major: 8 , minor: 0 , weight: 700 , leafWeight: 400 )
76+ ] ,
77+ throttleReadBpsDevice: [
78+ LinuxThrottleDevice ( major: 8 , minor: 16 , rate: 1_048_576 )
79+ ] ,
80+ throttleWriteBpsDevice: [
81+ LinuxThrottleDevice ( major: 8 , minor: 32 , rate: 2_097_152 )
82+ ] ,
83+ throttleReadIOPSDevice: [
84+ LinuxThrottleDevice ( major: 8 , minor: 48 , rate: 1_000 )
85+ ] ,
86+ throttleWriteIOPSDevice: [
87+ LinuxThrottleDevice ( major: 8 , minor: 64 , rate: 2_000 )
88+ ]
89+ )
90+
91+ let container = try LinuxContainer (
92+ " blkio-test " ,
93+ rootfs: . block( format: " ext4 " , source: " /tmp/rootfs.img " , destination: " / " ) ,
94+ vmm: StubVirtualMachineManager ( ) ,
95+ configuration: . init( process: . init( ) , blockIO: blockIO)
96+ )
97+
98+ let resources = try #require( container. generateRuntimeSpec ( ) . linux? . resources)
99+ let specBlockIO = try #require( resources. blockIO)
100+
101+ #expect( specBlockIO. weight == 500 )
102+ #expect( specBlockIO. leafWeight == 300 )
103+ #expect( specBlockIO. weightDevice. first? . major == 8 )
104+ #expect( specBlockIO. weightDevice. first? . minor == 0 )
105+ #expect( specBlockIO. weightDevice. first? . weight == 700 )
106+ #expect( specBlockIO. weightDevice. first? . leafWeight == 400 )
107+ #expect( specBlockIO. throttleReadBpsDevice. first? . rate == 1_048_576 )
108+ #expect( specBlockIO. throttleWriteBpsDevice. first? . rate == 2_097_152 )
109+ #expect( specBlockIO. throttleReadIOPSDevice. first? . rate == 1_000 )
110+ #expect( specBlockIO. throttleWriteIOPSDevice. first? . rate == 2_000 )
111+ }
112+ }
113+
114+ private struct StubVirtualMachineManager : VirtualMachineManager {
115+ func create( config: some VMCreationConfig ) async throws -> any VirtualMachineInstance {
116+ fatalError ( " StubVirtualMachineManager.create should not be called by LinuxContainerTests " )
117+ }
69118}
0 commit comments