all: add support for a basic "make test"

This commit is contained in:
Markus F.X.J. Oberhumer 2022-10-06 14:10:35 +02:00
parent e2b86a49db
commit c4437cb293
9 changed files with 87 additions and 54 deletions

View File

@ -174,6 +174,7 @@ if [[ $BM_B =~ (^|\+)coverage($|\+) ]]; then
fi fi
export UPX="--prefer-ucl --no-color --no-progress" export UPX="--prefer-ucl --no-color --no-progress"
export UPX_DEBUG_DISABLE_GITREV_WARNING=1
export UPX_DISABLE_GITREV_WARNING=1 export UPX_DISABLE_GITREV_WARNING=1
# let's go # let's go

View File

@ -49,7 +49,6 @@ jobs:
name: ${{ format('{0} cmake', matrix.os) }} name: ${{ format('{0} cmake', matrix.os) }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
env: env:
MATRIX_OS: ${{ matrix.os }}
UPX_CMAKE_BUILD_FLAGS: --verbose UPX_CMAKE_BUILD_FLAGS: --verbose
strategy: strategy:
fail-fast: false fail-fast: false
@ -72,7 +71,7 @@ jobs:
- name: 'Make artifact' - name: 'Make artifact'
id: make_artifact id: make_artifact
run: | run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${MATRIX_OS} N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
mkdir -p "tmp/artifact/$N" mkdir -p "tmp/artifact/$N"
(cd build && cp -ai --parents */upx "../tmp/artifact/$N") (cd build && cp -ai --parents */upx "../tmp/artifact/$N")
(cd tmp/artifact && tar --sort=name -czf "$N.tar.gz" "$N" && rm -rf "./$N") (cd tmp/artifact && tar --sort=name -czf "$N.tar.gz" "$N" && rm -rf "./$N")
@ -83,13 +82,18 @@ jobs:
with: with:
name: ${{ steps.make_artifact.outputs.upload_name }} name: ${{ steps.make_artifact.outputs.upload_name }}
path: tmp/artifact path: tmp/artifact
- name: 'Run basic tests'
run: |
make -C build/debug-gcc test
make -C build/release-gcc test
make -C build/debug-clang test
make -C build/release-clang test
job-macos-cmake: job-macos-cmake:
needs: [ job-rebuild-and-verify-stubs ] needs: [ job-rebuild-and-verify-stubs ]
name: ${{ format('{0} cmake', matrix.os) }} name: ${{ format('{0} cmake', matrix.os) }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
env: env:
MATRIX_OS: ${{ matrix.os }}
UPX_CMAKE_BUILD_FLAGS: --verbose UPX_CMAKE_BUILD_FLAGS: --verbose
strategy: strategy:
fail-fast: false fail-fast: false
@ -115,7 +119,7 @@ jobs:
- name: 'Make artifact' - name: 'Make artifact'
id: make_artifact id: make_artifact
run: | run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${MATRIX_OS} N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
mkdir -p "tmp/artifact/$N" mkdir -p "tmp/artifact/$N"
(cd build && rsync -R -a */upx "../tmp/artifact/$N/") (cd build && rsync -R -a */upx "../tmp/artifact/$N/")
(cd tmp/artifact && gtar --sort=name -czf "$N.tar.gz" "$N" && rm -rf "./$N") (cd tmp/artifact && gtar --sort=name -czf "$N.tar.gz" "$N" && rm -rf "./$N")
@ -126,13 +130,16 @@ jobs:
with: with:
name: ${{ steps.make_artifact.outputs.upload_name }} name: ${{ steps.make_artifact.outputs.upload_name }}
path: tmp/artifact path: tmp/artifact
- name: 'Run basic tests'
run: |
make -C build/debug-clang test
make -C build/release-clang test
job-windows-cmake: job-windows-cmake:
needs: [ job-rebuild-and-verify-stubs ] needs: [ job-rebuild-and-verify-stubs ]
name: ${{ format('{0} cmake', matrix.os) }} name: ${{ format('{0} cmake', matrix.os) }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
env: env:
MATRIX_OS: ${{ matrix.os }}
UPX_CMAKE_BUILD_FLAGS: --verbose UPX_CMAKE_BUILD_FLAGS: --verbose
strategy: strategy:
fail-fast: false fail-fast: false
@ -162,7 +169,7 @@ jobs:
id: make_artifact id: make_artifact
shell: bash shell: bash
run: | run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${MATRIX_OS} N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.os }}
mkdir -p "tmp/artifact/$N" mkdir -p "tmp/artifact/$N"
(cd build && cp -ai --parents */*/upx.exe "../tmp/artifact/$N") (cd build && cp -ai --parents */*/upx.exe "../tmp/artifact/$N")
# GitHub Actions magic: set "upload_name" Javascript outputs value for use in next step # GitHub Actions magic: set "upload_name" Javascript outputs value for use in next step
@ -172,6 +179,10 @@ jobs:
with: with:
name: ${{ steps.make_artifact.outputs.upload_name }} name: ${{ steps.make_artifact.outputs.upload_name }}
path: tmp/artifact path: tmp/artifact
- name: 'Run basic tests'
run: |
cmake --build build/debug --config Debug --target RUN_TESTS
cmake --build build/release --config Release --target RUN_TESTS
job-linux-toolchains: job-linux-toolchains:
if: ${{ false }} # disable for now if: ${{ false }} # disable for now
@ -306,7 +317,6 @@ jobs:
C: ${{ matrix.C }} C: ${{ matrix.C }}
B: release B: release
H: 'd:\a\upx' H: 'd:\a\upx'
MATRIX_NAME: ${{ matrix.name }}
strategy: strategy:
fail-fast: false fail-fast: false
@ -319,7 +329,6 @@ jobs:
- name: 'Check out code' - name: 'Check out code'
uses: actions/checkout@v3 uses: actions/checkout@v3
with: { submodules: true } with: { submodules: true }
- name: 'Prepare sources' - name: 'Prepare sources'
shell: cmd shell: cmd
run: | run: |
@ -330,12 +339,10 @@ jobs:
md build build\%C% deps md build build\%C% deps
cd deps cd deps
git clone --depth=1 https://github.com/upx/upx-testsuite git clone --depth=1 https://github.com/upx/upx-testsuite
- name: 'Set up Developer Command Prompt' - name: 'Set up Developer Command Prompt'
uses: ilammy/msvc-dev-cmd@v1 uses: ilammy/msvc-dev-cmd@v1
with: with:
arch: ${{ matrix.A }} arch: ${{ matrix.A }}
- name: 'Build' - name: 'Build'
shell: cmd shell: cmd
run: | run: |
@ -345,53 +352,49 @@ jobs:
md %BDIR% %BDIR%\ucl %BDIR%\upx %BDIR%\upx-testsuite %BDIR%\zlib md %BDIR% %BDIR%\ucl %BDIR%\upx %BDIR%\upx-testsuite %BDIR%\zlib
set DEFS=-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS set DEFS=-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS
git rev-parse --short=12 HEAD > %BDIR%\upx\.GITREV.txt git rev-parse --short=12 HEAD > %BDIR%\upx\.GITREV.txt
@REM build UCL @REM ===== build UCL =====
cd %BDIR%\ucl cd %BDIR%\ucl
set s=%H%\upx\vendor\ucl set s=%H%\upx\vendor\ucl
cl -MT -J -O2 -W4 %DEFS% -I%s%\include -I%s% -c %s%\src\*.c cl -MT -J -O2 -W4 %DEFS% -I%s%\include -I%s% -c %s%\src\*.c
link -lib -out:ucl.lib *.obj link -lib -out:ucl.lib *.obj
@REM build zlib @REM ===== build zlib =====
cd %BDIR%\zlib cd %BDIR%\zlib
cl -MT -J -O2 -W3 %DEFS% -c %H%\upx\vendor\zlib\*.c cl -MT -J -O2 -W3 %DEFS% -c %H%\upx\vendor\zlib\*.c
link -lib -out:zlib.lib *.obj link -lib -out:zlib.lib *.obj
@REM build UPX @REM ===== build UPX =====
cd %BDIR%\upx cd %BDIR%\upx
set s=%H%\upx\src set s=%H%\upx\src
cat .GITREV.txt cat .GITREV.txt
set /p GITREV=<.GITREV.txt set /p GITREV=<.GITREV.txt
cl -MT -EHsc -J -O2 -W4 -WX -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% -I%H%\upx\vendor\doctest -I%H%\upx\vendor\lzma-sdk -I%H%\upx\vendor\ucl\include -I%H%\upx\vendor\zlib -Feupx.exe %s%\*.cpp %s%\util\*.cpp %BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib /link setargv.obj cl -MT -EHsc -J -O2 -W4 -WX -DUPX_VERSION_GITREV="""%GITREV%""" %DEFS% -I%H%\upx\vendor\doctest -I%H%\upx\vendor\lzma-sdk -I%H%\upx\vendor\ucl\include -I%H%\upx\vendor\zlib -Feupx.exe %s%\*.cpp %s%\util\*.cpp %BDIR%\ucl\ucl.lib %BDIR%\zlib\zlib.lib /link setargv.obj
- name: 'Make artifact'
- name: 'Basic tests' id: make_artifact
shell: cmd shell: bash
run: | run: |
cd %H%\build\%C%\%B%\upx N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${{ matrix.name }}
set UPX=--no-color --no-progress mkdir -p "tmp/artifact/$N/$B"
cp -ai ../build/$C/$B/upx/upx*.exe "tmp/artifact/$N/$B"
# GitHub Actions magic: set "upload_name" Javascript outputs value for use in next step
echo "::set-output name=upload_name::$N"
- name: 'Upload artifact'
uses: actions/upload-artifact@v3
with:
name: ${{ steps.make_artifact.outputs.upload_name }}
path: tmp/artifact
- name: 'Run basic tests'
run: |
$ErrorActionPreference = 'stop'
$ErrorView = 'NormalView'
cd $Env:H\build\$Env:C\$Env:B\upx
$Env:UPX = "--no-color --no-progress"
.\upx.exe --version .\upx.exe --version
.\upx.exe upx.exe -o upx_packed.exe .\upx.exe upx.exe -o upx_packed.exe
dir *.exe dir *.exe
.\upx.exe -l upx_packed.exe .\upx.exe -l upx_packed.exe
.\upx.exe -t upx_packed.exe .\upx.exe -t upx_packed.exe
.\upx_packed.exe --version .\upx_packed.exe --version
- name: 'Run test suite' - name: 'Run test suite'
shell: cmd
run: | run: |
bash ./.github/travis_testsuite_1.sh bash ./.github/travis_testsuite_1.sh
- name: 'Make artifact'
id: make_artifact
shell: bash
run: |
N=upx-${GITHUB_REF_NAME}-${GITHUB_SHA:0:7}-${MATRIX_NAME}
mkdir -p "tmp/artifact/$N/$B"
cp -ai ../build/$C/$B/upx/upx*.exe "tmp/artifact/$N/$B"
# GitHub Actions magic: set "upload_name" Javascript outputs value for use in next step
echo "::set-output name=upload_name::$N"
- name: 'Upload artifact'
uses: actions/upload-artifact@v3
with:
name: ${{ steps.make_artifact.outputs.upload_name }}
path: tmp/artifact
# vim:set ts=2 sw=2 et: # vim:set ts=2 sw=2 et:

View File

@ -161,11 +161,26 @@ endif()
# "make test" # "make test"
#*********************************************************************** #***********************************************************************
# TODO: could add some explicit test programs; but then, the integrated if (NOT CMAKE_CROSSCOMPILING)
include(CTest)
set(exe ${CMAKE_EXECUTABLE_SUFFIX})
set(upx_self_exe "$<TARGET_FILE:upx>")
add_test(NAME upx-test-cleanup COMMAND rm -f ./upx.packed${exe} ./upx.unpacked${exe})
add_test(NAME upx-version COMMAND upx --version)
add_test(NAME upx-help COMMAND upx --help)
add_test(NAME upx-self-pack COMMAND upx -3 ${upx_self_exe} -o upx.packed${exe})
add_test(NAME upx-list COMMAND upx -l upx.packed${exe})
add_test(NAME upx-fileinfo COMMAND upx --fileinfo upx.packed${exe})
add_test(NAME upx-test COMMAND upx -t upx.packed${exe})
add_test(NAME upx-unpack COMMAND upx -d upx.packed${exe} -o upx.unpacked${exe})
add_test(NAME upx-run-unpacked COMMAND ./upx.unpacked${exe} --version)
add_test(NAME upx-run-packed COMMAND ./upx.packed${exe} --version)
endif()
# TODO: could add some more explicit test programs; but then, the integrated
# "doctest" is quite convenient and already covers a number of basic # "doctest" is quite convenient and already covers a number of basic
# checks - and more complex cases better should be handled by an # checks - and more complex cases better should be handled by an
# external test suite. # external test suite.
##include(CTest)
#*********************************************************************** #***********************************************************************
# "make install" # "make install"

View File

@ -1223,7 +1223,7 @@ int upx_main(int argc, char *argv[]) {
if (gitrev[0]) { if (gitrev[0]) {
bool warn = true; bool warn = true;
const char *ee = getenv("UPX_DISABLE_GITREV_WARNING"); const char *ee = getenv("UPX_DEBUG_DISABLE_GITREV_WARNING");
if (ee && ee[0] && strcmp(ee, "1") == 0) if (ee && ee[0] && strcmp(ee, "1") == 0)
warn = false; warn = false;
if (warn) { if (warn) {

View File

@ -413,7 +413,7 @@ void PackWcle::preprocessFixups()
set_le32(fix,0xFFFFFFFFUL); set_le32(fix,0xFFFFFFFFUL);
fix += 4; fix += 4;
sofixups = ptr_udiff(fix, ifixups); sofixups = ptr_udiff_bytes(fix, ifixups);
} }

View File

@ -1061,7 +1061,7 @@ unsigned PeFile::processImports0(ord_mask_t ord_mask) // pass 1
unsigned esize = ptr_diff_bytes(tarr, idlls[ic]->lookupt); unsigned esize = ptr_diff_bytes(tarr, idlls[ic]->lookupt);
lookups.add(idlls[ic]->lookupt,esize); lookups.add(idlls[ic]->lookupt,esize);
if (ptr_diff(ibuf.subref("bad import name %#x", idlls[ic]->iat, 1), (char *)idlls[ic]->lookupt)) if (ptr_diff_bytes(ibuf.subref("bad import name %#x", idlls[ic]->iat, 1), (char *)idlls[ic]->lookupt) != 0)
{ {
memcpy(ibuf.subref("bad import name %#x", idlls[ic]->iat, esize), idlls[ic]->lookupt, esize); memcpy(ibuf.subref("bad import name %#x", idlls[ic]->iat, esize), idlls[ic]->lookupt, esize);
iats.add(idlls[ic]->iat,esize); iats.add(idlls[ic]->iat,esize);
@ -1215,18 +1215,18 @@ void PeFile::Export::build(char *newbase, unsigned newoffs)
char * const enamep = ordinalp + 2 * edir.names; char * const enamep = ordinalp + 2 * edir.names;
char * exports = enamep + strlen(ename) + 1; char * exports = enamep + strlen(ename) + 1;
edir.addrtable = newoffs + ptr_diff(functionp, newbase); edir.addrtable = newoffs + ptr_diff_bytes(functionp, newbase);
edir.ordinaltable = newoffs + ptr_diff(ordinalp, newbase); edir.ordinaltable = newoffs + ptr_diff_bytes(ordinalp, newbase);
memcpy(ordinalp,ordinals,2 * edir.names); memcpy(ordinalp,ordinals,2 * edir.names);
edir.name = newoffs + ptr_diff(enamep, newbase); edir.name = newoffs + ptr_diff_bytes(enamep, newbase);
strcpy(enamep,ename); strcpy(enamep,ename);
edir.nameptrtable = newoffs + ptr_diff(namep, newbase); edir.nameptrtable = newoffs + ptr_diff_bytes(namep, newbase);
unsigned ic; unsigned ic;
for (ic = 0; ic < edir.names; ic++) for (ic = 0; ic < edir.names; ic++)
{ {
strcpy(exports,names[ic]); strcpy(exports,names[ic]);
set_le32(namep + 4 * ic,newoffs + ptr_diff(exports, newbase)); set_le32(namep + 4 * ic,newoffs + ptr_diff_bytes(exports, newbase));
exports += strlen(exports) + 1; exports += strlen(exports) + 1;
} }
@ -1235,7 +1235,7 @@ void PeFile::Export::build(char *newbase, unsigned newoffs)
if (names[edir.names + ic]) if (names[edir.names + ic])
{ {
strcpy(exports,names[edir.names + ic]); strcpy(exports,names[edir.names + ic]);
set_le32(functionp + 4 * ic,newoffs + ptr_diff(exports, newbase)); set_le32(functionp + 4 * ic,newoffs + ptr_diff_bytes(exports, newbase));
exports += strlen(exports) + 1; exports += strlen(exports) + 1;
} }

View File

@ -36,10 +36,13 @@ bool upx_doctest_check(int argc, char **argv) {
UNUSED(argc); UNUSED(argc);
UNUSED(argv); UNUSED(argv);
#else #else
const char *e = getenv("UPX_DEBUG_DOCTEST_DISABLE");
if (e && e[0] && strcmp(e, "0") != 0)
return true;
bool minimal = true; // only show failing tests bool minimal = true; // only show failing tests
bool duration = false; // show timings bool duration = false; // show timings
bool success = false; // show all tests bool success = false; // show all tests
const char *e = getenv("UPX_DEBUG_DOCTEST_VERBOSE"); e = getenv("UPX_DEBUG_DOCTEST_VERBOSE");
if (e && e[0] && strcmp(e, "0") != 0) { if (e && e[0] && strcmp(e, "0") != 0) {
minimal = false; minimal = false;
if (strcmp(e, "2") == 0) if (strcmp(e, "2") == 0)

View File

@ -35,19 +35,27 @@ unsigned long long span_check_stats_check_range = 0;
__acc_noinline void span_fail_nullptr() { __acc_noinline void span_fail_nullptr() {
throwCantUnpack("span unexpected NULL pointer; take care!"); throwCantUnpack("span unexpected NULL pointer; take care!");
} }
__acc_noinline void span_fail_not_same_base() { __acc_noinline void span_fail_not_same_base() {
throwInternalError("span unexpected base pointer; take care!"); throwInternalError("span unexpected base pointer; take care!");
} }
__acc_noinline void span_fail_range_nullptr() {
throwCantUnpack("span_check_range: unexpected NULL pointer; take care!");
}
__acc_noinline void span_fail_range_nullbase() {
throwCantUnpack("span_check_range: unexpected NULL base; take care!");
}
__acc_noinline void span_fail_range_range() {
throwCantUnpack("span_check_range: pointer out of range; take care!");
}
__acc_noinline void span_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes) { void span_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes) {
if __acc_very_unlikely (p == nullptr) if __acc_very_unlikely (p == nullptr)
throwCantUnpack("span_check_range: unexpected NULL pointer; take care!"); span_fail_range_nullptr();
if __acc_very_unlikely (base == nullptr) if __acc_very_unlikely (base == nullptr)
throwCantUnpack("span_check_range: unexpected NULL base; take care!"); span_fail_range_nullbase();
ptrdiff_t off = (const char *) p - (const char *) base; ptrdiff_t off = (const char *) p - (const char *) base;
if __acc_very_unlikely (off < 0 || off > size_in_bytes) if __acc_very_unlikely (off < 0 || off > size_in_bytes)
throwCantUnpack("span_check_range: pointer out of range; take care!"); span_fail_range_range();
span_check_stats_check_range += 1; span_check_stats_check_range += 1;
// fprintf(stderr, "span_check_range done\n"); // fprintf(stderr, "span_check_range done\n");
} }

View File

@ -43,7 +43,10 @@ SPAN_NAMESPACE_BEGIN
__acc_noinline void span_fail_nullptr(); __acc_noinline void span_fail_nullptr();
__acc_noinline void span_fail_not_same_base(); __acc_noinline void span_fail_not_same_base();
__acc_noinline void span_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes); __acc_noinline void span_fail_range_nullptr();
__acc_noinline void span_fail_range_nullbase();
__acc_noinline void span_fail_range_range();
void span_check_range(const void *p, const void *base, ptrdiff_t size_in_bytes);
// help constructor to distinguish between number of elements and bytes // help constructor to distinguish between number of elements and bytes
struct SpanCount { struct SpanCount {