all: enhance CMake tests; assorted updates
This commit is contained in:
+3
-3
@@ -3,8 +3,8 @@
|
||||
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
|
||||
# NOTE: this Makefile is deprecated - please directly use
|
||||
# the top-level CMake build instead.
|
||||
# NOTE: this Makefile is intended for developers - please use
|
||||
# the top-level Makefile instead
|
||||
|
||||
ifndef srcdir
|
||||
srcdir := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
|
||||
@@ -14,7 +14,7 @@ ifndef top_srcdir
|
||||
endif
|
||||
|
||||
#***********************************************************************
|
||||
# redirect to top-level CMake build
|
||||
# redirect to top-level Makefile
|
||||
#***********************************************************************
|
||||
|
||||
# NOTE that the top-level Makefile .DEFAULT_GOAL is build/release
|
||||
|
||||
+25
-15
@@ -56,7 +56,7 @@ int upx_doctest_check(int argc, char **argv) {
|
||||
// default for debug builds: do show the [doctest] summary
|
||||
minimal = false;
|
||||
#endif
|
||||
const char *e = getenv("UPX_DEBUG_DOCTEST_VERBOSE");
|
||||
const char *e = upx_getenv("UPX_DEBUG_DOCTEST_VERBOSE");
|
||||
if (e && e[0]) {
|
||||
if (strcmp(e, "0") == 0) {
|
||||
minimal = true;
|
||||
@@ -375,8 +375,8 @@ static noinline bool shall_test_float_division_by_zero(void) {
|
||||
static bool result = false; // default is false
|
||||
static upx_std_once_flag init_done;
|
||||
upx_std_call_once(init_done, []() noexcept {
|
||||
const char envvar[] = "UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO";
|
||||
const char *e = getenv(envvar);
|
||||
static const char envvar[] = "UPX_DEBUG_TEST_FLOAT_DIVISION_BY_ZERO";
|
||||
const char *e = upx_getenv(envvar);
|
||||
bool force = (e && e[0] && strcmp(e, "2") == 0);
|
||||
if (force)
|
||||
result = true;
|
||||
@@ -441,6 +441,8 @@ static noinline void check_basic_floating_point(void) noexcept {
|
||||
#include "../util/miniacc.h"
|
||||
|
||||
void upx_compiler_sanity_check(void) noexcept {
|
||||
check_basic_floating_point();
|
||||
|
||||
if (is_envvar_true("UPX_DEBUG_DOCTEST_DISABLE", "UPX_DEBUG_DISABLE_DOCTEST")) {
|
||||
// If UPX_DEBUG_DOCTEST_DISABLE is set then we don't want to throw any
|
||||
// exceptions in order to improve debugging experience.
|
||||
@@ -449,8 +451,6 @@ void upx_compiler_sanity_check(void) noexcept {
|
||||
check_basic_cxx_exception_handling(throwSomeValue);
|
||||
}
|
||||
|
||||
check_basic_floating_point();
|
||||
|
||||
// check_basic_decltype()
|
||||
{
|
||||
auto a = +0;
|
||||
@@ -716,6 +716,11 @@ TEST_CASE("ptr_invalidate_and_poison") {
|
||||
(void) dp;
|
||||
}
|
||||
|
||||
TEST_CASE("upx_getenv") {
|
||||
CHECK_EQ(upx_getenv(nullptr), nullptr);
|
||||
CHECK_EQ(upx_getenv(""), nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("working -fno-strict-aliasing") {
|
||||
bool ok;
|
||||
long v = 0;
|
||||
@@ -802,17 +807,22 @@ TEST_CASE("libc qsort") {
|
||||
assert_noexcept(a->id != b->id); // check not IDENTICAL
|
||||
return a->value < b->value ? -1 : (a->value == b->value ? 0 : 1);
|
||||
}
|
||||
static noinline bool check_sort(upx_sort_func_t sort, Elem *e, size_t n) {
|
||||
upx_uint32_t x = 5381 + n + (upx_rand() & 0xff);
|
||||
static noinline bool check_sort(upx_sort_func_t sort, Elem *e, size_t n, bool is_stable) {
|
||||
upx_uint32_t x = 5381 + (upx_rand() & 255);
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
e[i].id = (upx_uint16_t) i;
|
||||
x = x * 33 + 1 + (i & 255);
|
||||
e[i].value = (upx_uint16_t) x;
|
||||
e[i].value = (upx_uint16_t) ((x >> 4) & 15);
|
||||
}
|
||||
sort(e, n, sizeof(Elem), Elem::compare);
|
||||
for (size_t i = 1; i < n; i++)
|
||||
// verify
|
||||
for (size_t i = 1; i < n; i++) {
|
||||
if very_unlikely (e[i - 1].value > e[i].value)
|
||||
return false;
|
||||
if (is_stable)
|
||||
if very_unlikely (e[i - 1].value == e[i].value && e[i - 1].id >= e[i].id)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -820,17 +830,17 @@ TEST_CASE("libc qsort") {
|
||||
Elem e[N];
|
||||
for (size_t n = 0; n <= N; n = 2 * n + 1) {
|
||||
// system sort functions
|
||||
CHECK(Elem::check_sort(::qsort, e, n)); // libc qsort()
|
||||
CHECK(Elem::check_sort(::qsort, e, n, false)); // libc qsort()
|
||||
#if UPX_CONFIG_USE_STABLE_SORT
|
||||
upx_sort_func_t wrap_stable_sort = [](void *aa, size_t nn, size_t, upx_compare_func_t cc) {
|
||||
upx_std_stable_sort<sizeof(Elem)>(aa, nn, cc);
|
||||
};
|
||||
CHECK(Elem::check_sort(wrap_stable_sort, e, n)); // std::stable_sort()
|
||||
CHECK(Elem::check_sort(wrap_stable_sort, e, n, true)); // std::stable_sort()
|
||||
#endif
|
||||
// UPX sort functions
|
||||
CHECK(Elem::check_sort(upx_gnomesort, e, n));
|
||||
CHECK(Elem::check_sort(upx_shellsort_memswap, e, n));
|
||||
CHECK(Elem::check_sort(upx_shellsort_memcpy, e, n));
|
||||
// simple UPX sort functions
|
||||
CHECK(Elem::check_sort(upx_gnomesort, e, n, true));
|
||||
CHECK(Elem::check_sort(upx_shellsort_memswap, e, n, false));
|
||||
CHECK(Elem::check_sort(upx_shellsort_memcpy, e, n, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ TEST_CASE("upx::noncopyable") {
|
||||
namespace {
|
||||
template <class T>
|
||||
struct TestTriBool {
|
||||
static void test(bool expect_true) {
|
||||
static noinline void test(bool expect_true) {
|
||||
static_assert(std::is_class<T>::value);
|
||||
static_assert(std::is_nothrow_default_constructible<T>::value);
|
||||
static_assert(std::is_nothrow_destructible<T>::value);
|
||||
|
||||
+1
-1
@@ -214,7 +214,7 @@ upx_off_t InputFile::seek(upx_off_t off, int whence) {
|
||||
|
||||
upx_off_t InputFile::st_size_orig() const { return _length_orig; }
|
||||
|
||||
int InputFile::dup() may_throw {
|
||||
int InputFile::dupFd() may_throw {
|
||||
if (!isOpen())
|
||||
throwIOException("bad dup");
|
||||
#if defined(HAVE_DUP) && (HAVE_DUP + 0 == 0)
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ public:
|
||||
virtual upx_off_t seek(upx_off_t off, int whence) override;
|
||||
upx_off_t st_size_orig() const;
|
||||
|
||||
noinline int dup() may_throw;
|
||||
noinline int dupFd() may_throw;
|
||||
|
||||
protected:
|
||||
upx_off_t _length_orig = 0;
|
||||
|
||||
+1
-3
@@ -430,8 +430,6 @@ void show_version(bool one_line) {
|
||||
fprintf(f, "Copyright (C) 1996-2024 Markus Franz Xaver Johannes Oberhumer\n");
|
||||
fprintf(f, "Copyright (C) 1996-2024 Laszlo Molnar\n");
|
||||
fprintf(f, "Copyright (C) 2000-2024 John F. Reiser\n");
|
||||
// Jens contributed the ps1/exe format; no need to list as main author
|
||||
// fprintf(f, "Copyright (C) 2002-2024 Jens Medoch\n");
|
||||
#if (WITH_ZLIB)
|
||||
// see vendor/zlib/LICENSE
|
||||
fprintf(f, "Copyright (C) 1995" "-2024 Jean-loup Gailly and Mark Adler\n");
|
||||
@@ -591,7 +589,7 @@ void show_sysinfo(const char *options_var) {
|
||||
#endif
|
||||
|
||||
if (options_var && options_var[0]) {
|
||||
const char *e = getenv(options_var);
|
||||
const char *e = upx_getenv(options_var);
|
||||
con_fprintf(f, "\n");
|
||||
if (e && e[0])
|
||||
con_fprintf(f, "Contents of environment variable %s: '%s'\n\n", options_var, e);
|
||||
|
||||
+4
-1
@@ -37,6 +37,9 @@
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef OPTIONS_VAR
|
||||
// historical note: "UPX_OPTIONS" would be a better name, but back in the old
|
||||
// days environment variables used to be short; and we cannot change that now
|
||||
// because of backward compatibility issues
|
||||
#define OPTIONS_VAR "UPX"
|
||||
#endif
|
||||
|
||||
@@ -1086,7 +1089,7 @@ void main_get_envoptions() {
|
||||
static const char sep[] = " \t";
|
||||
char shortopts[256];
|
||||
|
||||
var = getenv(OPTIONS_VAR);
|
||||
var = upx_getenv(OPTIONS_VAR);
|
||||
if (var == nullptr || !var[0])
|
||||
return;
|
||||
env = strdup(var);
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ void Options::reset() noexcept {
|
||||
#endif
|
||||
// support NO_COLOR, see https://no-color.org/
|
||||
// "... when present and not an empty string (regardless of its value)"
|
||||
const char *e = getenv("NO_COLOR");
|
||||
const char *e = upx_getenv("NO_COLOR");
|
||||
if (e && e[0])
|
||||
o->console = CON_FILE;
|
||||
|
||||
|
||||
+2
-2
@@ -267,7 +267,7 @@ int PackVmlinuzI386::decompressKernel()
|
||||
fd_pos = -1;
|
||||
// open
|
||||
fi->seek(gzoff, SEEK_SET);
|
||||
fd = fi->dup();
|
||||
fd = fi->dupFd();
|
||||
if (fd < 0)
|
||||
break;
|
||||
gzFile zf = gzdopen(fd, "rb");
|
||||
@@ -849,7 +849,7 @@ int PackVmlinuzARMEL::decompressKernel()
|
||||
fd_pos = -1;
|
||||
// open
|
||||
fi->seek(gzoff, SEEK_SET);
|
||||
fd = fi->dup();
|
||||
fd = fi->dupFd();
|
||||
if (fd < 0)
|
||||
break;
|
||||
gzFile zf = gzdopen(fd, "rb");
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
#if defined(__has_include)
|
||||
#if __has_include(<features.h>)
|
||||
#include <features.h> // for __GLIBC__
|
||||
#include <features.h> // for __GLIBC__ and __GLIBC_MINOR__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
#endif
|
||||
#endif // _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
|
||||
|
||||
#if 0 // TODO later
|
||||
// libc++ hardenining
|
||||
#if defined(__cplusplus) && 0 // TODO later
|
||||
#if defined(__clang__) && defined(__clang_major__) && (__clang_major__ + 0 >= 18)
|
||||
#if DEBUG
|
||||
#define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEBUG
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "system_defs.h"
|
||||
|
||||
#if !(__cplusplus + 0 >= 201703L)
|
||||
#error "C++17 is required"
|
||||
#error "FATAL ERROR: C++17 is required"
|
||||
#endif
|
||||
|
||||
// check expected defines
|
||||
|
||||
+9
-3
@@ -254,6 +254,12 @@ TEST_CASE("ptr_check_no_overlap 3") {
|
||||
// stdlib
|
||||
**************************************************************************/
|
||||
|
||||
const char *upx_getenv(const char *envvar) noexcept {
|
||||
if (envvar != nullptr && envvar[0])
|
||||
return ::getenv(envvar);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int upx_rand(void) noexcept { return ::rand(); }
|
||||
|
||||
void *upx_calloc(size_t n, size_t element_size) may_throw {
|
||||
@@ -430,7 +436,7 @@ struct TestSortAllPermutations {
|
||||
memcpy(a, perm, sizeof(*a) * n);
|
||||
sort(a, n, sizeof(*a), CompareFunc);
|
||||
for (size_t i = 0; i < n; i++)
|
||||
assert_noexcept((a[i] == 255 + i));
|
||||
assert_noexcept(a[i] == 255 + i);
|
||||
num_perms += 1;
|
||||
} while (std::next_permutation(perm, perm + n));
|
||||
return num_perms;
|
||||
@@ -774,11 +780,11 @@ int fn_strcmp(const char *n1, const char *n2) {
|
||||
|
||||
// UPX convention: any environment variable that is set and is not strictly equal to "0" is true
|
||||
bool is_envvar_true(const char *envvar, const char *alternate_name) noexcept {
|
||||
const char *e = getenv(envvar);
|
||||
const char *e = upx_getenv(envvar);
|
||||
if (e != nullptr && e[0])
|
||||
return strcmp(e, "0") != 0;
|
||||
if (alternate_name != nullptr) {
|
||||
e = getenv(alternate_name);
|
||||
e = upx_getenv(alternate_name);
|
||||
if (e != nullptr && e[0])
|
||||
return strcmp(e, "0") != 0;
|
||||
}
|
||||
|
||||
@@ -145,6 +145,8 @@ inline void ptr_invalidate_and_poison(T *(&ptr)) noexcept {
|
||||
|
||||
noinline void *upx_calloc(size_t n, size_t element_size) may_throw;
|
||||
|
||||
noinline const char *upx_getenv(const char *envvar) noexcept;
|
||||
|
||||
void upx_memswap(void *a, void *b, size_t bytes) noexcept;
|
||||
|
||||
noinline int upx_rand(void) noexcept;
|
||||
|
||||
Reference in New Issue
Block a user