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

2.1 ssl stingray #306

Merged
merged 1 commit into from
May 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions certsuite/cert.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ def parse_permissions_results(expected_results_path, results, prefix, logger, re
log_results(unexpected_results, logger, report, 'permissions', prefix + 'unexpected-permissions-results')
return not unexpected_results

def run_marionette_script(script, chrome=False, async=False):
def run_marionette_script(script, chrome=False, async=False, host='localhost', port=2828):
"""Create a Marionette instance and run the provided script"""
m = marionette.Marionette()
m = marionette.Marionette(host, port)
m.start_session()
if chrome:
m.set_context(marionette.Marionette.CONTEXT_CHROME)
Expand Down
90 changes: 83 additions & 7 deletions certsuite/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
import gaiautils
import report

DeviceBackup = adb_b2g.DeviceBackup
_hasadb = True
_host = 'localhost'
_port = 2828
logger = None
stdio_handler = handlers.StreamHandler(sys.stderr,
formatters.MachFormatter())
Expand All @@ -64,14 +68,19 @@ def load_config(path):
return config


def iter_test_lists(suites_config):
def iter_test_lists(suites_config, mode='phone'):
'''
Query each subharness for the list of test groups it can run and
yield a tuple of (subharness, test group) for each one.
'''
for name, opts in suites_config.iteritems():
try:
cmd = [opts["cmd"], '--list-test-groups'] + opts.get("common_args", [])

if mode == 'stingray':
cmd.append('--mode')
cmd.append('stingray')

for group in subprocess.check_output(cmd).splitlines():
yield name, group
except (subprocess.CalledProcessError, OSError) as e:
Expand Down Expand Up @@ -140,9 +149,9 @@ def __exit__(self, ex_type, ex_value, tb):

# Consider upstreaming this to marionette-client:
class MarionetteSession(object):
def __init__(self, device):
def __init__(self, device, host='localhost', port=2828):
self.device = device
self.marionette = marionette.Marionette()
self.marionette = marionette.Marionette(host=host, port=port)

def __enter__(self):
self.device.forward("tcp:2828", "tcp:2828")
Expand All @@ -168,7 +177,10 @@ def iter_suites(self):
or the empty list to indicate all tests.
'''
if not self.args.tests:
tests = self.config["suites"].keys()
default_tests = self.config["suites"].keys()
if self.args.mode == 'stingray':
default_tests = ['webapi', 'security']
tests = default_tests
else:
tests = self.args.tests

Expand Down Expand Up @@ -266,6 +278,9 @@ def build_command(self, suite, groups, temp_dir):
output_files = [log_name]
output_files += [item % subn for item in suite_opts.get("extra_files", [])]

if self.args.mode == 'stingray' and (suite == 'webapi' or suite == 'security'):
cmd.extend([u'--host=%s' % _host, u'--port=%s' % _port, u'--mode=stingray'])

return cmd, output_files, log_name


Expand Down Expand Up @@ -298,10 +313,35 @@ def check_preconditions(config):

logger.info("Passed precondition checks")

class NoADBDeviceBackup():
def __enter__(self):
self.device = NoADB()
return self
def __exit__(self, *args, **kwargs):
pass
def restore(self):
pass

class NoADB():
def reboot(self):
pass
def wait_for_net(self):
pass
def shell_output(self):
pass
def forward(self, *args):
pass
def get_process_list(self):
return [[1447, '/sbin/adbd', 'root']]
def restart(self):
pass

def check_adb():
try:
logger.info("Testing ADB connection")
if not _hasadb:
logger.debug('Dummy ADB, please remember install Marionette and Cert Test App to device ')
return NoADB()
return adb_b2g.ADBB2G()
except (mozdevice.ADBError, mozdevice.ADBTimeoutError) as e:
logger.critical('Error connecting to device via adb (error: %s). Please be ' \
Expand All @@ -327,6 +367,10 @@ def check_root(device):


def install_marionette(device, version):
if not _hasadb:
logger.debug('The marionette should be installed manually by user.')
return True

try:
logger.info("Installing marionette extension")
try:
Expand Down Expand Up @@ -361,7 +405,7 @@ def ensure_settings(device):
"screen.brightness": 1.0,
"screen.timeout": 0.0}
logger.info("Setting up device for testing")
with MarionetteSession(device) as marionette:
with MarionetteSession(device, _host, _port) as marionette:
settings = gaiautils.Settings(marionette)
for k, v in test_settings.iteritems():
settings.set(k, v)
Expand All @@ -381,6 +425,10 @@ def wait_for_homescreen(marionette, timeout):

def check_server(device):
logger.info("Checking access to host machine")

if not _hasadb:
return True

routes = [("GET", "/", test_handler)]

host_ip = moznetwork.get_ip()
Expand Down Expand Up @@ -411,7 +459,15 @@ def check_server(device):


def list_tests(args, config):
for test, group in iter_test_lists(config["suites"]):
suites = OrderedDict.copy(config['suites'])

if args.mode == 'stingray':
stingray_suite_keys = ['webapi', 'security']
for key in suites.keys():
if key not in stingray_suite_keys:
del suites[key]

for test, group in iter_test_lists(suites, args.mode):
print "%s:%s" % (test, group)
return True

Expand All @@ -429,7 +485,7 @@ def run_tests(args, config):

check_preconditions(config)

with adb_b2g.DeviceBackup() as backup:
with DeviceBackup() as backup:
device = backup.device
runner = TestRunner(args, config)
for suite, groups in runner.iter_suites():
Expand Down Expand Up @@ -464,6 +520,15 @@ def get_parser():
parser.add_argument('--list-tests',
help='list all tests available to run',
action='store_true')
parser.add_argument('-H', '--host',
help='Hostname or ip for target device',
action='store', default='localhost')
parser.add_argument('-P', '--port',
help='Port for target device',
action='store', default=2828)
parser.add_argument('-m', '--mode',
help='Test mode (stingray, phone) default (phone)',
action='store', default='phone')
parser.add_argument('tests',
metavar='TEST',
help='tests to run',
Expand All @@ -476,6 +541,17 @@ def main():
args = parser.parse_args()
config = load_config(args.config)

global _host
global _port
global _hasadb
global DeviceBackup
_host = args.host
_port = int(args.port)

if args.mode == 'stingray':
_hasadb = False
DeviceBackup = NoADBDeviceBackup

if args.list_tests:
return list_tests(args, config)
else:
Expand Down
4 changes: 2 additions & 2 deletions securitysuite/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def whitelist_check(cls, name, flag='ok', whitelist=None):
return r.match(name) is not None

@classmethod
def run(cls, version=None):
def run(cls, version=None, host='localhost', port=2828, hasadb=True):
logger = get_default_logger()

try:
Expand Down Expand Up @@ -231,7 +231,7 @@ def whitelist_check(cls, name, flag='ok', whitelist=None):
return r.match(name) is not None

@classmethod
def run(cls, version=None):
def run(cls, version=None, host='localhost', port=2828, hasadb=True):
logger = get_default_logger()

try:
Expand Down
2 changes: 1 addition & 1 deletion securitysuite/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class seccomp(ExtraTest):
module = sys.modules[__name__]

@classmethod
def run(cls, version=None):
def run(cls, version=None, host='localhost', port=2828, hasadb=True):
logger = get_default_logger()

try:
Expand Down
33 changes: 18 additions & 15 deletions securitysuite/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,29 @@ def js_certdump():
'''


def __init__(self):
def __init__(self, hasadb=True):
self.hasadb = hasadb
self.logger = get_default_logger()
try:
self.dm = mozdevice.DeviceManagerADB(runAdbAsRoot=True)
if hasadb:
self.dm = mozdevice.DeviceManagerADB(runAdbAsRoot=True)
except mozdevice.DMError 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
self.logger.debug("Attempting to set up port forwarding for marionette")

def get_via_marionette(self, host='localhost', port=2828):
if self.hasadb:
self.dm.forward("tcp:2828", "tcp:2828")
return run_marionette_script(certdump.js_certdump(), chrome=True, host=host, port=port)

def get_via_marionette(self):
self.dm.forward("tcp:2828", "tcp:2828")
return run_marionette_script(certdump.js_certdump(), chrome=True)


def nssversion_via_marionette(self):
self.dm.forward("tcp:2828", "tcp:2828")
return run_marionette_script(certdump.js_nssversions(), chrome=True)
def nssversion_via_marionette(self, host='localhost', port=2828):
if self.hasadb:
self.dm.forward("tcp:2828", "tcp:2828")
return run_marionette_script(certdump.js_nssversions(), chrome=True, host=host, port=port)


#######################################################################################################################
Expand All @@ -117,12 +120,12 @@ class certdb_info(ExtraTest):
module = sys.modules[__name__]

@classmethod
def run(cls, version=None):
def run(cls, version=None, host='localhost', port=2828, hasadb=True):
logger = get_default_logger()

try:
dumper = certdump()
certs = dumper.get_via_marionette()
dumper = certdump(hasadb)
certs = dumper.get_via_marionette(host, port)
except:
cls.log_status('FAIL', 'Failed to gather information from the device via Marionette.')
return False
Expand All @@ -145,12 +148,12 @@ class nssversion_info(ExtraTest):
module = sys.modules[__name__]

@classmethod
def run(cls, version=None):
def run(cls, version=None, host='localhost', port=2828, hasadb=True):
logger = get_default_logger()

try:
dumper = certdump()
versions = dumper.nssversion_via_marionette()
dumper = certdump(hasadb)
versions = dumper.nssversion_via_marionette(host, port)
except:
cls.log_status('FAIL', 'Failed to gather information from the device via Marionette.')
return False
Expand Down
Loading