From 68f6ab5c32d89ec554b8421af583dee850e4536f Mon Sep 17 00:00:00 2001 From: Sylvie <35663410+Rangi42@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:34:44 -0400 Subject: [PATCH] Add test cases for SECTION UNION defining multiple identical labels (#1349) Exported labels should fail to link; non-exported ones should be okay. --- .github/workflows/testing.yml | 3 +- Makefile | 9 ++++-- test/CMakeLists.txt | 6 ++++ test/link/.gitignore | 2 ++ test/link/section-union/same-export/a.asm | 5 +++ test/link/section-union/same-export/b.asm | 5 +++ test/link/section-union/same-export/out.err | 1 + test/link/section-union/same-label/a.asm | 5 +++ test/link/section-union/same-label/b.asm | 5 +++ test/link/section-union/same-label/out.err | 0 test/link/test.sh | 34 +++++++++++++++++++++ test/link/unmangle.cpp | 16 ++++++++++ 12 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 test/link/.gitignore create mode 100644 test/link/section-union/same-export/a.asm create mode 100644 test/link/section-union/same-export/b.asm create mode 100644 test/link/section-union/same-export/out.err create mode 100644 test/link/section-union/same-label/a.asm create mode 100644 test/link/section-union/same-label/b.asm create mode 100644 test/link/section-union/same-label/out.err create mode 100644 test/link/unmangle.cpp diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 7dd2d4d7..af958d85 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -276,6 +276,7 @@ jobs: path: | test/gfx/randtilegen.exe test/gfx/rgbgfx_test.exe + test/link/unmangle.exe windows-mingw-testing: needs: windows-mingw-build @@ -296,7 +297,7 @@ jobs: uses: actions/download-artifact@v4 with: name: testing-programs-mingw-win${{ matrix.bits }} - path: test/gfx + path: test - name: Extract binaries shell: bash run: | diff --git a/Makefile b/Makefile index 39207e25..bc05d32d 100644 --- a/Makefile +++ b/Makefile @@ -129,6 +129,9 @@ test/gfx/randtilegen: test/gfx/randtilegen.cpp test/gfx/rgbgfx_test: test/gfx/rgbgfx_test.cpp $Q${CXX} ${REALLDFLAGS} ${PNGLDFLAGS} -o $@ $^ ${REALCXXFLAGS} ${PNGLDLIBS} +test/link/unmangle: test/link/unmangle.cpp + $Q${CXX} ${REALLDFLAGS} -o $@ $^ ${REALCXXFLAGS} + # Rules to process files # We want the Bison invocation to pass through our rules, not default ones @@ -176,7 +179,7 @@ clean: $Q${RM} rgbshim.sh $Q${RM} src/asm/parser.cpp src/asm/parser.hpp src/asm/stack.hh $Q${RM} src/link/script.cpp src/link/script.hpp src/link/stack.hh - $Q${RM} test/gfx/randtilegen test/gfx/rgbgfx_test + $Q${RM} test/gfx/randtilegen test/gfx/rgbgfx_test test/link/unmangle # Target used to install the binaries and man pages. @@ -233,13 +236,13 @@ coverage: # install instructions instead. mingw32: - $Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \ + $Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test test/link/unmangle \ CXX=i686-w64-mingw32-g++ \ CXXFLAGS="-O3 -flto -DNDEBUG -static-libgcc -static-libstdc++" \ PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/i686-w64-mingw32 pkg-config" mingw64: - $Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \ + $Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test test/link/unmangle \ CXX=x86_64-w64-mingw32-g++ \ PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/x86_64-w64-mingw32 pkg-config" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b7fa0d8f..e5a4a26f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,12 +2,18 @@ add_executable(randtilegen gfx/randtilegen.cpp) add_executable(rgbgfx_test gfx/rgbgfx_test.cpp) +add_executable(unmangle link/unmangle.cpp) install(TARGETS randtilegen rgbgfx_test DESTINATION ${rgbds_SOURCE_DIR}/test/gfx COMPONENT "Test support programs" EXCLUDE_FROM_ALL ) +install(TARGETS unmangle + DESTINATION ${rgbds_SOURCE_DIR}/test/link + COMPONENT "Test support programs" + EXCLUDE_FROM_ALL + ) foreach(TARGET randtilegen rgbgfx_test) if(LIBPNG_FOUND) # pkg-config diff --git a/test/link/.gitignore b/test/link/.gitignore new file mode 100644 index 00000000..f3cad6fa --- /dev/null +++ b/test/link/.gitignore @@ -0,0 +1,2 @@ +# Test binaries +/unmangle diff --git a/test/link/section-union/same-export/a.asm b/test/link/section-union/same-export/a.asm new file mode 100644 index 00000000..d0dd9328 --- /dev/null +++ b/test/link/section-union/same-export/a.asm @@ -0,0 +1,5 @@ +SECTION UNION "test", WRAM0 +Same:: + ds 1 +Foo:: + ds 2 diff --git a/test/link/section-union/same-export/b.asm b/test/link/section-union/same-export/b.asm new file mode 100644 index 00000000..46ad6ea7 --- /dev/null +++ b/test/link/section-union/same-export/b.asm @@ -0,0 +1,5 @@ +SECTION UNION "test", WRAM0 +Same:: + ds 2 +Bar:: + ds 1 diff --git a/test/link/section-union/same-export/out.err b/test/link/section-union/same-export/out.err new file mode 100644 index 00000000..c6261ac7 --- /dev/null +++ b/test/link/section-union/same-export/out.err @@ -0,0 +1 @@ +error: "Same" both in section-union/same-export/a.o from section-union/same-export/a.asm(2) and in section-union/same-export/b.o from section-union/same-export/b.asm(2) diff --git a/test/link/section-union/same-label/a.asm b/test/link/section-union/same-label/a.asm new file mode 100644 index 00000000..e6c11be8 --- /dev/null +++ b/test/link/section-union/same-label/a.asm @@ -0,0 +1,5 @@ +SECTION UNION "test", WRAM0 +Same: + ds 1 +Foo: + ds 2 diff --git a/test/link/section-union/same-label/b.asm b/test/link/section-union/same-label/b.asm new file mode 100644 index 00000000..b20798f5 --- /dev/null +++ b/test/link/section-union/same-label/b.asm @@ -0,0 +1,5 @@ +SECTION UNION "test", WRAM0 +Same: + ds 2 +Bar: + ds 1 diff --git a/test/link/section-union/same-label/out.err b/test/link/section-union/same-label/out.err new file mode 100644 index 00000000..e69de29b diff --git a/test/link/test.sh b/test/link/test.sh index 9f12c3a3..75bb9d01 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -3,6 +3,8 @@ export LC_ALL=C set -o pipefail +[[ -e ./unmangle ]] || make -C ../.. test/link/unmangle || exit + otemp="$(mktemp)" gbtemp="$(mktemp)" gbtemp2="$(mktemp)" @@ -82,6 +84,16 @@ evaluateTest () { fi } +substPath () { + # Escape regex metacharacters + subst="$(printf '%s\n' "$1" | sed 's:[][\/.^$*]:\\&:g')" + # Replace the file name with a different one to match changed output + sed -i'' -e "s|$subst|$2|g" "$3" + # Escape regex metacharacters in the un-MinGW-mangled path + subst="$(./unmangle "$1" | sed 's:[][\/.^$*]:\\&:g')" + sed -i'' -e "s|$subst|$2|g" "$3" +} + for i in *.asm; do test=${i%.asm} startTest @@ -215,6 +227,28 @@ rgblinkQuiet -o "$gbtemp" "$otemp" "$gbtemp2" tryCmpRom "$test"/ref.out.bin evaluateTest +test="section-union/same-export" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +"$RGBASM" -o "$gbtemp2" "$test"/b.asm +continueTest +rgblinkQuiet "$gbtemp2" "$otemp" 2>"$outtemp" +substPath "$otemp" "$test/a.o" "$outtemp" +substPath "$gbtemp2" "$test/b.o" "$outtemp" +tryDiff "$test"/out.err "$outtemp" +evaluateTest + +test="section-union/same-label" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +"$RGBASM" -o "$gbtemp2" "$test"/b.asm +continueTest +rgblinkQuiet "$gbtemp2" "$otemp" 2>"$outtemp" +substPath "$otemp" "$test/a.o" "$outtemp" +substPath "$gbtemp2" "$test/b.o" "$outtemp" +tryDiff "$test"/out.err "$outtemp" +evaluateTest + for i in section-union/*.asm; do test=${i%.asm} startTest diff --git a/test/link/unmangle.cpp b/test/link/unmangle.cpp new file mode 100644 index 00000000..b501933b --- /dev/null +++ b/test/link/unmangle.cpp @@ -0,0 +1,16 @@ +#include + +/** + * MinGW mangles path names before passing them as command-line arguments. + * Some RGBLINK warning/error messages include those mangled paths on Windows. + * We need to see those mangled paths in test.sh to replace them with placeholders. + * This tool simply echoes each argument, which will be mangled iff they are paths. + * (For example, the "/tmp/foo" will be unmangled to something like + * "C:/Users/RUNNER~1/AppData/Local/Temp/foo".) + */ + +int main(int argc, char *argv[]) { + for (int i = 1; i < argc; i++) + puts(argv[i]); + return 0; +}