Ejemplo n.º 1
0
func (inst *instance) repair() error {
	// Assume that the device is in a bad state initially and reboot it.
	for i := 0; i < 300; i++ {
		if _, err := inst.adb("shell", "pwd"); err == nil {
			break
		}
		if !vm.SleepInterruptible(time.Second) {
			return fmt.Errorf("shutdown in progress")
		}
	}
	// adb reboot episodically hangs, so we use a more reliable way.
	// Ignore errors because all other adb commands hang as well
	// and the binary can already be on the device.
	inst.adb("push", inst.cfg.Executor, "/data/syz-executor")
	if _, err := inst.adb("shell", "/data/syz-executor", "reboot"); err != nil {
		return err
	}
	// Now give it another 5 minutes to boot.
	if !vm.SleepInterruptible(10 * time.Second) {
		return fmt.Errorf("shutdown in progress")
	}
	var err error
	for i := 0; i < 300; i++ {
		if !vm.SleepInterruptible(time.Second) {
			return fmt.Errorf("shutdown in progress")
		}
		if _, err = inst.adb("shell", "pwd"); err == nil {
			return nil
		}
	}
	return fmt.Errorf("instance is dead and unrepairable: %v", err)
}
Ejemplo n.º 2
0
func (inst *instance) checkBatteryLevel() error {
	const (
		minLevel      = 20
		requiredLevel = 30
	)
	val, err := inst.getBatteryLevel(3)
	if err != nil {
		return err
	}
	if val >= minLevel {
		Logf(0, "device %v: battery level %v%%, OK", inst.cfg.Device, val)
		return nil
	}
	for {
		Logf(0, "device %v: battery level %v%%, waiting for %v%%", inst.cfg.Device, val, requiredLevel)
		if !vm.SleepInterruptible(time.Minute) {
			return nil
		}
		val, err = inst.getBatteryLevel(0)
		if err != nil {
			return err
		}
		if val >= requiredLevel {
			break
		}
	}
	return nil
}
Ejemplo n.º 3
0
func (inst *instance) repair() error {
	// Assume that the device is in a bad state initially and reboot it.
	// Ignore errors, maybe we will manage to reboot it anyway.
	inst.waitForSsh()
	// adb reboot episodically hangs, so we use a more reliable way.
	// Ignore errors because all other adb commands hang as well
	// and the binary can already be on the device.
	inst.adb("push", inst.cfg.Executor, "/data/syz-executor")
	if _, err := inst.adb("shell", "/data/syz-executor", "reboot"); err != nil {
		return err
	}
	// Now give it another 5 minutes to boot.
	if !vm.SleepInterruptible(10 * time.Second) {
		return fmt.Errorf("shutdown in progress")
	}
	if err := inst.waitForSsh(); err != nil {
		return err
	}
	// Switch to root for userdebug builds.
	inst.adb("root")
	if err := inst.waitForSsh(); err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 4
0
func waitInstanceBoot(ip, sshKey, sshUser string) error {
	for i := 0; i < 100; i++ {
		if !vm.SleepInterruptible(5 * time.Second) {
			return fmt.Errorf("shutdown in progress")
		}
		cmd := exec.Command("ssh", append(sshArgs(sshKey, "-p", 22), sshUser+"@"+ip, "pwd")...)
		if _, err := cmd.CombinedOutput(); err == nil {
			return nil
		}
	}
	return fmt.Errorf("can't ssh into the instance")
}
Ejemplo n.º 5
0
func (inst *instance) waitForSsh() error {
	var err error
	for i := 0; i < 300; i++ {
		if !vm.SleepInterruptible(time.Second) {
			return fmt.Errorf("shutdown in progress")
		}
		if _, err = inst.adb("shell", "pwd"); err == nil {
			return nil
		}
	}
	return fmt.Errorf("instance is dead and unrepairable: %v", err)
}