Ejemplo n.º 1
0
        LOG_HANDLE = open(ARGS.l, "w")
        if LOG_HANDLE:
            print("{}: writing log output to \"{}\".".format(PROMPT, ARGS.l))
        else:
            SUCCESS = False
            print("{}: unable to open log file \"{}\" for writing.".format(
                PROMPT, ARGS.l))
    if SUCCESS:
        # Set up a printer, with a None queue
        # since we're only running one instance
        # from here
        PRINTER = u_utils.PrintToQueue(None, LOG_HANDLE)

        # Make the connection
        CONNECTION_TYPE = CONNECTION_SERIAL
        CONNECTION_HANDLE = u_utils.open_serial(ARGS.port, 115200, PRINTER,
                                                PROMPT)
        if CONNECTION_HANDLE is None:
            CONNECTION_TYPE = CONNECTION_TELNET
            CONNECTION_HANDLE = u_utils.open_telnet(ARGS.port, PRINTER, PROMPT)
        if CONNECTION_HANDLE is None:
            CONNECTION_TYPE = CONNECTION_PIPE
            PROCESS_HANDLE, CONNECTION_HANDLE = start_exe(
                ARGS.port, PRINTER, PROMPT)
        if CONNECTION_HANDLE is not None:
            # Open the report file
            if ARGS.x:
                TEST_REPORT_HANDLE = open(ARGS.x, "w")
                if TEST_REPORT_HANDLE:
                    print("{}: writing test report to \"{}\".".format(
                        PROMPT, ARGS.x))
                else:
