#!/usr/bin/env tarantool
--
-- protoc-gen-tarantool / pb runtime conformance test runner.
--
-- Speaks the Google protobuf conformance protocol on stdin/stdout: each
-- request and response is a little-endian uint32 length followed by a
-- `conformance.ConformanceRequest` / `conformance.ConformanceResponse`
-- serialized as protobuf. Loops until EOF.
--
-- Run against the canonical Google conformance binary like so:
--
-- conformance_test_runner --enforce_recommended \
-- tarantool cmd/conformance-runner.lua
--
-- LUA_PATH must let this script find `pb`, the generated modules, and
-- the conformance core module under `cmd/`:
--
-- LUA_PATH="./runtime/?/init.lua;./runtime/?.lua;\
-- ./examples/expected/?.lua;./examples/expected/?/init.lua;\
-- ./cmd/?.lua;;"
local core = require('cmd.conformance.core')
local function read_n(n)
local got = io.stdin:read(n)
if got == nil or #got < n then return nil end
return got
end
local function read_request_bytes()
local hdr = read_n(4)
if hdr == nil then return nil end
local b1, b2, b3, b4 = hdr:byte(1, 4)
return read_n(b1 + b2 * 256 + b3 * 65536 + b4 * 16777216)
end
local function write_response_bytes(payload)
local n = #payload
io.stdout:write(string.char(
n % 256,
math.floor(n / 256) % 256,
math.floor(n / 65536) % 256,
math.floor(n / 16777216) % 256))
io.stdout:write(payload)
io.stdout:flush()
end
while true do
local req_bytes = read_request_bytes()
if req_bytes == nil then break end
write_response_bytes(core.handle_request(req_bytes))
end
os.exit(0)