def __do_arduino_build_wf(self, task, start_task_num=1, end_task_num=2): ########################## ## Task - Probe dir ## ########################## sketch = self.__pre_arduino_build() task.set_progress(start_task_num, end_task_num) #################################### ## Task - Build Arduino Project ## #################################### self.__console_msg("Building Arduino project.") # self.__console_msg(' '.join(self.__get_build_cmd(sketch=sketch))) try: proc = promises.ProcessWrapper(self.__get_build_cmd(sketch=sketch), spawn_console="") except: self.__error_exit("Could not launch Arduino build...") return ret, output = yield proc.wait_until_terminate() if ret is not 0: self.__error_exit("{} returned an error.".format( self.__get_build_cmd(sketch=sketch)[0])) return task.set_progress(start_task_num + 1, end_task_num)
def run_gnatcov_with_instrumentation_wf(self, main_name): # Get the executable to analyze exe = str(GPS.File(main_name).executable_path) # Build the coverage runtime p = promises.TargetWrapper("GNATcov Build Coverage Runtime") r = yield p.wait_on_execute(quiet=True) if r is not 0: GPS.Console("Messages").write("GNATcov runtime build failed ", mode="error") return # Install the coverage runtime p = promises.TargetWrapper("GNATcov Install Coverage Runtime") r = yield p.wait_on_execute(quiet=True) if r is not 0: GPS.Console("Messages").write("GNATcov runtime build failed ", mode="error") return # Run GNATcov with instrumentation on it p = promises.TargetWrapper("Run GNATcov with instrumentation") r = yield p.wait_on_execute(exe, quiet=True) if r is not 0: GPS.Console("Messages").write("GNATcov run failed ", mode="error") return # Build the instrumented main p = promises.TargetWrapper("GNATcov Build Instrumented Main") r = yield p.wait_on_execute(quiet=True) if r is not 0: GPS.Console("Messages").write("Can't build the project with " + "the GNATcov switches", mode="error") return # Go to the object directory before executing the instrumented main: we # want to produce the trace file in the object dir and not in the # project's root directory obj_dir = GPS.Project.root().object_dirs()[0] GPS.cd(obj_dir) # Build the instrumented main p = promises.ProcessWrapper(cmdargs=[exe]) r = yield p.wait_until_terminate() # Generate and display the GNATcov Coverage Report p = promises.TargetWrapper("Generate GNATcov Instrumented Main Report") r = yield p.wait_on_execute(exe, quiet=True)
def on_activate(): f = GPS.current_context().file() cmd = ["astyle", f.path] try: con = promises.ProcessWrapper(cmd) except Exception: GPS.Console().write("Could not launch executable %s" % (cmd[0])) return status, output = yield con.wait_until_terminate() if status != 0: # Show output in the Messages view on error GPS.Console().write(output) GPS.Console().write("%s returned an error." % (cmd[0])) else: GPS.EditorBuffer.get(f, force=True, open=True)
def __do_run_all(self, task): base_proj = GPS.Project.root() proj_list = base_proj.dependencies(recursive = True) # since the top level project may have executables we have # to add it to the project list proj_list.append(base_proj) # loop over each project in top level dependencies for proj in proj_list: # get all executables list in project exec_list = proj.get_attribute_as_list("main") # if there are no executables, then skip this project if len(exec_list) > 0: self.__console_msg("Running %s..." % proj.name()) # get list of sources in project sources = proj.sources() # loop over each executable in project for ex in exec_list: # find the executable in the list of project sources for source in sources: if os.path.basename(source.path) == ex: # now we have the full path of the executable exec_path = source.executable_path.path exec_name = os.path.basename(exec_path) try: proc = promises.ProcessWrapper([exec_path], spawn_console="") except: self.__console_msg("Could not run %s" % exec_name, mode="error") self.__console_msg("[workflow stopped]", mode="error") return ret, output = yield proc.wait_until_terminate() if ret is not 0: self.__error_exit("{} returned an error.".format(exec_name)) return # log output of executable run to file self.__log_output(proj.artifacts_dir(), exec_name, output) break
def __do_arduino_flash_wf(self, task, start_task_num=1, end_task_num=2): ########################## ## Task - Probe dir ## ########################## sketches = glob.glob('*.ino') if len(sketches) is not 1: self.__error_exit("Could not find sketch file.") return sketch = sketches[0] self.__console_msg("Found Arduino sketch %s" % sketch) if not self.__get_conf_paths(): return flash_options = self.__read_flashfile() task.set_progress(start_task_num, end_task_num) ################################### ## Task - Flash image to board ## ################################### self.__console_msg("Flashing image to board.") # self.__console_msg(' '.join(self.__get_flash_cmd(flash_options=flash_options, sketch=sketch))) try: proc = promises.ProcessWrapper(self.__get_flash_cmd( flash_options=flash_options, sketch=sketch), spawn_console="") except: self.__error_exit("Could not launch avrdude.") return ret, output = yield proc.wait_until_terminate() if ret is not 0: self.__error_exit("Flash to board failed.") return self.__console_msg("Flashing complete.") task.set_progress(start_task_num + 1, end_task_num)
def __get_runtime_deps(self, dir): self.__console_msg("Generating RTL dependency list.") try: proc = promises.ProcessWrapper(self.__get_gnatls_cmd(dir)) except: self.__error_exit("Failed to run cmd for runtime deps") return ret, output = yield proc.wait_until_terminate() if ret is not 0: self.__error_exit(output) self.__error_exit("Could not get runtime deps.") return src_list = [ os.path.basename(x.name().lower()) for x in GPS.Project.root().sources() ] # this fugly line strips all blank lines out of the gnatls output, and removes all duplicates and src_files ada_dep_list = set([ re.sub('adainclude', 'adalib', x) for x in (line.strip() for line in output.splitlines()) if x and x not in src_list ]) dep_list = set() for line in ada_dep_list: fpath, fn_wext = os.path.split(line) fn_next = os.path.splitext(fn_wext)[0] cfile = os.path.join(fpath, fn_next + '.c') hfile = os.path.join(fpath, fn_next + '.h') if os.path.isfile(cfile): dep_list.add(cfile) if os.path.isfile(hfile): dep_list.add(hfile) self.__rtl_dep_list = list(dep_list)
def __debug_wf(self, main_name): """ Workflow to build, flash and debug the program on the real board. """ # Return with a warning message if we are still processing a previously # launched workflow. if self.__is_busy: self.__display_message(("Warning: 'Debug on Board' " "already being executed"), mode="error") return # Reset the connection if still alive self.__reset_all() # Tell GPS that we can't run another workflow until we finish # the one that is currently running. self.__is_busy = True # Check if we have a main to debug if main_name is None: self.__error_exit(msg="Main not specified") return # Build the executable builder = promises.TargetWrapper("Build Main") r0 = yield builder.wait_on_execute(main_name) if r0 is not 0: self.__reset_all() return # Check that the settings are correctly set to debug on board success = self.__verify_settings(for_debug=True) if not success: self.__error_exit(msg="Could not connect to the board.") return # Switch directly to the "Debug" perspective so that the # connection tool console is still visible when spawning the debugger. GPS.MDI.load_perspective("Debug") # Launch the connection tool, if any if self.__connector: # Launch the connection tool with its associated console cmd = self.__connector.get_command_line() self.__display_message("Launching: %s" % (' '.join(cmd))) try: self.__connection = promises.ProcessWrapper(cmd) self.__connection.lines.subscribe(self.__display_message) output = yield self.__connection.wait_until_match( self.__get_connection_detection_regexp(), 120000) if output is None: self.__error_exit(msg="Could not connect to the board.") return except Exception: self.__error_exit("Could not connect to the board.") return # Spawn the debugger on the executable and load it self.__display_message("Launching debugger.") exe = GPS.File(main_name).executable_path debugger_promise = promises.DebuggerWrapper( exe, remote_target=self.__remote_target, remote_protocol=self.__remote_protocol) # Load the executable yield debugger_promise.wait_and_send( cmd='load "%s"' % (exe), block=True) # Reset the board yield debugger_promise.wait_and_send( cmd="monitor reset halt", block=True) # Not busy anymore self.__is_busy = False
def __flash_wf(self, main_name): """Workflow to build and flash the program on the board. """ # Return with a warning message if we are still processing a previously # launched workflow. if self.__is_busy: self.__display_message( msg="Warning: 'Flash to Board' already being executed", mode="error") return self.__is_busy = True # Check if we have a main to flash if main_name is None: self.__error_exit(msg="Could not find the name of the main.") return # Build the executable builder = promises.TargetWrapper("Build Main") r0 = yield builder.wait_on_execute(main_name) if r0 is not 0: self.__reset_all() return # Check that the settings are correctly set to flash the board success = self.__verify_settings() if not success: self.__error_exit(msg="Could not flash the board.") return # Get the executable path exe = GPS.File(main_name).executable_path.path # Retrieve the load address of the executable with objdump self.__display_message("Retrieving the load address.") cmd = ["%s-objdump" % (self.__target), exe, "-h"] self.__display_message(' '.join(cmd)) try: con = promises.ProcessWrapper(cmd) except Exception: self.__error_exit("Could not launch executable %s" % (cmd[0])) return # We want to match the line after # the Algn to get the first load address. output = yield con.wait_until_match("Algn\n.+") if output is None: self.__error_exit("%s returned an error." % (cmd[0])) return # We know that the first LMA is at index 5. self.__load_address = "0x%s" % (output.split()[5]) self.__display_message("Load address is: %s" % (self.__load_address)) # Create the flashable binary with objcopy self.__display_message("Creating the binary (flashable) image.") binary = exe + ".bin" cmd = ["%s-objcopy" % (self.__target), "-O", "binary", exe, binary] self.__display_message(' '.join(cmd)) try: con = promises.ProcessWrapper(cmd) except Exception: self.__error_exit("Could not launch executable %s." % (cmd[0])) return status, output = yield con.wait_until_terminate() if status != 0: # Show output in the Messages view on error self.__display_message(output) self.__error_exit("%s returned an error." % (cmd[0])) return # Flash the binary and wait until it completes cmd = self.__get_flashing_command_line(binary) self.__display_message("Flashing image to board...") self.__display_message(' '.join(cmd)) try: con = promises.ProcessWrapper(cmd) con.lines.subscribe(self.__display_message) output = yield con.wait_until_match( self.__get_flashing_complete_regexp(), 120000) if output is None: self.__error_exit(msg="Could not flash the executable.") con.terminate() return except Exception: self.__error_exit("Could not connect to the board.") return self.__display_message(("Flashing complete. " "You may need to reset (or cycle power).")) # Not busy anymore self.__is_busy = False
def run_instrumented_main_wf(self, main_name, generate=False): exe = str(GPS.File(main_name).executable_path) # Go to the object directory before executing the instrumented main: we # want to produce the trace file in the object dir and not in the # project's root directory obj_dir = GPS.Project.root().object_dirs()[0] GPS.cd(obj_dir) # Clean the previous trace file if it exists (the run can fails and # then the trace file will not be overwritten: it will show outdated # data) srctrace_filename = os.path.join(obj_dir, exe + ".srctrace") try: os.remove(srctrace_filename) except FileNotFoundError: pass # Run the instrumented main (through GNATemulator for cross targets) # it will generate the new trace file. target = GPS.get_target() if target == "": cmdargs = [exe] p = promises.ProcessWrapper(cmdargs) GPS.Console().write(' '.join(cmdargs)) status, output = yield p.wait_until_terminate(show_if_error=True) if status != 0: GPS.Console("Messages").write( "Failed to execute main with status " + str(status)) else: # Launch the instrumented executable through GNATemulator cmdargs = GPS.BuildTarget( "Run GNATemulator").get_expanded_command_line() cmdargs.append(exe) GPS.Console().write(' '.join(cmdargs) + "\n") gnatemu_promise = promises.ProcessWrapper(cmdargs=cmdargs) status, output = yield gnatemu_promise.wait_until_terminate( show_if_error=True) # Put the output in a file and use 'gnatcov extract-base64-trace' # to retrieve the traces information from it out_filename = os.path.join(obj_dir, exe + ".out") with open(out_filename, "w") as f: f.write(output) extract_trace_cmd = [ "gnatcov", "extract-base64-trace", out_filename, srctrace_filename ] GPS.Console().write(' '.join(extract_trace_cmd) + "\n") status = GPS.Process(extract_trace_cmd).wait() if status != 0: GPS.Console().write( "Could not extract traces info from executable's output", mode="error") if status == 0 and generate: # Generate and display the GNATcov Coverage Report p = promises.TargetWrapper( "Generate GNATcov Instrumented Main Report") yield p.wait_on_execute(exe, quiet=True) return status