Ejemplo n.º 2
0
def run(instance, mcu, toolchain, connection, connection_lock,
        platform_lock, misc_locks, clean, defines, ubxlib_dir,
        working_dir, printer, reporter, test_report_handle):
    '''Build/run on ESP-IDF'''
    return_value = -1
    instance_text = u_utils.get_instance_text(instance)
    filter_string = "*\r\n"

    # No issues with running in parallel on ESP-IDF
    del platform_lock

    # Only one toolchain for ESP-IDF
    del toolchain

    prompt = PROMPT + instance_text + ": "

    # Print out what we've been told to do
    text = "running ESP-IDF for " + mcu
    if connection and connection["serial_port"]:
        text += ", on serial port " + connection["serial_port"]
    if clean:
        text += ", clean build"
    if defines:
        text += ", with #define(s)"
        for idx, define in enumerate(defines):
            if idx == 0:
                text += " \"" + define + "\""
            else:
                text += ", \"" + define + "\""
    if ubxlib_dir:
        text += ", ubxlib directory \"" + ubxlib_dir + "\""
    if working_dir:
        text += ", working directory \"" + working_dir + "\""
    printer.string("{}{}.".format(prompt, text))

    reporter.event(u_report.EVENT_TYPE_BUILD,
                   u_report.EVENT_START,
                   "ESP-IDF")
    printer.string("{}CD to {}...".format(prompt, working_dir))
    with u_utils.ChangeDir(working_dir):
        # Fetch ESP-IDF into the right sub directory
        # and install the tools
        esp_idf_location = get_esp_idf_location(instance)
        esp_idf_dir = ESP_IDF_ROOT + os.sep + esp_idf_location["subdir"]
        if esp_idf_location:
            system_lock = None
            if misc_locks and ("system_lock" in misc_locks):
                system_lock = misc_locks["system_lock"]
            returned_env = install(esp_idf_location["url"], esp_idf_dir,
                                   esp_idf_location["branch"], system_lock,
                                   printer, prompt, reporter)
            if returned_env:
                # From here on the ESP-IDF tools need to set up
                # and use the set of environment variables
                # returned above.
                print_env(returned_env, printer, prompt)
                # Now do the build
                build_dir = working_dir + os.sep + BUILD_SUBDIR
                build_start_time = time()
                if build(esp_idf_dir, ubxlib_dir, build_dir,
                         defines, returned_env, clean,
                         printer, prompt, reporter):
                    reporter.event(u_report.EVENT_TYPE_BUILD,
                                   u_report.EVENT_PASSED,
                                   "build took {:.0f} second(s)". \
                                   format(time() - build_start_time))
                    with u_connection.Lock(connection, connection_lock,
                                           CONNECTION_LOCK_GUARD_TIME_SECONDS,
                                           printer, prompt) as locked:
                        if locked:
                            # Have seen this fail, only with Python 3 for
                            # some reason, so give it a few goes
                            reporter.event(u_report.EVENT_TYPE_DOWNLOAD,
                                           u_report.EVENT_START)
                            retries = 0
                            while not download(esp_idf_dir, ubxlib_dir, build_dir,
                                               connection["serial_port"], returned_env,
                                               printer, prompt) and (retries < 3):
                                reporter.event(u_report.EVENT_TYPE_DOWNLOAD,
                                               u_report.EVENT_WARNING,
                                               "unable to download, will retry...")
                                retries += 1
                                sleep(5)
                            if retries < 3:
                                reporter.event(u_report.EVENT_TYPE_DOWNLOAD,
                                               u_report.EVENT_COMPLETE)
                                reporter.event(u_report.EVENT_TYPE_TEST,
                                               u_report.EVENT_START)
                                # Search the defines list to see if it includes a
                                # "U_CFG_APP_FILTER=blah" item.  On ESP32 the tests
                                # that are run are not selected at compile time,
                                # they are selected by sending the "blah" string
                                # over the COM port where it must match a "module name",
                                # a thing in [square brackets] which our naming convention
                                # dictates will be an API name (e.g. "port") or "example".
                                for define in defines:
                                    tmp = u_utils.FILTER_MACRO_NAME + "="
                                    if define.startswith(tmp):
                                        filter_string = define[len(tmp):]
                                        reporter.event(u_report.EVENT_TYPE_TEST,
                                                       u_report.EVENT_INFORMATION,
                                                       "only running module \"" +
                                                       filter_string + "\"")
                                        printer.string("{} will use filter [{}].".   \
                                                       format(prompt, filter_string))
                                        # Add the top and tail it needs for sending
                                        filter_string = "[" + filter_string + "]\r\n"
                                        break
                                # Open the COM port to get debug output
                                serial_handle = u_utils.open_serial(connection["serial_port"],
                                                                    115200, printer, prompt)
                                if serial_handle is not None:
                                    # Monitor progress
                                    return_value = u_monitor.main(serial_handle,
                                                                  u_monitor.CONNECTION_SERIAL,
                                                                  RUN_GUARD_TIME_SECONDS,
                                                                  RUN_INACTIVITY_TIME_SECONDS,
                                                                  instance, printer, reporter,
                                                                  test_report_handle,
                                                                  send_string=filter_string)
                                    serial_handle.close()
                                else:
                                    reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                                                   u_report.EVENT_FAILED,
                                                   "unable to open serial port " +      \
                                                   connection["serial_port"])
                                if return_value == 0:
                                    reporter.event(u_report.EVENT_TYPE_TEST,
                                                   u_report.EVENT_COMPLETE)
                                else:
                                    reporter.event(u_report.EVENT_TYPE_TEST,
                                                   u_report.EVENT_FAILED)
                            else:
                                reporter.event(u_report.EVENT_TYPE_DOWNLOAD,
                                               u_report.EVENT_FAILED,
                                               "unable to download to the target")
                        else:
                            reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                                           u_report.EVENT_FAILED,
                                           "unable to lock a connection")
                else:
                    reporter.event(u_report.EVENT_TYPE_BUILD,
                                   u_report.EVENT_FAILED,
                                   "unable to build, check debug log for details")
            else:
                reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                               u_report.EVENT_FAILED,
                               "tools installation failed")
        else:
            reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                           u_report.EVENT_FAILED,
                           "don't have ESP-IDF URL for this instance")
            printer.string("{}error: don't have ESP-IDF URL instance {}.".
                           format(prompt, instance_text))

    return return_value
