11package runtime
22
33import (
4+ "fmt"
45 "github.com/TechnologyTailors/Schedune/schedune-control-plane/pkg/schema/launch"
56 "os"
67 "strings"
@@ -11,6 +12,7 @@ func TestKvmExecutor_PrepareMissingImage(t *testing.T) {
1112 exec := & KvmExecutor {}
1213
1314 spec := launch.LaunchSpec {
15+ WorkloadID : "test-missing-id" ,
1416 Architecture : "aarch64" ,
1517 Storage : []launch.StorageAttachmentSpec {
1618 {HostPath : "/tmp/non_existent_image_12345.qcow2" , Format : "qcow2" },
@@ -35,6 +37,7 @@ func TestKvmExecutor_PrepareValidImageLegacy(t *testing.T) {
3537 defer os .Remove (f .Name ())
3638
3739 spec := launch.LaunchSpec {
40+ WorkloadID : "test-legacy-id" ,
3841 Architecture : "aarch64" ,
3942 ImageReference : f .Name (),
4043 Vcpu : 2 ,
@@ -43,7 +46,7 @@ func TestKvmExecutor_PrepareValidImageLegacy(t *testing.T) {
4346
4447 prep , err := exec .Prepare (spec )
4548 if err != nil {
46- t .Errorf ("expected Prepare to succeed, got %v" , err )
49+ t .Fatalf ("expected Prepare to succeed, got %v" , err )
4750 }
4851
4952 if prep .KvmQemu == nil {
@@ -54,15 +57,26 @@ func TestKvmExecutor_PrepareValidImageLegacy(t *testing.T) {
5457 t .Errorf ("expected qemu-system-aarch64, got %s" , prep .KvmQemu .BinaryPath )
5558 }
5659
60+ if prep .KvmQemu .ControlSocketPath == "" || ! strings .Contains (prep .KvmQemu .ControlSocketPath , "test-legacy-id/qemu.sock" ) {
61+ t .Errorf ("expected qemu control socket path, got %v" , prep .KvmQemu .ControlSocketPath )
62+ }
63+
5764 foundDrive := false
58- for _ , arg := range prep .KvmQemu .CommandArgs {
65+ foundQmp := false
66+ for i , arg := range prep .KvmQemu .CommandArgs {
5967 if strings .Contains (arg , "format=qcow2" ) {
6068 foundDrive = true
6169 }
70+ if arg == "-qmp" && i + 1 < len (prep .KvmQemu .CommandArgs ) && prep .KvmQemu .CommandArgs [i + 1 ] == fmt .Sprintf ("unix:%s,server,nowait" , prep .KvmQemu .ControlSocketPath ) {
71+ foundQmp = true
72+ }
6273 }
6374 if ! foundDrive {
6475 t .Errorf ("expected format=qcow2 in args, got %v" , prep .KvmQemu .CommandArgs )
6576 }
77+ if ! foundQmp {
78+ t .Errorf ("expected exact -qmp socket in args, got %v" , prep .KvmQemu .CommandArgs )
79+ }
6680}
6781
6882func TestKvmExecutor_PrepareValidImageTyped (t * testing.T ) {
@@ -75,6 +89,7 @@ func TestKvmExecutor_PrepareValidImageTyped(t *testing.T) {
7589 defer os .Remove (f .Name ())
7690
7791 spec := launch.LaunchSpec {
92+ WorkloadID : "test-typed-id" ,
7893 Architecture : "x86_64" ,
7994 Storage : []launch.StorageAttachmentSpec {
8095 {HostPath : f .Name (), Format : "raw" },
@@ -85,7 +100,7 @@ func TestKvmExecutor_PrepareValidImageTyped(t *testing.T) {
85100
86101 prep , err := exec .Prepare (spec )
87102 if err != nil {
88- t .Errorf ("expected Prepare to succeed, got %v" , err )
103+ t .Fatalf ("expected Prepare to succeed, got %v" , err )
89104 }
90105
91106 if prep .KvmQemu == nil {
@@ -113,6 +128,7 @@ func TestCloudHypervisorExecutor_PrepareValidImageTyped(t *testing.T) {
113128 defer os .Remove (f .Name ())
114129
115130 spec := launch.LaunchSpec {
131+ WorkloadID : "test-ch-id" ,
116132 Architecture : "x86_64" ,
117133 Storage : []launch.StorageAttachmentSpec {
118134 {HostPath : f .Name (), Format : "raw" },
@@ -123,28 +139,40 @@ func TestCloudHypervisorExecutor_PrepareValidImageTyped(t *testing.T) {
123139
124140 prep , err := exec .Prepare (spec )
125141 if err != nil {
126- t .Errorf ("expected Prepare to succeed, got %v" , err )
142+ t .Fatalf ("expected Prepare to succeed, got %v" , err )
127143 }
128144
129145 if prep .CloudHypervisor == nil {
130146 t .Fatalf ("expected CloudHypervisor prepared state, got nil" )
131147 }
132148
149+ if prep .CloudHypervisor .ControlSocketPath == "" || ! strings .Contains (prep .CloudHypervisor .ControlSocketPath , "test-ch-id/cloudhypervisor.sock" ) {
150+ t .Errorf ("expected cloudhypervisor control socket path, got %v" , prep .CloudHypervisor .ControlSocketPath )
151+ }
152+
133153 foundDrive := false
134- for _ , arg := range prep .CloudHypervisor .CommandArgs {
154+ foundApi := false
155+ for i , arg := range prep .CloudHypervisor .CommandArgs {
135156 if strings .Contains (arg , "path=" + f .Name ()) {
136157 foundDrive = true
137158 }
159+ if arg == "--api-socket" && i + 1 < len (prep .CloudHypervisor .CommandArgs ) && prep .CloudHypervisor .CommandArgs [i + 1 ] == prep .CloudHypervisor .ControlSocketPath {
160+ foundApi = true
161+ }
138162 }
139163 if ! foundDrive {
140164 t .Errorf ("expected path in args, got %v" , prep .CloudHypervisor .CommandArgs )
141165 }
166+ if ! foundApi {
167+ t .Errorf ("expected api-socket in args matching control socket, got %v" , prep .CloudHypervisor .CommandArgs )
168+ }
142169}
143170
144171func TestFirecrackerExecutor_PrepareValidImageTyped (t * testing.T ) {
145172 exec := & FirecrackerExecutor {}
146173
147174 spec := launch.LaunchSpec {
175+ WorkloadID : "test-fc-id" ,
148176 Architecture : "x86_64" ,
149177 Storage : []launch.StorageAttachmentSpec {
150178 {HostPath : "/tmp/rootfs.ext4" , Format : "ext4" , MountPoint : "/" },
@@ -156,7 +184,7 @@ func TestFirecrackerExecutor_PrepareValidImageTyped(t *testing.T) {
156184
157185 prep , err := exec .Prepare (spec )
158186 if err != nil {
159- t .Errorf ("expected Prepare to succeed, got %v" , err )
187+ t .Fatalf ("expected Prepare to succeed, got %v" , err )
160188 }
161189
162190 if prep .Firecracker == nil {
@@ -169,6 +197,28 @@ func TestFirecrackerExecutor_PrepareValidImageTyped(t *testing.T) {
169197 if prep .Firecracker .KernelImagePath != "/tmp/vmlinux" {
170198 t .Errorf ("expected kernel image path to be set from typed storage" )
171199 }
200+
201+ if prep .Firecracker .ControlSocketPath == "" || ! strings .Contains (prep .Firecracker .ControlSocketPath , "test-fc-id/firecracker.sock" ) {
202+ t .Errorf ("expected firecracker control socket path, got %v" , prep .Firecracker .ControlSocketPath )
203+ }
204+
205+ foundApi := false
206+ foundConfig := false
207+ for i , arg := range prep .Firecracker .CommandArgs {
208+ if arg == "--api-sock" && i + 1 < len (prep .Firecracker .CommandArgs ) && prep .Firecracker .CommandArgs [i + 1 ] == prep .Firecracker .ControlSocketPath {
209+ foundApi = true
210+ }
211+ if arg == "--config-file" && i + 1 < len (prep .Firecracker .CommandArgs ) && strings .Contains (prep .Firecracker .CommandArgs [i + 1 ], "test-fc-id/fc-config.json" ) {
212+ foundConfig = true
213+ }
214+ }
215+
216+ if ! foundApi {
217+ t .Errorf ("expected --api-sock argument with control socket path, got %v" , prep .Firecracker .CommandArgs )
218+ }
219+ if ! foundConfig {
220+ t .Errorf ("expected --config-file argument with config path, got %v" , prep .Firecracker .CommandArgs )
221+ }
172222}
173223
174224func TestKvmExecutor_ExecuteSpawnFails (t * testing.T ) {
@@ -179,6 +229,7 @@ func TestKvmExecutor_ExecuteSpawnFails(t *testing.T) {
179229 KvmQemu : & launch.PreparedQemuLaunch {
180230 BinaryPath : "qemu-system-non-existent-binary-12345" ,
181231 CommandArgs : []string {"-m" , "1024" },
232+ // Omit ControlSocketPath to intentionally bypass MkdirAll during this test
182233 },
183234 }
184235
0 commit comments