| 
									
										
										
										
											2015-11-18 17:16:17 +02:00
										 |  |  | # Copyright 2014-2015 Ivan Kravets <me@ikravets.com> | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  | # you may not use this file except in compliance with the License. | 
					
						
							|  |  |  | # You may obtain a copy of the License at | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #    http://www.apache.org/licenses/LICENSE-2.0 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  | # distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  | # See the License for the specific language governing permissions and | 
					
						
							|  |  |  | # limitations under the License. | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | import json | 
					
						
							|  |  |  | from os.path import isfile, join | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  | from platformio import util | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  | from platformio.commands.boards import cli as cmd_boards | 
					
						
							|  |  |  | from platformio.commands.platforms import \ | 
					
						
							|  |  |  |     platforms_install as cmd_platforms_install | 
					
						
							|  |  |  | from platformio.commands.platforms import \ | 
					
						
							|  |  |  |     platforms_search as cmd_platforms_search | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  | def test_board_json_output(platformio_setup, clirunner, validate_cliresult): | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  |     result = clirunner.invoke(cmd_boards, ["cortex", "--json-output"]) | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  |     validate_cliresult(result) | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  |     boards = json.loads(result.output) | 
					
						
							|  |  |  |     assert isinstance(boards, dict) | 
					
						
							|  |  |  |     assert "teensy30" in boards | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  | def test_board_raw_output(platformio_setup, clirunner, validate_cliresult): | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  |     result = clirunner.invoke(cmd_boards, ["energia"]) | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  |     validate_cliresult(result) | 
					
						
							| 
									
										
										
										
											2015-02-20 16:41:42 +02:00
										 |  |  |     assert "titiva" in result.output | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  | def test_board_options(platformio_setup, clirunner, validate_cliresult): | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  |     required_opts = set( | 
					
						
							|  |  |  |         ["build", "platform", "upload", "name"]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  |     # fetch available platforms | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  |     result = clirunner.invoke(cmd_platforms_search, ["--json-output"]) | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  |     validate_cliresult(result) | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  |     search_result = json.loads(result.output) | 
					
						
							|  |  |  |     assert isinstance(search_result, list) | 
					
						
							|  |  |  |     assert len(search_result) | 
					
						
							| 
									
										
										
										
											2015-03-16 14:15:57 +02:00
										 |  |  |     platforms = [item['type'] for item in search_result] | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-16 14:15:57 +02:00
										 |  |  |     for _, opts in util.get_boards().iteritems(): | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  |         assert required_opts.issubset(set(opts)) | 
					
						
							|  |  |  |         assert opts['platform'] in platforms | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  | def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): | 
					
						
							|  |  |  |     result = clirunner.invoke( | 
					
						
							| 
									
										
										
										
											2015-04-17 12:37:03 +01:00
										 |  |  |         cmd_platforms_install, [ | 
					
						
							| 
									
										
										
										
											2015-03-09 12:18:46 +02:00
										 |  |  |             "ststm32", | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  |             "--skip-default-package", | 
					
						
							|  |  |  |             "--with-package=ldscripts" | 
					
						
							|  |  |  |         ]) | 
					
						
							| 
									
										
										
										
											2015-02-21 15:15:00 +02:00
										 |  |  |     validate_cliresult(result) | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  |     ldscripts_path = join(util.get_home_dir(), "packages", "ldscripts") | 
					
						
							|  |  |  |     for _, opts in util.get_boards().iteritems(): | 
					
						
							|  |  |  |         if opts['build'].get("ldscript"): | 
					
						
							| 
									
										
										
										
											2015-10-16 16:17:24 +03:00
										 |  |  |             if "libopencm3" in opts['frameworks']: | 
					
						
							|  |  |  |                 continue | 
					
						
							| 
									
										
										
										
											2015-02-20 13:48:17 +02:00
										 |  |  |             assert isfile(join(ldscripts_path, opts['build'].get("ldscript"))) |