Ejemplo n.º 3
0
def run(instance,
        mcu,
        board,
        toolchain,
        connection,
        connection_lock,
        platform_lock,
        misc_locks,
        clean,
        defines,
        ubxlib_dir,
        working_dir,
        printer,
        reporter,
        test_report_handle,
        keep_going_flag=None,
        unity_dir=None):
    '''Build/run on Arduino'''
    return_value = -1
    monitor_dtr_rts_on = None
    installed = False
    sketch_paths = []
    build_paths = []
    return_values = []
    instance_text = u_utils.get_instance_text(instance)

    # None of the misc locks are required
    del misc_locks

    # Since we only currently support ESP-IDF we don't need
    # unity as ESP-IDF already has a copy built in
    del unity_dir

    prompt = PROMPT + instance_text + ": "

    toolchain = toolchain.lower()

    # Print out what we've been told to do and at the
    # same time check for the DTR/RTS off marker
    text = "running Arduino for " + mcu + " with SDK " + toolchain + \
           " on board with FQBN \"" + board + "\""
    if connection and connection["serial_port"]:
        text += ", serial port " + connection["serial_port"]
    if clean:
        text += ", clean build"
    if defines:
        text += ", with #define(s)"
        for idx, define in enumerate(defines):
            if define == MONITOR_DTR_RTS_OFF_MARKER:
                monitor_dtr_rts_on = False
            if idx == 0:
                text += " \"" + define + "\""
            else:
                text += ", \"" + define + "\""
    if ubxlib_dir:
        text += ", ubxlib directory \"" + ubxlib_dir + "\""
    if working_dir:
        text += ", working directory \"" + working_dir + "\""
    printer.string("{}{}.".format(prompt, text))

    reporter.event(u_report.EVENT_TYPE_BUILD, u_report.EVENT_START, "Arduino")
    printer.string("{}CD to {}...".format(prompt, working_dir))

    with u_utils.ChangeDir(working_dir):
        # Lock the Arduino platform while we install the tools
        with u_utils.Lock(platform_lock, PLATFORM_LOCK_GUARD_TIME_SECONDS,
                          "platform", printer, prompt,
                          keep_going_flag) as locked_platform:
            if locked_platform:
                installed = install(board, ARDUINO_BOARDS_URLS, printer,
                                    prompt, keep_going_flag)

        if installed:
            arduino_dir = os.path.join(ubxlib_dir, ARDUINO_SUB_DIR)
            library_path = os.path.join(working_dir, LIBRARIES_SUB_DIR)
            # Clear out any pre-built ubxlib library or rebuilds
            # won't pick up changes
            clear_prebuilt_library(os.path.join(library_path, LIBRARY_NAME),
                                   mcu, printer, prompt)
            # Create the ubxlib Arduino library
            if create_library(ubxlib_dir, arduino_dir, toolchain,
                              os.path.join(library_path, LIBRARY_NAME),
                              LIBRARY_NAME_LIB_POSTFIX, clean, printer, prompt,
                              keep_going_flag):
                # Create the ubxlib Arduino test library
                if create_library(ubxlib_dir, arduino_dir, toolchain,
                                  os.path.join(library_path, LIBRARY_NAME),
                                  LIBRARY_NAME_TEST_POSTFIX, clean, printer,
                                  prompt, keep_going_flag):
                    # We now build both libraries with the test sketch and we also
                    # build the examples with the just the ubxlib Arduino library.
                    # Make a list of the sketches to build
                    sketch_paths.append(
                        os.path.join(arduino_dir, TEST_SKETCH_SUB_PATH))
                    for root, _directories, files in os.walk(library_path):
                        for file in files:
                            if os.sep + "examples" + os.sep in root and file.endswith(
                                    ".ino"):
                                sketch_paths.append(os.path.join(root, file))
                    printer.string("{}{} thing(s) to build.".format(
                        prompt, len(sketch_paths)))
                    # Build the sketches: note that the first build of the ubxlib
                    # Arduino library to a .a file will be copied back into the library
                    # directory for use in the following builds
                    build_dir = os.path.join(working_dir, BUILD_SUBDIR)
                    for sketch_path in sketch_paths:
                        build_start_time = time()
                        build_path = build(build_dir, sketch_path,
                                           library_path, mcu, board, defines,
                                           clean, printer, prompt, reporter,
                                           keep_going_flag)
                        if not u_utils.keep_going(keep_going_flag, printer,
                                                  prompt) or not build_path:
                            break
                        build_paths.append(build_path)
                        reporter.event(u_report.EVENT_TYPE_BUILD,
                                       u_report.EVENT_PASSED,
                                       "build {} of {} took {:.0f} second(s)". \
                                       format(len(build_paths), len(sketch_paths),
                                              time() - build_start_time))
                    if len(build_paths) == len(sketch_paths):
                        # Download and run the builds
                        with u_connection.Lock(
                                connection, connection_lock,
                                CONNECTION_LOCK_GUARD_TIME_SECONDS, printer,
                                prompt, keep_going_flag) as locked:
                            if locked:
                                for build_path in build_paths:
                                    # I have seen download failures occur if two
                                    # are initiated at the same time so lock the
                                    # platform for this
                                    downloaded = False
                                    with u_utils.Lock(
                                            platform_lock,
                                            PLATFORM_LOCK_GUARD_TIME_SECONDS,
                                            "platform", printer, prompt,
                                            keep_going_flag
                                    ) as locked_platform:
                                        if locked_platform:
                                            # Have seen this fail, so give it a few goes
                                            reporter.event(
                                                u_report.EVENT_TYPE_DOWNLOAD,
                                                u_report.EVENT_START)
                                            retries = 0
                                            while u_utils.keep_going(keep_going_flag, printer,
                                                                     prompt) and               \
                                                  not downloaded and (retries < 3):
                                                downloaded = download(
                                                    build_path, board,
                                                    connection["serial_port"],
                                                    printer, prompt,
                                                    keep_going_flag)
                                                if not downloaded:
                                                    reporter.event(u_report.EVENT_TYPE_DOWNLOAD,
                                                                   u_report.EVENT_WARNING,
                                                                   "unable to download, will" \
                                                                   " retry...")
                                                    retries += 1
                                                    sleep(5)
                                    if downloaded:
                                        reporter.event(
                                            u_report.EVENT_TYPE_DOWNLOAD,
                                            u_report.EVENT_COMPLETE)
                                        reporter.event(
                                            u_report.EVENT_TYPE_TEST,
                                            u_report.EVENT_START)
                                        # Open the COM port to get debug output
                                        serial_handle = u_utils.open_serial(
                                            connection["serial_port"],
                                            115200,
                                            printer,
                                            prompt,
                                            dtr_set_on=monitor_dtr_rts_on,
                                            rts_set_on=monitor_dtr_rts_on)
                                        if serial_handle is not None:
                                            # Monitor progress
                                            return_values.append(
                                                u_monitor.main(
                                                    serial_handle,
                                                    u_monitor.
                                                    CONNECTION_SERIAL,
                                                    RUN_GUARD_TIME_SECONDS,
                                                    RUN_INACTIVITY_TIME_SECONDS,
                                                    "\r",
                                                    instance,
                                                    printer,
                                                    reporter,
                                                    test_report_handle,
                                                    keep_going_flag=
                                                    keep_going_flag))
                                            # Delays and flushes here to make sure
                                            # that the serial port actually closes
                                            # since we might need to re-open it for
                                            # another download going around the loop
                                            serial_handle.cancel_read()
                                            sleep(1)
                                            serial_handle.reset_input_buffer()
                                            serial_handle.reset_output_buffer()
                                            sleep(1)
                                            serial_handle.close()
                                            reporter.event(
                                                u_report.
                                                EVENT_TYPE_INFRASTRUCTURE,
                                                u_report.EVENT_COMPLETE,
                                                "serial port closed")
                                            sleep(5)
                                        else:
                                            reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                                                           u_report.EVENT_FAILED,
                                                           "unable to open serial port " +      \
                                                           connection["serial_port"])
                                        if return_values and return_values[
                                                -1] == 0:
                                            reporter.event(
                                                u_report.EVENT_TYPE_TEST,
                                                u_report.EVENT_COMPLETE)
                                        else:
                                            reporter.event(
                                                u_report.EVENT_TYPE_TEST,
                                                u_report.EVENT_FAILED)
                                    else:
                                        reporter.event(
                                            u_report.EVENT_TYPE_DOWNLOAD,
                                            u_report.EVENT_FAILED,
                                            "unable to download to the target")
                                if return_values:
                                    return_value = 0
                                    for item in return_values:
                                        # If a return value goes negative then
                                        # only count the negative values, i.e. the
                                        # number of infrastructure failures
                                        if (item < 0) and (return_value >= 0):
                                            return_value = item
                                        else:
                                            if (((item > 0) and (return_value >= 0)) or  \
                                                ((item < 0) and (return_value < 0))):
                                                return_value += item
                            else:
                                reporter.event(
                                    u_report.EVENT_TYPE_INFRASTRUCTURE,
                                    u_report.EVENT_FAILED,
                                    "unable to lock a connection")
                    else:
                        reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                                       u_report.EVENT_FAILED, "failed a build")
                else:
                    reporter.event(
                        u_report.EVENT_TYPE_BUILD, u_report.EVENT_FAILED,
                        "unable to build library, check debug log for details")
            else:
                reporter.event(
                    u_report.EVENT_TYPE_INFRASTRUCTURE, u_report.EVENT_FAILED,
                    "unable to create library, check debug log for details")
        else:
            reporter.event(
                u_report.EVENT_TYPE_INFRASTRUCTURE, u_report.EVENT_FAILED,
                "unable to install tools, check debug log for details")

    return return_value
