Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #312 from ShakoHo/change_devicemanageadb_2_adbb2g
Browse files Browse the repository at this point in the history
Change devicemanageadb 2 adbb2g
  • Loading branch information
ShakoHo committed Jul 9, 2015
2 parents 928f095 + f32cb28 commit ea508d5
Show file tree
Hide file tree
Showing 20 changed files with 595 additions and 437 deletions.
37 changes: 23 additions & 14 deletions mcts/certsuite/cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
last_test_started = 'None'
logger = None

expected_results_path = '../static/expected_results'

# supported_versions = ["2.2", "2.1", "2.0", "1.4", "1.3"]

expected_result_folder = os.path.join('..', 'static', 'expected_results')
Expand Down Expand Up @@ -96,9 +98,8 @@ def webapi_log_handler(request, response):
("POST", "/webapi_log", webapi_log_handler),
("GET", "/*", wptserve.handlers.file_handler)]

static_path = os.path.abspath(os.path.join(
os.path.dirname(__file__), "static"))

mcts_current_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
static_path = os.path.join(mcts_current_path, "static")

def read_manifest(app):
with open(os.path.join(app, 'manifest.webapp')) as f:
Expand Down Expand Up @@ -174,7 +175,8 @@ def test_webapi(logger, report, args, addr):
webapi_results = None

appname = '%s WebAPI Verifier' % apptype.capitalize()
apppath = os.path.join(static_path, 'webapi-test-app')
sampleapppath = os.path.join(static_path, 'sample_apps')
apppath = os.path.join(sampleapppath, 'webapi-test-app')
install_app(logger, appname, args.version, apptype, apppath, True,
{'results_uri.js':
'RESULTS_URI="http://%s:%s/webapi_results";LOG_URI="http://%s:%s/webapi_log";' % (addr * 2)},
Expand Down Expand Up @@ -252,14 +254,16 @@ def test_permissions(logger, report, args, addr):

# first install test app for embed-apps permission test
embed_appname = 'Embed Apps Test App'
apppath = os.path.join(static_path, 'embed-apps-test-app')
sampleapppath = os.path.join(static_path, 'sample_apps')
apppath = os.path.join(sampleapppath, 'embed-apps-test-app')
install_app(logger, embed_appname, args.version, 'certified', apppath, True,
{'results_uri.js': 'RESULTS_URI="http://%s:%s/webapi_results_embed_apps";' % addr},
False)

appname = 'Permissions Test App'
installed_appname = appname.lower().replace(" ", "-")
apppath = os.path.join(static_path, 'permissions-test-app')
sampleapppath = os.path.join(static_path, 'sample_apps')
apppath = os.path.join(sampleapppath, 'permissions-test-app')
install_app(logger, appname, args.version, 'web', apppath, False,
{'results_uri.js':
'RESULTS_URI="http://%s:%s/webapi_results";LOG_URI="http://%s:%s/webapi_log";' % (addr * 2)})
Expand Down Expand Up @@ -396,7 +400,8 @@ def test_open_remote_window(logger, version, addr):

appname = 'Open Remote Window Test App'
installed_appname = appname.lower().replace(" ", "-")
apppath = os.path.join(static_path, 'open-remote-window-test-app')
sampleapppath = os.path.join(static_path, 'sample_apps')
apppath = os.path.join(sampleapppath, 'open-remote-window-test-app')
install_app(logger, appname, version, 'web', apppath, False,
{'results_uri.js':
'RESULTS_URI="http://%s:%s/webapi_results";' % addr})
Expand Down Expand Up @@ -602,10 +607,14 @@ def tabelize(value):

def get_application_ini(dm):
# application.ini information
appinicontents = dm.pullFile('/system/b2g/application.ini')
sf = StringIO.StringIO(appinicontents)
config = ConfigParser.ConfigParser()
config.readfp(sf)
#appinicontents = dm.pullFile('/system/b2g/application.ini')
#sf = StringIO.StringIO(appinicontents)
#config = ConfigParser.ConfigParser()
#config.readfp(sf)
ini_file = '_app.ini'
dm.pull('/system/b2g/application.ini', ini_file)
config = ConfigParser.RawConfigParser()
config.read(ini_file)
application_ini = {}
for section in config.sections():
application_ini[section] = dict(config.items(section))
Expand All @@ -615,7 +624,7 @@ def get_application_ini(dm):
def get_buildprop(dm):
# get build properties
buildprops = {}
buildpropoutput = dm.shellCheckOutput(["cat", "/system/build.prop"])
buildpropoutput = dm.shell_output("cat /system/build.prop")
for buildprop in [line for line in buildpropoutput.splitlines() if '=' \
in line]:
eq = buildprop.find('=')
Expand All @@ -626,11 +635,11 @@ def get_buildprop(dm):


def get_processes_running(dm):
return map(lambda p: {'name': p[1], 'user': p[2]}, dm.getProcessList())
return map(lambda p: {'name': p[1], 'user': p[2]}, dm.get_process_list())


def get_kernel_version(dm):
return dm.shellCheckOutput(["cat", "/proc/version"])
return dm.shell_output("cat /proc/version")


def _run(args, logger):
Expand Down
3 changes: 0 additions & 3 deletions mcts/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
"%(temp_dir)s/omni_diff_report.html"]}],
["webapi", {"cmd": "webapirunner",
"run_args": ["--version=%(version)s"]}],
["web-platform-tests", {"cmd": "wptrunner",
"common_args": ["--include-manifest=mcts/web-platform-tests/include.ini", "--config=mcts/web-platform-tests/wptrunner.ini"],
"run_args": ["--product=b2g", "--test-type=testharness", "--b2g-no-backup"]}],
["security", {"cmd": "securityrunner", "run_args":["--version=%(version)s"]}]
]
}
17 changes: 17 additions & 0 deletions mcts/config.json.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{"version": "2.2",
"suites": [
["cert", {"cmd": "cert",
"run_args": ["--version=%(version)s",
"--result-file=%(temp_dir)s/cert_results.json",
"--html-result-file=%(temp_dir)s/cert_results.html"],
"extra_files": ["%(temp_dir)s/cert_results.json",
"%(temp_dir)s/cert_results.html",
"%(temp_dir)s/omni_diff_report.html"]}],
["webapi", {"cmd": "webapirunner",
"run_args": ["--version=%(version)s"]}],
["web-platform-tests", {"cmd": "wptrunner",
"common_args": ["--include-manifest=mcts/web-platform-tests/include.ini", "--config=mcts/web-platform-tests/wptrunner.ini"],
"run_args": ["--product=b2g", "--test-type=testharness", "--b2g-no-backup"]}],
["security", {"cmd": "securityrunner", "run_args":["--version=%(version)s"]}]
]
}
2 changes: 2 additions & 0 deletions mcts/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ def restart(self):
pass
def root(self):
pass
def devices(self, timeout=None):
pass

