diff options
| author | Vishwath Mohan <vishwath@google.com> | 2016-09-06 13:17:08 -0700 |
|---|---|---|
| committer | Vishwath Mohan <vishwath@google.com> | 2016-09-06 13:17:08 -0700 |
| commit | b9b1bb2a04d8c27cfbfd4a76aab6d5de7daa691c (patch) | |
| tree | ea0fad307671449157a8c06abbdbba5d4c4e2831 /vm | |
| parent | 9decc82111be1754889e46944a6c6bfdfefdbeb7 (diff) | |
Improve Case Closed Debugging Port Detection.
The code to detect the ttyUSB number that a Suzy-Q connected device was
exposing wasn't handling the case when the devices were plugged in via a
USB hub (which extends the port numbering scheme). This CL changes the
regexp to detect the serial correctly in these cases as well.
Diffstat (limited to 'vm')
| -rw-r--r-- | vm/adb/adb.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/vm/adb/adb.go b/vm/adb/adb.go index e8090eddb..162d7d098 100644 --- a/vm/adb/adb.go +++ b/vm/adb/adb.go @@ -12,7 +12,6 @@ import ( "os/exec" "path/filepath" "regexp" - "strconv" "sync" "time" @@ -82,16 +81,18 @@ func (inst *instance) findConsole() error { if err != nil { return fmt.Errorf("failed to execute 'adb devices -l': %v\n%v\n", err, string(out)) } - re := regexp.MustCompile(fmt.Sprintf("%v +device usb:([0-9]+)-([0-9]+)\\.([0-9]+) ", inst.cfg.Device)) + // The regexp matches devices strings of the form usb:a-b.c.d....x, and + // then treats everything but the final .x as the bus/port combo to look + // for the ttyUSB number + re := regexp.MustCompile(fmt.Sprintf("%v +device usb:([0-9]+-[0-9]+.*)(\\.[0-9]+) product.*\n", inst.cfg.Device)) match := re.FindAllStringSubmatch(string(out), 1) if match == nil { return fmt.Errorf("can't find adb device '%v' in 'adb devices' output:\n%v\n", inst.cfg.Device, string(out)) } - bus, _ := strconv.ParseUint(match[0][1], 10, 64) - port, _ := strconv.ParseUint(match[0][2], 10, 64) - files, err := filepath.Glob(fmt.Sprintf("/sys/bus/usb/devices/%v-%v.2:1.1/ttyUSB*", bus, port)) + busAndPort := match[0][1] + files, err := filepath.Glob(fmt.Sprintf("/sys/bus/usb/devices/%v.2:1.1/ttyUSB*", busAndPort)) if err != nil || len(files) == 0 { - return fmt.Errorf("can't find any ttyUDB devices for adb device '%v' on bus %v-%v", inst.cfg.Device, bus, port) + return fmt.Errorf("can't find any ttyUSB devices for adb device '%v' on bus/port %v", inst.cfg.Device, busAndPort) } inst.console = "/dev/" + filepath.Base(files[0]) consoleCache[inst.cfg.Device] = inst.console |
