91 lines
3.3 KiB
C++
91 lines
3.3 KiB
C++
/**
|
||
* @file abi_matrix_smoke.cpp
|
||
* @brief 微内核 P3-2:插件 ABI 兼容矩阵 CTest
|
||
*
|
||
* 宿主(内核 1.x / 插件 ABI 1.9)对声明 ABI 的插件进行加载矩阵验证:
|
||
* 接受:1.0 / 1.1 / 1.2 / 1.3 / 1.4 / 1.5 / 1.6 / 1.7 / 1.8 / 1.9(major 相等且 plugin minor <= host minor)
|
||
* 拒绝:2.0(major 不相等;动态库加载前拒绝)
|
||
* 使用内核真实宿主服务表(插件 init 会校验必需几何入口)。
|
||
* 成功输出含 ABI_MATRIX_PASS(CTest PASS_REGULAR_EXPRESSION)。
|
||
*/
|
||
#include "vde/plugin/geometry_host_services.h"
|
||
#include "vde/plugin/plugin_manager.h"
|
||
#include "vde/plugin/vde_plugin_api.h"
|
||
|
||
#include <cstdio>
|
||
#include <string>
|
||
|
||
namespace {
|
||
|
||
struct MatrixCase {
|
||
const char* dir; ///< <build>/plugin_abi_matrix/<dir>
|
||
int major; ///< 清单声明的插件 ABI major
|
||
int minor; ///< 清单声明的插件 ABI minor
|
||
bool expect_accept;
|
||
};
|
||
|
||
} // namespace
|
||
|
||
int main() {
|
||
const MatrixCase cases[] = {
|
||
{"abi1_0", 1, 0, true},
|
||
{"abi1_1", 1, 1, true},
|
||
{"abi1_2", 1, 2, true},
|
||
{"abi1_3", 1, 3, true},
|
||
{"abi1_4", 1, 4, true},
|
||
{"abi1_5", 1, 5, true},
|
||
{"abi1_6", 1, 6, true},
|
||
{"abi1_7", 1, 7, true},
|
||
{"abi1_8", 1, 8, true},
|
||
{"abi1_9", 1, 9, true},
|
||
{"abi2_0", 2, 0, false},
|
||
};
|
||
const std::string root = VDE_ABI_MATRIX_DIR;
|
||
auto& pm = vde::plugin::PluginManager::instance();
|
||
|
||
std::size_t accepted = 0;
|
||
std::size_t rejected = 0;
|
||
std::size_t failures = 0;
|
||
std::printf("ABI_MATRIX host_abi=%d.%d root=%s\n", VDE_PLUGIN_ABI_MAJOR,
|
||
VDE_PLUGIN_ABI_MINOR, root.c_str());
|
||
for (const auto& test : cases) {
|
||
pm.clear();
|
||
const VdePluginHost host = vde::plugin::make_geometry_host_services();
|
||
pm.set_host_services(host);
|
||
const std::string path = root + "/" + test.dir;
|
||
std::string error;
|
||
pm.add_search_path(path);
|
||
const std::size_t found = pm.scan_directory(path, &error);
|
||
const auto plugins = pm.plugins();
|
||
if (found != 1 || plugins.size() != 1) {
|
||
std::printf(
|
||
"ABI_MATRIX dir=%s declared=%d.%d result=DISCOVERY_FAIL "
|
||
"found=%zu error=%s\n",
|
||
test.dir, test.major, test.minor, found, error.c_str());
|
||
++failures;
|
||
continue;
|
||
}
|
||
const std::string plugin_id = plugins.front().id;
|
||
std::string load_error;
|
||
const bool loaded = pm.load(plugin_id, &load_error);
|
||
const bool expect = test.expect_accept;
|
||
const bool ok = (loaded == expect);
|
||
if (!ok) ++failures;
|
||
if (loaded) ++accepted;
|
||
if (!loaded) ++rejected;
|
||
std::printf(
|
||
"ABI_MATRIX dir=%s declared=%d.%d expect=%s result=%s reason=%s\n",
|
||
test.dir, test.major, test.minor, expect ? "accept" : "reject",
|
||
loaded ? "accepted" : "rejected",
|
||
load_error.empty() ? "-" : load_error.c_str());
|
||
if (loaded) {
|
||
std::string unload_error;
|
||
pm.unload(plugin_id, &unload_error);
|
||
}
|
||
}
|
||
pm.clear();
|
||
const bool pass = failures == 0 && accepted == 10 && rejected == 1;
|
||
std::printf("ABI_MATRIX_%s accepted=%zu rejected=%zu failures=%zu\n",
|
||
pass ? "PASS" : "FAIL", accepted, rejected, failures);
|
||
return pass ? 0 : 1;
|
||
} |