From 46e272bf1903924a39919a8bb534e91ffccca664 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 14:11:36 +0100 Subject: [PATCH] Exercise the release Mesa and Xvfb GLX graphics paths --- tests/x11/README.md | 2 ++ tests/x11/egl.v | 79 +++++++++++++++++++++++++++++++++++++++++++ tests/x11/glx.v | 64 +++++++++++++++++++++++++++++++++++ tests/x11/graphics.sh | 38 +++++++++++++++++++++ 4 files changed, 183 insertions(+) create mode 100644 tests/x11/egl.v create mode 100644 tests/x11/glx.v create mode 100644 tests/x11/graphics.sh diff --git a/tests/x11/README.md b/tests/x11/README.md index 43f5d1f..c260696 100644 --- a/tests/x11/README.md +++ b/tests/x11/README.md @@ -46,3 +46,5 @@ The cold AArch64 LLVM build SDK installed eight signed packages, including GCC's Keep the completed LLVM runtime build tree until its development archive is packaged. Install the signed runtime in the development SDK and set `VINIX_LLVM_BUILD` to the runtime's CMake build directory inside the same worker environment. The recipe compares the built shared object to the installed runtime and asks Ninja for the headers and `llvm-config` using the existing objects. With the variable unset, the source recipe builds those targets independently. Both recipe fixtures reused a configured tree, packaged headers and a versioned `llvm-config`, and rejected a different runtime file. See `xorg/llvm/reuse-dev-fixture-02`, receipt SHA-256 `8123239e3d4ac7ed770df0f1be8d03bf9e214029e22596438a5b3f105033e9b6`. The release builds and LLVM guest checks are separate gates. The Mesa 24.2.8 recipe compiles Gallium once and uses one Meson installation to produce `mesa` and `mesa-gallium-sdk`. EGL, GLES and GBM stay in the runtime archive. The SDK archive carries OSMesa and XA for builds that request them. Both architecture plans resolve the split outputs to the same recipe, and the install fixture confirmed that the two outputs own disjoint paths. See `foundation/release-split-plan-01`, receipt SHA-256 `124659b0ae78559071f072e3845c4c5903da1b2f9a0b523931e422b21ac3b585`. The real Mesa binaries still need the LLVM dependencies and their guest graphics checks. + +For those checks, install `vinix-release-x11` and `busybox-init` from the signed feed into a clean root and audit it. Build `egl.v` and `glx.v` against that SDK and place the executables at `/vinix-egl-check` and `/vinix-glx-check` in a disposable guest root. Boot `graphics.sh` using `tests/disk-root.py`. The fixture reads back the expected pixel from current Mesa's surfaceless EGL and again from an authenticated indirect GLX connection to `Xvfb-glx` using the legacy DRI directory. diff --git a/tests/x11/egl.v b/tests/x11/egl.v new file mode 100644 index 0000000..273ab6b --- /dev/null +++ b/tests/x11/egl.v @@ -0,0 +1,79 @@ +// Exercise the current Gallium runtime without an X server or hardware GPU. +module main + +#include +#include +#include +#flag -lEGL +#flag -lGLESv2 + +fn C.eglGetPlatformDisplay(u32, voidptr, voidptr) voidptr +fn C.eglInitialize(voidptr, &int, &int) u32 +fn C.eglBindAPI(u32) u32 +fn C.eglChooseConfig(voidptr, &int, &voidptr, int, &int) u32 +fn C.eglCreatePbufferSurface(voidptr, voidptr, &int) voidptr +fn C.eglCreateContext(voidptr, voidptr, voidptr, &int) voidptr +fn C.eglMakeCurrent(voidptr, voidptr, voidptr, voidptr) u32 +fn C.eglDestroyContext(voidptr, voidptr) u32 +fn C.eglDestroySurface(voidptr, voidptr) u32 +fn C.eglTerminate(voidptr) u32 +fn C.eglGetError() int +fn C.glClearColor(f32, f32, f32, f32) +fn C.glClear(u32) +fn C.glReadPixels(int, int, int, int, u32, u32, voidptr) +fn C.glGetError() u32 +fn C.glGetString(u32) &u8 + +fn render() ! { + display := C.eglGetPlatformDisplay(C.EGL_PLATFORM_SURFACELESS_MESA, unsafe { nil }, unsafe { nil }) + mut major := 0 + mut minor := 0 + if isnil(display) || C.eglInitialize(display, &major, &minor) == 0 { + return error('surfaceless EGL initialization failed: 0x${C.eglGetError():x}') + } + defer { C.eglTerminate(display) } + mut config := voidptr(0) + mut count := 0 + config_attributes := [int(C.EGL_SURFACE_TYPE), C.EGL_PBUFFER_BIT, C.EGL_RENDERABLE_TYPE, + C.EGL_OPENGL_ES2_BIT, C.EGL_RED_SIZE, 8, C.EGL_GREEN_SIZE, 8, C.EGL_BLUE_SIZE, 8, + C.EGL_ALPHA_SIZE, 8, C.EGL_NONE]! + if C.eglBindAPI(C.EGL_OPENGL_ES_API) == 0 + || C.eglChooseConfig(display, &config_attributes[0], &config, 1, &count) == 0 || count != 1 { + return error('could not choose an RGBA GLES2 pbuffer configuration: 0x${C.eglGetError():x}') + } + size := [int(C.EGL_WIDTH), 1, C.EGL_HEIGHT, 1, C.EGL_NONE]! + surface := C.eglCreatePbufferSurface(display, config, &size[0]) + if isnil(surface) { + return error('could not create an EGL pbuffer: 0x${C.eglGetError():x}') + } + defer { C.eglDestroySurface(display, surface) } + attributes := [int(C.EGL_CONTEXT_CLIENT_VERSION), 2, C.EGL_NONE]! + context := C.eglCreateContext(display, config, unsafe { nil }, &attributes[0]) + if isnil(context) { + return error('could not create a GLES2 context: 0x${C.eglGetError():x}') + } + defer { C.eglDestroyContext(display, context) } + if C.eglMakeCurrent(display, surface, surface, context) == 0 { + return error('could not bind the GLES2 context: 0x${C.eglGetError():x}') + } + defer { C.eglMakeCurrent(display, unsafe { nil }, unsafe { nil }, unsafe { nil }) } + renderer := C.glGetString(C.GL_RENDERER) + if isnil(renderer) { + return error('missing OpenGL renderer name') + } + C.glClearColor(0, 1, 0, 1) + C.glClear(C.GL_COLOR_BUFFER_BIT) + mut pixel := [4]u8{} + C.glReadPixels(0, 0, 1, 1, C.GL_RGBA, C.GL_UNSIGNED_BYTE, &pixel[0]) + if C.glGetError() != C.GL_NO_ERROR || pixel != [u8(0), 255, 0, 255]! { + return error('GLES2 readback did not match the clear color: ${pixel}') + } + println('EGL ${major}.${minor}, renderer ${unsafe { tos_clone(renderer) }}, RGBA ${pixel}.') +} + +fn main() { + render() or { + eprintln(err) + exit(1) + } +} diff --git a/tests/x11/glx.v b/tests/x11/glx.v new file mode 100644 index 0000000..7051779 --- /dev/null +++ b/tests/x11/glx.v @@ -0,0 +1,64 @@ +// Test the legacy GLX server and client together in the Vinix guest. +module main + +#include +#include +#include +#flag -lGL +#flag -lX11 + +@[typedef] +struct C.XVisualInfo { + depth int +} + +fn C.XOpenDisplay(&char) voidptr +fn C.XDefaultScreen(voidptr) int +fn C.XRootWindow(voidptr, int) u64 +fn C.XCreatePixmap(voidptr, u64, u32, u32, u32) u64 +fn C.XFreePixmap(voidptr, u64) int +fn C.XFree(voidptr) int +fn C.XCloseDisplay(voidptr) int +fn C.glXChooseVisual(voidptr, int, &int) &C.XVisualInfo +fn C.glXCreateGLXPixmap(voidptr, &C.XVisualInfo, u64) u64 +fn C.glXDestroyGLXPixmap(voidptr, u64) +fn C.glXCreateContext(voidptr, &C.XVisualInfo, voidptr, int) voidptr +fn C.glXMakeCurrent(voidptr, u64, voidptr) int +fn C.glXIsDirect(voidptr, voidptr) int +fn C.glXDestroyContext(voidptr, voidptr) +fn C.glClearColor(f32, f32, f32, f32) +fn C.glClear(u32) +fn C.glReadBuffer(u32) +fn C.glReadPixels(int, int, int, int, u32, u32, voidptr) +fn C.glGetError() u32 + +fn main() { + display := C.XOpenDisplay(unsafe { nil }) + assert display != unsafe { nil } + defer { C.XCloseDisplay(display) } + screen := C.XDefaultScreen(display) + mut attributes := [int(C.GLX_RGBA), C.GLX_RED_SIZE, 8, C.GLX_GREEN_SIZE, 8, C.GLX_BLUE_SIZE, 8, 0]! + visual := C.glXChooseVisual(display, screen, &attributes[0]) + assert visual != unsafe { nil } + defer { C.XFree(visual) } + pixmap := C.XCreatePixmap(display, C.XRootWindow(display, screen), 1, 1, u32(visual.depth)) + assert pixmap != 0 + defer { C.XFreePixmap(display, pixmap) } + drawable := C.glXCreateGLXPixmap(display, visual, pixmap) + assert drawable != 0 + defer { C.glXDestroyGLXPixmap(display, drawable) } + context := C.glXCreateContext(display, visual, unsafe { nil }, C.False) + assert context != unsafe { nil } + defer { C.glXDestroyContext(display, context) } + assert C.glXIsDirect(display, context) == C.False + assert C.glXMakeCurrent(display, drawable, context) != C.False + defer { C.glXMakeCurrent(display, 0, unsafe { nil }) } + C.glClearColor(0, 1, 0, 1) + C.glClear(C.GL_COLOR_BUFFER_BIT) + C.glReadBuffer(C.GL_FRONT) + mut pixel := [4]u8{} + C.glReadPixels(0, 0, 1, 1, C.GL_RGBA, C.GL_UNSIGNED_BYTE, &pixel[0]) + assert C.glGetError() == C.GL_NO_ERROR + assert pixel[0] == 0 && pixel[1] == 255 && pixel[2] == 0 + println('Indirect GLX rendered a green pixel in Xvfb.') +} diff --git a/tests/x11/graphics.sh b/tests/x11/graphics.sh new file mode 100644 index 0000000..3ed0a8d --- /dev/null +++ b/tests/x11/graphics.sh @@ -0,0 +1,38 @@ +#!/bin/sh +set -eu +export PATH=/bin:/usr/bin:/sbin:/usr/sbin HOME=/tmp +export DISPLAY=:71 XAUTHORITY=/tmp/vinix-glx.Xauthority LIBGL_ALWAYS_SOFTWARE=1 +server= +phase=egl +finish() { + status=$? + if [ "$status" -ne 0 ]; then + echo "Vinix graphics fixture failed at $phase" + if [ -f /tmp/xvfb-glx.log ]; then cat /tmp/xvfb-glx.log; fi + fi + if [ -n "$server" ]; then kill "$server" 2>/dev/null || true; fi + /sbin/poweroff -f +} +trap finish EXIT + +test "$(uname -o)" = Vinix +LIBGL_DRIVERS_PATH=/usr/lib/mesa24/dri /vinix-egl-check + +phase=glx-server +export LIBGL_DRIVERS_PATH=/usr/lib/xorg/modules/dri +mkdir -p /tmp +xauth -q -f "$XAUTHORITY" add "$DISPLAY" MIT-MAGIC-COOKIE-1 0123456789abcdef0123456789abcdef +Xvfb-glx "$DISPLAY" -auth "$XAUTHORITY" -nolisten tcp -noreset -screen 0 128x128x24 \ + +extension GLX +iglx >/tmp/xvfb-glx.log 2>&1 & +server=$! +attempt=0 +until xset q >/tmp/xset-glx.log 2>&1; do + kill -0 "$server" + attempt=$((attempt + 1)) + [ "$attempt" -lt 30 ] + sleep 1 +done + +phase=glx-client +LIBGL_ALWAYS_INDIRECT=1 /vinix-glx-check +echo 'VPAC FIXTURE GUEST PASS' -- 2.56.1