#!/usr/bin/python
import os
import sys

target = "/home/jacob/mydroid/out/target/product/dream-open/system/bin/offload"

def run(times, op_unit):
	command = "adb shell 'cd /data/local/tmp; ./offload "+str(times)+" 0 "+op_unit+"'"
	os.system(command);


def upload(filename, target_dir):
	command = "adb push "+filename+" /data/local/tmp/"+target_dir
	os.system(command);
	print "[UPLOAD] "+filename+" uploaded."

'''
Target: automatic generate multiple test case, run test case, upload files
'''
if len(sys.argv) == 1:
	# Upload files to device
	upload()
	#run(20, "cpu")
elif len(sys.argv) == 2 and sys.argv[1] == "auto":
    '''
    file = "/system/bin/mediaserver"
    for i in range(1, 6, 1):
        run(file, "cpu")
    for i in range(1, 9, 1):
        run(file, "cloud")
    for i in range(1, 16, 1):
        run(file, "cloud")
    '''
    n = 220;
    for i in range(1, 6, 1):
        run(n, "cpu")
    for i in range(1, 9, 1):
        run(n, "cloud")
    for i in range(1, 16, 1):
        run(n, "cloud")
elif len(sys.argv) == 2 and sys.argv[1] == "fd":
    #for i in range(1, 9, 1):
        #run("/system/bin/mediaserver", "cloud")
    #for i in range(0, 50):
        #command= "adb shell 'cd /data/local/tmp; ./offload  1'"
        #os.system(command);
    for i in range(1, 6, 1):
        run(200, "cpu")
    for i in range(0, 50):
        command= "adb shell 'cd /data/local/tmp; ./offload 200 0.3'"
        os.system(command);
elif len(sys.argv) == 2 and sys.argv[1] == "rm":
    command = "adb shell rm /data/local/tmp/Docs/exec-log; adb shell rm \
    /data/local/tmp/Docs/dec-log"
    os.system(command);
else:
	print "usage: upload auto begin end interval"

