conformance fixtures: pure lib, plugin, kernel, provider, tool

This commit is contained in:
Marqdo Extension Fixtures committed 2026-11-21 23:41:32 +08:00
commit 40bf1f932e
31 files changed
+2361

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Build the C sensor provider and write provider/build/provider.json (schema v2)
# with the host target triple and the real artifact SHA-256.
set -euo pipefail
here="$(cd "$(dirname "$0")" && pwd)"
out="$here/build"
mkdir -p "$out"
host="$(rustc -vV | sed -n 's/^host: //p')"
case "$host" in
*windows*) echo "unsupported: Windows C ABI provider is not implemented in this fixture" >&2; exit 3 ;;
*apple-darwin*) ext="dylib"; flags=(-dynamiclib -fPIC) ;;
*) ext="so"; flags=(-shared -fPIC) ;;
esac
artifact="libsensor.$ext"
cc -std=c11 -O2 "${flags[@]}" -o "$out/$artifact" "$here/src/sensor.c"
if command -v sha256sum >/dev/null 2>&1; then
hash="$(sha256sum "$out/$artifact" | cut -d' ' -f1)"
else
hash="$(shasum -a 256 "$out/$artifact" | cut -d' ' -f1)"
fi
cat > "$out/provider.json" <<JSON
{
"schema": "marqdo.provider",
"schema_version": 2,
"name": "demo.sensor",
"version": "0.1.0",
"abi": "c-abi-1",
"transport": "worker",
"kinds": ["demo.sensor"],
"artifacts": [
{
"target": "$host",
"path": "lib/$artifact",
"sha256": "$hash"
}
],
"permissions_requested": []
}
JSON
mkdir -p "$out/lib"
mv "$out/$artifact" "$out/lib/$artifact"
echo "built $out/lib/$artifact for $host (sha256 $hash)"
+35
View File
@@ -0,0 +1,35 @@
# @knowledge 设备测试
## @exec main
打开独立仓库提供的资源;此标题仅决定文档语义,不涉及 Provider 注册。
`流 = resource.open("demo.sensor", "unit-1", ["read"])`
`内存 = memory.new(1, 1)`
`读取 = resource.read(流, 内存, 0, 5)`
`关闭 = resource.close(流)`
`if not 读取.ok`
`return 读取`
`else`
`if not 关闭.ok`
`return 关闭`
`else`
`if true`
`return 读取.value.count`
`end`
`end`
`end`
+17
View File
@@ -0,0 +1,17 @@
{
"schema": "marqdo.provider",
"schema_version": 2,
"name": "demo.sensor",
"version": "0.1.0",
"abi": "c-abi-1",
"transport": "worker",
"kinds": ["demo.sensor"],
"artifacts": [
{
"target": "x86_64-unknown-linux-gnu",
"path": "lib/libsensor.so",
"sha256": "0000000000000000000000000000000000000000000000000000000000000000"
}
],
"permissions_requested": []
}
+111
View File
@@ -0,0 +1,111 @@
/*
* Conformance resource provider (C ABI v1) for the unknown kind `demo.sensor`.
*
* The host's released `marqdo-provider-worker` helper loads this library and
* serves the framed-JSON resource protocol; the CLI never links this code.
* The provider ABI is re-declared here from the public C ABI specification
* (no standalone header is published yet).
*
* Behaviour used by the fixture:
* open("demo.sensor", "unit-1", ["read"]) -> token
* first read(max_bytes>=5) -> "hello", eof=true
* write(bytes) -> accepted, discarded
* close(token) -> closes exactly once
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define ABI_VERSION 1
#define MQ_OK 0
#define MQ_ERR 1
static char g_last_error[256];
static int closed = 0;
uint32_t marqdo_resource_provider_abi_version(void) { return ABI_VERSION; }
static int fail(const char *message) {
snprintf(g_last_error, sizeof(g_last_error), "%s", message);
return MQ_ERR;
}
int32_t marqdo_resource_open(
const char *kind,
const char *descriptor,
const char *rights,
uint64_t *token
) {
(void)descriptor;
if (kind == NULL || strcmp(kind, "demo.sensor") != 0) {
return fail("unsupported kind");
}
if (rights == NULL || strstr(rights, "read") == NULL) {
return fail("read right is required");
}
if (token == NULL) {
return fail("token pointer is NULL");
}
*token = 1;
closed = 0;
snprintf(g_last_error, sizeof(g_last_error), "%s", "ok");
return MQ_OK;
}
int32_t marqdo_resource_read(
uint64_t token,
uint8_t *buffer,
uint32_t capacity,
uint32_t *read,
int32_t *eof
) {
static const char payload[] = "hello";
if (token != 1 || buffer == NULL || read == NULL || eof == NULL) {
return fail("invalid read arguments");
}
if (closed) {
return fail("resource is closed");
}
if (capacity < sizeof(payload) - 1) {
return fail("buffer is too small");
}
memcpy(buffer, payload, sizeof(payload) - 1);
*read = (uint32_t)(sizeof(payload) - 1);
*eof = 1;
return MQ_OK;
}
int32_t marqdo_resource_write(
uint64_t token,
const uint8_t *bytes,
uint32_t length,
uint32_t *written
) {
if (token != 1 || written == NULL || (bytes == NULL && length != 0)) {
return fail("invalid write arguments");
}
if (closed) {
return fail("resource is closed");
}
*written = length;
return MQ_OK;
}
int32_t marqdo_resource_close(uint64_t token) {
if (token != 1) {
return fail("unknown token");
}
if (closed) {
return fail("resource is already closed");
}
closed = 1;
return MQ_OK;
}
int32_t marqdo_resource_last_error(char *buffer, uint32_t capacity) {
if (buffer == NULL || capacity == 0) {
return MQ_ERR;
}
snprintf(buffer, capacity, "%s", g_last_error);
return MQ_OK;
}
+5
View File
@@ -0,0 +1,5 @@
## @exec main
`流 = resource.open("demo.sensor", "unit-1", ["read"])`
`return resource.close(流)`