From 1fda6db74e9aa92fc2d772fb535991cc1666cab8 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 4 Dec 2023 11:44:57 +0100 Subject: [PATCH] Prepare infra to add integration test --- .../integrationtest/compile_4/compile_test.go | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/internal/integrationtest/compile_4/compile_test.go b/internal/integrationtest/compile_4/compile_test.go index a61d68563a5..80eedf8acd7 100644 --- a/internal/integrationtest/compile_4/compile_test.go +++ b/internal/integrationtest/compile_4/compile_test.go @@ -904,56 +904,58 @@ func comparePreprocessGoldenFile(t *testing.T, sketchDir *paths.Path, preprocess require.Equal(t, buf.String(), strings.ReplaceAll(preprocessedSketch, "\r\n", "\n")) } -func TestCoreCaching(t *testing.T) { +func TestBuildCaching(t *testing.T) { env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t) defer env.CleanUp() - sketchPath, err := paths.New("..", "testdata", "bare_minimum").Abs() - require.NoError(t, err) - // Install Arduino AVR Boards - _, _, err = cli.Run("core", "install", "arduino:avr@1.8.6") + _, _, err := cli.Run("core", "install", "arduino:avr@1.8.6") require.NoError(t, err) - // Create temporary cache dir - buildCachePath, err := paths.MkTempDir("", "test_build_cache") - require.NoError(t, err) - defer buildCachePath.RemoveAll() + t.Run("CoreCaching", func(t *testing.T) { + sketchPath, err := paths.New("..", "testdata", "bare_minimum").Abs() + require.NoError(t, err) - // Build first time - _, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String()) - require.NoError(t, err) + // Create temporary cache dir + buildCachePath, err := paths.MkTempDir("", "test_build_cache") + require.NoError(t, err) + defer buildCachePath.RemoveAll() - // Find cached core and save timestamp - pathList, err := buildCachePath.ReadDirRecursiveFiltered(nil, paths.FilterPrefixes("core.a")) - require.NoError(t, err) - require.Len(t, pathList, 1) - cachedCoreFile := pathList[0] - lastUsedPath := cachedCoreFile.Parent().Join(".last-used") - require.True(t, lastUsedPath.Exist()) - coreStatBefore, err := cachedCoreFile.Stat() - require.NoError(t, err) + // Build first time + _, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String()) + require.NoError(t, err) - // Run build again and check timestamp is unchanged - _, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String()) - require.NoError(t, err) - coreStatAfterRebuild, err := cachedCoreFile.Stat() - require.NoError(t, err) - require.Equal(t, coreStatBefore.ModTime(), coreStatAfterRebuild.ModTime()) + // Find cached core and save timestamp + pathList, err := buildCachePath.ReadDirRecursiveFiltered(nil, paths.FilterPrefixes("core.a")) + require.NoError(t, err) + require.Len(t, pathList, 1) + cachedCoreFile := pathList[0] + lastUsedPath := cachedCoreFile.Parent().Join(".last-used") + require.True(t, lastUsedPath.Exist()) + coreStatBefore, err := cachedCoreFile.Stat() + require.NoError(t, err) - // Touch a file of the core and check if the builder invalidate the cache - time.Sleep(time.Second) - now := time.Now().Local() - coreFolder := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6") - err = coreFolder.Join("cores", "arduino", "Arduino.h").Chtimes(now, now) - require.NoError(t, err) + // Run build again and check timestamp is unchanged + _, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String()) + require.NoError(t, err) + coreStatAfterRebuild, err := cachedCoreFile.Stat() + require.NoError(t, err) + require.Equal(t, coreStatBefore.ModTime(), coreStatAfterRebuild.ModTime()) - // Run build again, to verify that the builder rebuilds core.a - _, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String()) - require.NoError(t, err) - coreStatAfterTouch, err := cachedCoreFile.Stat() - require.NoError(t, err) - require.NotEqual(t, coreStatBefore.ModTime(), coreStatAfterTouch.ModTime()) + // Touch a file of the core and check if the builder invalidate the cache + time.Sleep(time.Second) + now := time.Now().Local() + coreFolder := cli.DataDir().Join("packages", "arduino", "hardware", "avr", "1.8.6") + err = coreFolder.Join("cores", "arduino", "Arduino.h").Chtimes(now, now) + require.NoError(t, err) + + // Run build again, to verify that the builder rebuilds core.a + _, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-cache-path", buildCachePath.String(), sketchPath.String()) + require.NoError(t, err) + coreStatAfterTouch, err := cachedCoreFile.Stat() + require.NoError(t, err) + require.NotEqual(t, coreStatBefore.ModTime(), coreStatAfterTouch.ModTime()) + }) } func TestMergeSketchWithBootloader(t *testing.T) {