-
Notifications
You must be signed in to change notification settings - Fork 46
fix(esp32): restore emulator float output and add regression coverage #1699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2f68148
fe2cb9f
6d61f9f
fdb7c48
e5411f2
158fd2c
250f41e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Hello World |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package main | ||
|
|
||
| import "github.com/goplus/lib/c" | ||
|
|
||
| func main() { | ||
| c.Printf(c.Str("Hello World\n")) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| +5.000000e+00 +8.000000e+00 | ||
| 1 +2.000000e+00 | ||
| 0x0 +0.000000e+00 notOk: true | ||
| 0x0 +0.000000e+00 true | ||
| 3 +6.280000e+00 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package main | ||
|
|
||
| type point struct { | ||
| x float64 | ||
| y float64 | ||
| } | ||
|
|
||
| type myPoint = point | ||
|
|
||
| func (p *point) scale(factor float64) { | ||
| p.x *= factor | ||
| p.y *= factor | ||
| } | ||
|
|
||
| func (p *myPoint) move(dx, dy float64) { | ||
| p.x += dx | ||
| p.y += dy | ||
| } | ||
|
|
||
| func pair(f float64) (int, float64) { | ||
| return 1, f | ||
| } | ||
|
|
||
| type bar struct { | ||
| pb *byte | ||
| f float32 | ||
| } | ||
|
|
||
| type foo struct { | ||
| pb *byte | ||
| f float32 | ||
| } | ||
|
|
||
| func xadd(a, b int) int { | ||
| return a + b | ||
| } | ||
|
|
||
| func double(v float64) float64 { | ||
| return v * 2 | ||
| } | ||
|
|
||
| func main() { | ||
| pt := &myPoint{1, 2} | ||
| pt.scale(2) | ||
| pt.move(3, 4) | ||
| println(pt.x, pt.y) | ||
|
|
||
| i, f := pair(2.0) | ||
| println(i, f) | ||
|
|
||
| // Keep this case on the float-format path without triggering | ||
| // esp32 type-assert timeout cases tracked separately. | ||
| ret, ok := bar{}, false | ||
| println(ret.pb, ret.f, "notOk:", !ok) | ||
|
|
||
| ret2, ok2 := foo{}, true | ||
| println(ret2.pb, ret2.f, ok2) | ||
|
|
||
| println(xadd(1, 2), double(3.14)) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -558,8 +558,8 @@ func TestGetNewlibESP32ConfigXtensa(t *testing.T) { | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Test Groups configuration | ||||||||||||||
| if len(config.Groups) != 3 { | ||||||||||||||
| t.Errorf("Expected 2 groups, got %d", len(config.Groups)) | ||||||||||||||
| if len(config.Groups) != 6 { | ||||||||||||||
| t.Errorf("Expected 6 groups, got %d", len(config.Groups)) | ||||||||||||||
| } else { | ||||||||||||||
| // Group 0: libcrt0 | ||||||||||||||
| group0 := config.Groups[0] | ||||||||||||||
|
|
@@ -631,6 +631,92 @@ func TestGetNewlibESP32ConfigXtensa(t *testing.T) { | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Group 3: libm sources with -fbuiltin -fno-math-errno. | ||||||||||||||
| group3 := config.Groups[3] | ||||||||||||||
| expectedOutput3 := "libm-fbuiltin_fno_math_errno-" + target + ".a" | ||||||||||||||
| if group3.OutputFileName != expectedOutput3 { | ||||||||||||||
| t.Errorf("Group3 OutputFileName expected '%s', got '%s'", expectedOutput3, group3.OutputFileName) | ||||||||||||||
| } | ||||||||||||||
| for _, sample := range []string{ | ||||||||||||||
| filepath.Join(baseDir, "newlib", "libm", "common", "s_fpclassify.c"), | ||||||||||||||
| filepath.Join(baseDir, "newlib", "libm", "common", "sf_fpclassify.c"), | ||||||||||||||
| } { | ||||||||||||||
| found := false | ||||||||||||||
| for _, file := range group3.Files { | ||||||||||||||
| if file == sample { | ||||||||||||||
| found = true | ||||||||||||||
| break | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| if !found { | ||||||||||||||
| t.Errorf("Expected file '%s' not found in group3 files", sample) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| if !slices.Contains(group3.CFlags, "-fbuiltin") || !slices.Contains(group3.CFlags, "-fno-math-errno") { | ||||||||||||||
| t.Errorf("Expected group3 CFlags to contain -fbuiltin and -fno-math-errno") | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Group 4: default libm sources. | ||||||||||||||
| group4 := config.Groups[4] | ||||||||||||||
| expectedOutput4 := "libm-default-" + target + ".a" | ||||||||||||||
| if group4.OutputFileName != expectedOutput4 { | ||||||||||||||
| t.Errorf("Group4 OutputFileName expected '%s', got '%s'", expectedOutput4, group4.OutputFileName) | ||||||||||||||
| } | ||||||||||||||
| for _, sample := range []string{ | ||||||||||||||
| filepath.Join(baseDir, "newlib", "libm", "complex", "cabs.c"), | ||||||||||||||
| filepath.Join(baseDir, "newlib", "libm", "math", "e_acos.c"), | ||||||||||||||
| } { | ||||||||||||||
| found := false | ||||||||||||||
| for _, file := range group4.Files { | ||||||||||||||
| if file == sample { | ||||||||||||||
| found = true | ||||||||||||||
| break | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| if !found { | ||||||||||||||
| t.Errorf("Expected file '%s' not found in group4 files", sample) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| if slices.Contains(group4.CFlags, "-fbuiltin") || slices.Contains(group4.CFlags, "-fno-math-errno") || slices.Contains(group4.CFlags, "-D_LIBM") { | ||||||||||||||
| t.Errorf("Expected group4 CFlags to not contain -fbuiltin/-fno-math-errno/-D_LIBM") | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Group 5: machine/xtensa libm sources built with -D_LIBM. | ||||||||||||||
| group5 := config.Groups[5] | ||||||||||||||
| expectedOutput5 := "libm-machine_xtensa_d_libm-" + target + ".a" | ||||||||||||||
| if group5.OutputFileName != expectedOutput5 { | ||||||||||||||
| t.Errorf("Group5 OutputFileName expected '%s', got '%s'", expectedOutput5, group5.OutputFileName) | ||||||||||||||
| } | ||||||||||||||
| for _, sample := range []string{ | ||||||||||||||
| filepath.Join(baseDir, "newlib", "libm", "machine", "xtensa", "ef_sqrt.c"), | ||||||||||||||
| filepath.Join(baseDir, "newlib", "libm", "machine", "xtensa", "fegetenv.c"), | ||||||||||||||
| } { | ||||||||||||||
| found := false | ||||||||||||||
| for _, file := range group5.Files { | ||||||||||||||
| if file == sample { | ||||||||||||||
| found = true | ||||||||||||||
| break | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| if !found { | ||||||||||||||
| t.Errorf("Expected file '%s' not found in group5 files", sample) | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| if !slices.Contains(group5.CFlags, "-D_LIBM") { | ||||||||||||||
| t.Errorf("Expected group5 CFlags to contain -D_LIBM") | ||||||||||||||
| } | ||||||||||||||
| if !slices.Contains(group5.CFlags, "-I"+filepath.Join(baseDir, "newlib", "libc", "machine", "xtensa", "include")) { | ||||||||||||||
| t.Errorf("Expected group5 CFlags to contain xtensa machine include path") | ||||||||||||||
| } | ||||||||||||||
| if !slices.Contains(group5.CFlags, "-I"+filepath.Join(baseDir, "newlib", "libc", "xtensa")) { | ||||||||||||||
| t.Errorf("Expected group5 CFlags to contain xtensa sys include path") | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| totalLibmFiles := len(group3.Files) + len(group4.Files) + len(group5.Files) | ||||||||||||||
| if totalLibmFiles != 380 { | ||||||||||||||
| t.Errorf("Expected 380 xtensa libm files from command-log build list, got %d", totalLibmFiles) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Test LDFlags and CCFlags | ||||||||||||||
| if len(group0.LDFlags) == 0 { | ||||||||||||||
| t.Error("Expected non-empty LDFlags in group0") | ||||||||||||||
|
|
@@ -698,8 +784,8 @@ func TestGroupConfiguration(t *testing.T) { | |||||||||||||
|
|
||||||||||||||
| t.Run("Xtensa_GroupCount", func(t *testing.T) { | ||||||||||||||
| config := getNewlibESP32ConfigXtensa(baseDir, target) | ||||||||||||||
| if len(config.Groups) != 3 { | ||||||||||||||
| t.Errorf("Expected 2 groups for Xtensa, got %d", len(config.Groups)) | ||||||||||||||
| if len(config.Groups) != 6 { | ||||||||||||||
| t.Errorf("Expected 6 groups for Xtensa, got %d", len(config.Groups)) | ||||||||||||||
| } | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -726,12 +812,13 @@ func TestGroupConfiguration(t *testing.T) { | |||||||||||||
| expectedNames := []string{ | ||||||||||||||
| "libcrt0-" + target + ".a", | ||||||||||||||
| "libgloss-" + target + ".a", | ||||||||||||||
| "libc-" + target + ".a", | ||||||||||||||
| "libm-fbuiltin_fno_math_errno-" + target + ".a", | ||||||||||||||
| "libm-default-" + target + ".a", | ||||||||||||||
| "libm-machine_xtensa_d_libm-" + target + ".a", | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| for i, group := range config.Groups { | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old guard Consider bounding the loop or adding a length check:
Suggested change
|
||||||||||||||
| if i >= len(expectedNames) { | ||||||||||||||
| return | ||||||||||||||
| } | ||||||||||||||
| if group.OutputFileName != expectedNames[i] { | ||||||||||||||
| t.Errorf("Group %d expected name '%s', got '%s'", i, expectedNames[i], group.OutputFileName) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The comment says "without triggering esp32 type-assert timeout cases" but the code uses a plain composite literal — no type assertion is involved. The intent is clear (avoid the
struczero-stylev.(bar)path), but the phrasing could confuse readers into thinking this code somehow relates to type assertions. Consider rephrasing to make it explicit, e.g.: