Skip to content

Commit

Permalink
Porting legacy tests to new integration-test infra (part 4...) (ard…
Browse files Browse the repository at this point in the history
…uino#2315)

* ported SketchThatIncludesArduinoH from legacy into integration test

* ported SketchWithStaticAsserts from legacy into integration test

* ported SketchWithEnumClass from legacy into integration test

* ported SketchWithExternC from legacy into integration test

* ported testBuilderSketchWithMultilinePrototypes from legacy into integration test

* ported SketchWithExternCMultiline from legacy into integration test

* ported SketchWithMultilineTemplate from legacy into integration test

* ported SketchWithFakeFunctionPointer from legacy into integration test

* fix wrong templating

* ported SketchWithMinMaxDefinitions from legacy into integration test

* ported SketchWithFastledsLibrary from legacy into integration test

* ported sketch with merged sketch and bootloader from legacy into integration test

* temporary disable legacy test, before porting them to the new infra

* update .gitignore

* ported CheckBuildOptionsFile from legacy into integration test

* ported SketchClassFunction from legacy into integration test

* ported SketchThatChecksIfSPIHasTransactionsAndIncludesMissingEthernet from legacy into integration test

* remove legacy builder test folder

* remove unsued fields from context
  • Loading branch information
alessio-perugini authored Sep 15, 2023
1 parent 9c073c1 commit 6d57ce6
Show file tree
Hide file tree
Showing 122 changed files with 630 additions and 12,222 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ venv
/dist
/.pytest-tmp-dir
/node_modules/
__debug_bin*

# gRPC client example folder
/client_example/client_example
Expand Down
273 changes: 273 additions & 0 deletions internal/integrationtest/compile_4/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/go-paths-helper"
"github.com/stretchr/testify/require"
"go.bug.st/testifyjson/requirejson"
"golang.org/x/exp/slices"
)

Expand Down Expand Up @@ -63,6 +64,8 @@ func TestCompileOfProblematicSketches(t *testing.T) {
require.NoError(t, err)
_, _, err = cli.Run("lib", "install", "CapacitiveSensor@0.5")
require.NoError(t, err)
_, _, err = cli.Run("lib", "install", "FastLED@3.1.0")
require.NoError(t, err)

// Install custom hardware required for tests
customHwDir, err := paths.New("..", "testdata", "user_hardware").Abs()
Expand Down Expand Up @@ -99,12 +102,24 @@ func TestCompileOfProblematicSketches(t *testing.T) {
{"SketchNoFunctionsTwoFiles", testBuilderSketchNoFunctionsTwoFiles},
{"SketchWithClassAndMethodSubstring", testBuilderSketchWithClassAndMethodSubstring},
{"SketchThatChecksIfSPIHasTransactions", tryBuildAvrLeonardo},
{"SketchThatChecksIfSPIHasTransactionsAndIncludesMissingEthernet", testBuilderSketchThatChecksIfSPIHasTransactionsAndIncludesMissingEthernet},
{"SketchWithDependendLibraries", tryBuildAvrLeonardo},
{"SketchWithFunctionPointer", tryBuildAvrLeonardo},
{"USBHostExample", testBuilderUSBHostExample},
{"SketchWithConflictingLibraries", testBuilderSketchWithConflictingLibraries},
{"SketchLibraryProvidesAllIncludes", testBuilderSketchLibraryProvidesAllIncludes},
{"UserHardware", testBuilderWithUserHardware},
{"SketchThatIncludesArduinoH", testBuilderSketchThatIncludesArduinoH},
{"SketchWithStaticAsserts", testBuilderSketchWithStaticAsserts},
{"SketchWithEnumClass", testBuilderSketchWithEnumClass},
{"SketchWithExternC", testBuilderSketchWithExternC},
{"SketchWithMultilinePrototypes", testBuilderSketchWithMultilinePrototypes},
{"SketchWithExternCMultiline", testBuilderSketchWithExternCMultiline},
{"SketchWithMultilineTemplate", testBuilderSketchWithMultilineTemplate},
{"SketchWithFakeFunctionPointer", testBuilderSketchWithFakeFunctionPointer},
{"SketchWithMinMaxDefinitions", testBuilderSketchWithMinMaxDefinitions},
{"SketchWithFastledsLibrary", testBuilderSketchWithFastledsLibrary},
{"SketchClassFunction", testBuilderSketchClassFunction},
}.Run(t, env, cli)
}

Expand Down Expand Up @@ -613,6 +628,179 @@ func tryBuildAvrLeonardo(t *testing.T, env *integrationtest.Environment, cli *in
require.NoError(t, err)
}

