Files
asmjit/test/broken.h
Petr Kobalicek 5d40561d14 Refactored register allocator asm Compiler. (#249)
Refactored build system macros (ASMJIT_BUILD_STATIC -> ASMJIT_STATIC)
Refactored AVX512 broadcast {1toN} - moved to operand from instruction.
Refactored naming - renamed getters to not use get prefix.
Refactored code structure - move arch-specific stuff into x86 namespace.
Refactored some compiler/arch-specific macros, respect rel/abs option in mov REG, [ADDR].
Refactored StringBuilder (Renamed to String, added small string optimization).
Refactored LabelId<->LabelEntry mapping, force label offset to 64-bits on all archs.
Renamed Runtime to Target (JitRuntime kept for now).
Renamed VirtMemManager to JitAllocator.
Renamed VirtMem to JitUtils.
Renamed FuncSignatureX to FuncSignatureBuilder.
Fixed xchg [mem], rex-lo, refactored RelocEntry.
Fixed Logger to always show abs|rel when formatting a memory operand
Fixed Logger to prefix HEX numbers with 0x prefix
Fixed Support::ctzGeneric to always return uint32_t, T doesn't matter.
Fixed LightCall to not save MMX and K registers
Fixed CpuInfo constructor to propagate NoInit (#243)
Added VAES, AVX512_VBMI2, AVX512_VNNI, and AVX512_BITALG cpu-features and instructions.
Added emscripten support (asmjit can be now compiled by emscripten).
Added asmjit.natvis for better MSVC experience
Added x86::ptr_abs|ptr_rel
Added support for multibyte nop r/m (#135)
Added support for 32-bit to 64-bit zero-extended addresses, improved validation of memory addresses, and removed wrt address type as this will be reworked
Added support for multiple sections, reworked address table support (previously known as trampolines)
Added the following x86 modifiers to the x86::Emitter - xacquire(), xrelease(), and k(kreg)
Added a possibility to use REP prefix with RET instruction
Added a possibility to relocate [rel addr] during relocate()
Added a variadic function-call support (Compiler), argument duplication (Compiler), better /dev/shm vs /tmp shared memory handling (VirtMem).
Removed imm_u imm_ptr helpers, imm() can now accept any integer and pointer.
Changed the default behavior of optimizing instructions to disabled with a possibility to enable that feature through kOptionOptimizedForSize
Use default copy construction / assignment to prevent new kind of warnings introduced by GCC 9
2019-07-16 01:24:22 +02:00

112 lines
3.1 KiB
C++

// [Broken]
// Lightweight Unit Testing for C++.
//
// [License]
// Public Domain (Unlicense)
#ifndef BROKEN_INTERNAL_H
#define BROKEN_INTERNAL_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <utility>
// Hide everything when using Doxygen. Ideally this can be protected by a macro,
// but there is not globally and widely used one across multiple projects.
//! \internal
//! \{
// ============================================================================
// [Broken - API]
// ============================================================================
struct BrokenAPI {
//! Entry point of a unit test defined by `UNIT` macro.
typedef void (*Entry)(void);
//! Test defined by `UNIT` macro.
struct Unit {
const char* name;
Entry entry;
size_t finished;
Unit* next;
};
//! Automatic unit registration by using static initialization.
struct AutoUnit : Unit {
inline AutoUnit(const char* _name, Entry _entry) noexcept {
name = _name;
entry = _entry;
finished = false;
next = NULL;
BrokenAPI::add(this);
}
};
static bool hasArg(const char* name) noexcept;
//! Register a new unit test (called automatically by `AutoUnit` and `UNIT`).
static void add(Unit* unit) noexcept;
//! Set output file to a `file`.
static void setOutputFile(FILE* file) noexcept;
//! Initialize `Broken` framework.
//!
//! Returns `true` if `run()` should be called.
static int run(int argc, const char* argv[], Entry onBeforeRun = nullptr, Entry onAfterRun = nullptr) noexcept;
//! Log message, adds automatically new line if not present.
static void info(const char* fmt, ...) noexcept;
//! Called on `EXPECT()` failure.
static void fail(const char* file, int line, const char* fmt, ...) noexcept;
//! Used internally by `EXPECT` macro.
template<typename T>
static inline void expect(const char* file, int line, const T& exp) noexcept {
if (!exp)
fail(file, line, nullptr);
}
//! Used internally by `EXPECT` macro.
template<typename T, typename... Args>
static inline void expect(const char* file, int line, const T& exp, const char* fmt, Args&&... args) noexcept {
if (!exp)
fail(file, line, fmt, std::forward<Args>(args)...);
}
};
// ============================================================================
// [Broken - Macros]
// ============================================================================
//! Define a unit test.
//!
//! `NAME` can only contain ASCII characters, numbers and underscore. It has
//! the same rules as identifiers in C and C++.
#define UNIT(NAME) \
static void unit_##NAME##_entry(void) noexcept; \
\
static ::BrokenAPI::AutoUnit unit_##NAME##_autoinit( \
#NAME, unit_##NAME##_entry); \
\
static void unit_##NAME##_entry(void) noexcept
//! #define INFO(FORMAT [, ...])
//!
//! Informative message printed to `stdout`.
#define INFO(...) ::BrokenAPI::info(__VA_ARGS__)
//! #define INFO(EXP [, FORMAT [, ...]])
//!
//! Expect `EXP` to be true or evaluates to true, fail otherwise.
#define EXPECT(...) ::BrokenAPI::expect(__FILE__, __LINE__, __VA_ARGS__)
//! \}
#endif // BROKEN_INTERNAL_H