mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
60f8a62978
This commit adds support for a scheduler that runs a scheduler on all available cores. It is meant to be used on baremetal systems with a fixed number of cores, such as the RP2040. The initial implementation adds support for multicore scheduling to the riscv-qemu target as a convenient testing target. This means that this new multicore scheduler is tested in CI, including a bunch of standard library tests (`make tinygo-test-baremetal`). This should ensure the new scheduler is reasonably well tested before trying to use it on harder-to-debug targets like the RP2040.
133 lines
2.7 KiB
Go
133 lines
2.7 KiB
Go
package compileopts_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/tinygo-org/tinygo/compileopts"
|
|
)
|
|
|
|
func TestVerifyOptions(t *testing.T) {
|
|
|
|
expectedGCError := errors.New(`invalid gc option 'incorrect': valid values are none, leaking, conservative, custom, precise, boehm`)
|
|
expectedSchedulerError := errors.New(`invalid scheduler option 'incorrect': valid values are none, tasks, asyncify, threads, cores`)
|
|
expectedPrintSizeError := errors.New(`invalid size option 'incorrect': valid values are none, short, full, html`)
|
|
expectedPanicStrategyError := errors.New(`invalid panic option 'incorrect': valid values are print, trap`)
|
|
|
|
testCases := []struct {
|
|
name string
|
|
opts compileopts.Options
|
|
expectedError error
|
|
}{
|
|
{
|
|
name: "OptionsEmpty",
|
|
opts: compileopts.Options{},
|
|
},
|
|
{
|
|
name: "InvalidGCOption",
|
|
opts: compileopts.Options{
|
|
GC: "incorrect",
|
|
},
|
|
expectedError: expectedGCError,
|
|
},
|
|
{
|
|
name: "GCOptionNone",
|
|
opts: compileopts.Options{
|
|
GC: "none",
|
|
},
|
|
},
|
|
{
|
|
name: "GCOptionLeaking",
|
|
opts: compileopts.Options{
|
|
GC: "leaking",
|
|
},
|
|
},
|
|
{
|
|
name: "GCOptionConservative",
|
|
opts: compileopts.Options{
|
|
GC: "conservative",
|
|
},
|
|
},
|
|
{
|
|
name: "GCOptionCustom",
|
|
opts: compileopts.Options{
|
|
GC: "custom",
|
|
},
|
|
},
|
|
{
|
|
name: "InvalidSchedulerOption",
|
|
opts: compileopts.Options{
|
|
Scheduler: "incorrect",
|
|
},
|
|
expectedError: expectedSchedulerError,
|
|
},
|
|
{
|
|
name: "SchedulerOptionNone",
|
|
opts: compileopts.Options{
|
|
Scheduler: "none",
|
|
},
|
|
},
|
|
{
|
|
name: "SchedulerOptionTasks",
|
|
opts: compileopts.Options{
|
|
Scheduler: "tasks",
|
|
},
|
|
},
|
|
{
|
|
name: "InvalidPrintSizeOption",
|
|
opts: compileopts.Options{
|
|
PrintSizes: "incorrect",
|
|
},
|
|
expectedError: expectedPrintSizeError,
|
|
},
|
|
{
|
|
name: "PrintSizeOptionNone",
|
|
opts: compileopts.Options{
|
|
PrintSizes: "none",
|
|
},
|
|
},
|
|
{
|
|
name: "PrintSizeOptionShort",
|
|
opts: compileopts.Options{
|
|
PrintSizes: "short",
|
|
},
|
|
},
|
|
{
|
|
name: "PrintSizeOptionFull",
|
|
opts: compileopts.Options{
|
|
PrintSizes: "full",
|
|
},
|
|
},
|
|
{
|
|
name: "InvalidPanicOption",
|
|
opts: compileopts.Options{
|
|
PanicStrategy: "incorrect",
|
|
},
|
|
expectedError: expectedPanicStrategyError,
|
|
},
|
|
{
|
|
name: "PanicOptionPrint",
|
|
opts: compileopts.Options{
|
|
PanicStrategy: "print",
|
|
},
|
|
},
|
|
{
|
|
name: "PanicOptionTrap",
|
|
opts: compileopts.Options{
|
|
PanicStrategy: "trap",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := tc.opts.Verify()
|
|
if tc.expectedError != err {
|
|
if tc.expectedError.Error() != err.Error() {
|
|
t.Errorf("expected %v, got %v", tc.expectedError, err)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|