def check_adb():
try:
Expand Down
21 changes: 11 additions & 10 deletions mcts/securitysuite/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# getter for shared logger instance
from mozlog.structured import get_default_logger
from mcts.utils.device.devicehelper import DeviceHelper
from mozdevice.adb import ADBError


# ######################################################################################################################
Expand Down Expand Up @@ -45,8 +46,8 @@ def parse_ls(out):

# adb returns newline as \r\n
# but mozdevice uses \n
for dirstr in out[2:-2].split('\n\n'):
lines = dirstr.split('\n')
for dirstr in out[2:-2].split('\r\n\r\n'):
lines = dirstr.split('\r\n')
dirname = lines[0][:-1]
if len(lines) == 2 and lines[1].startswith("opendir failed"):
continue
Expand Down Expand Up @@ -176,16 +177,16 @@ def run(cls, version=None):
logger = get_default_logger()

try:
dm = DeviceHelper.getDevice(runAdbAsRoot=True)
except mozdevice.DMError as e:
device = DeviceHelper.getDevice()
except ADBError as e:
logger.error("Error connecting to device via adb (error: %s). Please be " \
"sure device is connected and 'remote debugging' is enabled." % \
e.msg)
raise

try:
out = dm.shellCheckOutput(['ls', '-alR', '/'], root=True)
except mozdevice.DMError as e:
out = device.shell_output('ls -alR /', root=True)
except ADBError as e:
cls.log_status('FAIL', 'Failed to gather filesystem information from device via adb: %s' % e.msg)
return False

Expand Down Expand Up @@ -236,16 +237,16 @@ def run(cls, version=None):
logger = get_default_logger()

try:
dm = DeviceHelper.getDevice(runAdbAsRoot=True)
except mozdevice.DMError as e:
device = DeviceHelper.getDevice()
except ADBError as e:
logger.error("Error connecting to device via adb (error: %s). Please be " \
"sure device is connected and 'remote debugging' is enabled." % \
e.msg)
raise

