sut_tools/config.py
author Chris AtLee <catlee@mozilla.com>
Fri, 25 Mar 2011 16:16:28 -0400
changeset 1310 28dcc684794dcc084402823187f2990279f59aa7
parent 1306 309b378527a21791d56be02063f9d4b513a9fa80
child 1315 e8baf75d973dab9af7a3481d1a94230dee8a210f
permissions -rw-r--r--
Bug 643816: Don't sign D3DCompiler_42.dll or d3dx9_42.dll. r=bhearsum

#!/usr/bin/env python

import os, sys
import time
import random
import socket
import devicemanager


def setFlag(flagfile, contents=None):
    print flagfile
    h = open(flagfile, 'a+')
    if contents is not None:
        print contents
        h.write('%s\n' % contents)
    h.close()
    time.sleep(30)

def clearFlag(flagfile):
    if os.path.exists(flagfile):
        os.remove(flagfile)

def calculatePort():
    s = os.environ['SUT_NAME']
    try:
        n = 50000 + int(s.split('-')[1])
    except:
        n = random.randint(40000, 50000)
    return n

def getOurIP():
    try:
        result = os.environ['CP_IP']
    except:
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            s.connect(('mozilla.com', 80))
            result = s.getsockname()[0]
            s.close()
        except:
            result = None
            dumpException('unable to determine our IP address')

    return result

def getResolution(dm):
    parts = dm.getInfo('screen')['screen'][0].split()
    width = int(parts[0].split(':')[1])
    height = int(parts[1].split(':')[1])
    return width, height

def checkDeviceRoot():
    dr = dm.getDeviceRoot()
    # checking for /mnt/sdcard/...
    print "devroot %s" % str(dr)
    if not dr or dr == '/tests':
        return None
    return dr

def waitForDevice(waitTime=60):
    print "Waiting for tegra to come back..."
    time.sleep(waitTime)
    tegraIsBack = False
    tries = 0
    maxTries = 20
    while tries <= maxTries:
        tries += 1
        print "Try %d" % tries
        if checkDeviceRoot() is not None:
            tegraIsBack = True
            break
        time.sleep(60)
    if not tegraIsBack:
        print("Remote Device Error: waiting for tegra timed out.")
        sys.exit(1)

# Stop buffering!
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

if (len(sys.argv) <> 3):
  print "usage: config.py <ip address> <testname>"
  sys.exit(1)

cwd       = os.getcwd()
testname  = sys.argv[2]
errorFile = os.path.join(cwd, '..', 'error.flg')
proxyIP   = getOurIP()
proxyPort = calculatePort()
refHeight = 1680
refWidth  = 1050

print "connecting to: %s" % sys.argv[1]
dm = devicemanager.DeviceManager(sys.argv[1])
# Moar data!
dm.debug = 3
devRoot  = dm.getDeviceRoot()

# checking for /mnt/sdcard/...
print "devroot %s" % devRoot
if devRoot is None or devRoot == '/tests':
    setFlag(errorFile, "Remote Device Error: devRoot from devicemanager [%s] is not correct - exiting" % devRoot)
    sys.exit(1)

width, height = getResolution(dm)
#adjust resolution up if we are part of a reftest run
if testname.startswith('reftest') and width < refWidth:
    dm.adjustResolution(refHeight, refWidth, 'crt')
    dm.reboot(proxyIP, proxyPort)
    waitForDevice()

    width, height = getResolution(dm)

    if width != refWidth and height != refHeight:
        setFlag(errorFile, "Remote Device Error: current resolution X:%d Y:%d does not match what was set X:%d Y:%d" % (height, width, refHeight, refWidth))
        sys.exit(1)