Skip to content

Commit b2bf3bd

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
Fix e2e target to run on real device via adb
Detect /dev/binder in TestMain to skip emulator setup when running on-device. bindercli tests skip automatically. Split into make e2e (device) and make e2e-bindercli (emulator).
1 parent 6949041 commit b2bf3bd

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

Makefile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: generate genversions test e2e vet build build-examples lint clean readme smoke \
1+
.PHONY: generate genversions test e2e e2e-bindercli vet build build-examples lint clean readme smoke \
22
bindercli genbindercli genservicemap genaccessors list-commands check-generated release
33

44
# Generated top-level directories.
@@ -19,9 +19,18 @@ generate:
1919
test:
2020
go test -v -race $(GO_PACKAGES)
2121

22-
# Run E2E tests (requires Android emulator or device).
22+
# Run E2E tests on a connected device via adb.
23+
# Cross-compiles the test binary, pushes it, and runs on the device.
24+
# bindercli tests are skipped (they require an emulator); on-device tests
25+
# open /dev/binder directly.
2326
e2e:
24-
go test -tags e2e ./tests/e2e/... -run TestAidlcli -v -timeout 300s
27+
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go test -tags e2e -c -o build/e2e_test ./tests/e2e/
28+
adb push build/e2e_test /data/local/tmp/
29+
adb shell /data/local/tmp/e2e_test -test.v -test.timeout 300s
30+
31+
# Run bindercli E2E tests via emulator (starts emulator if needed).
32+
e2e-bindercli:
33+
go test -tags e2e ./tests/e2e/... -run TestBindercli -v -timeout 300s
2534

2635
# Run go vet on all packages.
2736
vet:

tests/e2e/aidlcli_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,20 @@ var emulatorSerial string
3434
// so cleanup only kills it if we own it.
3535
var emulatorStartedByTest bool
3636

37+
// onDevice reports whether the test binary is running directly on an
38+
// Android device (i.e. /dev/binder is accessible). When true, the
39+
// emulator/adb setup is skipped — on-device tests open /dev/binder
40+
// directly, and aidlcli tests are skipped.
41+
var onDevice bool
42+
3743
func TestMain(m *testing.M) {
44+
if _, err := os.Stat("/dev/binder"); err == nil {
45+
// Running on the device itself — skip emulator setup.
46+
onDevice = true
47+
os.Exit(m.Run())
48+
}
49+
50+
// Running on the host — need emulator for aidlcli tests.
3851
serial := findEmulator()
3952
if serial == "" {
4053
startEmulator()
@@ -217,9 +230,13 @@ func shellQuote(s string) string {
217230
return "'" + strings.ReplaceAll(s, "'", "'\\''") + "'"
218231
}
219232

220-
// runBindercliOrSkip runs bindercli; skips the test when the service is unavailable.
233+
// runBindercliOrSkip runs bindercli; skips the test when the service is unavailable
234+
// or when running directly on the device (aidlcli tests require adb from the host).
221235
func runBindercliOrSkip(t *testing.T, args ...string) string {
222236
t.Helper()
237+
if onDevice {
238+
t.Skip("bindercli tests require adb from host; skipping on-device")
239+
}
223240
stdout, stderr, err := runBindercli(args...)
224241
if err != nil {
225242
combined := stderr + stdout
@@ -685,6 +702,9 @@ func runBindercliHALOrSkip(
685702
args ...string,
686703
) string {
687704
t.Helper()
705+
if onDevice {
706+
t.Skip("bindercli tests require adb from host; skipping on-device")
707+
}
688708
fullArgs := append([]string{serviceName}, args...)
689709
stdout, stderr, err := runBindercli(fullArgs...)
690710
if err != nil {

0 commit comments

Comments
 (0)