예제 #1
0
파일: main.go 프로젝트: yashodhank/rats
func main() {
	rats.PollDevices()

	argCount := len(os.Args)
	if argCount != 2 && argCount != 3 {
		fmt.Println("Usage: cli-client <main apk [optional]> <test apk>")
		fmt.Println("   * main apk not required for library tests")
		return
	}

	devices := <-rats.GetAllDevices()

	for _, arg := range os.Args[1:] {
		rats.Install(arg, devices)
	}

	for _, device := range devices {
		device.SetScreenOn(true)
		device.Unlock()
	}

	testFile := os.Args[len(os.Args)-1]
	manifest := rats.GetManifest(testFile)

	s := test.RunTests(manifest, devices)
	str, err := xml.Marshal(s)
	if err == nil {
		fmt.Println(string(str))
	}

	rats.Uninstall(manifest.Package, devices)
	rats.Uninstall(manifest.Instrument.Target, devices)
}
예제 #2
0
파일: main.go 프로젝트: yashodhank/rats
func RunTests(w http.ResponseWriter, r *http.Request, db *mgo.Database) error {
	uuid, err := uuid()
	if err != nil {
		return err
	}
	main, _, err := r.FormFile("apk")
	testApk, _, err := r.FormFile("test-apk")
	if err != nil {
		return errors.New("A Test Apk must be supplied")
	}

	size := getLength(testApk)

	count, _ := strconv.Atoi(r.FormValue("count"))
	serialList := r.FormValue("serials")
	strict := r.FormValue("strict")
	msg := r.FormValue("message")

	var serials []string
	if serialList != "" {
		serials = strings.Split(serialList, ",")
	}

	filter := &rats.DeviceFilter{
		Count:  count,
		Strict: strict == "true",
	}
	filter.Serials = serials

	manifest := rats.GetManifest(testApk, size)
	filter.MinSdk = manifest.Sdk.Min
	filter.MaxSdk = manifest.Sdk.Max

	testApk.Seek(0, 0) // reset for new reader

	devices := <-rats.GetDevices(filter)
	rats.Reserve(devices...)

	// Remove old if left over
	rats.Uninstall(manifest.Package, devices...)
	rats.Uninstall(manifest.Instrument.Target, devices...)

	// Install New
	if main != nil {
		rats.Install("main.apk", main, devices...)
	}
	rats.Install("test.apk", testApk, devices...)

	rats.Unlock(devices)

	finished, out := test.RunTests(manifest, devices)

	var s *test.TestSuites
SuitesLoop:
	for {
		select {
		case s = <-out:
			break SuitesLoop
		case device := <-finished:
			go func() {
				rats.Uninstall(manifest.Package, device)
				rats.Uninstall(manifest.Instrument.Target, device)
				rats.Release(device)
			}()
		}
	}

	s.Name = uuid
	s.Timestamp = time.Now()
	s.Project = manifest.Instrument.Target
	if msg != "" {
		s.Message = msg
	}

	if dbErr := db.C("runs").Insert(&s); dbErr != nil {
		w.WriteHeader(http.StatusConflict)
		json.NewEncoder(w).Encode(dbErr.Error())
	}

	if !s.Success {
		w.WriteHeader(http.StatusInternalServerError)
	}

	return json.NewEncoder(w).Encode(s)
}