func testBuilderSketchThatIncludesArduinoH(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithStaticAsserts(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithEnumClass(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithExternC(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithMultilinePrototypes(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithExternCMultiline(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithMultilineTemplate(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithFakeFunctionPointer(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithMinMaxDefinitions(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:samd:arduino_zero_native")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:samd:arduino_zero_native")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchWithFastledsLibrary(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:samd:arduino_zero_native")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:samd:arduino_zero_native")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchClassFunction(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
})

t.Run("Preprocess", func(t *testing.T) {
// Preprocess
sketchPath, preprocessedSketch, err := tryPreprocess(t, env, cli, "arduino:avr:leonardo")
require.NoError(t, err)
comparePreprocessGoldenFile(t, sketchPath, preprocessedSketch)
})
}

func testBuilderSketchThatChecksIfSPIHasTransactionsAndIncludesMissingEthernet(t *testing.T, env *integrationtest.Environment, cli *integrationtest.ArduinoCLI) {
t.Run("Build", func(t *testing.T) {
// Build
_, err := tryBuild(t, env, cli, "arduino:avr:leonardo")
require.Error(t, err)
})
}

type builderOutput struct {
CompilerOut string `json:"compiler_out"`
CompilerErr string `json:"compiler_err"`
Expand Down Expand Up @@ -765,3 +953,88 @@ func TestCoreCaching(t *testing.T) {
require.NoError(t, err)
require.NotEqual(t, coreStatBefore.ModTime(), coreStatAfterTouch.ModTime())
}

func TestMergeSketchWithBootloader(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

sketchPath, err := paths.New("testdata", "SketchWithMergedSketchAndBootloader").Abs()
require.NoError(t, err)

// Install Arduino AVR Boards
_, _, err = cli.Run("core", "install", "arduino:avr@1.8.6")
require.NoError(t, err)

buildPath, err := paths.MkTempDir("", "arduino-integration-test")
require.NoError(t, err)
defer buildPath.RemoveAll()

// Build first time
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)

bytes, err := buildPath.Join("SketchWithMergedSketchAndBootloader.ino.with_bootloader.hex").ReadFile()
require.NoError(t, err)
mergedSketchHex := string(bytes)

require.Contains(t, mergedSketchHex, ":100000000C9434000C9446000C9446000C9446006A\n")
require.True(t, strings.HasSuffix(mergedSketchHex, ":00000001FF\n"))
}

func TestBuildOptionsFile(t *testing.T) {
env, cli := integrationtest.CreateArduinoCLIWithEnvironment(t)
defer env.CleanUp()

sketchPath := cli.CopySketch("sketch_simple")
defer sketchPath.RemoveAll()

_, _, err := cli.Run("core", "install", "arduino:avr@1.8.6")
require.NoError(t, err)

buildPath, err := paths.MkTempDir("", "arduino-integration-test")
require.NoError(t, err)
defer buildPath.RemoveAll()

// Build first time
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)

exist, err := buildPath.Join("build.options.json").ExistCheck()
require.NoError(t, err)
require.True(t, exist)

buildOptionsBytes, err := buildPath.Join("build.options.json").ReadFile()
require.NoError(t, err)

requirejson.Query(t, buildOptionsBytes, "keys", `[
"additionalFiles",
"builtInToolsFolders",
"compiler.optimization_flags",
"customBuildProperties",
"fqbn",
"hardwareFolders",
"otherLibrariesFolders",
"sketchLocation"
]`)
requirejson.Query(t, buildOptionsBytes, ".fqbn", `"arduino:avr:uno"`)
requirejson.Query(t, buildOptionsBytes, ".customBuildProperties", `"build.warn_data_percentage=75"`)

// Recompiling a second time should provide the same result
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(), sketchPath.String())
require.NoError(t, err)

buildOptionsBytes, err = buildPath.Join("build.options.json").ReadFile()
require.NoError(t, err)
requirejson.Query(t, buildOptionsBytes, ".customBuildProperties", `"build.warn_data_percentage=75"`)

// Recompiling with a new build option must produce a new `build.options.json`
_, _, err = cli.Run("compile", "-b", "arduino:avr:uno", "--build-path", buildPath.String(),
"--build-property", "custom=prop",
sketchPath.String(),
)
require.NoError(t, err)

buildOptionsBytes, err = buildPath.Join("build.options.json").ReadFile()
require.NoError(t, err)
requirejson.Query(t, buildOptionsBytes, ".customBuildProperties", `"custom=prop,build.warn_data_percentage=75"`)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <Arduino.h>
#line 1 {{QuoteCppString .sketchMainFile}}
class test {
void asdf() {}
};
#line 4 {{QuoteCppString .sketchMainFile}}
void setup();
#line 7 {{QuoteCppString .sketchMainFile}}
void loop();
#line 8 {{QuoteCppString .sketchMainFile}}
void asdf();
#line 4 {{QuoteCppString .sketchMainFile}}
void setup() {
asdf();
}
void loop() {}
void asdf() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#line 1 {{QuoteCppString .sketchMainFile}}
// Arduino.h should not be automatically included by the Arduino
// preprocessor before the explicit include line in this sketch.

#if defined(HIGH)
#error Arduino.h seems to be automatically included
#endif

# include <Arduino.h>

#line 10 {{QuoteCppString .sketchMainFile}}
void setup();
#line 13 {{QuoteCppString .sketchMainFile}}
void loop();
#line 10 {{QuoteCppString .sketchMainFile}}
void setup() {
}

void loop() {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <Arduino.h>
#line 1 {{QuoteCppString .sketchMainFile}}
#line 1 {{QuoteCppString .sketchMainFile}}
void test();
#line 11 {{QuoteCppString .sketchMainFile}}
void test2();
#line 14 {{QuoteCppString .sketchMainFile}}
void setup();
#line 17 {{QuoteCppString .sketchMainFile}}
void loop();
#line 1 {{QuoteCppString .sketchMainFile}}
void test() {
test2();
}

enum class MyEnum
{
AValue = 0,
AnotherValue = 1
};

void test2() {
}

void setup() {
}

void loop() {
}


Loading

0 comments on commit 6d57ce6

Please sign in to comment.