Esempio n. 1
0
//Roborium executor
func (mf MonkeyFrame) TaskExecutor(jobId, deviceId, sdkPath string) {
	outPath := path.Join(jobId, deviceId, OUTPATH)

	file, err := os.Create(outPath)
	if err != nil {
		fmt.Println("InstallFrame create out file err!")
		fmt.Println(err)
	}
	var adb = path.Join(sdkPath, ADB_PATH)
	var out string = ""

	cmd := adb + " -s" + deviceId + " uninstall " + mf.PkgName
	comm.ExeCmd(cmd)
	cmd = adb + " -s " + deviceId + " install " + mf.AppPath
	out += comm.ExeCmd(cmd)
	//	cmd = "sleep 120"
	//	comm.ExeCmd(cmd)
	cmd = adb + " -s " + deviceId + " shell monkey -p " + mf.PkgName + " " + mf.Argu
	out += comm.ExeCmd(cmd)
	cmd = adb + " -s " + deviceId + " uninstall " + mf.PkgName
	comm.ExeCmd(cmd)

	file.WriteString(out)
	file.Sync()
	file.Close()
}
Esempio n. 2
0
//move test file to target file
func (bf RobotFrame) MoveTestFile(disPath string) FrameStruct {
	jobPath := path.Join(disPath, comm.APPNAME)
	cmd := "cp " + bf.AppPath + " " + jobPath
	comm.ExeCmd(cmd)
	bf.AppPath = jobPath

	jobPath = path.Join(disPath, comm.TESTNAME)
	cmd = "cp " + bf.TestPath + " " + jobPath
	comm.ExeCmd(cmd)
	bf.TestPath = jobPath
	return bf
}
Esempio n. 3
0
//Roborium executor
func (bf RobotFrame) TaskExecutor(jobId, deviceId, sdkPath string) {
	outPath := path.Join(jobId, deviceId)
	cmd := "java  -Djava.awt.headless=true -jar spoon-runner.jar --apk " + bf.AppPath
	cmd += " --test-apk " + bf.TestPath + " --output " + outPath + " --sdk " + sdkPath
	cmd += " -serial " + deviceId
	comm.ExeCmd(cmd)
}
Esempio n. 4
0
func (m *DeviceManager) updateDevInfo() {
	adb := path.Join(getAndroidSDKPath(), framework.ADB_PATH)
	comm.ExeCmd(GET_DEVICE_CMD + " " + adb)

	exist, err := comm.FileExists("dinfo.json")
	if !exist {
		log.Println("dinfo.json not exist!", err)
		return
	}

	//read info from this json
	content, err := ioutil.ReadFile("dinfo.json")
	if err != nil {
		log.Println("dinfo.json not exist!", err)
		return
	}

	//struct this json
	var dvinfos comp.DeviceInfoSlice
	err = json.Unmarshal(content, &dvinfos)
	if err != nil {
		log.Println(err)
		return
	}

	log.Println("Devices num: ", len(dvinfos.DeviceInfos))

	//get update devices map
	newMap := make(map[string]comp.Device)
	for _, dvinfo := range dvinfos.DeviceInfos {
		var dev comp.Device
		dev.State = comp.DEVICE_FREE
		dev.Info = dvinfo
		newMap[dvinfo.Id] = dev
		//fmt.Println(dvinfo)
	}

	m.deviceLock.Lock()
	defer m.deviceLock.Unlock()

	for id, ndev := range newMap {
		dev, ok := m.deviceMap[id]
		//old device
		if ok {
			newMap[id] = dev
		} else {
			//new device
			go startMinicap(id, ndev.Info.Resolution)
		}
	}
	for id, _ := range m.deviceMap {
		_, ok := newMap[id]
		if !ok {
			//miss device
			stopMinicap(id)
		}
	}
	m.deviceMap = newMap
}
Esempio n. 5
0
//move test file to target file
func (f InstallFrame) MoveTestFile(disPath string) FrameStruct {
	jobPath := path.Join(disPath, comm.APPNAME)
	cmd := "cp " + f.AppPath + " " + jobPath
	comm.ExeCmd(cmd)
	f.AppPath = jobPath

	return f
}
Esempio n. 6
0
//Roborium executor
func (f InstallFrame) TaskExecutor(jobId, deviceId, sdkPath string) {
	outPath := path.Join(jobId, deviceId, OUTPATH)
	file, err := os.Create(outPath)
	if err != nil {
		fmt.Println("InstallFrame create out file err!")
		fmt.Println(err)
	}

	var out string = ""

	cmd := "adb -s " + deviceId + " uninstall " + f.PkgName
	comm.ExeCmd(cmd)
	cmd = "adb -s " + deviceId + " install " + f.AppPath
	out += comm.ExeCmd(cmd)
	cmd = "adb -s " + deviceId + " shell monkey -p " + f.PkgName + " -v 1"
	out += comm.ExeCmd(cmd)
	cmd = "adb -s " + deviceId + " uninstall " + f.PkgName
	comm.ExeCmd(cmd)

	file.WriteString(out)
	file.Sync()
	file.Close()
}
Esempio n. 7
0
//when a new device is connected, start minicap server in the device and read the images data
func startMinicap(id, resolution string) {
	port := portManager.allocatePort(id)
	if port == -1 {
		log.Println("Port is not enough for", id)
		return
	}
	portManager.addDevWS(id, CreateDevWS(id))
	defer stopMinicap(id)

	//forward port
	ps := strconv.Itoa(port)
	out := comm.ExeCmd(getADBPath() + " -s " + id + " forward tcp:" + ps + " localabstract:minicap")
	if len(out) > 0 {
		log.Println(out)
		return
	}

	//regist this device in websocket server
	registDeviceInWS(id)

	//run minicap in the device
	cmd, err := runMCinDeviceCmd(id, resolution)
	if err != nil {
		log.Println("Minicap cmd create err", err)
		return
	}
	cmd.Start()
	defer func() {
		err = cmd.Process.Kill()
		if err != nil {
			log.Println("process kill err", err)
		}
	}()
	time.Sleep(2 * time.Second)

	//start get log and sent the log
	startLogcat(id)

	//start to send the image buffer
	log.Println("Start minicap on", port, " for ", id)
	parserImage(id, strconv.Itoa(port))
}
Esempio n. 8
0
//run minicap in device
func runMCinDevice(id, resolution string) {
	//defer portManager.freePort(id)
	wh := strings.Split(resolution, "x")
	if len(wh) != 2 {
		return
	}
	w, err := strconv.Atoi(wh[0])
	if err != nil {
		return
	}
	h, err := strconv.Atoi(wh[1])
	if err != nil {
		return
	}

	sw := w * SCREEN_SIZE / h
	args := resolution + "@" + strconv.Itoa(sw) + "x" + strconv.Itoa(SCREEN_SIZE) + "/0"
	out := comm.ExeCmd("./minicap.sh " + args + " " + id)
	log.Println("minicap: ", out)
	portManager.freePort(id)
}
Esempio n. 9
0
func (m *TaskManager) getTaskInfo() map[string]comp.Task {
	tasks := make(map[string]comp.Task)

	m.taskLock.Lock()
	for ke, ts := range m.taskMap {
		tasks[ke] = ts.TaskInfo
	}

	//remove finished task
	for ke, ts := range tasks {
		if ts.State == comp.TASK_COMPLETE || ts.State == comp.TASK_FAIL {
			//TODO move file is time-consuming
			srcPath := path.Join(ts.JobId, ts.DeviceId)
			dstPath := path.Join(getSharePath(), ts.JobId)
			cmd := "cp -r " + srcPath + " " + dstPath
			comm.ExeCmd(cmd)
			delete(m.taskMap, ke)
		}
	}
	m.taskLock.Unlock()
	return tasks
}
Esempio n. 10
0
//get UI event from client
func getEvent(ws *websocket.Conn, id, resolution string) {
	wh := strings.Split(resolution, "x")
	if len(wh) != 2 {
		log.Println("resolution err: ", resolution)
		return
	}

	h, err := strconv.Atoi(wh[1])
	if err != nil {
		log.Println("resolution h: ", wh[1])
		return
	}

	zoom := float64(h) / float64(SCREEN_SIZE)
	for {
		var evtString string
		if err := websocket.Message.Receive(ws, &evtString); err != nil {
			log.Println("Get event err", err)
			break
		}
		xy := strings.Split(evtString, ",")
		if len(xy) == 2 {
			x, err := strconv.Atoi(xy[0])
			if err != nil {
				continue
			}
			y, err := strconv.Atoi(xy[1])
			if err != nil {
				continue
			}
			x = int(zoom * float64(x))
			y = int(zoom * float64(y))
			cmd := getADBPath() + " -s " + id + " shell input tap " + strconv.Itoa(x) + " " + strconv.Itoa(y)
			comm.ExeCmd(cmd)
		} else if len(xy) == 4 {
			x1, err := strconv.Atoi(xy[0])
			if err != nil {
				continue
			}
			y1, err := strconv.Atoi(xy[1])
			if err != nil {
				continue
			}
			x2, err := strconv.Atoi(xy[2])
			if err != nil {
				continue
			}
			y2, err := strconv.Atoi(xy[3])
			if err != nil {
				continue
			}
			x1 = int(zoom * float64(x1))
			y1 = int(zoom * float64(y1))
			x2 = int(zoom * float64(x2))
			y2 = int(zoom * float64(y2))
			cmd := getADBPath() + " -s " + id + " shell input swipe " + strconv.Itoa(x1) + " " + strconv.Itoa(y1) + " " + strconv.Itoa(x2) + " " + strconv.Itoa(y2)
			comm.ExeCmd(cmd)
		} else if len(xy) == 1 {
			cmd := getADBPath() + " -s " + id + " shell input keyevent "
			isKey := true
			switch xy[0] {
			case "back":
				cmd += "4"
			case "home":
				cmd += "3"
			case "menu":
				cmd += "1"
			case "power":
				cmd += "26"
			case "reboot":
				cmd = getADBPath() + " -s " + id + " reboot "
			default:
				isKey = false
				log.Println("Get event", xy[0])
			}
			if isKey {
				comm.ExeCmd(cmd)
			}
		} else {
			log.Println("Get event", xy)
		}

	}
}
Esempio n. 11
0
//move test file to target file
func (mf MonkeyFrame) MoveTestFile(disPath string) FrameStruct {
	jobPath := path.Join(disPath, comm.APPNAME)
	cmd := "cp " + mf.AppPath + " " + jobPath
	comm.ExeCmd(cmd)
	return mf
}