try:
out = dm.shellCheckOutput(['ls', '-alR', '/'], root=True)
except mozdevice.DMError as e:
out = device.shell_output('ls -alR /', root=True)
except ADBError as e:
cls.log_status('FAIL', 'Failed to gather filesystem information from device via adb: %s' % e.msg)
return False

Expand Down
17 changes: 9 additions & 8 deletions mcts/securitysuite/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from mozlog.structured import get_default_logger

from mcts.utils.device.devicehelper import DeviceHelper
from mozdevice.adb import ADBError

# ######################################################################################################################
# shared module functions
Expand Down Expand Up @@ -44,16 +45,16 @@ class b2gps(object):
def __init__(self):
self.logger = get_default_logger()
try:
self.dm = DeviceHelper.getDevice()
except mozdevice.DMError as e:
self.device = DeviceHelper.getDevice()
except ADBError as e:
self.logger.error("Error connecting to device via adb (error: %s). Please be "
"sure device is connected and 'remote debugging' is enabled." %
e.msg)
raise

try:
self.ps = self.dm.shellCheckOutput(['b2g-ps'], root=True).split('\n')
except mozdevice.DMError as e:
self.ps = self.device.shell_output('b2g-ps', root=True).split('\r\n')
except ADBError as e:
self.logger.error("Error reading b2g-ps result from device: %s" % e.msg)
raise

Expand Down Expand Up @@ -83,16 +84,16 @@ class procpid(object):
def __init__(self):
self.logger = get_default_logger()
try:
self.dm = DeviceHelper.getDevice(runAdbAsRoot)
except mozdevice.DMError as e:
self.device = DeviceHelper.getDevice()
except ADBError as e:
self.logger.error("Error connecting to device via adb (error: %s). Please be "
"sure device is connected and 'remote debugging' is enabled." %
e.msg)
raise

def get_pidlist(self):
out = self.dm.shellCheckOutput(['ls', '/proc/*/status'], root=True)
proclines = out.split('\n')[-1] # skip 'self' which is always last
out = self.device.shell_output('ls /proc/*/status', root=True)
proclines = out.split('\r\n')[-1] # skip 'self' which is always last
pids = [x.split('/')[2] for x in proclines]
return pids

Expand Down
25 changes: 13 additions & 12 deletions mcts/securitysuite/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from mozlog.structured import commandline, get_default_logger
from time import sleep
from mcts.utils.device.devicehelper import DeviceHelper
from mozdevice.adb import ADBError

# ######################################################################################################################
# Test class that all test must be derived from
Expand Down Expand Up @@ -77,7 +78,7 @@ def run_groups(groups=[], version=None, host='localhost', port=2828, mode='phone
# setup marionette before any test
marionette = DeviceHelper.getMarionette(host=host, port=port)
# setup device before any test
device = DeviceHelper.getDevice(runAdbAsRoot=True)
device = DeviceHelper.getDevice()

for g in groups:
logger.debug("running securitysuite test group %s" % g)
Expand Down Expand Up @@ -111,25 +112,25 @@ def log_status(cls, status, msg):

def wait_for_adb_device():
try:
adb = DeviceHelper.getDevice(runAdbAsRoot=True)
except DMError:
adb = None
device = DeviceHelper.getDevice()
except ADBError:
device = None
print "Waiting for adb connection..."
while adb is None:
while device is None:
try:
adb = DeviceHelper.getDevice(runAdbAsRoot=True)
except DMError:
device = DeviceHelper.getDevice()
except ADBError:
sleep(0.2)
if len(adb.devices()) < 1:
if len(device.devices()) < 1:
print "Waiting for adb device..."
while len(adb.devices()) < 1:
while len(device.devices()) < 1:
sleep(0.2)


def adb_has_root():
# normally this should check via root=True to .shellCheckOutput, but doesn't work
adb = DeviceHelper.getDevice(runAdbAsRoot=True)
return adb.shellCheckOutput(["id"]).startswith("uid=0(root)")
# normally this should check via root=True to .shell_output, but doesn't work
device = DeviceHelper.getDevice()
return device.shell_output("id").startswith("uid=0(root)")


#######################################################################################################################
Expand Down
Loading

0 comments on commit ea508d5

Please sign in to comment.