<s> """<STR_LIT>""" <EOL> import os <EOL> import json <EOL> import sys <EOL> from subprocess import Popen , STDOUT , PIPE <EOL> from pyOCD . tools . gdb_server import GDBServerTool <EOL> from pyOCD . board import MbedBoard <EOL> from test_util import Test , TestResult <EOL> TEST_PARAM_FILE = "<STR_LIT>" <EOL> TEST_RESULT_FILE = "<STR_LIT>" <EOL> PYTHON_GDB_FOR_OS = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> PYTHON_GDB = None <EOL> for prefix , program in PYTHON_GDB_FOR_OS . iteritems ( ) : <EOL> if sys . platform . startswith ( prefix ) : <EOL> PYTHON_GDB = program <EOL> break <EOL> parentdir = os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) <EOL> class GdbTestResult ( TestResult ) : <EOL> def __init__ ( self ) : <EOL> super ( self . __class__ , self ) . __init__ ( None , None , None ) <EOL> class GdbTest ( Test ) : <EOL> def __init__ ( self ) : <EOL> super ( self . __class__ , self ) . __init__ ( "<STR_LIT>" , test_gdb ) <EOL> def print_perf_info ( self , result_list , output_file = None ) : <EOL> pass <EOL> def run ( self , board ) : <EOL> try : <EOL> result = self . test_function ( board . getUniqueID ( ) ) <EOL> except Exception as e : <EOL> result = GdbTestResult ( ) <EOL> result . passed = False <EOL> print ( "<STR_LIT>" % <EOL> ( e , board . getUniqueID ( ) ) ) <EOL> result . board = board <EOL> result . test = self <EOL> return result <EOL> TEST_RESULT_KEYS = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> def test_gdb ( board_id = None ) : <EOL> result = GdbTestResult ( ) <EOL> with MbedBoard . chooseBoard ( board_id = board_id ) as board : <EOL> memory_map = board . target . getMemoryMap ( ) <EOL> ram_regions = [ region for region in memory_map if region . type == '<STR_LIT>' ] <EOL> ram_region = ram_regions [ <NUM_LIT:0> ] <EOL> rom_region = memory_map . getBootMemory ( ) <EOL> target_type = board . getTargetType ( ) <EOL> binary_file = os . path . join ( parentdir , '<STR_LIT>' , <EOL> board . getTestBinary ( ) ) <EOL> if board_id is None : <EOL> board_id = board . getUniqueID ( ) <EOL> test_clock = <NUM_LIT> <EOL> test_port = <NUM_LIT> <EOL> error_on_invalid_access = True <EOL> ignore_hw_bkpt_result = <NUM_LIT:1> if ram_region . start >= <NUM_LIT> else <NUM_LIT:0> <EOL> if target_type == "<STR_LIT>" : <EOL> test_clock = <NUM_LIT> <EOL> error_on_invalid_access = False <EOL> board . flash . flashBinary ( binary_file , rom_region . start ) <EOL> board . uninit ( False ) <EOL> test_params = { } <EOL> test_params [ "<STR_LIT>" ] = rom_region . start <EOL> test_params [ "<STR_LIT>" ] = rom_region . length <EOL> test_params [ "<STR_LIT>" ] = ram_region . start <EOL> test_params [ "<STR_LIT>" ] = ram_region . length <EOL> test_params [ "<STR_LIT>" ] = <NUM_LIT> <EOL> test_params [ "<STR_LIT>" ] = <NUM_LIT> <EOL> test_params [ "<STR_LIT>" ] = error_on_invalid_access <EOL> test_params [ "<STR_LIT>" ] = ignore_hw_bkpt_result <EOL> with open ( TEST_PARAM_FILE , "<STR_LIT:wb>" ) as f : <EOL> f . write ( json . dumps ( test_params ) ) <EOL> gdb = [ PYTHON_GDB , "<STR_LIT>" ] <EOL> with open ( "<STR_LIT>" , "<STR_LIT:wb>" ) as f : <EOL> program = Popen ( gdb , stdin = PIPE , stdout = f , stderr = STDOUT ) <EOL> args = [ '<STR_LIT>' % test_port , "<STR_LIT>" % test_clock , "<STR_LIT>" % board_id ] <EOL> server = GDBServerTool ( ) <EOL> server . run ( args ) <EOL> program . wait ( ) <EOL> with open ( TEST_RESULT_FILE , "<STR_LIT:rb>" ) as f : <EOL> test_result = json . loads ( f . read ( ) ) <EOL> if set ( TEST_RESULT_KEYS ) . issubset ( test_result ) : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" % test_result [ "<STR_LIT>" ] ) <EOL> print ( "<STR_LIT>" % test_result [ "<STR_LIT>" ] ) <EOL> print ( "<STR_LIT>" % <EOL> test_result [ "<STR_LIT>" ] ) <EOL> print ( "<STR_LIT>" % test_result [ "<STR_LIT>" ] ) <EOL> print ( "<STR_LIT>" % test_result [ "<STR_LIT>" ] ) <EOL> print ( "<STR_LIT>" % test_result [ "<STR_LIT>" ] ) <EOL> result . passed = test_result [ "<STR_LIT>" ] == <NUM_LIT:0> <EOL> else : <EOL> result . passed = False <EOL> os . remove ( TEST_RESULT_FILE ) <EOL> os . remove ( TEST_PARAM_FILE ) <EOL> return result <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_gdb ( ) </s>
