Fix Webarchy WebKit renderer on the 2720 Flip

This commit is contained in:
Luxferre committed 2026-11-10 12:43:41 +02:00
1 parent d4f0134e32
commit 77d95c715c
9 files changed
+259 -18

No files matched your search

+146
View File
@@ -0,0 +1,146 @@
#!/usr/bin/env python3
"""Host unit test for Webarchy's WebKit renderer profile selection.
The plugin is cross-compiled for armv7 inside Docker. This test extracts the
three renderer-profile functions from webarchy_plugin.cpp and compiles them on
the host with stubbed device-tree and home paths, so the device matrix and the
WebKit presence-flag handling can be verified without a phone.
"""
import pathlib
import re
import subprocess
import sys
import tempfile
BASE = pathlib.Path(__file__).resolve().parent.parent
SOURCE = BASE / "src/dwm-plugins/webarchy_plugin.cpp"
FUNCTIONS = (
"std::string deviceTreeCompatibles",
"bool webarchySoftwareRendererPreferred",
"void configureWebkitRenderer",
)
def extract(name, text):
start = text.find("\n" + name + "(")
if start < 0:
raise SystemExit("missing function %s in webarchy_plugin.cpp" % name)
start += 1
depth = 0
opened = False
for pos in range(start, len(text)):
if text[pos] == "{":
depth += 1
opened = True
elif text[pos] == "}":
depth -= 1
if opened and depth == 0:
return text[start:pos + 1] + "\n"
raise SystemExit("unterminated function %s" % name)
HARNESS_HEAD = r'''
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <unistd.h>
static const char* g_compat_path = nullptr;
static const char* g_home = nullptr;
std::string getHomeDirPath() { return std::string(g_home); }
SOFTWARE_FLAG
#define CHECK(cond) do { \
if (!(cond)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); return 1; } \
} while (0)
'''
HARNESS_MAIN = r'''
int main(int argc, char** argv) {
CHECK(argc == 4);
g_compat_path = argv[1];
g_home = argv[2];
const int expect_software = (argv[3][0] == '1');
std::string flag = std::string(g_home) + kSoftwareRendererFlag;
CHECK(webarchySoftwareRendererPreferred() == (expect_software != 0));
::unlink(flag.c_str());
::setenv("WEBKIT_DISABLE_DMABUF_RENDERER", "0", 1);
::setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "0", 1);
::setenv("JSC_useJIT", "0", 1);
configureWebkitRenderer(false);
CHECK(::getenv("WEBKIT_DISABLE_DMABUF_RENDERER") == nullptr);
CHECK(::getenv("WEBKIT_DISABLE_COMPOSITING_MODE") == nullptr);
CHECK(std::string(::getenv("JSC_useJIT")) == "0");
FILE* f = std::fopen(flag.c_str(), "wb");
CHECK(f != nullptr);
std::fclose(f);
CHECK(webarchySoftwareRendererPreferred());
configureWebkitRenderer(true);
CHECK(std::string(::getenv("WEBKIT_DISABLE_DMABUF_RENDERER")) == "1");
CHECK(std::string(::getenv("WEBKIT_SKIA_ENABLE_CPU_RENDERING")) == "1");
CHECK(std::string(::getenv("WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS")) == "1");
CHECK(std::string(::getenv("GDK_BACKEND")) == "x11");
return 0;
}
'''
def main():
text = SOURCE.read_text(encoding="utf-8")
flag_decl = re.search(
r'constexpr const char\* kSoftwareRendererFlag =\s*"([^"]+)";', text)
if not flag_decl:
raise SystemExit("missing kSoftwareRendererFlag in webarchy_plugin.cpp")
funcs = "\n".join(extract(name, text) for name in FUNCTIONS)
funcs = funcs.replace('"/proc/device-tree/compatible"', 'g_compat_path')
if '"/proc/device-tree/compatible"' in funcs:
raise SystemExit("could not redirect the device-tree path")
harness = HARNESS_HEAD.replace(
"SOFTWARE_FLAG",
'constexpr const char* kSoftwareRendererFlag = "%s";' % flag_decl.group(1))
harness += funcs + HARNESS_MAIN
with tempfile.TemporaryDirectory(prefix="bananarchy-webarchy-") as tmp:
root = pathlib.Path(tmp)
src = root / "renderer_test.cpp"
exe = root / "renderer_test"
compat = root / "compatible"
home = root / "home"
(home / ".config/sxmo").mkdir(parents=True)
flag = home / flag_decl.group(1).lstrip("/")
src.write_text(harness, encoding="utf-8")
build = subprocess.run(
["g++", "-std=c++20", "-Wall", "-Wextra", "-Werror", str(src), "-o", str(exe)],
capture_output=True, text=True)
if build.returncode:
sys.stderr.write(build.stderr)
return 1
cases = (
("argon", b"nokia,argon\0qcom,msm8905\0", "0", False),
("beatles", b"nokia,beatles\0nokia,argon\0qcom,msm8905\0", "1", False),
("argon + override", b"nokia,argon\0qcom,msm8905\0", "1", True),
)
for label, data, expected, override in cases:
compat.write_bytes(data)
if override:
flag.write_bytes(b"1\n")
elif flag.exists():
flag.unlink()
probe = subprocess.run([str(exe), str(compat), str(home), expected],
capture_output=True, text=True)
if probe.returncode:
sys.stderr.write("%s: %s" % (label, probe.stderr))
return 1
print("[ok] renderer profile: %s" % label)
print("webarchy renderer profile: all checks passed")
return 0
if __name__ == "__main__":
sys.exit(main())