From 3348b645af5d5e26ee1b577927f721b735fff780 Mon Sep 17 00:00:00 2001 From: xgopilot Date: Mon, 3 Nov 2025 02:15:24 +0000 Subject: [PATCH] chore: remove redundant test files - Remove _demo/embed/export/test.sh (replaced by .github/workflows/export_test.sh) - Remove test/export_test.go (not needed) Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- _demo/embed/export/test.sh | 118 --------------------------- test/export_test.go | 160 ------------------------------------- 2 files changed, 278 deletions(-) delete mode 100755 _demo/embed/export/test.sh delete mode 100644 test/export_test.go diff --git a/_demo/embed/export/test.sh b/_demo/embed/export/test.sh deleted file mode 100755 index 0a132931..00000000 --- a/_demo/embed/export/test.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash - -# Test script for //export with different symbol names -# This is essential for embedded development where hardware specifications require -# specific symbol names (e.g., ARM Cortex-M interrupt handlers). - -set -e # Exit on any error - -# Get script directory -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd "$SCRIPT_DIR" - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -# Function to print colored output -print_status() { - echo -e "${GREEN}[INFO]${NC} $1" -} - -print_error() { - echo -e "${RED}[ERROR]${NC} $1" -} - -# Check if llgo command is available -if ! command -v llgo &> /dev/null; then - print_error "llgo command not found, please install llgo first" - exit 1 -fi - -# Check if LLGO_ROOT is set -if [[ -z "$LLGO_ROOT" ]]; then - print_error "LLGO_ROOT environment variable is not set" - exit 1 -fi - -print_status "Starting export symbol name test..." -print_status "Working directory: $SCRIPT_DIR" -print_status "LLGO_ROOT: $LLGO_ROOT" - -echo "" - -# Build the test program -print_status "=== Building test program ===" -if llgo build -o test_export main.go; then - print_status "Build succeeded" -else - print_error "Build failed" - exit 1 -fi - -# Check for expected symbols using nm -print_status "=== Checking exported symbols with nm ===" -if ! command -v nm &> /dev/null; then - print_error "nm command not found, skipping symbol verification" - exit 1 -fi - -NM_OUTPUT=$(nm test_export) - -# Verify LPSPI2_IRQHandler symbol exists (not interruptLPSPI2) -if echo "$NM_OUTPUT" | grep -q "LPSPI2_IRQHandler"; then - print_status "✓ Symbol LPSPI2_IRQHandler found" -else - print_error "✗ Symbol LPSPI2_IRQHandler not found" - echo "Available symbols:" - echo "$NM_OUTPUT" - exit 1 -fi - -# Verify SysTick_Handler symbol exists (not systemTickHandler) -if echo "$NM_OUTPUT" | grep -q "SysTick_Handler"; then - print_status "✓ Symbol SysTick_Handler found" -else - print_error "✗ Symbol SysTick_Handler not found" - echo "Available symbols:" - echo "$NM_OUTPUT" - exit 1 -fi - -# Verify Add symbol exists (same name) -if echo "$NM_OUTPUT" | grep -q "Add"; then - print_status "✓ Symbol Add found" -else - print_error "✗ Symbol Add not found" - echo "Available symbols:" - echo "$NM_OUTPUT" - exit 1 -fi - -# Verify that the original function names are NOT exported as main symbols -# (they should only appear as internal symbols, not as exported text symbols 'T') -EXPORTED_SYMBOLS=$(echo "$NM_OUTPUT" | grep " T " || true) - -if echo "$EXPORTED_SYMBOLS" | grep -q "interruptLPSPI2"; then - print_error "✗ Unexpected exported symbol: interruptLPSPI2 (should be LPSPI2_IRQHandler)" - exit 1 -else - print_status "✓ interruptLPSPI2 not exported as main symbol" -fi - -if echo "$EXPORTED_SYMBOLS" | grep -q "systemTickHandler"; then - print_error "✗ Unexpected exported symbol: systemTickHandler (should be SysTick_Handler)" - exit 1 -else - print_status "✓ systemTickHandler not exported as main symbol" -fi - -echo "" -print_status "=== All symbol name tests passed! ===" - -# Cleanup -rm -f test_export - -print_status "Export symbol name test completed successfully!" diff --git a/test/export_test.go b/test/export_test.go deleted file mode 100644 index 88b273dc..00000000 --- a/test/export_test.go +++ /dev/null @@ -1,160 +0,0 @@ -//go:build !llgo -// +build !llgo - -package test - -import ( - "os" - "os/exec" - "path/filepath" - "strings" - "testing" -) - -// TestExportSymbolNames tests that //export directive supports different symbol names -// This is essential for embedded development where hardware specifications require -// specific symbol names (e.g., ARM Cortex-M interrupt handlers). -func TestExportSymbolNames(t *testing.T) { - // Create temporary directory for test - tmpDir, err := os.MkdirTemp("", "llgo-export-test-*") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpDir) - - // Write test program - testCode := `package main - -//export LPSPI2_IRQHandler -func interruptLPSPI2() { - println("LPSPI2 interrupt handled") -} - -//export SysTick_Handler -func systemTickHandler() { - println("System tick") -} - -//export Add -func Add(a, b int) int { - return a + b -} - -func main() { - interruptLPSPI2() - systemTickHandler() - println("Add(2, 3) =", Add(2, 3)) -} -` - mainGo := filepath.Join(tmpDir, "main.go") - if err := os.WriteFile(mainGo, []byte(testCode), 0644); err != nil { - t.Fatal(err) - } - - // Get llgo binary path - llgoPath := findLLGo(t) - - // Build the test program - testBinary := filepath.Join(tmpDir, "test_export") - cmd := exec.Command(llgoPath, "build", "-o", testBinary, mainGo) - cmd.Env = append(os.Environ(), "LLGO_ROOT="+findLLGORoot(t)) - if output, err := cmd.CombinedOutput(); err != nil { - t.Fatalf("Build failed: %v\nOutput: %s", err, output) - } - - // Check for expected symbols using nm - nmCmd := exec.Command("nm", testBinary) - nmOutput, err := nmCmd.CombinedOutput() - if err != nil { - t.Fatalf("nm command failed: %v\nOutput: %s", err, nmOutput) - } - - nmStr := string(nmOutput) - - // Verify LPSPI2_IRQHandler symbol exists (not interruptLPSPI2) - if !strings.Contains(nmStr, "LPSPI2_IRQHandler") { - t.Errorf("Symbol LPSPI2_IRQHandler not found in binary") - t.Logf("Available symbols:\n%s", nmStr) - } - - // Verify SysTick_Handler symbol exists (not systemTickHandler) - if !strings.Contains(nmStr, "SysTick_Handler") { - t.Errorf("Symbol SysTick_Handler not found in binary") - t.Logf("Available symbols:\n%s", nmStr) - } - - // Verify Add symbol exists (same name) - if !strings.Contains(nmStr, "Add") { - t.Errorf("Symbol Add not found in binary") - t.Logf("Available symbols:\n%s", nmStr) - } - - // Verify that the original function names are NOT exported - // (they should only appear as internal symbols, not exported with 'T') - lines := strings.Split(nmStr, "\n") - for _, line := range lines { - if strings.Contains(line, " T ") || strings.Contains(line, " t ") { - if strings.Contains(line, "interruptLPSPI2") { - t.Errorf("Unexpected exported symbol: interruptLPSPI2 (should be LPSPI2_IRQHandler)") - } - if strings.Contains(line, "systemTickHandler") { - t.Errorf("Unexpected exported symbol: systemTickHandler (should be SysTick_Handler)") - } - } - } -} - -// findLLGo finds the llgo binary -func findLLGo(t *testing.T) string { - t.Helper() - - // Always use the repository version for testing to ensure we test the latest code - root := findLLGORoot(t) - llgoPath := filepath.Join(root, "llgo") - - // Check if it exists - if _, err := os.Stat(llgoPath); err == nil { - return llgoPath - } - - // Try to build it - cmd := exec.Command("go", "build", "-o", llgoPath, "./cmd/llgo") - cmd.Dir = root - if err := cmd.Run(); err != nil { - t.Skipf("llgo cannot be built: %v", err) - } - - return llgoPath -} - -// findLLGORoot finds the LLGO repository root -func findLLGORoot(t *testing.T) string { - t.Helper() - - // Check LLGO_ROOT environment variable - if root := os.Getenv("LLGO_ROOT"); root != "" { - return root - } - - // Try to find it relative to this test file - wd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - - // Walk up to find go.mod - dir := wd - for { - if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil { - return dir - } - parent := filepath.Dir(dir) - if parent == dir { - break - } - dir = parent - } - - t.Fatal("Cannot find LLGO_ROOT") - return "" -}