diff options
author | kobalicek <kobalicek.petr@gmail.com> | 2019-10-01 01:17:14 +0300 |
---|---|---|
committer | kobalicek <kobalicek.petr@gmail.com> | 2019-10-01 01:17:14 +0300 |
commit | 17556b2d4984ab67bdc00e6b5a626efc75d95e07 (patch) | |
tree | f1c9774f2e1b1a309002e7f83e63b02bd3283ee0 /test | |
parent | 238243530a35f5ad6205695ff0267b8bd639543a (diff) |
[Bug] Fixed wrong encoding of vpdpbusd, vgf2p8mulb, vgf2p8affineqb, and vgf2p8affineinvqb instructions with memory operand
Diffstat (limited to 'test')
-rw-r--r-- | test/asmjit_test_x86_cc.cpp | 59 | ||||
-rw-r--r-- | test/broken.cpp | 25 | ||||
-rw-r--r-- | test/broken.h | 55 |
3 files changed, 105 insertions, 34 deletions
diff --git a/test/asmjit_test_x86_cc.cpp b/test/asmjit_test_x86_cc.cpp index b49d2a9..9175201 100644 --- a/test/asmjit_test_x86_cc.cpp +++ b/test/asmjit_test_x86_cc.cpp @@ -2886,10 +2886,7 @@ public: b += b; c += c; d += d; - return a + - b + - c + - d; + return a + b + c + d; } virtual void compile(x86::Compiler& cc) { @@ -3642,15 +3639,15 @@ public: }; // ============================================================================ -// [X86Test_MiscConstPool] +// [X86Test_MiscLocalConstPool] // ============================================================================ -class X86Test_MiscConstPool : public X86Test { +class X86Test_MiscLocalConstPool : public X86Test { public: - X86Test_MiscConstPool() : X86Test("MiscConstPool1") {} + X86Test_MiscLocalConstPool() : X86Test("MiscLocalConstPool") {} static void add(X86TestApp& app) { - app.add(new X86Test_MiscConstPool()); + app.add(new X86Test_MiscLocalConstPool()); } virtual void compile(x86::Compiler& cc) { @@ -3685,6 +3682,49 @@ public: }; // ============================================================================ +// [X86Test_MiscGlobalConstPool] +// ============================================================================ + +class X86Test_MiscGlobalConstPool : public X86Test { +public: + X86Test_MiscGlobalConstPool() : X86Test("MiscGlobalConstPool") {} + + static void add(X86TestApp& app) { + app.add(new X86Test_MiscGlobalConstPool()); + } + + virtual void compile(x86::Compiler& cc) { + cc.addFunc(FuncSignatureT<int>(CallConv::kIdHost)); + + x86::Gp v0 = cc.newInt32("v0"); + x86::Gp v1 = cc.newInt32("v1"); + + x86::Mem c0 = cc.newInt32Const(ConstPool::kScopeGlobal, 200); + x86::Mem c1 = cc.newInt32Const(ConstPool::kScopeGlobal, 33); + + cc.mov(v0, c0); + cc.mov(v1, c1); + cc.add(v0, v1); + + cc.ret(v0); + cc.endFunc(); + } + + virtual bool run(void* _func, String& result, String& expect) { + typedef int (*Func)(void); + Func func = ptr_as_func<Func>(_func); + + int resultRet = func(); + int expectRet = 233; + + result.assignFormat("ret=%d", resultRet); + expect.assignFormat("ret=%d", expectRet); + + return resultRet == expectRet; + } +}; + +// ============================================================================ // [X86Test_MiscMultiRet] // ============================================================================ @@ -3977,7 +4017,8 @@ int main(int argc, char* argv[]) { app.addT<X86Test_FuncCallMisc5>(); // Miscellaneous tests. - app.addT<X86Test_MiscConstPool>(); + app.addT<X86Test_MiscLocalConstPool>(); + app.addT<X86Test_MiscGlobalConstPool>(); app.addT<X86Test_MiscMultiRet>(); app.addT<X86Test_MiscMultiFunc>(); app.addT<X86Test_MiscUnfollow>(); diff --git a/test/broken.cpp b/test/broken.cpp index de67218..eae6e5c 100644 --- a/test/broken.cpp +++ b/test/broken.cpp @@ -47,6 +47,14 @@ static bool BrokenAPI_startsWith(const char* a, const char* b) noexcept { } } +//! Compares names and priority of two unit tests. +static int BrokenAPI_compareUnits(const BrokenAPI::Unit* a, const BrokenAPI::Unit* b) noexcept { + if (a->priority == b->priority) + return strcmp(a->name, b->name); + else + return a->priority > b->priority ? 1 : -1; +} + // Get whether the strings `a` and `b` are equal, ignoring case and treating // `-` as `_`. static bool BrokenAPI_matchesFilter(const char* a, const char* b) noexcept { @@ -109,9 +117,17 @@ static void BrokenAPI_runAll() noexcept { bool hasUnits = unit != NULL; size_t count = 0; + int currentPriority = 0; while (unit != NULL) { if (BrokenAPI_canRun(unit)) { + if (currentPriority != unit->priority) { + if (count) + INFO(""); + INFO("[[Priority=%d]]", unit->priority); + } + + currentPriority = unit->priority; BrokenAPI_runUnit(unit); count++; } @@ -134,7 +150,7 @@ static void BrokenAPI_listAll() noexcept { if (unit != NULL) { INFO("Units:"); do { - INFO(" %s", unit->name); + INFO(" %s [priority=%d]", unit->name, unit->priority); unit = unit->next; } while (unit != NULL); } @@ -155,7 +171,7 @@ void BrokenAPI::add(Unit* unit) noexcept { // C++ static initialization doesn't guarantee anything. We sort all units by // name so the execution will always happen in deterministic order. while (current != NULL) { - if (strcmp(current->name, unit->name) >= 0) + if (BrokenAPI_compareUnits(current, unit) >= 0) break; pPrev = ¤t->next; @@ -172,7 +188,7 @@ void BrokenAPI::setOutputFile(FILE* file) noexcept { global._file = file; } -int BrokenAPI::run(int argc, const char* argv[], Entry onBeforeRun, Entry onAfterRun) noexcept { +int BrokenAPI::run(int argc, const char* argv[], Entry onBeforeRun, Entry onAfterRun) { BrokenGlobal& global = _brokenGlobal; global._argc = argc; @@ -183,7 +199,7 @@ int BrokenAPI::run(int argc, const char* argv[], Entry onBeforeRun, Entry onAfte INFO(" --help - print this usage"); INFO(" --list - list all tests"); INFO(" --run-... - run a test(s), trailing wildcards supported"); - INFO(" --run-all - run all tests"); + INFO(" --run-all - run all tests (default)"); return 0; } @@ -248,6 +264,7 @@ static void BrokenAPI_printMessage(const char* prefix, const char* fmt, va_list void BrokenAPI::info(const char* fmt, ...) noexcept { BrokenGlobal& global = _brokenGlobal; + va_list ap; va_start(ap, fmt); BrokenAPI_printMessage(global._unitRunning ? " " : "", fmt, ap); diff --git a/test/broken.h b/test/broken.h index 8d7db6f..9923ce1 100644 --- a/test/broken.h +++ b/test/broken.h @@ -2,7 +2,7 @@ // Lightweight Unit Testing for C++. // // [License] -// Public Domain (Unlicense) +// Public Domain (Unlicense) or Zlib. #ifndef BROKEN_INTERNAL_H #define BROKEN_INTERNAL_H @@ -15,8 +15,7 @@ // 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 -//! \{ +//! \cond // ============================================================================ // [Broken - API] @@ -26,22 +25,30 @@ struct BrokenAPI { //! Entry point of a unit test defined by `UNIT` macro. typedef void (*Entry)(void); + enum Flags : unsigned { + kFlagFinished = 0x1 + }; + //! Test defined by `UNIT` macro. struct Unit { - const char* name; Entry entry; - size_t finished; + const char* name; + int priority; + unsigned flags; 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; - + inline AutoUnit(Entry entry_, const char* name_, int priority_ = 0, int dummy_ = 0) noexcept { + // Not used, only to trick `UNIT()` macro. + (void)dummy_; + + this->entry = entry_; + this->name = name_; + this->priority = priority_; + this->flags = 0; + this->next = nullptr; BrokenAPI::add(this); } }; @@ -57,7 +64,7 @@ struct BrokenAPI { //! 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; + static int run(int argc, const char* argv[], Entry onBeforeRun = nullptr, Entry onAfterRun = nullptr); //! Log message, adds automatically new line if not present. static void info(const char* fmt, ...) noexcept; @@ -84,17 +91,23 @@ struct BrokenAPI { // [Broken - Macros] // ============================================================================ -//! Define a unit test. +//! Internal macro used by `UNIT()`. +#define UNIT_INTERNAL(NAME, ...) \ + static void unit_##NAME##_entry(void); \ + static ::BrokenAPI::AutoUnit unit_##NAME##_autoinit(unit_##NAME##_entry, #NAME, __VA_ARGS__); \ + static void unit_##NAME##_entry(void) + +//! \def UNIT(NAME [, PRIORITY]) +//! +//! Define a unit test with an optional priority. //! //! `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 +//! +//! `PRIORITY` specifies the order in which unit tests are run. Lesses value +//! increases the priority. At the moment all units are first sorted by +//! priority and then by name - this makes the run always deterministic. +#define UNIT(...) UNIT_INTERNAL(__VA_ARGS__, 0) //! #define INFO(FORMAT [, ...]) //! @@ -106,6 +119,6 @@ struct BrokenAPI { //! Expect `EXP` to be true or evaluates to true, fail otherwise. #define EXPECT(...) ::BrokenAPI::expect(__FILE__, __LINE__, __VA_ARGS__) -//! \} +//! \endcond #endif // BROKEN_INTERNAL_H |