|
| 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 compile_test |
| 17 | + |
| 18 | +import ( |
| 19 | + "strings" |
| 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 | + "golang.org/x/exp/slices" |
| 26 | +) |
| 27 | + |
| 28 | +func TestCompileCoreCacheGeneration(t *testing.T) { |
| 29 | + // See: |
| 30 | + // https://forum.arduino.cc/t/teensy-compile-sketch-fails-clear-out-temp-build-completes/1110104/6 |
| 31 | + // https://forum.pjrc.com/threads/72572-Teensyduino-1-59-Beta-2?p=324071&viewfull=1#post324071 |
| 32 | + // https://github.com/arduino/arduino-ide/issues/1990 |
| 33 | + |
| 34 | + env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) |
| 35 | + defer env.CleanUp() |
| 36 | + |
| 37 | + // Run update-index with our test index |
| 38 | + _, _, err := cli. Run( "core", "install", "arduino:[email protected]") |
| 39 | + require.NoError(t, err) |
| 40 | + |
| 41 | + // Prepare sketch |
| 42 | + sketch, err := paths.New("testdata", "bare_minimum").Abs() |
| 43 | + require.NoError(t, err) |
| 44 | + |
| 45 | + // Perform two compile that should result in different cached cores |
| 46 | + _, _, err = cli.Run("compile", "-b", "arduino:avr:mega", sketch.String()) |
| 47 | + require.NoError(t, err) |
| 48 | + _, _, err = cli.Run("compile", "-b", "arduino:avr:mega:cpu=atmega1280", sketch.String()) |
| 49 | + require.NoError(t, err) |
| 50 | + |
| 51 | + // Perform the same compile again and track the cached cores |
| 52 | + extractCachedCoreFromStdout := func(stdout []byte) string { |
| 53 | + prefix := "Using precompiled core: " |
| 54 | + lines := strings.Split(string(stdout), "\n") |
| 55 | + i := slices.IndexFunc(lines, func(l string) bool { |
| 56 | + return strings.Contains(l, prefix) |
| 57 | + }) |
| 58 | + require.NotEqual(t, -1, i, "Could not find precompiled core in output") |
| 59 | + return strings.TrimPrefix(lines[i], prefix) |
| 60 | + } |
| 61 | + stdout, _, err := cli.Run("compile", "-b", "arduino:avr:mega", sketch.String(), "-v") |
| 62 | + require.NoError(t, err) |
| 63 | + core1 := extractCachedCoreFromStdout(stdout) |
| 64 | + stdout, _, err = cli.Run("compile", "-b", "arduino:avr:mega:cpu=atmega1280", sketch.String(), "-v") |
| 65 | + require.NoError(t, err) |
| 66 | + core2 := extractCachedCoreFromStdout(stdout) |
| 67 | + require.NotEqual(t, core1, core2, "Precompile core must be different!") |
| 68 | +} |
0 commit comments