• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ARMmbed / mbed-os-tools / #457

24 Aug 2024 09:15PM CUT coverage: 0.0% (-59.9%) from 59.947%
#457

push

coveralls-python

web-flow
Merge 7c6dbce13 into c467d6f14

0 of 4902 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/mbed_os_tools/test/cmake_handlers.py
1
# Copyright (c) 2018, Arm Limited and affiliates.
2
# SPDX-License-Identifier: Apache-2.0
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
import re
×
17
import os
×
18
import os.path
×
19

20
from .mbed_greentea_log import gt_logger
×
21

22

23
def load_ctest_testsuite(link_target, binary_type=".bin", verbose=False):
×
24
    """! Loads CMake.CTest formatted data about tests from test directory
25
    @return Dictionary of { test_case : test_case_path } pairs
26
    """
27
    result = {}
×
28
    if link_target is not None:
×
29
        ctest_path = os.path.join(link_target, "test", "CTestTestfile.cmake")
×
30
        try:
×
31
            with open(ctest_path) as ctest_file:
×
32
                for line in ctest_file:
×
33
                    line_parse = parse_ctesttestfile_line(
×
34
                        link_target, binary_type, line, verbose=verbose
35
                    )
36
                    if line_parse:
×
37
                        test_case, test_case_path = line_parse
×
38
                        result[test_case] = test_case_path
×
39
        except:  # noqa: E722
×
40
            pass  # Return empty list if path is not found
×
41
    return result
×
42

43

44
def parse_ctesttestfile_line(link_target, binary_type, line, verbose=False):
×
45
    """! Parse lines of CTestTestFile.cmake file and searches for 'add_test'
46
    @return Dictionary of { test_case : test_case_path } pairs or None if
47
    failed to parse 'add_test' line
48
    @details Example path with CTestTestFile.cmake:
49
    c:/temp/xxx/mbed-sdk-private/build/frdm-k64f-gcc/test/
50

51
    Example format of CTestTestFile.cmake:
52
    # CMake generated Testfile for
53
    # Source directory: c:/temp/xxx/mbed-sdk-private/build/frdm-k64f-gcc/test
54
    # Build directory: c:/temp/xxx/mbed-sdk-private/build/frdm-k64f-gcc/test
55
    #
56
    # This file includes the relevant testing commands required for
57
    # testing this directory and lists subdirectories to be tested as well.
58
    add_test(mbed-test-stdio "mbed-test-stdio")
59
    add_test(mbed-test-call_before_main "mbed-test-call_before_main")
60
    add_test(mbed-test-dev_null "mbed-test-dev_null")
61
    add_test(mbed-test-div "mbed-test-div")
62
    add_test(mbed-test-echo "mbed-test-echo")
63
    add_test(mbed-test-ticker "mbed-test-ticker")
64
    add_test(mbed-test-hello "mbed-test-hello")
65
    """
66
    add_test_pattern = r'[adtesADTES_]{8}\([\w\d_-]+ \"([\w\d_-]+)\"'
×
67
    re_ptrn = re.compile(add_test_pattern)
×
68
    if line.lower().startswith("add_test"):
×
69
        m = re_ptrn.search(line)
×
70
        if m and len(m.groups()) > 0:
×
71
            if verbose:
×
72
                print(m.group(1) + binary_type)
×
73
            test_case = m.group(1)
×
74
            test_case_path = os.path.join(link_target, "test", m.group(1) + binary_type)
×
75
            return test_case, test_case_path
×
76
    return None
×
77

78

79
def list_binaries_for_targets(build_dir="./build", verbose_footer=False):
×
80
    """! Prints tests in target directories, only if tests exist.
81
    @param build_dir Yotta default build directory where tests will be
82
    @param verbose_footer Prints additional "how to use" Greentea footer
83
    @details Skips empty / no tests for target directories.
84
    """
85
    dir = build_dir
×
86
    sub_dirs = (
×
87
        [
88
            os.path.join(dir, o)
89
            for o in os.listdir(dir)
90
            if os.path.isdir(os.path.join(dir, o))
91
        ]
92
        if os.path.exists(dir)
93
        else []
94
    )
95

96
    def count_tests():
×
97
        result = 0
×
98
        for sub_dir in sub_dirs:
×
99
            test_list = load_ctest_testsuite(sub_dir, binary_type="")
×
100
            if len(test_list):
×
101
                for test in test_list:
×
102
                    result += 1
×
103
        return result
×
104

105
    if count_tests():
×
106
        for sub_dir in sub_dirs:
×
107
            target_name = sub_dir.split(os.sep)[-1]
×
108
            gt_logger.gt_log(
×
109
                "available tests for target '%s', location '%s'"
110
                % (target_name, os.path.abspath(os.path.join(build_dir, sub_dir)))
111
            )
112
            test_list = load_ctest_testsuite(sub_dir, binary_type="")
×
113
            if len(test_list):
×
114
                for test in sorted(test_list):
×
115
                    gt_logger.gt_log_tab("test '%s'" % test)
×
116
    else:
117
        gt_logger.gt_log_warn("no tests found in current location")
×
118

119
    if verbose_footer:
×
120
        print(
×
121
            "\nExample: execute 'mbedgt -t TARGET_NAME -n TEST_NAME' to run "
122
            "test TEST_NAME for target TARGET_NAME"
123
        )
124

125

126
def list_binaries_for_builds(test_spec, verbose_footer=False):
×
127
    """! Parse test spec and list binaries (BOOTABLE) in lexicographical order
128
    @param test_spec Test specification object
129
    @param verbose_footer Prints additional "how to use" Greentea footer
130
    """
131
    test_builds = test_spec.get_test_builds()
×
132
    for tb in test_builds:
×
133
        gt_logger.gt_log(
×
134
            "available tests for build '%s', location '%s'"
135
            % (tb.get_name(), tb.get_path())
136
        )
137
        for tc in sorted(tb.get_tests().keys()):
×
138
            gt_logger.gt_log_tab("test '%s'" % tc)
×
139

140
    if verbose_footer:
×
141
        print(
×
142
            "\nExample: execute 'mbedgt -t BUILD_NAME -n TEST_NAME' to run test "
143
            "TEST_NAME for build TARGET_NAME in current test specification"
144
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc