From 8f45043c5fa3167cd50a9008cde1ae611087b79f Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Tue, 10 Oct 2023 10:32:43 +0900 Subject: [PATCH 01/15] fixed go test timeout to 2m --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4197b2e..2b7f19e 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ fmt: .PHONY: test test: - go test -p 1 -exec "go run $(PWD)/cmd/codesign" ./... -timeout 60s -v + go test -p 1 -exec "go run $(PWD)/cmd/codesign" ./... -timeout 2m -v .PHONY: test/run test/run: From 5c092aea83d283d83a07a9f16601c69096761249 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Tue, 10 Oct 2023 10:33:33 +0900 Subject: [PATCH 02/15] introduce backoff like adjuster in testing --- virtualization_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/virtualization_test.go b/virtualization_test.go index f42d8dd..e4f1cd8 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -172,6 +172,7 @@ func newVirtualizationMachine( time.Sleep(5 * time.Second) } + tempDelay := time.Second // how long to sleep on accept failure RETRY: for i := 1; ; i++ { conn, err := socketDevice.Connect(2222) @@ -182,7 +183,8 @@ RETRY: } if nserr.Code == int(syscall.ECONNRESET) { t.Logf("retry vsock connect: %d", i) - time.Sleep(time.Second) + time.Sleep(tempDelay) + tempDelay += time.Duration(i*10) * time.Millisecond continue RETRY } t.Fatalf("failed to connect vsock: %v", err) From 4f5b813857ef442df1e2e2e58705fdc70289fdc7 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Tue, 10 Oct 2023 10:58:21 +0900 Subject: [PATCH 03/15] use dispatch_async --- virtualization_11.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virtualization_11.m b/virtualization_11.m index 518367d..2fe9ca4 100644 --- a/virtualization_11.m +++ b/virtualization_11.m @@ -605,7 +605,7 @@ void setStorageDevicesVZVirtualMachineConfiguration(void *config, void VZVirtioSocketDevice_setSocketListenerForPort(void *socketDevice, void *vmQueue, void *listener, uint32_t port) { if (@available(macOS 11, *)) { - dispatch_sync((dispatch_queue_t)vmQueue, ^{ + dispatch_async((dispatch_queue_t)vmQueue, ^{ [(VZVirtioSocketDevice *)socketDevice setSocketListener:(VZVirtioSocketListener *)listener forPort:port]; }); return; From 86bc91bd81502108ee5e9b0baf8962e9d5339757 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Tue, 10 Oct 2023 11:11:39 +0900 Subject: [PATCH 04/15] increase retry count --- virtualization_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virtualization_test.go b/virtualization_test.go index e4f1cd8..7b9d9f6 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -178,7 +178,7 @@ RETRY: conn, err := socketDevice.Connect(2222) if err != nil { var nserr *vz.NSError - if !errors.As(err, &nserr) || i > 5 { + if !errors.As(err, &nserr) || i > 8 { t.Fatal(err) } if nserr.Code == int(syscall.ECONNRESET) { From 6f17fbec3b4c0b98fd49c8a095300c17fe7696b2 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Tue, 10 Oct 2023 12:44:02 +0900 Subject: [PATCH 05/15] added sleep --- virtualization_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/virtualization_test.go b/virtualization_test.go index 7b9d9f6..843229f 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -170,6 +170,8 @@ func newVirtualizationMachine( // does not seem to have a connection timeout set. if vz.Available(12) { time.Sleep(5 * time.Second) + } else { + time.Sleep(time.Second) } tempDelay := time.Second // how long to sleep on accept failure From a03988d3016d1e13a6b025b8c2782003ed1cd074 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Tue, 10 Oct 2023 12:53:19 +0900 Subject: [PATCH 06/15] fixed yaml --- .github/workflows/compile.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index fba2c0e..cef7679 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -23,7 +23,7 @@ jobs: build: needs: formatting-check runs-on: ${{ matrix.os }} - timeout-minutes: 6 + timeout-minutes: 8 strategy: fail-fast: false matrix: @@ -38,10 +38,9 @@ jobs: - name: Check out repository code uses: actions/checkout@v3 - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go }} - cache: true - name: vet run: go vet ./... - name: Download Linux kernel From fa66ff184b7ca245ee19e66249f86633b66ff831 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Sun, 15 Oct 2023 22:58:59 +0900 Subject: [PATCH 07/15] fixed timeout --- .github/workflows/compile.yml | 4 ++-- virtualization_test.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml index cef7679..8ad7e70 100644 --- a/.github/workflows/compile.yml +++ b/.github/workflows/compile.yml @@ -23,7 +23,7 @@ jobs: build: needs: formatting-check runs-on: ${{ matrix.os }} - timeout-minutes: 8 + timeout-minutes: 10 strategy: fail-fast: false matrix: @@ -47,7 +47,7 @@ jobs: run: make download_kernel - name: Unit Test run: make test - timeout-minutes: 3 + timeout-minutes: 5 - name: Build Linux run: make -C example/linux - name: Build GUI Linux diff --git a/virtualization_test.go b/virtualization_test.go index 843229f..46a9418 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -174,19 +174,20 @@ func newVirtualizationMachine( time.Sleep(time.Second) } + const max = 10 tempDelay := time.Second // how long to sleep on accept failure RETRY: for i := 1; ; i++ { conn, err := socketDevice.Connect(2222) if err != nil { var nserr *vz.NSError - if !errors.As(err, &nserr) || i > 8 { + if !errors.As(err, &nserr) || i > max { t.Fatal(err) } if nserr.Code == int(syscall.ECONNRESET) { t.Logf("retry vsock connect: %d", i) time.Sleep(tempDelay) - tempDelay += time.Duration(i*10) * time.Millisecond + tempDelay += time.Duration(i) * time.Second continue RETRY } t.Fatalf("failed to connect vsock: %v", err) From ae6e217057f0301db8c7f27a21907185a4254aae Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Sun, 15 Oct 2023 23:27:19 +0900 Subject: [PATCH 08/15] use vm.Stop above macOS 12 --- virtualization_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/virtualization_test.go b/virtualization_test.go index 46a9418..6a4263f 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -272,7 +272,12 @@ func TestRun(t *testing.T) { // waitState(t, 5*time.Second, vm, vz.VirtualMachineStateStopping) // waitState(t, 5*time.Second, vm, vz.VirtualMachineStateStopped) - sshSession.Run("poweroff") + if vz.Available(12) { + sshSession.Run("poweroff") + } else { + vm.Stop() + waitState(t, timeout, vm, vz.VirtualMachineStateStopping) + } waitState(t, timeout, vm, vz.VirtualMachineStateStopped) From 9ed69d66317b8345ba3a9a4830e1831fd482b067 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Sun, 15 Oct 2023 23:48:28 +0900 Subject: [PATCH 09/15] fixed test again --- virtualization_test.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/virtualization_test.go b/virtualization_test.go index 6a4263f..762ef22 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -164,18 +164,20 @@ func newVirtualizationMachine( sshConfig := testhelper.NewSshConfig("root", "passwd") - // Workaround for macOS 11 - // - // This is a workaround. This version of the API does not immediately return an error and - // does not seem to have a connection timeout set. - if vz.Available(12) { - time.Sleep(5 * time.Second) - } else { - time.Sleep(time.Second) + sleep := func() { + // Workaround for macOS 11 + // + // This is a workaround. This version of the API does not immediately return an error and + // does not seem to have a connection timeout set. + if vz.Available(12) { + time.Sleep(5 * time.Second) + } else { + time.Sleep(time.Second) + } } + sleep() - const max = 10 - tempDelay := time.Second // how long to sleep on accept failure + const max = 8 RETRY: for i := 1; ; i++ { conn, err := socketDevice.Connect(2222) @@ -186,8 +188,13 @@ RETRY: } if nserr.Code == int(syscall.ECONNRESET) { t.Logf("retry vsock connect: %d", i) - time.Sleep(tempDelay) - tempDelay += time.Duration(i) * time.Second + if !vz.Available(12) { + vm.Stop() + waitState(t, 2*time.Second, vm, vz.VirtualMachineStateStopping) + waitState(t, 2*time.Second, vm, vz.VirtualMachineStateStopped) + vm.Start() + sleep() + } continue RETRY } t.Fatalf("failed to connect vsock: %v", err) From e4508559ad4581582f3c63f765258f9c7e630d19 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Sun, 15 Oct 2023 23:52:54 +0900 Subject: [PATCH 10/15] fixed test again 2 --- virtualization_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/virtualization_test.go b/virtualization_test.go index 762ef22..8f64bd5 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -193,6 +193,8 @@ RETRY: waitState(t, 2*time.Second, vm, vz.VirtualMachineStateStopping) waitState(t, 2*time.Second, vm, vz.VirtualMachineStateStopped) vm.Start() + waitState(t, 2*time.Second, vm, vz.VirtualMachineStateStarting) + waitState(t, 2*time.Second, vm, vz.VirtualMachineStateRunning) sleep() } continue RETRY From 5e7619010888ee80ae758fb75d6f0c02f8fb20c5 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Mon, 16 Oct 2023 00:22:57 +0900 Subject: [PATCH 11/15] changed vsock retry logic --- virtualization_test.go | 141 ++++++++++++++++++++++++++--------------- 1 file changed, 90 insertions(+), 51 deletions(-) diff --git a/virtualization_test.go b/virtualization_test.go index 8f64bd5..ae71cd3 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -115,6 +115,24 @@ func newVirtualizationMachine( t *testing.T, configs ...func(*vz.VirtualMachineConfiguration) error, ) *Container { + t.Helper() +RETRY: + for { + container, err := newVirtualizationMachineErr(configs...) + if err != nil { + if isECONNRESET(err) { + time.Sleep(time.Second) + continue RETRY + } + t.Fatal(err) + } + return container + } +} + +func newVirtualizationMachineErr( + configs ...func(*vz.VirtualMachineConfiguration) error, +) (*Container, error) { vmlinuz := "./testdata/Image" initramfs := "./testdata/initramfs.cpio.gz" bootLoader, err := vz.NewLinuxBootLoader( @@ -123,108 +141,129 @@ func newVirtualizationMachine( vz.WithInitrd(initramfs), ) if err != nil { - t.Fatal(err) + return nil, err } config, err := setupConfiguration(bootLoader) if err != nil { - t.Fatal(err) + return nil, err } for _, setConfig := range configs { if err := setConfig(config); err != nil { - t.Fatal(err) + return nil, err } } validated, err := config.Validate() if !validated || err != nil { - t.Fatal(validated, err) + return nil, fmt.Errorf("validated=%v: %w", validated, err) } vm, err := vz.NewVirtualMachine(config) if err != nil { - t.Fatal(err) + return nil, err } socketDevices := vm.SocketDevices() if len(socketDevices) != 1 { - t.Fatalf("want the number of socket devices is 1 but got %d", len(socketDevices)) + return nil, fmt.Errorf("want the number of socket devices is 1 but got %d", len(socketDevices)) } socketDevice := socketDevices[0] if canStart := vm.CanStart(); !canStart { - t.Fatal("want CanStart is true") + return nil, fmt.Errorf("want CanStart is true") } if err := vm.Start(); err != nil { - t.Fatal(err) + return nil, err } - waitState(t, 3*time.Second, vm, vz.VirtualMachineStateStarting) - waitState(t, 3*time.Second, vm, vz.VirtualMachineStateRunning) + timeout := 3 * time.Second + if err := waitStateErr(timeout, vm, vz.VirtualMachineStateStarting); err != nil { + return nil, err + } + if err := waitStateErr(timeout, vm, vz.VirtualMachineStateRunning); err != nil { + return nil, err + } sshConfig := testhelper.NewSshConfig("root", "passwd") - sleep := func() { - // Workaround for macOS 11 - // - // This is a workaround. This version of the API does not immediately return an error and - // does not seem to have a connection timeout set. + // Workaround for macOS 11 + // + // This is a workaround. This version of the API does not immediately return an error and + // does not seem to have a connection timeout set. + if vz.Available(12) { + time.Sleep(5 * time.Second) + } else { + time.Sleep(time.Second) + } + + stop := func() { if vz.Available(12) { - time.Sleep(5 * time.Second) + vm.RequestStop() } else { - time.Sleep(time.Second) + vm.Stop() } - } - sleep() - const max = 8 -RETRY: - for i := 1; ; i++ { - conn, err := socketDevice.Connect(2222) - if err != nil { - var nserr *vz.NSError - if !errors.As(err, &nserr) || i > max { - t.Fatal(err) - } - if nserr.Code == int(syscall.ECONNRESET) { - t.Logf("retry vsock connect: %d", i) - if !vz.Available(12) { - vm.Stop() - waitState(t, 2*time.Second, vm, vz.VirtualMachineStateStopping) - waitState(t, 2*time.Second, vm, vz.VirtualMachineStateStopped) - vm.Start() - waitState(t, 2*time.Second, vm, vz.VirtualMachineStateStarting) - waitState(t, 2*time.Second, vm, vz.VirtualMachineStateRunning) - sleep() + LOOP: + for { + select { + case got := <-vm.StateChangedNotify(): + if got == vz.VirtualMachineStateStopping { + continue LOOP } - continue RETRY + if got == vz.VirtualMachineStateStopped { + return + } + case <-time.After(timeout): + return } - t.Fatalf("failed to connect vsock: %v", err) } + } - sshClient, err := testhelper.NewSshClient(conn, ":22", sshConfig) - if err != nil { - conn.Close() - t.Fatalf("failed to create a new ssh client: %v", err) - } + conn, err := socketDevice.Connect(2222) + if err != nil { + stop() + return nil, fmt.Errorf("failed to connect vsock: %w", err) + } - return &Container{ - VirtualMachine: vm, - Client: sshClient, - } + sshClient, err := testhelper.NewSshClient(conn, ":22", sshConfig) + if err != nil { + conn.Close() + stop() + return nil, fmt.Errorf("failed to create a new ssh client: %w", err) } + + return &Container{ + VirtualMachine: vm, + Client: sshClient, + }, nil +} + +func isECONNRESET(err error) bool { + var nserr *vz.NSError + if !errors.As(err, &nserr) { + return false + } + return nserr.Code == int(syscall.ECONNRESET) } func waitState(t *testing.T, wait time.Duration, vm *vz.VirtualMachine, want vz.VirtualMachineState) { t.Helper() + if err := waitStateErr(wait, vm, want); err != nil { + t.Fatal(err) + } +} + +func waitStateErr(wait time.Duration, vm *vz.VirtualMachine, want vz.VirtualMachineState) error { select { case got := <-vm.StateChangedNotify(): if want != got { - t.Fatalf("unexpected state want %d but got %d", want, got) + return fmt.Errorf("unexpected state want %d but got %d", want, got) } case <-time.After(wait): - t.Fatal("failed to wait state changed notification") + return fmt.Errorf("failed to wait state changed notification") } + return nil } func TestRun(t *testing.T) { From a227f037985f75bd81438af8d1d44e512d6595d2 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Mon, 16 Oct 2023 00:35:10 +0900 Subject: [PATCH 12/15] use async --- virtualization_11.m | 16 ++++++++-------- virtualization_12.m | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/virtualization_11.m b/virtualization_11.m index 2fe9ca4..6360dd9 100644 --- a/virtualization_11.m +++ b/virtualization_11.m @@ -773,7 +773,7 @@ bool requestStopVirtualMachine(void *machine, void *queue, void **error) { if (@available(macOS 11, *)) { __block BOOL ret; - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ ret = [(VZVirtualMachine *)machine requestStopWithError:(NSError *_Nullable *_Nullable)error]; }); return (bool)ret; @@ -794,7 +794,7 @@ void startWithCompletionHandler(void *machine, void *queue, uintptr_t cgoHandle) { if (@available(macOS 11, *)) { vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle); - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ [(VZVirtualMachine *)machine startWithCompletionHandler:handler]; }); Block_release(handler); @@ -808,7 +808,7 @@ void pauseWithCompletionHandler(void *machine, void *queue, uintptr_t cgoHandle) { if (@available(macOS 11, *)) { vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle); - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ [(VZVirtualMachine *)machine pauseWithCompletionHandler:handler]; }); Block_release(handler); @@ -822,7 +822,7 @@ void resumeWithCompletionHandler(void *machine, void *queue, uintptr_t cgoHandle { if (@available(macOS 11, *)) { vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle); - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ [(VZVirtualMachine *)machine resumeWithCompletionHandler:handler]; }); Block_release(handler); @@ -837,7 +837,7 @@ bool vmCanStart(void *machine, void *queue) { if (@available(macOS 11, *)) { __block BOOL result; - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canStart; }); return (bool)result; @@ -850,7 +850,7 @@ bool vmCanPause(void *machine, void *queue) { if (@available(macOS 11, *)) { __block BOOL result; - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canPause; }); return (bool)result; @@ -863,7 +863,7 @@ bool vmCanResume(void *machine, void *queue) { if (@available(macOS 11, *)) { __block BOOL result; - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canResume; }); return (bool)result; @@ -876,7 +876,7 @@ bool vmCanRequestStop(void *machine, void *queue) { if (@available(macOS 11, *)) { __block BOOL result; - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canRequestStop; }); return (bool)result; diff --git a/virtualization_12.m b/virtualization_12.m index 4bcbcfb..0bb46bd 100644 --- a/virtualization_12.m +++ b/virtualization_12.m @@ -10,7 +10,7 @@ bool vmCanStop(void *machine, void *queue) { if (@available(macOS 12, *)) { __block BOOL result; - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canStop; }); return (bool)result; @@ -23,7 +23,7 @@ void stopWithCompletionHandler(void *machine, void *queue, uintptr_t cgoHandle) { if (@available(macOS 12, *)) { vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle); - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ [(VZVirtualMachine *)machine stopWithCompletionHandler:handler]; }); Block_release(handler); From ea837f0e5238e83fb1fa992d0fffaa5f14d982fd Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Mon, 16 Oct 2023 00:43:48 +0900 Subject: [PATCH 13/15] use dispatch_async --- virtualization_11.m | 10 +++++----- virtualization_12.m | 2 +- virtualization_12_arm64.m | 4 ++-- virtualization_13.m | 2 +- virtualization_14_arm64.m | 4 ++-- virtualization_test.go | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/virtualization_11.m b/virtualization_11.m index 6360dd9..6f25ca7 100644 --- a/virtualization_11.m +++ b/virtualization_11.m @@ -622,7 +622,7 @@ void VZVirtioSocketDevice_setSocketListenerForPort(void *socketDevice, void *vmQ void VZVirtioSocketDevice_removeSocketListenerForPort(void *socketDevice, void *vmQueue, uint32_t port) { if (@available(macOS 11, *)) { - dispatch_sync((dispatch_queue_t)vmQueue, ^{ + dispatch_async((dispatch_queue_t)vmQueue, ^{ [(VZVirtioSocketDevice *)socketDevice removeSocketListenerForPort:port]; }); return; @@ -837,7 +837,7 @@ bool vmCanStart(void *machine, void *queue) { if (@available(macOS 11, *)) { __block BOOL result; - dispatch_async((dispatch_queue_t)queue, ^{ + dispatch_sync((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canStart; }); return (bool)result; @@ -850,7 +850,7 @@ bool vmCanPause(void *machine, void *queue) { if (@available(macOS 11, *)) { __block BOOL result; - dispatch_async((dispatch_queue_t)queue, ^{ + dispatch_sync((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canPause; }); return (bool)result; @@ -863,7 +863,7 @@ bool vmCanResume(void *machine, void *queue) { if (@available(macOS 11, *)) { __block BOOL result; - dispatch_async((dispatch_queue_t)queue, ^{ + dispatch_sync((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canResume; }); return (bool)result; @@ -876,7 +876,7 @@ bool vmCanRequestStop(void *machine, void *queue) { if (@available(macOS 11, *)) { __block BOOL result; - dispatch_async((dispatch_queue_t)queue, ^{ + dispatch_sync((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canRequestStop; }); return (bool)result; diff --git a/virtualization_12.m b/virtualization_12.m index 0bb46bd..fc7c0a9 100644 --- a/virtualization_12.m +++ b/virtualization_12.m @@ -10,7 +10,7 @@ bool vmCanStop(void *machine, void *queue) { if (@available(macOS 12, *)) { __block BOOL result; - dispatch_async((dispatch_queue_t)queue, ^{ + dispatch_sync((dispatch_queue_t)queue, ^{ result = ((VZVirtualMachine *)machine).canStop; }); return (bool)result; diff --git a/virtualization_12_arm64.m b/virtualization_12_arm64.m index f408684..0063dcb 100644 --- a/virtualization_12_arm64.m +++ b/virtualization_12_arm64.m @@ -409,7 +409,7 @@ VZMacHardwareModelStruct convertVZMacHardwareModel2Struct(void *hardwareModelPtr __block VZMacOSInstaller *ret; NSString *restoreImageFilePathNSString = [NSString stringWithUTF8String:restoreImageFilePath]; NSURL *restoreImageFileURL = [NSURL fileURLWithPath:restoreImageFilePathNSString]; - dispatch_sync((dispatch_queue_t)vmQueue, ^{ + dispatch_async((dispatch_queue_t)vmQueue, ^{ ret = [[VZMacOSInstaller alloc] initWithVirtualMachine:(VZVirtualMachine *)virtualMachine restoreImageURL:restoreImageFileURL]; }); return ret; @@ -427,7 +427,7 @@ void installByVZMacOSInstaller(void *installerPtr, void *vmQueue, void *progress { if (@available(macOS 12, *)) { VZMacOSInstaller *installer = (VZMacOSInstaller *)installerPtr; - dispatch_sync((dispatch_queue_t)vmQueue, ^{ + dispatch_async((dispatch_queue_t)vmQueue, ^{ [installer installWithCompletionHandler:^(NSError *error) { macOSInstallCompletionHandler(completionHandler, error); }]; diff --git a/virtualization_13.m b/virtualization_13.m index cb54591..b3ad8a3 100644 --- a/virtualization_13.m +++ b/virtualization_13.m @@ -430,7 +430,7 @@ void startWithOptionsCompletionHandler(void *machine, void *queue, void *options #ifdef INCLUDE_TARGET_OSX_13 if (@available(macOS 13, *)) { vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle); - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ [(VZVirtualMachine *)machine startWithOptions:options completionHandler:handler]; }); Block_release(handler); diff --git a/virtualization_14_arm64.m b/virtualization_14_arm64.m index a5e19e0..6a71449 100644 --- a/virtualization_14_arm64.m +++ b/virtualization_14_arm64.m @@ -39,7 +39,7 @@ void restoreMachineStateFromURLWithCompletionHandler(void *machine, void *queue, NSString *saveFilePathNSString = [NSString stringWithUTF8String:saveFilePath]; NSURL *saveFileURL = [NSURL fileURLWithPath:saveFilePathNSString]; vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle); - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ [(VZVirtualMachine *)machine restoreMachineStateFromURL:saveFileURL completionHandler:handler]; }); Block_release(handler); @@ -74,7 +74,7 @@ void saveMachineStateToURLWithCompletionHandler(void *machine, void *queue, uint NSString *saveFilePathNSString = [NSString stringWithUTF8String:saveFilePath]; NSURL *saveFileURL = [NSURL fileURLWithPath:saveFilePathNSString]; vm_completion_handler_t handler = makeVMCompletionHandler(cgoHandle); - dispatch_sync((dispatch_queue_t)queue, ^{ + dispatch_async((dispatch_queue_t)queue, ^{ [(VZVirtualMachine *)machine saveMachineStateToURL:saveFileURL completionHandler:handler]; }); Block_release(handler); diff --git a/virtualization_test.go b/virtualization_test.go index ae71cd3..3d5d99a 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -345,7 +345,7 @@ func TestStop(t *testing.T) { vm := container.VirtualMachine if got := vm.CanStop(); !got { - t.Fatal("want CanRequestStop is true") + t.Fatal("want CanStop is true") } if err := vm.Stop(); err != nil { t.Fatal(err) From 538433019fff62556fff709710cc1882e23dffda Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Mon, 16 Oct 2023 00:52:16 +0900 Subject: [PATCH 14/15] fixed timeout 2m to 5m --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2b7f19e..ebbad05 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ fmt: .PHONY: test test: - go test -p 1 -exec "go run $(PWD)/cmd/codesign" ./... -timeout 2m -v + go test -p 1 -exec "go run $(PWD)/cmd/codesign" ./... -timeout 5m -v .PHONY: test/run test/run: From 6000086510df4478c4b1f26a1362b1648814ff39 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Mon, 16 Oct 2023 01:13:37 +0900 Subject: [PATCH 15/15] added logging --- virtualization_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/virtualization_test.go b/virtualization_test.go index 3d5d99a..ee0e50d 100644 --- a/virtualization_test.go +++ b/virtualization_test.go @@ -117,11 +117,12 @@ func newVirtualizationMachine( ) *Container { t.Helper() RETRY: - for { + for i := 1; ; i++ { container, err := newVirtualizationMachineErr(configs...) if err != nil { if isECONNRESET(err) { time.Sleep(time.Second) + t.Logf("retry: %d", i) continue RETRY } t.Fatal(err)