Ejemplo n.º 4
0
def run(instance,
        mcu,
        toolchain,
        connection,
        connection_lock,
        platform_lock,
        misc_locks,
        clean,
        defines,
        ubxlib_dir,
        working_dir,
        printer,
        reporter,
        test_report_handle,
        keep_going_flag=None):
    '''Build/run on ESP-IDF'''
    return_value = -1
    monitor_dtr_rts_on = None
    instance_text = u_utils.get_instance_text(instance)

    # No issues with running in parallel on ESP-IDF
    del platform_lock

    # Only one toolchain for ESP-IDF
    del toolchain

    prompt = PROMPT + instance_text + ": "

    # Print out what we've been told to do and at the
    # same time check for the DTR/RTS off marker
    text = "running ESP-IDF for " + mcu
    if connection and connection["serial_port"]:
        text += ", on serial port " + connection["serial_port"]
    if clean:
        text += ", clean build"
    if defines:
        text += ", with #define(s)"
        for idx, define in enumerate(defines):
            if define == MONITOR_DTR_RTS_OFF_MARKER:
                monitor_dtr_rts_on = False
            if idx == 0:
                text += " \"" + define + "\""
            else:
                text += ", \"" + define + "\""
    if ubxlib_dir:
        text += ", ubxlib directory \"" + ubxlib_dir + "\""
    if working_dir:
        text += ", working directory \"" + working_dir + "\""
    printer.string("{}{}.".format(prompt, text))

    reporter.event(u_report.EVENT_TYPE_BUILD, u_report.EVENT_START, "ESP-IDF")
    printer.string("{}CD to {}...".format(prompt, working_dir))
    with u_utils.ChangeDir(working_dir):
        # Fetch ESP-IDF into the right sub directory
        # and install the tools
        esp_idf_dir = ESP_IDF_ROOT + os.sep + ESP_IDF_LOCATION["subdir"]
        system_lock = None
        if u_utils.keep_going(keep_going_flag, printer, prompt) and \
           misc_locks and ("system_lock" in misc_locks):
            system_lock = misc_locks["system_lock"]
        returned_env = install(ESP_IDF_LOCATION["url"], esp_idf_dir,
                               ESP_IDF_LOCATION["branch"], system_lock,
                               keep_going_flag, printer, prompt, reporter)
        if u_utils.keep_going(keep_going_flag, printer, prompt) and \
           returned_env:
            # From here on the ESP-IDF tools need to set up
            # and use the set of environment variables
            # returned above.
            print_env(returned_env, printer, prompt)
            # Now do the build
            build_dir = working_dir + os.sep + BUILD_SUBDIR
            build_start_time = time()
            if u_utils.keep_going(keep_going_flag, printer, prompt) and \
               build(esp_idf_dir, ubxlib_dir, build_dir,
                     defines, returned_env, clean,
                     printer, prompt, reporter, keep_going_flag):
                reporter.event(u_report.EVENT_TYPE_BUILD,
                               u_report.EVENT_PASSED,
                               "build took {:.0f} second(s)". \
                               format(time() - build_start_time))
                with u_connection.Lock(connection, connection_lock,
                                       CONNECTION_LOCK_GUARD_TIME_SECONDS,
                                       printer, prompt,
                                       keep_going_flag) as locked:
                    if locked:
                        # Have seen this fail, only with Python 3 for
                        # some reason, so give it a few goes
                        reporter.event(u_report.EVENT_TYPE_DOWNLOAD,
                                       u_report.EVENT_START)
                        retries = 0
                        downloaded = False
                        while u_utils.keep_going(keep_going_flag, printer, prompt) and \
                              not downloaded and (retries < 3):
                            downloaded = download(esp_idf_dir, ubxlib_dir,
                                                  build_dir,
                                                  connection["serial_port"],
                                                  returned_env, printer,
                                                  prompt)
                            if not downloaded:
                                reporter.event(
                                    u_report.EVENT_TYPE_DOWNLOAD,
                                    u_report.EVENT_WARNING,
                                    "unable to download, will retry...")
                                retries += 1
                                sleep(5)
                        if downloaded:
                            reporter.event(u_report.EVENT_TYPE_DOWNLOAD,
                                           u_report.EVENT_COMPLETE)
                            reporter.event(u_report.EVENT_TYPE_TEST,
                                           u_report.EVENT_START)
                            # Open the COM port to get debug output
                            serial_handle = u_utils.open_serial(
                                connection["serial_port"],
                                115200,
                                printer,
                                prompt,
                                dtr_set_on=monitor_dtr_rts_on,
                                rts_set_on=monitor_dtr_rts_on)
                            if serial_handle is not None:
                                # Monitor progress
                                return_value = u_monitor.main(
                                    serial_handle,
                                    u_monitor.CONNECTION_SERIAL,
                                    RUN_GUARD_TIME_SECONDS,
                                    RUN_INACTIVITY_TIME_SECONDS,
                                    "\r",
                                    instance,
                                    printer,
                                    reporter,
                                    test_report_handle,
                                    keep_going_flag=keep_going_flag)
                                serial_handle.close()
                            else:
                                reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                                               u_report.EVENT_FAILED,
                                               "unable to open serial port " +      \
                                               connection["serial_port"])
                            if return_value == 0:
                                reporter.event(u_report.EVENT_TYPE_TEST,
                                               u_report.EVENT_COMPLETE)
                            else:
                                reporter.event(u_report.EVENT_TYPE_TEST,
                                               u_report.EVENT_FAILED)
                        else:
                            reporter.event(u_report.EVENT_TYPE_DOWNLOAD,
                                           u_report.EVENT_FAILED,
                                           "unable to download to the target")
                    else:
                        reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                                       u_report.EVENT_FAILED,
                                       "unable to lock a connection")
            else:
                reporter.event(u_report.EVENT_TYPE_BUILD,
                               u_report.EVENT_FAILED,
                               "unable to build, check debug log for details")
        else:
            reporter.event(u_report.EVENT_TYPE_INFRASTRUCTURE,
                           u_report.EVENT_FAILED, "tools installation failed")

    return return_value