|
75 | 75 | default=None, help="The mbed serial port")
|
76 | 76 | parser.add_option("-b", "--baud", type="int", dest="baud",
|
77 | 77 | default=None, help="The mbed serial baud rate")
|
78 |
| - |
| 78 | + parser.add_option("-L", "--list-tests", action="store_true", dest="list_tests", |
| 79 | + default=False, help="List available tests in order and exit") |
| 80 | + |
79 | 81 | # Ideally, all the tests with a single "main" thread can be run with, or
|
80 | 82 | # without the rtos
|
81 | 83 | parser.add_option("--rtos", action="store_true", dest="rtos",
|
82 | 84 | default=False, help="Link to the rtos")
|
83 |
| - |
| 85 | + |
84 | 86 | # Specify a different linker script
|
85 | 87 | parser.add_option("-l", "--linker", dest="linker_script",
|
86 | 88 | default=None, help="use the specified linker script")
|
87 |
| - |
| 89 | + |
88 | 90 | (options, args) = parser.parse_args()
|
89 | 91 |
|
| 92 | + # Print available tests in order and exit |
| 93 | + if options.list_tests is True: |
| 94 | + print '\n'.join(map(str, sorted(TEST_MAP.values()))) |
| 95 | + sys.exit() |
| 96 | + |
90 | 97 | # force program to "0" if a source dir is specified
|
91 | 98 | if options.source_dir is not None:
|
92 | 99 | p = 0
|
|
106 | 113 | args_error(parser, "[ERROR] Program with name '%s' not found" % n)
|
107 | 114 | else:
|
108 | 115 | n = alias
|
109 |
| - p = TEST_MAP[n].n |
| 116 | + p = TEST_MAP[n].n |
110 | 117 | if p is None or (p < 0) or (p > (len(TESTS)-1)):
|
111 | 118 | message = "[ERROR] You have to specify one of the following tests:\n"
|
112 | 119 | message += '\n'.join(map(str, sorted(TEST_MAP.values())))
|
113 | 120 | args_error(parser, message)
|
114 |
| - |
| 121 | + |
115 | 122 | # Target
|
116 | 123 | if options.mcu is None :
|
117 | 124 | args_error(parser, "[ERROR] You should specify an MCU")
|
118 | 125 | mcu = options.mcu
|
119 |
| - |
| 126 | + |
120 | 127 | # Toolchain
|
121 | 128 | if options.tool is None:
|
122 | 129 | args_error(parser, "[ERROR] You should specify a TOOLCHAIN")
|
123 | 130 | toolchain = options.tool
|
124 |
| - |
| 131 | + |
125 | 132 | # Test
|
126 | 133 | test = Test(p)
|
127 | 134 | if options.automated is not None:
|
|
140 | 147 | if not test.is_supported(mcu, toolchain):
|
141 | 148 | print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain)
|
142 | 149 | sys.exit()
|
143 |
| - |
| 150 | + |
144 | 151 | # RTOS
|
145 | 152 | if options.rtos:
|
146 | 153 | test.dependencies.append(RTOS_LIBRARIES)
|
147 |
| - |
| 154 | + |
148 | 155 | build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id)
|
149 |
| - if options.source_dir is not None: |
| 156 | + if options.source_dir is not None: |
150 | 157 | test.source_dir = options.source_dir
|
151 | 158 | build_dir = options.source_dir
|
152 | 159 |
|
153 |
| - if options.build_dir is not None: |
| 160 | + if options.build_dir is not None: |
154 | 161 | build_dir = options.build_dir
|
155 |
| - |
| 162 | + |
156 | 163 | target = TARGET_MAP[mcu]
|
157 | 164 | try:
|
158 | 165 | bin = build_project(test.source_dir, build_dir, target, toolchain,
|
|
161 | 168 | clean=options.clean, verbose=options.verbose,
|
162 | 169 | macros=options.macros)
|
163 | 170 | print 'Image: %s' % bin
|
164 |
| - |
| 171 | + |
165 | 172 | if options.disk:
|
166 | 173 | # Simple copy to the mbed disk
|
167 | 174 | copy(bin, options.disk)
|
168 |
| - |
| 175 | + |
169 | 176 | if options.serial:
|
170 | 177 | # Import pyserial: https://pypi.python.org/pypi/pyserial
|
171 | 178 | from serial import Serial
|
172 |
| - |
| 179 | + |
173 | 180 | sleep(target.program_cycle_s())
|
174 |
| - |
| 181 | + |
175 | 182 | serial = Serial(options.serial, timeout = 1)
|
176 | 183 | if options.baud:
|
177 | 184 | serial.setBaudrate(options.baud)
|
178 |
| - |
| 185 | + |
179 | 186 | serial.flushInput()
|
180 | 187 | serial.flushOutput()
|
181 |
| - |
| 188 | + |
182 | 189 | serial.sendBreak()
|
183 |
| - |
| 190 | + |
184 | 191 | while True:
|
185 | 192 | c = serial.read(512)
|
186 | 193 | sys.stdout.write(c)
|
187 | 194 | sys.stdout.flush()
|
188 |
| - |
| 195 | + |
189 | 196 | except KeyboardInterrupt, e:
|
190 | 197 | print "\n[CTRL+c] exit"
|
191 | 198 | except Exception,e:
|
|
0 commit comments