コード例 #1
0
def print_execution_header(exe_filepath):
    print("")
    print("--- {} [{}] ---".format(
        ColorString("Executing").yellow,
        ColorString(os.path.basename(exe_filepath)).yellow))
    print("")
    sys.stdout.flush()
コード例 #2
0
def print_signal_exception(signal):
    error_string = "{} ({})".format(signal.name, "0x" + hex(signal.code)[2:].upper())
    message = ColorString("Unit-test executable crashed! {}".format(error_string)).red
    print(message)
    print("")

    recommendation = "Your code logic is likely doing something malicious and needs to be fixed."
    print(ColorString(recommendation).red)
    print("")
コード例 #3
0
def print_execution_footer(exe_filepath, error):
    print("")
    if not error:
        result = ColorString("SUCCESS").green
        filename = ColorString(os.path.basename(exe_filepath)).green
    else:
        result = ColorString("FAILED").red
        filename = ColorString(os.path.basename(exe_filepath)).red
    print("--- {} - Completed [{}] with error code [{}] ---".format(
        result, filename, error))
    print("")
    print("=" * 120)
    sys.stdout.flush()
コード例 #4
0
def print_timeout_expired(timeout):
    message = ColorString("Timeout expired after {} seconds!".format(timeout)).red
    print(message)
    print("")

    recommendation = (
        "Unit-tests should normally be designed to quickly execute and finish.\n"
        "It is likely that you have an infinite loop and need to revise the logic.\n"
        "If you really believe your unit-test is meant to take a long time, invoke scons with an extended timeout.\n"
        "Example timeout of 10 seconds:\n"
        "> scons --timeout=10"
    ).format(timeout)
    print(ColorString(recommendation).red)
    print("")
コード例 #5
0
def main():
    args = get_args()
    dbc_filepath = args.dbc
    output = args.output
    print_only = args.print_only
    dbc_node_name = args.dbc_node_name

    if not os.path.isfile(dbc_filepath):
        print("Unable to find DBC file: [{}]".format(dbc_filepath))
        return 1  # Return early

    try:
        code_writer = CodeWriter(dbc_filepath, dbc_node_name)
    except InvalidDBCNodeError as err:
        print(ColorString(str(err)).red)
        return 1  # Return early

    if not print_only:
        dbc_filename = os.path.basename(dbc_filepath)
        basename, ext = os.path.splitext(os.path.basename(dbc_filepath))
        output_filename = "{}.h".format(basename)

        if output is None:
            output_filepath = output_filename
        elif os.path.isdir(output) or "." not in os.path.basename(output):
            output_filepath = os.path.join(output, output_filename)
        else:
            output_filepath = output

        message = "Generating code [{}] -> [{}]".format(
            dbc_filename, output_filename)
        if dbc_node_name != GENERATE_ALL_NODE_NAME:
            message += " using node [{}]".format(dbc_node_name)
        print(ColorString(message).green)

        if not os.path.isdir(os.path.dirname(output_filepath)):
            os.makedirs(os.path.dirname(output_filepath))
        with open(output_filepath, "w") as file:
            file.write(str(code_writer))
    else:
        print(code_writer)

    return 0
コード例 #6
0
def print_execution_footer(exe_filepath, error, timeout_expired=None):
    print("")
    if not error:
        result = ColorString("SUCCESS").green
        filename = ColorString(os.path.basename(exe_filepath)).green
    else:
        result = ColorString("FAILED").red
        filename = ColorString(os.path.basename(exe_filepath)).red
    print("--- {} - Completed [{}] with error code [{}] ---".format(result, filename, error))
    print("")

    if error:
        if timeout_expired:
            print_timeout_expired(timeout_expired)
        else:
            signal_exception = get_signal_exception(error)
            if signal_exception is not None:
                print_signal_exception(signal_exception)

    print("=" * 120)
    sys.stdout.flush()
コード例 #7
0
 def _get_result_string_colored(self, result):
     result_color_map = {
         self.RESULT_PASSED: ColorString(result).green,
         self.RESULT_FAILED: ColorString(result).red,
     }
     return result_color_map[result]