|
| 1 | +// This file is part of arduino-cli. |
| 2 | +// |
| 3 | +// Copyright 2022 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This software is released under the GNU General Public License version 3, |
| 6 | +// which covers the main part of arduino-cli. |
| 7 | +// The terms of this license can be found at: |
| 8 | +// https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | +// |
| 10 | +// You can be released from the requirements of the above licenses by purchasing |
| 11 | +// a commercial license. Buying such a license is mandatory if you want to |
| 12 | +// modify or otherwise use the software for commercial activities involving the |
| 13 | +// Arduino software without disclosing the source code of your own applications. |
| 14 | +// To purchase a commercial license, send an email to [email protected]. |
| 15 | + |
| 16 | +package board_test |
| 17 | + |
| 18 | +import ( |
| 19 | + "runtime" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/arduino/arduino-cli/internal/integrationtest" |
| 23 | + "github.com/arduino/go-paths-helper" |
| 24 | + "github.com/stretchr/testify/require" |
| 25 | + "go.bug.st/testifyjson/requirejson" |
| 26 | +) |
| 27 | + |
| 28 | +func TestHardwareLoading(t *testing.T) { |
| 29 | + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) |
| 30 | + defer env.CleanUp() |
| 31 | + |
| 32 | + // install two cores, boards must be ordered by package name and platform name |
| 33 | + _, _, err := cli. Run( "core", "install", "arduino:[email protected]") |
| 34 | + require.NoError(t, err) |
| 35 | + // _, _, err = cli.Run("core", "install", "arduino:sam") |
| 36 | + // require.NoError(t, err) |
| 37 | + |
| 38 | + localTxt, err := paths.New("testdata", "custom_local_txts").Abs() |
| 39 | + require.NoError(t, err) |
| 40 | + downloadedHardwareAvr := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6") |
| 41 | + localTxt.Join("boards.local.txt").CopyTo(downloadedHardwareAvr.Join("boards.local.txt")) |
| 42 | + localTxt.Join("platform.local.txt").CopyTo(downloadedHardwareAvr.Join("platform.local.txt")) |
| 43 | + |
| 44 | + t.Run("Simple", func(t *testing.T) { |
| 45 | + { |
| 46 | + out, _, err := cli.Run("core", "list", "--format", "json") |
| 47 | + require.NoError(t, err) |
| 48 | + jsonOut := requirejson.Parse(t, out) |
| 49 | + jsonOut.LengthMustEqualTo(1) |
| 50 | + jsonOut.MustContain(`[ |
| 51 | + { |
| 52 | + "id": "arduino:avr", |
| 53 | + "installed": "1.8.6", |
| 54 | + "name": "Arduino AVR Boards", |
| 55 | + "boards": [ |
| 56 | + { |
| 57 | + "name": "Arduino Uno", |
| 58 | + "fqbn": "arduino:avr:uno" |
| 59 | + }, |
| 60 | + { |
| 61 | + "name": "Arduino Yún", |
| 62 | + "fqbn": "arduino:avr:yun" |
| 63 | + } |
| 64 | + ] |
| 65 | + } |
| 66 | + ]`) |
| 67 | + } |
| 68 | + |
| 69 | + { |
| 70 | + // Also test local platform.txt properties override |
| 71 | + out, _, err := cli.Run("board", "details", "-b", "arduino:avr:uno", "--format", "json") |
| 72 | + require.NoError(t, err) |
| 73 | + jsonOut := requirejson.Parse(t, out) |
| 74 | + jsonOut.MustContain(`{ |
| 75 | + "version": "1.8.6", |
| 76 | + "properties_id": "uno", |
| 77 | + "build_properties": [ |
| 78 | + "_id=uno", |
| 79 | + "tools.avrdude.bootloader.params.verbose=-v", |
| 80 | + "tools.avrdude.cmd.path=/my/personal/avrdude" |
| 81 | + ], |
| 82 | + "programmers": [ |
| 83 | + { |
| 84 | + "platform": "Arduino AVR Boards", |
| 85 | + "id": "usbasp", |
| 86 | + "name": "USBasp" |
| 87 | + }, |
| 88 | + { |
| 89 | + "platform": "Arduino AVR Boards", |
| 90 | + "id": "avrispmkii", |
| 91 | + "name": "AVRISP mkII" |
| 92 | + } |
| 93 | + ] |
| 94 | + }`) |
| 95 | + } |
| 96 | + |
| 97 | + { |
| 98 | + out, _, err := cli.Run("board", "details", "-b", "arduino:avr:yun", "--format", "json") |
| 99 | + require.NoError(t, err) |
| 100 | + jsonOut := requirejson.Parse(t, out) |
| 101 | + jsonOut.MustContain(`{ |
| 102 | + "version": "1.8.6", |
| 103 | + "properties_id": "yun", |
| 104 | + "build_properties": [ |
| 105 | + "_id=yun", |
| 106 | + "upload.wait_for_upload_port=true" |
| 107 | + ] |
| 108 | + }`) |
| 109 | + } |
| 110 | + |
| 111 | + { |
| 112 | + // Check un-expansion of board_properties |
| 113 | + out, _, err := cli.Run("board", "details", "-b", "arduino:avr:robotMotor", "--show-properties=unexpanded", "--format", "json") |
| 114 | + require.NoError(t, err) |
| 115 | + jsonOut := requirejson.Parse(t, out) |
| 116 | + jsonOut.MustContain(`{ |
| 117 | + "version": "1.8.6", |
| 118 | + "properties_id": "robotMotor", |
| 119 | + "build_properties": [ |
| 120 | + "_id=robotMotor", |
| 121 | + "build.extra_flags={build.usb_flags}", |
| 122 | + "upload.wait_for_upload_port=true" |
| 123 | + ] |
| 124 | + }`) |
| 125 | + } |
| 126 | + |
| 127 | + { |
| 128 | + // Also test local boards.txt properties override |
| 129 | + out, _, err := cli.Run("board", "details", "-b", "arduino:avr:diecimila", "--show-properties=unexpanded", "--format", "json") |
| 130 | + require.NoError(t, err) |
| 131 | + jsonOut := requirejson.Parse(t, out) |
| 132 | + jsonOut.MustContain(`{ |
| 133 | + "version": "1.8.6", |
| 134 | + "properties_id": "diecimila", |
| 135 | + "build_properties": [ |
| 136 | + "_id=diecimila", |
| 137 | + "menu.cpu.atmega123=ATmega123" |
| 138 | + ] |
| 139 | + }`) |
| 140 | + } |
| 141 | + }) |
| 142 | + |
| 143 | + t.Run("MixingUserHardware", func(t *testing.T) { |
| 144 | + // Install custom hardware required for tests |
| 145 | + customHwDir, err := paths.New("..", "testdata", "user_hardware").Abs() |
| 146 | + require.NoError(t, err) |
| 147 | + require.NoError(t, customHwDir.CopyDirTo(cli.SketchbookDir().Join("hardware"))) |
| 148 | + |
| 149 | + { |
| 150 | + out, _, err := cli.Run("core", "list", "--format", "json") |
| 151 | + require.NoError(t, err) |
| 152 | + jsonOut := requirejson.Parse(t, out) |
| 153 | + if runtime.GOOS == "windows" { |
| 154 | + //a package is a symlink, and windows does not support them |
| 155 | + jsonOut.LengthMustEqualTo(2) |
| 156 | + } else { |
| 157 | + jsonOut.LengthMustEqualTo(3) |
| 158 | + } |
| 159 | + jsonOut.MustContain(`[ |
| 160 | + { |
| 161 | + "id": "arduino:avr", |
| 162 | + "installed": "1.8.6", |
| 163 | + "name": "Arduino AVR Boards", |
| 164 | + "boards": [ |
| 165 | + { |
| 166 | + "name": "Arduino Uno", |
| 167 | + "fqbn": "arduino:avr:uno" |
| 168 | + }, |
| 169 | + { |
| 170 | + "name": "Arduino Yún", |
| 171 | + "fqbn": "arduino:avr:yun" |
| 172 | + } |
| 173 | + ] |
| 174 | + } |
| 175 | + ]`) |
| 176 | + jsonOut.MustContain(`[ |
| 177 | + { |
| 178 | + "id": "my_avr_platform:avr", |
| 179 | + "installed": "9.9.9", |
| 180 | + "name": "My AVR Boards", |
| 181 | + "boards": [ |
| 182 | + { |
| 183 | + "name": "Arduino Yún", |
| 184 | + "fqbn": "my_avr_platform:avr:custom_yun" |
| 185 | + } |
| 186 | + ], |
| 187 | + "manually_installed": true, |
| 188 | + "missing_metadata": true |
| 189 | + } |
| 190 | + ]`) |
| 191 | + |
| 192 | + // require.False(t, myAVRPlatformAvrArch.Properties.ContainsKey("preproc.includes.flags")) |
| 193 | + |
| 194 | + if runtime.GOOS != "windows" { |
| 195 | + jsonOut.MustContain(`[ |
| 196 | + { |
| 197 | + "id": "my_symlinked_avr_platform:avr", |
| 198 | + "manually_installed": true, |
| 199 | + "missing_metadata": true |
| 200 | + } |
| 201 | + ]`) |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + { |
| 206 | + // Also test local platform.txt properties override |
| 207 | + out, _, err := cli.Run("board", "details", "-b", "arduino:avr:uno", "--format", "json") |
| 208 | + require.NoError(t, err) |
| 209 | + jsonOut := requirejson.Parse(t, out) |
| 210 | + jsonOut.MustContain(`{ |
| 211 | + "version": "1.8.6", |
| 212 | + "properties_id": "uno", |
| 213 | + "build_properties": [ |
| 214 | + "_id=uno", |
| 215 | + "tools.avrdude.bootloader.params.verbose=-v", |
| 216 | + "tools.avrdude.cmd.path=/my/personal/avrdude" |
| 217 | + ], |
| 218 | + "programmers": [ |
| 219 | + { |
| 220 | + "platform": "Arduino AVR Boards", |
| 221 | + "id": "usbasp", |
| 222 | + "name": "USBasp" |
| 223 | + }, |
| 224 | + { |
| 225 | + "platform": "Arduino AVR Boards", |
| 226 | + "id": "avrispmkii", |
| 227 | + "name": "AVRISP mkII" |
| 228 | + } |
| 229 | + ] |
| 230 | + }`) |
| 231 | + } |
| 232 | + |
| 233 | + { |
| 234 | + out, _, err := cli.Run("board", "details", "-b", "arduino:avr:yun", "--show-properties=unexpanded", "--format", "json") |
| 235 | + require.NoError(t, err) |
| 236 | + jsonOut := requirejson.Parse(t, out) |
| 237 | + jsonOut.MustContain(`{ |
| 238 | + "version": "1.8.6", |
| 239 | + "properties_id": "yun", |
| 240 | + "build_properties": [ |
| 241 | + "_id=yun", |
| 242 | + "upload.wait_for_upload_port=true", |
| 243 | + "preproc.includes.flags=-w -x c++ -M -MG -MP", |
| 244 | + "preproc.macros.flags=-w -x c++ -E -CC", |
| 245 | + "recipe.preproc.includes=\"{compiler.path}{compiler.cpp.cmd}\" {compiler.cpp.flags} {preproc.includes.flags} -mmcu={build.mcu} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {includes} \"{source_file}\"" |
| 246 | + ] |
| 247 | + }`) |
| 248 | + jsonOut.Query(`isempty( .build_properties[] | select(startswith("preproc.macros.compatibility_flags")) )`).MustEqual("true") |
| 249 | + } |
| 250 | + }) |
| 251 | +} |
0 commit comments