161 lines
5.4 KiB
Python
Executable File
161 lines
5.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Host unit test for Geminux Webarchy renderer profile & ultrawide vertical tab wiring."""
|
|
import pathlib
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
|
|
BASE = pathlib.Path(__file__).resolve().parent.parent
|
|
SOURCE = BASE / "src/webarchy/webarchy.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 src/webarchy/webarchy.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);
|
|
::unsetenv("GTK_THEME");
|
|
configureWebkitRenderer(false);
|
|
CHECK(::getenv("WEBKIT_DISABLE_DMABUF_RENDERER") == nullptr);
|
|
CHECK(::getenv("WEBKIT_DISABLE_COMPOSITING_MODE") == nullptr);
|
|
CHECK(::getenv("GTK_THEME") == 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")
|
|
for needle in (
|
|
'gtk_box_pack_end(GTK_BOX(root), app->tabSidebar',
|
|
'gtk_widget_set_hexpand(app->tabSidebar, FALSE)',
|
|
'gtk_widget_set_hexpand_set(app->tabSidebar, TRUE)',
|
|
'"wa-tabbar"',
|
|
'"wa-tablist"',
|
|
'g_unix_signal_add(SIGUSR1, onSigUsr1ThemeReload',
|
|
'onWebProcessTerminated',
|
|
'WEBKIT_WEB_PROCESS_CRASHED',
|
|
'WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION',
|
|
):
|
|
if needle not in text:
|
|
raise SystemExit("missing expected Webarchy UI/engine marker: %s" % needle)
|
|
if 'gtk_widget_set_hexpand(GTK_WIDGET(app->tabHeaderLabel), TRUE)' in text:
|
|
raise SystemExit("tabHeaderLabel must not set hexpand=TRUE (expands right sidebar)")
|
|
if re.search(r"font-size:\s*[0-9.]+px", text):
|
|
raise SystemExit("src/webarchy/webarchy.cpp CSS must use DPI-scaled 'pt' font sizes, not 'px'")
|
|
|
|
flag_decl = re.search(
|
|
r'constexpr const char\* kSoftwareRendererFlag =\s*"([^"]+)";', text)
|
|
if not flag_decl:
|
|
raise SystemExit("missing kSoftwareRendererFlag in src/webarchy/webarchy.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="geminux-webarchy-") as tmp:
|
|
root = pathlib.Path(tmp)
|
|
src = root / "renderer_test.cpp"
|
|
exe = root / "renderer_test"
|
|
compat = root / "compatible"
|
|
home = root / "home"
|
|
(home / ".config/geminux/webarchy").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 = (
|
|
("geminux-x27", b"planet,gemini-pda\0mediatek,mt6797\0", "0", False),
|
|
("beatles", b"nokia,beatles\0nokia,argon\0qcom,msm8905\0", "1", False),
|
|
("geminux-x27 + override", b"planet,gemini-pda\0mediatek,mt6797\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 & layout: all checks passed")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|