def buzzer(): run_shell('echo {} > /sys/class/gpio/export'.format(str(gpio))) run_shell('echo "out" > /sys/class/gpio/gpio{}/direction'.format( str(gpio))) run_shell('echo 1 > /sys/class/gpio/gpio{}/value'.format(str(gpio))) sleep(0.3) run_shell('echo 0 > /sys/class/gpio/gpio{}/value'.format(str(gpio)))
def emmc_speed(d): result = [] standard = d["speed"] shell_result = run_shell("dd if=/dev/zero of=file bs=1M count=1024") run_shell("rm -rf file") speed = deal_shell(shell_result) if speed == -1: result.append({"flag": False, "message": "Emmc speed test failed"}) if speed < standard: result.append({ "flag": False, "message": "Emmc speed is {} GB/s".format(str(speed)) }) if speed >= standard: result.append({ "flag": True, "message": "Emmc speed is {} GB/s".format(str(speed)) }) return result
def shell_date(d, shell_str): try: datetime_one = int(run_shell(shell_str)[17:19]) time_one = int(time()) sleep(d['time']) datetime_two = int(run_shell(shell_str)[17:19]) time_two = int(time()) print(time_one, ' ', time_two) print(datetime_one, ' ', datetime_two) if datetime_one + d['time'] > 60: datetime_two = 60 + datetime_two print(datetime_one, ' ', datetime_two) if datetime_two - datetime_one == d['time'] + 1: return True return False except Exception as e: return False
def emmc_speed(d): result = [] standard = d["speed"] best_size = d["size"] shell_result = run_shell("dd if=/dev/zero of=file bs=1M count=1024") run_shell("sudo rm -rf file") speed = deal_shell(shell_result) if speed == -1: result.append({ "flag": False, "message": "Emmc speed test failed" }) if speed < standard: result.append({ "flag": False, "message": "Emmc speed is {} GB/s".format(str(speed)) }) if speed >= standard: result.append({ "flag": True, "message": "Emmc speed is {} GB/s".format(str(speed)) }) shell_result = run_shell("free -h") size = size_shell(shell_result) if size == -1: result.append({ "flag": False, "message": "Emmc size query fails" }) if best_size-0.2 > size or best_size+0.2 < size: result.append({ "flag": False, "message": "Emmc size is {} GB".format(str(size)) }) else: result.append({ "flag": True, "message": "Emmc size is {} GB".format(str(size)) }) return result
def cpu_stress(d): shell_str = '$HOME/test/bin/stress -c 1 -t {}' result_str = run_shell(shell_str.format(str(d['time']))) result = [{ "flag": True, "message": "CPU stress pass!" }] if result_str.find('completed') == -1: result[0]['flag'] = False result[0]['message'] = "CPU stress failed!" return result
def ram_stress(d): shell_str = '$HOME/test/bin/stress --vm {} --vm-bytes {} --vm-hang {} --timeout {}' result_str = run_shell( shell_str.format(str(d['num']), str(d['size']), str(d['release_time']), str(d['last_time']), )) result = [{ "flag": True, "message": "ram stress pass!" }] if result_str.find('completed') == -1: result[0]['flag'] = False result[0]['message'] = "ram stress failed!" return result
def ram_speed(d): standard = d["speed"] average = 0 index = 0 results = [] for i in range(0, 10): result = run_shell("dd if=/dev/zero of=/dev/null bs=1M count=1024") if result.find("/s") == -1: results.append({ "flag": False, "message": "num: " + str(i) + " ram speed test failed" }) continue for line in result.split("\r\n"): unit = 1 if line.find("copied") == -1: continue speed = float(line[line.rfind(",") + 1:line.find("/s") - 2].strip()) if line.find("MB") > 0: unit = 1000 if line.find("KB") > 0 or line.find("kB") > 0: unit = 1000000 speed = speed / unit results.append({ "flag": True, "message": "num: " + str(i) + " ram speed: " + str(speed) + "GB/s" }) average = average + speed index = index + 1 if index == 0: average = 0 else: average = average / index flag = True if average < standard: flag = False results.append({ "flag": flag, "message": "average ram: " + str(average) + "GB/s" }) return results
def eth_speed(d): serverip = d["serverip"] standard = d["speed"] result = [] command = "$HOME/test/bin/iperf -c " + serverip + " -f m" shell_result = run_shell(command) speed = deal_shell(shell_result) if speed == -1: result.append({"flag": False, "message": 'cant connect iperf server!'}) elif speed < standard: result.append({ "flag": False, "message": 'Eth speed is {} Mb/s'.format(str(speed)) }) elif speed >= standard: result.append({ "flag": True, "message": 'Eth speed is {} Mb/s'.format(str(speed)) }) return result