InstCountCI: Hardcode the offset to load tests into

Depending on where the assembly was getting loaded in to memory it was
causing slight code generation differences.

Map the entire file to the same fixed offset as our ASM tests to ensure
consistency and removing flakes in CI.
This commit is contained in:
Ryan Houdek 2024-05-18 16:53:41 -07:00
parent 048c8ded88
commit ac1a096bae
No known key found for this signature in database

View File

@ -9,6 +9,8 @@
#include <FEXCore/Utils/LogManager.h> #include <FEXCore/Utils/LogManager.h>
#include <FEXCore/Utils/SignalScopeGuards.h> #include <FEXCore/Utils/SignalScopeGuards.h>
#include <sys/stat.h>
namespace CodeSize { namespace CodeSize {
class CodeSizeValidation final { class CodeSizeValidation final {
public: public:
@ -251,7 +253,8 @@ struct TestHeader {
uint8_t Data[]; uint8_t Data[];
}; };
static fextl::vector<char> TestData; static void* TestData;
static size_t TestDataSize;
static const TestHeader* TestHeaderData {}; static const TestHeader* TestHeaderData {};
static const TestInfo* TestsStart {}; static const TestInfo* TestsStart {};
static fextl::vector<std::pair<std::string_view, std::string_view>> EnvironmentVariables {}; static fextl::vector<std::pair<std::string_view, std::string_view>> EnvironmentVariables {};
@ -355,11 +358,35 @@ static bool TestInstructions(FEXCore::Context::Context* CTX, FEXCore::Core::Inte
} }
bool LoadTests(const char* Path) { bool LoadTests(const char* Path) {
if (!FEXCore::FileLoading::LoadFile(TestData, Path)) { constexpr uint64_t Code_start_page = 0x1'0000;
int FD = open(Path, O_RDONLY | O_CLOEXEC);
if (FD == -1) {
return false; return false;
} }
TestHeaderData = reinterpret_cast<const TestHeader*>(TestData.data()); struct stat buf;
if (fstat(FD, &buf) == -1) {
close(FD);
return false;
}
TestDataSize = buf.st_size;
TestData = FEXCore::Allocator::mmap(reinterpret_cast<void*>(Code_start_page), TestDataSize, PROT_READ, MAP_PRIVATE, FD, 0);
if (reinterpret_cast<uint64_t>(TestData) == ~0ULL) {
close(FD);
return false;
}
if (reinterpret_cast<uint64_t>(TestData) != Code_start_page) {
FEXCore::Allocator::VirtualFree(TestData, TestDataSize);
close(FD);
return false;
}
close(FD);
TestHeaderData = reinterpret_cast<const TestHeader*>(TestData);
// Need to walk past the environment variables to get to the actual tests. // Need to walk past the environment variables to get to the actual tests.
const uint8_t* Data = TestHeaderData->Data; const uint8_t* Data = TestHeaderData->Data;
@ -583,5 +610,7 @@ int main(int argc, char** argv, char** const envp) {
// Test all the instructions. // Test all the instructions.
auto Result = TestInstructions(CTX.get(), ParentThread, argc >= 2 ? argv[2] : nullptr) ? 0 : 1; auto Result = TestInstructions(CTX.get(), ParentThread, argc >= 2 ? argv[2] : nullptr) ? 0 : 1;
CTX->DestroyThread(ParentThread); CTX->DestroyThread(ParentThread);
FEXCore::Allocator::VirtualFree(TestData, TestDataSize);
return Result; return Result;
} }