Skip to content

Commit

Permalink
Added --list switch, you can now list all test case binaries' names i…
Browse files Browse the repository at this point in the history
…n target directory
  • Loading branch information
PrzemekWirkus committed May 21, 2015
1 parent 90c4d32 commit 75a4cf7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 23 deletions.
51 changes: 36 additions & 15 deletions mbed_greentea/cmake_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,61 @@

import re
import os
import os.path


def load_ctest_testsuite(link_target, binary_type='.bin', verbose=False):
""" Loads CMake.CTest formatted data about tests from test directory
Example path with CTestTestFile.cmake:
c:/temp/xxx/mbed-sdk-private/build/frdm-k64f-gcc/test/
Example format of CTestTestFile.cmake:
# CMake generated Testfile for
# CMake generated Testfile for
# Source directory: c:/temp/xxx/mbed-sdk-private/build/frdm-k64f-gcc/test
# Build directory: c:/temp/xxx/mbed-sdk-private/build/frdm-k64f-gcc/test
#
# This file includes the relevant testing commands required for
#
# This file includes the relevant testing commands required for
# testing this directory and lists subdirectories to be tested as well.
add_test(mbed-test-stdio "mbed-test-stdio")
add_test(mbed-test-call_before_main "mbed-test-call_before_main")
add_test(mbed-test-dev_null "mbed-test-dev_null")
add_test(mbed-test-div "mbed-test-div")
add_test(mbed-test-echo "mbed-test-echo")
add_test(mbed-test-ticker "mbed-test-ticker")
add_test(mbed-test-hello "mbed-test-hello")
add_test(mbed-test-hello "mbed-test-hello")
"""
result = {}
add_test_pattern = '[adtesADTES_]{8}\([\w\d_-]+ \"([\w\d_-]+)\"'
re_ptrn = re.compile(add_test_pattern)
if link_target is not None:
ctest_path = os.path.join(link_target, 'test', 'CTestTestfile.cmake')
with open(ctest_path) as ctest_file:
for line in ctest_file:
if line.lower().startswith('add_test'):
m = re_ptrn.search(line)
if m and len(m.groups()) > 0:
if verbose:
print m.group(1) + binary_type
result[m.group(1)] = os.path.join(link_target, 'test', m.group(1) + binary_type)
try:
with open(ctest_path) as ctest_file:
for line in ctest_file:
if line.lower().startswith('add_test'):
m = re_ptrn.search(line)
if m and len(m.groups()) > 0:
if verbose:
print m.group(1) + binary_type
result[m.group(1)] = os.path.join(link_target, 'test', m.group(1) + binary_type)
except:
pass # Return empty list if path is not found
return result

def list_binaries_for_targets(build_dir='./build'):
""" Prints tests in target directories, only if tests exist.
Skips empty / no tests for target directories.
"""
dir = build_dir
sub_dirs = [os.path.join(dir, o) for o in os.listdir(dir) if os.path.isdir(os.path.join(dir, o))]
print "mbedgt: available tests for built targets"
for sub_dir in sub_dirs:
test_list = load_ctest_testsuite(sub_dir, binary_type='')
if len(test_list):
print "target '%s':" % sub_dir.split(os.sep)[-1]
for test in test_list:
print "\ttest '%s'" % test
print
print "Example: execute 'mbedgt --target=TARGET_NAME -n TEST_NAME' to run TEST_NAME test only"
20 changes: 12 additions & 8 deletions mbed_greentea/mbed_greentea_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from mbed_test_api import run_cli_command
from mbed_test_api import TEST_RESULTS
from cmake_handlers import load_ctest_testsuite
from cmake_handlers import list_binaries_for_targets
from mbed_target_info import get_mbed_clasic_target_info
from mbed_target_info import get_mbed_supported_test

Expand All @@ -42,14 +43,6 @@
MBED_HOST_TESTS = 'mbed_host_tests' in sys.modules


# git clone repository
# cd repo
# yotta target frdm-....
# yt build
#
# yt --target=frdm-XXXX,* build
#

def main():

if not MBED_LMTOOLS:
Expand Down Expand Up @@ -100,6 +93,12 @@ def main():
action="store_true",
help='If possible force build in debug mode (yotta -d).')

parser.add_option('', '--list',
dest='list_binaries',
default=False,
action="store_true",
help='List available binaries')

parser.add_option('', '--digest',
dest='digest_source',
help='Redirect input from where test suite should take console input. You can use stdin or file name to get test case console output')
Expand All @@ -121,6 +120,11 @@ def main():

(opts, args) = parser.parse_args()

# List available test binaries (names, no extension)
if opts.list_binaries:
list_binaries_for_targets()
exit(0)

# Capture alternative test console inputs
if opts.digest_source:
host_test_result = run_host_test(image_path=None, disk=None, port=None,
Expand Down

0 comments on commit 75a4cf7

Please sign in to comment.