commit
bba5c8a39a
109 files changed
+14085
No files matched your search
@@ -0,0 +1,49 @@
|
||||
// E2E: stock-toolchain pipeline.
|
||||
//
|
||||
// CMake compiles add_real.c with -fPIC -c, invokes voidlink pack-elf to
|
||||
// produce add_real.vls, then this test loads it via dlopen (which hits the
|
||||
// libvoid interposer) and confirms add(7, 35) == 42.
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#ifndef VOIDLIBC_TEST_VLC_PATH
|
||||
#error "VOIDLIBC_TEST_VLC_PATH must be set by CMake"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
#define REQUIRE(cond) do { \
|
||||
if (!(cond)) { \
|
||||
std::fprintf(stderr, "FAIL: %s (line %d)\n", #cond, \
|
||||
__LINE__); \
|
||||
const char* le = ::dlerror(); \
|
||||
if (le) std::fprintf(stderr, " dlerror: %s\n", le); \
|
||||
std::exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
int run() {
|
||||
void* h = ::dlopen(VOIDLIBC_TEST_VLC_PATH, RTLD_NOW);
|
||||
REQUIRE(h != nullptr);
|
||||
|
||||
using add_fn_t = int (*)(int, int);
|
||||
auto* add = reinterpret_cast<add_fn_t>(::dlsym(h, "add"));
|
||||
REQUIRE(add != nullptr);
|
||||
|
||||
const int result = add(7, 35);
|
||||
if (result != 42) {
|
||||
std::fprintf(stderr, "FAIL: add(7, 35) = %d (expected 42)\n", result);
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
REQUIRE(::dlclose(h) == 0);
|
||||
std::printf("PASS: e2e_load_real_add — stock toolchain → .vls → libvoid → %d\n",
|
||||
result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() { return run(); }
|
||||
Reference in new issue
Block a user