diff --git a/internal/crosscompile/compile/libc/libc_test.go b/internal/crosscompile/compile/libc/libc_test.go index 3689d9fa..383c116a 100644 --- a/internal/crosscompile/compile/libc/libc_test.go +++ b/internal/crosscompile/compile/libc/libc_test.go @@ -2,10 +2,73 @@ package libc import ( "path/filepath" + "strings" "testing" ) -func TestGetPicolibcConfig(t *testing.T) { +func TestGetNewlibESP32Config_LibConfig(t *testing.T) { + config := GetNewlibESP32Config() + + // Test basic configuration fields + expectedName := "newlib-esp32" + if config.Name != expectedName { + t.Errorf("Expected Name '%s', got '%s'", expectedName, config.Name) + } + + expectedVersion := "esp-4.3.0_20250211-patch2" + if config.Version != expectedVersion { + t.Errorf("Expected Version '%s', got '%s'", expectedVersion, config.Version) + } + + expectedUrl := "https://github.com/goplus/newlib/archive/refs/tags/esp-4.3.0_20250211-patch2.tar.gz" + if config.Url != expectedUrl { + t.Errorf("Expected Url '%s', got '%s'", expectedUrl, config.Url) + } + + expectedArchiveSrcDir := "newlib-esp-4.3.0_20250211-patch2" + if config.ArchiveSrcDir != expectedArchiveSrcDir { + t.Errorf("Expected ArchiveSrcDir '%s', got '%s'", expectedArchiveSrcDir, config.ArchiveSrcDir) + } + + // Test String() method + expectedString := "newlib-esp32-esp-4.3.0_20250211-patch2" + if config.String() != expectedString { + t.Errorf("Expected String() '%s', got '%s'", expectedString, config.String()) + } +} + +func TestGetPicolibcConfig_LibConfig(t *testing.T) { + config := GetPicolibcConfig() + + // Test basic configuration fields + expectedName := "picolibc" + if config.Name != expectedName { + t.Errorf("Expected Name '%s', got '%s'", expectedName, config.Name) + } + + expectedVersion := "v0.1.0" + if config.Version != expectedVersion { + t.Errorf("Expected Version '%s', got '%s'", expectedVersion, config.Version) + } + + expectedUrl := "https://github.com/goplus/picolibc/archive/refs/heads/main.zip" + if config.Url != expectedUrl { + t.Errorf("Expected Url '%s', got '%s'", expectedUrl, config.Url) + } + + expectedArchiveSrcDir := "picolibc-main" + if config.ArchiveSrcDir != expectedArchiveSrcDir { + t.Errorf("Expected ArchiveSrcDir '%s', got '%s'", expectedArchiveSrcDir, config.ArchiveSrcDir) + } + + // Test String() method + expectedString := "picolibc-v0.1.0" + if config.String() != expectedString { + t.Errorf("Expected String() '%s', got '%s'", expectedString, config.String()) + } +} + +func TestGetPicolibcCompileConfig(t *testing.T) { baseDir := "/test/base" target := "test-target" @@ -131,6 +194,119 @@ func TestGetPicolibcConfig_EdgeCases(t *testing.T) { }) } +func TestPicolibcFileStructure(t *testing.T) { + baseDir := "/test/base" + target := "test-target" + + config := GetPicolibcCompileConfig(baseDir, target) + group := config.Groups[0] + + // Test that all files have .c extension (no assembly files in picolibc config) + for _, file := range group.Files { + if !strings.HasSuffix(file, ".c") { + t.Errorf("File '%s' does not have .c extension", file) + } + } + + // Test that files are from expected directories + stringFiles := 0 + stdlibFiles := 0 + tinystdioFiles := 0 + + for _, file := range group.Files { + if strings.Contains(file, "/string/") { + stringFiles++ + } else if strings.Contains(file, "/stdlib/") { + stdlibFiles++ + } else if strings.Contains(file, "/tinystdio/") { + tinystdioFiles++ + } + } + + if stringFiles < 50 { + t.Errorf("Expected at least 50 string files, got %d", stringFiles) + } + if stdlibFiles < 5 { + t.Errorf("Expected at least 5 stdlib files, got %d", stdlibFiles) + } + if tinystdioFiles < 3 { + t.Errorf("Expected at least 3 tinystdio files, got %d", tinystdioFiles) + } + + // Test that all files have correct base directory + for _, file := range group.Files { + if !strings.HasPrefix(file, baseDir) { + t.Errorf("File '%s' does not have expected base directory '%s'", file, baseDir) + } + } +} + +func TestPicolibcCompilerFlags(t *testing.T) { + baseDir := "/test/base" + target := "test-target" + + config := GetPicolibcCompileConfig(baseDir, target) + group := config.Groups[0] + + // Test that required preprocessor definitions are present + requiredDefines := []string{ + "-D_COMPILING_NEWLIB", + "-D_HAVE_ALIAS_ATTRIBUTE", + "-DTINY_STDIO", + "-DPOSIX_IO", + "-DFORMAT_DEFAULT_INTEGER", + "-D_IEEE_LIBM", + "-D_WANT_IO_C99_FORMATS", + } + + for _, define := range requiredDefines { + found := false + for _, flag := range group.CFlags { + if flag == define { + found = true + break + } + } + if !found { + t.Errorf("Required define '%s' not found in CFlags", define) + } + } + + // Test that required include paths are present + requiredIncludes := []string{ + "-I" + baseDir, + "-isystem" + filepath.Join(baseDir, "newlib", "libc", "include"), + "-I" + filepath.Join(baseDir, "newlib", "libm", "common"), + "-I" + filepath.Join(baseDir, "newlib", "libc", "locale"), + "-I" + filepath.Join(baseDir, "newlib", "libc", "tinystdio"), + } + + for _, include := range requiredIncludes { + found := false + for _, flag := range group.CFlags { + if flag == include { + found = true + break + } + } + if !found { + t.Errorf("Required include '%s' not found in CFlags", include) + } + } + + // Test that nostdlib is present + found := false + for _, flag := range group.CFlags { + if flag == "-nostdlib" { + found = true + break + } + } + if !found { + t.Error("Required flag '-nostdlib' not found in CFlags") + } +} + func TestGetNewlibESP32ConfigRISCV(t *testing.T) { baseDir := "/test/base" target := "riscv32-unknown-elf" diff --git a/internal/crosscompile/compile/libc/newlibesp.go b/internal/crosscompile/compile/libc/newlibesp.go index dd6c57fb..95f30622 100644 --- a/internal/crosscompile/compile/libc/newlibesp.go +++ b/internal/crosscompile/compile/libc/newlibesp.go @@ -27,10 +27,10 @@ func withDefaultCCFlags(ccflags []string) []string { func GetNewlibESP32Config() compile.LibConfig { return compile.LibConfig{ - Url: "https://github.com/goplus/newlib/archive/refs/tags/v0.3.0.tar.gz", + Url: "https://github.com/goplus/newlib/archive/refs/tags/esp-4.3.0_20250211-patch2.tar.gz", Name: "newlib-esp32", - Version: "v0.3.0", - ArchiveSrcDir: "newlib-0.3.0", + Version: "esp-4.3.0_20250211-patch2", + ArchiveSrcDir: "newlib-esp-4.3.0_20250211-patch2", } } diff --git a/internal/crosscompile/compile/rtlib/compiler_rt.go b/internal/crosscompile/compile/rtlib/compiler_rt.go index 1a7f4590..d526251c 100644 --- a/internal/crosscompile/compile/rtlib/compiler_rt.go +++ b/internal/crosscompile/compile/rtlib/compiler_rt.go @@ -103,9 +103,9 @@ func withPlatformSpecifiedFiles(baseDir, target string, files []string) []string func GetCompilerRTConfig() compile.LibConfig { return compile.LibConfig{ Name: "compiler-rt", - Url: "https://github.com/goplus/compiler-rt/archive/refs/tags/v0.1.0.tar.gz", - Version: "v0.1.0", - ArchiveSrcDir: "compiler-rt-0.1.0", + Url: "https://github.com/goplus/compiler-rt/archive/refs/tags/xtensa_release_19.1.2.tar.gz", + Version: "xtensa_release_19.1.2", + ArchiveSrcDir: "compiler-rt-xtensa_release_19.1.2", } } diff --git a/internal/crosscompile/compile/rtlib/rt_test.go b/internal/crosscompile/compile/rtlib/rt_test.go index ca18e1b5..427ecd5b 100644 --- a/internal/crosscompile/compile/rtlib/rt_test.go +++ b/internal/crosscompile/compile/rtlib/rt_test.go @@ -5,6 +5,37 @@ import ( "testing" ) +func TestGetNewlibESP32Config_LibConfig(t *testing.T) { + config := GetCompilerRTConfig() + + // Test basic configuration fields + expectedName := "compiler-rt" + if config.Name != expectedName { + t.Errorf("Expected Name '%s', got '%s'", expectedName, config.Name) + } + + expectedVersion := "xtensa_release_19.1.2" + if config.Version != expectedVersion { + t.Errorf("Expected Version '%s', got '%s'", expectedVersion, config.Version) + } + + expectedUrl := "https://github.com/goplus/compiler-rt/archive/refs/tags/xtensa_release_19.1.2.tar.gz" + if config.Url != expectedUrl { + t.Errorf("Expected Url '%s', got '%s'", expectedUrl, config.Url) + } + + expectedArchiveSrcDir := "compiler-rt-xtensa_release_19.1.2" + if config.ArchiveSrcDir != expectedArchiveSrcDir { + t.Errorf("Expected ArchiveSrcDir '%s', got '%s'", expectedArchiveSrcDir, config.ArchiveSrcDir) + } + + // Test String() method + expectedString := "compiler-rt-xtensa_release_19.1.2" + if config.String() != expectedString { + t.Errorf("Expected String() '%s', got '%s'", expectedString, config.String()) + } +} + func TestPlatformSpecifiedFiles(t *testing.T) { tests := []struct { target string