Example #1
0
def test_config(name):
    """Run a particular configuration test

    :param name: test name (same as directory name)
    """
    test_dir = join(root_dir, name)
    test_data = json.load(open(data_path(test_dir)))
    targets_json = os.path.join(test_dir, "targets.json")
    set_targets_json_location(targets_json if isfile(targets_json) else None)
    for target, expected in test_data.items():
        try:
            cfg, macros, features = get_config(test_dir, target, "GCC_ARM")
            res = compare_config(cfg, expected)
            assert not(res), res
            expected_macros = expected.get("expected_macros", None)
            expected_features = expected.get("expected_features", None)

            if expected_macros is not None:
                macros = Config.config_macros_to_macros(macros)
                assert sorted(expected_macros) == sorted(macros)
            if expected_features is not None:
                assert sorted(expected_features) == sorted(features)
        except ConfigException as e:
            err_msg = str(e)
            if "exception_msg" not in expected:
                assert not(err_msg), "Unexpected Error: %s" % e
            else:
                assert expected["exception_msg"] in err_msg
def test_config(name):
    """Run a particular configuration test

    :param name: test name (same as directory name)
    """
    test_dir = join(root_dir, name)
    test_data = json.load(open(data_path(test_dir)))
    targets_json = os.path.join(test_dir, "targets.json")
    set_targets_json_location(targets_json if isfile(targets_json) else None)
    for target, expected in test_data.items():
        try:
            cfg, macros, features = get_config(test_dir, target, "GCC_ARM")
            res = compare_config(cfg, expected)
            assert not (res), res
            expected_macros = expected.get("expected_macros", None)
            expected_features = expected.get("expected_features", None)

            if expected_macros is not None:
                macros = Config.config_macros_to_macros(macros)
                assert sorted(expected_macros) == sorted(macros)
            if expected_features is not None:
                assert sorted(expected_features) == sorted(features)
        except ConfigException as e:
            err_msg = str(e)
            if "exception_msg" not in expected:
                assert not (err_msg), "Unexpected Error: %s" % e
            else:
                assert expected["exception_msg"] in err_msg
Example #3
0
def test_tree(full_name, name):
    failed = 0
    sys.path.append(full_name)
    if "test_data" in sys.modules:
        del sys.modules["test_data"]
    import test_data
    for target, expected in test_data.expected_results.items():
        sys.stdout.write("%s:'%s'(%s) " % (name, expected["desc"], target))
        sys.stdout.flush()
        err_msg = None
        try:
            cfg, macros = get_config(full_name, target, "GCC_ARM")
        except ConfigException as e:
            err_msg = e.message
        if err_msg:
            if expected.has_key("exception_msg"):
                if err_msg.find(expected["exception_msg"]) == -1:
                    print "FAILED!"
                    sys.stderr.write("    Unexpected error message!\n")
                    sys.stderr.write("    Expected: '%s'\n" %
                                     expected["exception_msg"])
                    sys.stderr.write("    Got: '%s'\n" % err_msg)
                    failed += 1
                else:
                    print "OK"
            else:
                print "FAILED!"
                sys.stderr.write("    Error while getting configuration!\n")
                sys.stderr.write("    " + err_msg + "\n")
                failed += 1
        else:
            res = compare_config(cfg, expected)
            if res:
                print "FAILED!"
                sys.stdout.write("    " + res + "\n")
                failed += 1
            else:
                expected_macros = expected.get("expected_macros", None)
                if expected_macros is not None:
                    if sorted(expected_macros) != sorted(macros):
                        print "FAILED!"
                        sys.stderr.write("    List of macros doesn't match\n")
                        sys.stderr.write("    Expected: '%s'\n" %
                                         ",".join(sorted(expected_macros)))
                        sys.stderr.write("    Got: '%s'\n" %
                                         ",".join(sorted(expected_macros)))
                        failed += 1
                    else:
                        print "OK"
                else:
                    print "OK"
    sys.path.remove(full_name)
    return failed
Example #4
0
def test_config(name):
    """Run a particular configuration test

    :param name: test name (same as directory name)
    """
    test_dir = join(root_dir, name)
    test_data = json.load(open(data_path(test_dir)))
    targets_json = os.path.join(test_dir, "targets.json")
    set_targets_json_location(targets_json if isfile(targets_json) else None)
    for target, expected in test_data.items():
        try:
            cfg, macros, features, resources = get_config(
                test_dir, target, "GCC_ARM")
            res = compare_config(cfg, expected)
            assert not (res), res
            expected_macros = expected.get("expected_macros", None)
            expected_features = expected.get("expected_features", None)

            if expected_macros is not None:
                macros = Config.config_macros_to_macros(macros)
                assert sorted(expected_macros) == sorted(macros)
            if expected_features is not None:
                assert sorted(expected_features) == sorted(features)

            included_source = [
                normpath(join(test_dir, src))
                for src in expected.get("included_source", [])
            ]
            excluded_source = [
                normpath(join(test_dir, src))
                for src in expected.get("excluded_source", [])
            ]
            for typ in Resources.ALL_FILE_TYPES:
                for _, path in resources.get_file_refs(typ):
                    path = normpath(path)
                    if included_source and path in included_source:
                        included_source.remove(path)
                    if excluded_source:
                        assert (path not in excluded_source)
            assert (not included_source)
            if included_source:
                assert (False)
        except ConfigException as e:
            err_msg = str(e)
            if "exception_msg" not in expected:
                assert not (err_msg), "Unexpected Error: %s" % e
            else:
                assert expected["exception_msg"] in err_msg
Example #5
0
    options = parser.parse_args()

    # Target
    if options.mcu is None :
        args_error(parser, "argument -m/--mcu is required")
    target = options.mcu[0]

    # Toolchain
    if options.tool is None:
        args_error(parser, "argument -t/--toolchain is required")
    toolchain = options.tool[0]

    options.prefix = options.prefix or [""]

    try:
        params, macros, features = get_config(options.source_dir, target, toolchain)
        if not params and not macros:
            print "No configuration data available."
            _exit(0)
        if params:
            print "Configuration parameters"
            print "------------------------"
            for p in params:
                for s in options.prefix:
                    if p.startswith(s):
                        print(str(params[p]) if not options.verbose else params[p].get_verbose_description())
                        break
            print ""

        print "Macros"
        print "------"
Example #6
0
    options = parser.parse_args()

    # Target
    if options.mcu is None:
        args_error(parser, "argument -m/--mcu is required")
    target = options.mcu[0]

    # Toolchain
    if options.tool is None:
        args_error(parser, "argument -t/--toolchain is required")
    toolchain = options.tool[0]

    options.prefix = options.prefix or [""]

    try:
        params, macros, features = get_config(options.source_dir, target,
                                              toolchain)
        if not params and not macros:
            print "No configuration data available."
            _exit(0)
        if params:
            print "Configuration parameters"
            print "------------------------"
            for p in params:
                for s in options.prefix:
                    if p.startswith(s):
                        print(
                            str(params[p]) if not options.verbose else
                            params[p].get_verbose_description())
                        break
            print ""
Example #7
0
                        default=False,
                        help="Verbose diagnostic output")

    options = parser.parse_args()

    # Target
    if options.mcu is None:
        args_error(parser, "argument -m/--mcu is required")
    target = extract_mcus(parser, options)[0]

    options.prefix = options.prefix or [""]

    try:
        params, macros, features, _ = get_config(
            options.source_dir,
            target,
            options.tool[0] if options.tool else None,
            app_config=options.app_config)
        if not params and not macros:
            print("No configuration data available.")
            sys.exit(0)
        if params:
            print("Configuration parameters")
            print("------------------------")
            for p in sorted(list(params.keys())):
                if any(p.startswith(s) for s in options.prefix):
                    if options.verbose:
                        print(params[p].get_verbose_description())
                    else:
                        print(str(params[p]))
            print("")
