Skip to content

Commit 61a81f9

Browse files
committed
Added test for core caching
Signed-off-by: Cristian Maglie <[email protected]>
1 parent 19751fe commit 61a81f9

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

src/arduino.cc/builder/test/builder_test.go

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@
3030
package test
3131

3232
import (
33-
"arduino.cc/builder"
34-
"arduino.cc/builder/constants"
35-
"arduino.cc/builder/types"
36-
"github.com/stretchr/testify/require"
3733
"os"
3834
"os/exec"
3935
"path/filepath"
4036
"testing"
37+
"time"
38+
39+
"arduino.cc/builder"
40+
"arduino.cc/builder/builder_utils"
41+
"arduino.cc/builder/constants"
42+
"arduino.cc/builder/types"
43+
"github.com/stretchr/testify/require"
4144
)
4245

4346
func TestBuilderEmptySketch(t *testing.T) {
@@ -410,3 +413,52 @@ func TestBuilderWithBuildPathInSketchDir(t *testing.T) {
410413
err = command.Run(ctx)
411414
NoError(t, err)
412415
}
416+
417+
func TestBuilderCacheCoreAFile(t *testing.T) {
418+
DownloadCoresAndToolsAndLibraries(t)
419+
420+
ctx := &types.Context{
421+
HardwareFolders: []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware"},
422+
ToolsFolders: []string{"downloaded_tools"},
423+
BuiltInLibrariesFolders: []string{"downloaded_libraries"},
424+
OtherLibrariesFolders: []string{"libraries"},
425+
SketchLocation: filepath.Join("sketch1", "sketch.ino"),
426+
FQBN: "arduino:avr:uno",
427+
ArduinoAPIVersion: "10801",
428+
}
429+
SetupBuildPath(t, ctx)
430+
defer os.RemoveAll(ctx.BuildPath)
431+
432+
// Cleanup cached core
433+
coreFile := builder_utils.GetCoreArchivePath(ctx.FQBN)
434+
os.Remove(coreFile)
435+
436+
// Run build
437+
bldr := builder.Builder{}
438+
err := bldr.Run(ctx)
439+
NoError(t, err)
440+
coreStatBefore, err := os.Stat(coreFile)
441+
require.NoError(t, err)
442+
443+
// Run build again, to verify that the builder skips rebuilding core.a
444+
err = bldr.Run(ctx)
445+
NoError(t, err)
446+
447+
coreStatAfterRebuild, err := os.Stat(coreFile)
448+
require.NoError(t, err)
449+
require.Equal(t, coreStatBefore.ModTime(), coreStatAfterRebuild.ModTime())
450+
451+
// Touch a file of the core and check if the builder invalidate the cache
452+
time.Sleep(time.Second)
453+
now := time.Now().Local()
454+
err = os.Chtimes(filepath.Join("downloaded_hardware", "arduino", "avr", "cores", "arduino", "Arduino.h"), now, now)
455+
require.NoError(t, err)
456+
457+
// Run build again, to verify that the builder rebuilds core.a
458+
err = bldr.Run(ctx)
459+
NoError(t, err)
460+
461+
coreStatAfterTouch, err := os.Stat(coreFile)
462+
require.NoError(t, err)
463+
require.NotEqual(t, coreStatBefore.ModTime(), coreStatAfterTouch.ModTime())
464+
}

0 commit comments

Comments
 (0)