mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
fix(testrun): pass the jvm the flag that silences the jdk 24 unsafe warning
This commit is contained in:
1 parent
7b44b0c9a9
commit
8c31e2bf6f
2 files changed
+61
-7
No files matched your search
@@ -154,13 +154,7 @@ func buildDriver(ctx context.Context, options Options, stdout io.Writer) (driver
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
sidecarArgs := []string{"-jar", jarPath,
|
sidecarArgs := sidecarArguments(ctx, jarPath, sidecarPort, options.Platform, options.Device)
|
||||||
"--port", strconv.Itoa(sidecarPort),
|
|
||||||
"--platform", options.Platform,
|
|
||||||
}
|
|
||||||
if options.Device != "" {
|
|
||||||
sidecarArgs = append(sidecarArgs, "--serial", options.Device)
|
|
||||||
}
|
|
||||||
adbPath, err := android.AdbBinary()
|
adbPath, err := android.AdbBinary()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, preflightFailure("android", err)
|
return nil, nil, preflightFailure("android", err)
|
||||||
@@ -212,6 +206,25 @@ func buildDriver(ctx context.Context, options Options, stdout io.Writer) (driver
|
|||||||
return driverClient, cleanup, nil
|
return driverClient, cleanup, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// From JDK 24 the JVM prints a four-line sun.misc.Unsafe deprecation warning
|
||||||
|
// on every sidecar start, because the netty that grpc pulls in still reads
|
||||||
|
// field offsets through it. The flag that silences it did not exist before JDK
|
||||||
|
// 23 and an older JVM refuses to start when handed it, so ask this JVM whether
|
||||||
|
// it takes the flag rather than reading its version string.
|
||||||
|
const unsafeMemoryAccessAllow = "--sun-misc-unsafe-memory-access=allow"
|
||||||
|
|
||||||
|
func sidecarArguments(ctx context.Context, jarPath string, port int, platform, serial string) []string {
|
||||||
|
var args []string
|
||||||
|
if exec.CommandContext(ctx, "java", unsafeMemoryAccessAllow, "-version").Run() == nil {
|
||||||
|
args = append(args, unsafeMemoryAccessAllow)
|
||||||
|
}
|
||||||
|
args = append(args, "-jar", jarPath, "--port", strconv.Itoa(port), "--platform", platform)
|
||||||
|
if serial != "" {
|
||||||
|
args = append(args, "--serial", serial)
|
||||||
|
}
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
// watchSidecar reaps the sidecar and publishes its exit status. The channel is
|
// watchSidecar reaps the sidecar and publishes its exit status. The channel is
|
||||||
// closed after the send so the shutdown path can still receive once the startup
|
// closed after the send so the shutdown path can still receive once the startup
|
||||||
// path has taken the status.
|
// path has taken the status.
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -305,3 +308,41 @@ func TestResolveIOSTargetDeviceResolutionErrorSurfaces(t *testing.T) {
|
|||||||
t.Fatal("expected the device-resolution error to surface")
|
t.Fatal("expected the device-resolution error to surface")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fakeJava(t *testing.T, script string) {
|
||||||
|
t.Helper()
|
||||||
|
directory := t.TempDir()
|
||||||
|
path := filepath.Join(directory, "java")
|
||||||
|
if err := os.WriteFile(path, []byte("#!/bin/sh\n"+script+"\n"), 0o755); err != nil {
|
||||||
|
t.Fatalf("write fake java: %v", err)
|
||||||
|
}
|
||||||
|
t.Setenv("PATH", directory)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSidecarArgumentsSilencesTheUnsafeWarningOnAJvmThatTakesTheFlag(t *testing.T) {
|
||||||
|
fakeJava(t, "exit 0")
|
||||||
|
|
||||||
|
args := sidecarArguments(context.Background(), "/tmp/sidecar.jar", 51129, "android", "663c91b1")
|
||||||
|
|
||||||
|
want := []string{
|
||||||
|
"--sun-misc-unsafe-memory-access=allow",
|
||||||
|
"-jar", "/tmp/sidecar.jar",
|
||||||
|
"--port", "51129",
|
||||||
|
"--platform", "android",
|
||||||
|
"--serial", "663c91b1",
|
||||||
|
}
|
||||||
|
if !slices.Equal(args, want) {
|
||||||
|
t.Fatalf("sidecar argv = %q, want %q", args, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSidecarArgumentsOmitsTheFlagAJvmBefore23WouldRefuseToStartWith(t *testing.T) {
|
||||||
|
fakeJava(t, `case "$1" in --sun-misc-unsafe-memory-access=*) echo "Unrecognized option: $1" >&2; exit 1;; esac; exit 0`)
|
||||||
|
|
||||||
|
args := sidecarArguments(context.Background(), "/tmp/sidecar.jar", 51129, "android", "")
|
||||||
|
|
||||||
|
want := []string{"-jar", "/tmp/sidecar.jar", "--port", "51129", "--platform", "android"}
|
||||||
|
if !slices.Equal(args, want) {
|
||||||
|
t.Fatalf("sidecar argv = %q, want %q", args, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user