Example #8
0
def test_tree(full_name, name):
    failed = 0
    sys.path.append(full_name)
    if "test_data" in sys.modules:
        del sys.modules["test_data"]
    import test_data
    # If the test defines custom targets, they must exist in a file called
    # "targets.json" in the test's directory.
    if os.path.isfile(os.path.join(full_name, "targets.json")):
        set_targets_json_location(os.path.join(full_name, "targets.json"))
    else:  # uset the regular set of targets
        set_targets_json_location()
    for target, expected in test_data.expected_results.items():
        sys.stdout.write("%s:'%s'(%s) " % (name, expected["desc"], target))
        sys.stdout.flush()
        err_msg = None
        try:
            cfg, macros, features = get_config(full_name, target, "GCC_ARM")
            macros = Config.config_macros_to_macros(macros)
        except ConfigException as e:
            err_msg = e.message
        if err_msg:
            if expected.has_key("exception_msg"):
                if err_msg.find(expected["exception_msg"]) == -1:
                    print "FAILED!"
                    sys.stderr.write("    Unexpected error message!\n")
                    sys.stderr.write("    Expected: '%s'\n" %
                                     expected["exception_msg"])
                    sys.stderr.write("    Got: '%s'\n" % err_msg)
                    failed += 1
                else:
                    print "OK"
            else:
                print "FAILED!"
                sys.stderr.write("    Error while getting configuration!\n")
                sys.stderr.write("    " + err_msg + "\n")
                failed += 1
        else:
            res = compare_config(cfg, expected)
            expected_macros = expected.get("expected_macros", None)
            expected_features = expected.get("expected_features", None)

            if res:
                print "FAILED!"
                sys.stdout.write("    " + res + "\n")
                failed += 1
            elif expected_macros is not None:
                if sorted(expected_macros) != sorted(macros):
                    print "FAILED!"
                    sys.stderr.write("    List of macros doesn't match\n")
                    sys.stderr.write("    Expected: '%s'\n" %
                                     ",".join(sorted(expected_macros)))
                    sys.stderr.write("    Got: '%s'\n" %
                                     ",".join(sorted(expected_macros)))
                    failed += 1
                else:
                    print "OK"
            elif expected_features is not None:
                if sorted(expected_features) != sorted(features):
                    print "FAILED!"
                    sys.stderr.write("    List of features doesn't match\n")
                    sys.stderr.write("    Expected: '%s'\n" %
                                     ",".join(sorted(expected_features)))
                    sys.stderr.write("    Got: '%s'\n" %
                                     ",".join(sorted(expected_features)))
                    failed += 1
                else:
                    print "OK"
            else:
                print "OK"
    sys.path.remove(full_name)
    return failed
def test_tree(full_name, name):
    failed = 0
    sys.path.append(full_name)
    if "test_data" in sys.modules:
       del sys.modules["test_data"]
    import test_data
    for target, expected in test_data.expected_results.items():
        sys.stdout.write("%s:'%s'(%s) " % (name, expected["desc"], target))
        sys.stdout.flush()
        err_msg = None
        try:
            # Use 'set_targets_json_location' to remove the previous custom targets from the target list
            set_targets_json_location(Target._Target__targets_json_location)
            cfg, macros, features = get_config(full_name, target, "GCC_ARM")
            macros = Config.config_macros_to_macros(macros)
        except ConfigException as e:
            err_msg = e.message
        if err_msg:
            if expected.has_key("exception_msg"):
                if err_msg.find(expected["exception_msg"]) == -1:
                    print "FAILED!"
                    sys.stderr.write("    Unexpected error message!\n")
                    sys.stderr.write("    Expected: '%s'\n" % expected["exception_msg"])
                    sys.stderr.write("    Got: '%s'\n" % err_msg)
                    failed += 1
                else:
                    print "OK"
            else:
                print "FAILED!"
                sys.stderr.write("    Error while getting configuration!\n")
                sys.stderr.write("    " + err_msg + "\n")
                failed += 1
        else:
            res = compare_config(cfg, expected)
            expected_macros = expected.get("expected_macros", None)
            expected_features = expected.get("expected_features", None)

            if res:
                print "FAILED!"
                sys.stdout.write("    " + res + "\n")
                failed += 1
            elif expected_macros is not None:
                if sorted(expected_macros) != sorted(macros):
                    print "FAILED!"
                    sys.stderr.write("    List of macros doesn't match\n")
                    sys.stderr.write("    Expected: '%s'\n" % ",".join(sorted(expected_macros)))
                    sys.stderr.write("    Got: '%s'\n" % ",".join(sorted(expected_macros)))
                    failed += 1
                else:
                    print "OK"
            elif expected_features is not None:
                if sorted(expected_features) != sorted(features):
                    print "FAILED!"
                    sys.stderr.write("    List of features doesn't match\n")
                    sys.stderr.write("    Expected: '%s'\n" % ",".join(sorted(expected_features)))
                    sys.stderr.write("    Got: '%s'\n" % ",".join(sorted(expected_features)))
                    failed += 1
                else:
                    print "OK"
            else:
                print "OK"
    sys.path.remove(full_name)
    return failed