feat: initial ANODE desktop environment adapted from Geminux
This commit is contained in:
commit
65bfe3c65a
137 files changed
+33788
No files matched your search
Executable
+95
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify strict POSIX Makefile compliance and POSIX /bin/sh syntax across all scripts."""
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
|
||||
def check_makefile() -> None:
|
||||
mk_path = os.path.join(ROOT, "Makefile")
|
||||
with open(mk_path, "r", encoding="utf-8") as f:
|
||||
lines = f.read().splitlines()
|
||||
|
||||
assert any(l.strip() == ".POSIX:" for l in lines), "Makefile must begin with .POSIX:"
|
||||
|
||||
# Check for GNU-only or BSD-only constructs
|
||||
forbidden = [
|
||||
(r"^\s*(ifeq|ifneq|ifdef|ifndef|else|endif)\b", "GNU conditional"),
|
||||
(r"\$\(shell\b", "$(shell ...) GNU function"),
|
||||
(r"\$\(wildcard\b", "$(wildcard ...) GNU function"),
|
||||
(r"\$\(patsubst\b", "$(patsubst ...) GNU function"),
|
||||
(r"\$\(subst\b", "$(subst ...) GNU function"),
|
||||
(r":=", "non-POSIX immediate assignment :="),
|
||||
(r"\+=", "non-POSIX append assignment +="),
|
||||
(r"\?=", "non-POSIX conditional assignment ?="),
|
||||
(r"\$\^", "non-POSIX automatic variable $^"),
|
||||
(r"^[^#]*%[^:]*:", "GNU pattern rule %.o"),
|
||||
(r"^\s*include\b|^\s*-include\b", "non-POSIX include directive"),
|
||||
(r"^\s*export\b", "GNU export directive"),
|
||||
(r"\bmake\s+-C\b|\$\(MAKE\)\s+-C\b", "GNU make -C option"),
|
||||
]
|
||||
for lineno, line in enumerate(lines, 1):
|
||||
stripped = line.strip()
|
||||
if stripped.startswith("#") or not stripped:
|
||||
continue
|
||||
for pat, desc in forbidden:
|
||||
assert not re.search(pat, line), f"Makefile:{lineno}: {desc}: {line}"
|
||||
# $< is only allowed in inference rules (e.g. .c.o:), not explicit target rules
|
||||
if "$<" in line:
|
||||
raise AssertionError(f"Makefile:{lineno}: avoid $< in explicit rules: {line}")
|
||||
|
||||
# Verify Makefile parses cleanly under make -n (no syntax errors)
|
||||
res = subprocess.run(["make", "-n", "-f", mk_path], cwd=ROOT, capture_output=True, text=True)
|
||||
assert res.returncode == 0, f"make -n failed: {res.stderr}"
|
||||
|
||||
|
||||
def check_scripts() -> None:
|
||||
script_files = [
|
||||
"scripts/detect-env.sh",
|
||||
"scripts/anode-apply-scale",
|
||||
"scripts/anode-apply-theme",
|
||||
"scripts/anode-sync-gtk-theme",
|
||||
"scripts/anode-sync-dunst-theme",
|
||||
"scripts/anode-session",
|
||||
"scripts/anode-launcher",
|
||||
"data/env.sh",
|
||||
"src/dmenu/dmenu_path",
|
||||
"src/dmenu/dmenu_run",
|
||||
]
|
||||
bad_patterns = [
|
||||
(r"\[\[\s", "bash [[ conditional"),
|
||||
(r"\becho\s+-e\b", "non-portable echo -e"),
|
||||
(r"\blocal\s+", "non-POSIX local keyword"),
|
||||
(r"\bpidof\b", "Linux-only pidof"),
|
||||
(r"\bsed\s+-i\b", "non-POSIX sed -i"),
|
||||
(r"\bxargs\s+-r\b", "GNU xargs -r"),
|
||||
(r"\bcp\s+-a\b", "GNU cp -a"),
|
||||
(r"\bln\s+-sfn\b", "GNU ln -sfn"),
|
||||
(r"\bmktemp\s+-p\b", "GNU mktemp -p"),
|
||||
]
|
||||
for rel in script_files:
|
||||
p = os.path.join(ROOT, rel)
|
||||
assert os.path.isfile(p), f"Missing script: {rel}"
|
||||
st = subprocess.run(["sh", "-n", p], capture_output=True, text=True)
|
||||
assert st.returncode == 0, f"sh -n failed on {rel}: {st.stderr}"
|
||||
|
||||
with open(p, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
for lineno, line in enumerate(content.splitlines(), 1):
|
||||
# Skip comments
|
||||
code = line.split("#", 1)[0]
|
||||
if not code.strip():
|
||||
continue
|
||||
# Allow '#!/bin/sh'
|
||||
for pat, desc in bad_patterns:
|
||||
assert not re.search(pat, code), f"{rel}:{lineno}: {desc}: {line}"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_makefile()
|
||||
check_scripts()
|
||||
print("test_posix_make: OK")
|
||||
Executable
+144
@@ -0,0 +1,144 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify .xth theme switching and fractional DPI scaling across toolkits without double-scaling."""
|
||||
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
THEMES_DIR = os.path.join(ROOT, "data", "themes")
|
||||
APPLY_SCALE = os.path.join(ROOT, "scripts", "anode-apply-scale")
|
||||
APPLY_THEME = os.path.join(ROOT, "scripts", "anode-apply-theme")
|
||||
|
||||
|
||||
def run_env(env, cmd):
|
||||
res = subprocess.run(cmd, env=env, capture_output=True, text=True)
|
||||
assert res.returncode == 0, f"Command failed: {cmd}\nstdout={res.stdout}\nstderr={res.stderr}"
|
||||
return res
|
||||
|
||||
|
||||
def parse_xres(path):
|
||||
out = {}
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
s = line.strip()
|
||||
if not s or s.startswith("!") or s.startswith("#"):
|
||||
continue
|
||||
if ":" in s:
|
||||
k, v = s.split(":", 1)
|
||||
out[k.strip()] = v.strip()
|
||||
return out
|
||||
|
||||
|
||||
def test_fractional_scales():
|
||||
scales = [
|
||||
("0.75", 72, "1", 11),
|
||||
("1.00", 96, "1", 15),
|
||||
("1.25", 120, "1", 19),
|
||||
("1.50", 144, "1", 23),
|
||||
("1.75", 168, "2", 26),
|
||||
("2.00", 192, "2", 30),
|
||||
("2.50", 240, "3", 38),
|
||||
]
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
env = dict(os.environ)
|
||||
env.pop("DISPLAY", None)
|
||||
env["HOME"] = tmp
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
|
||||
for s_str, exp_dpi, exp_gdk, exp_px in scales:
|
||||
run_env(env, [APPLY_SCALE, s_str, "--touch=1"])
|
||||
scale_env_p = os.path.join(tmp, ".config", "anode", "scale.env")
|
||||
with open(scale_env_p, "r", encoding="utf-8") as f:
|
||||
senv = f.read()
|
||||
assert f'export GDK_SCALE="{exp_gdk}"' in senv, senv
|
||||
assert 'export GDK_DPI_SCALE="1.0"' in senv, senv
|
||||
assert f'export QT_SCALE_FACTOR="{s_str}"' in senv, senv
|
||||
assert 'export QT_FONT_DPI="96"' in senv, senv
|
||||
assert 'export QT_AUTO_SCREEN_SCALE_FACTOR="0"' in senv, senv
|
||||
assert 'export QT_SCALE_FACTOR_ROUNDING_POLICY="PassThrough"' in senv, senv
|
||||
|
||||
xres = parse_xres(os.path.join(tmp, ".Xresources"))
|
||||
assert int(xres["Xft.dpi"]) == exp_dpi, f"scale={s_str} dpi={xres['Xft.dpi']}"
|
||||
assert int(xres["theme.baseFontSize"]) == exp_px, f"scale={s_str} base={xres['theme.baseFontSize']}"
|
||||
assert xres["theme.fontFace"] == "Fira Code"
|
||||
assert "Fira Code" in xres["st.font"] and f"pixelsize={exp_px}" in xres["st.font"]
|
||||
assert "Fira Code" in xres["dwm.font"] and f"{exp_px}px" in xres["dwm.font"]
|
||||
assert xres["*TkTheme"] == "gtkTtk"
|
||||
assert xres["theme.touchMode"] == "1"
|
||||
|
||||
# Verify xsettingsd omits Xft/DPI so GTK3 does not double-scale
|
||||
xs_p = os.path.join(tmp, ".config", "xsettingsd", "xsettingsd.conf")
|
||||
with open(xs_p, "r", encoding="utf-8") as f:
|
||||
xs = f.read()
|
||||
assert "Xft/DPI" not in xs, f"Xft/DPI must not exist in xsettingsd.conf:\n{xs}"
|
||||
assert f"Gdk/WindowScalingFactor {exp_gdk}" in xs, xs
|
||||
|
||||
# Verify Qt5 + Qt6 + Kvantum + Dunst + GTK2/3/4 files
|
||||
for p in [
|
||||
".gtkrc-2.0",
|
||||
".config/gtk-3.0/gtk.css",
|
||||
".config/gtk-3.0/settings.ini",
|
||||
".config/gtk-4.0/gtk.css",
|
||||
".config/gtk-4.0/settings.ini",
|
||||
".config/qt5ct/qt5ct.conf",
|
||||
".config/qt6ct/qt6ct.conf",
|
||||
".config/Kvantum/kvantum.kvconfig",
|
||||
".config/dunst/dunstrc",
|
||||
]:
|
||||
full = os.path.join(tmp, p)
|
||||
assert os.path.isfile(full) and os.path.getsize(full) > 20, f"Missing/empty {p}"
|
||||
|
||||
|
||||
def test_all_22_themes_and_legacy_192dpi_import():
|
||||
themes = sorted(glob.glob(os.path.join(THEMES_DIR, "*.xth")))
|
||||
assert len(themes) == 22, f"Expected 22 .xth themes, got {len(themes)}"
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
env = dict(os.environ)
|
||||
env.pop("DISPLAY", None)
|
||||
env["HOME"] = tmp
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(tmp, ".config")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
run_env(env, [APPLY_SCALE, "1.00", "--touch=0", "--no-apply"])
|
||||
|
||||
for th in themes:
|
||||
run_env(env, [APPLY_THEME, th])
|
||||
xres = parse_xres(os.path.join(tmp, ".Xresources"))
|
||||
tname = xres["theme.name"]
|
||||
assert xres["Xft.dpi"] == "96"
|
||||
assert xres["theme.baseFontSize"] == "15"
|
||||
assert xres["theme.fontFace"] == "Fira Code"
|
||||
assert os.path.isfile(os.path.join(tmp, ".config", "qt6ct", "colors", f"ANODE-{tname}.conf"))
|
||||
assert os.path.isfile(os.path.join(tmp, ".config", "qt5ct", "colors", f"ANODE-{tname}.conf"))
|
||||
|
||||
# Legacy 192-DPI import must normalize back to 96 DPI / 15px at 1.00x scale
|
||||
legacy_xth = os.path.join(tmp, "LegacyHiDpi.xth")
|
||||
with open(legacy_xth, "w", encoding="utf-8") as f:
|
||||
f.write(
|
||||
"theme.name: LegacyHiDpi\n"
|
||||
"Xft.dpi: 192\n"
|
||||
"Xcursor.size: 64\n"
|
||||
"theme.fontFace: Fira Code\n"
|
||||
"theme.baseFontSize: 32\n"
|
||||
"dwm.borderpx: 4\n"
|
||||
"theme.bgMain: #101010\n"
|
||||
"theme.fgMain: #eeeeee\n"
|
||||
"theme.accent: #55aaff\n"
|
||||
)
|
||||
run_env(env, [APPLY_THEME, legacy_xth])
|
||||
xres = parse_xres(os.path.join(tmp, ".Xresources"))
|
||||
assert xres["Xft.dpi"] == "96"
|
||||
assert int(xres["theme.baseFontSize"]) == 16, xres["theme.baseFontSize"]
|
||||
assert int(xres["dwm.borderpx"]) == 2, xres["dwm.borderpx"]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_fractional_scales()
|
||||
test_all_22_themes_and_legacy_192dpi_import()
|
||||
print("test_theme_scale: ALL PASSED (7 fractional scales, 22 themes, legacy 192-DPI import)")
|
||||
@@ -0,0 +1,207 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "anode_scale.h"
|
||||
#include "anode_plat.h"
|
||||
#include "anode_dns_valid.h"
|
||||
#include "anode_tz_valid.h"
|
||||
#include "anode_audio_parse.h"
|
||||
#include "anode_wifi_list.h"
|
||||
#include "anode_bt_list.h"
|
||||
#include "anode_power_policy.h"
|
||||
#include "anode-touch-gesture.h"
|
||||
|
||||
static void test_scale_math(void) {
|
||||
assert(anode_clamp_scale(0.1) == 0.5);
|
||||
assert(anode_clamp_scale(9.0) == 4.0);
|
||||
assert(anode_clamp_scale(1.25) == 1.25);
|
||||
assert(anode_clamp_dpi(12.0) == 48.0);
|
||||
assert(anode_clamp_dpi(600.0) == 384.0);
|
||||
assert(anode_scale_from_dpi(144.0) == 1.5);
|
||||
assert(anode_scale_from_dpi(192.0) == 2.0);
|
||||
assert(anode_scale_px(15, 1.0) == 15);
|
||||
assert(anode_scale_px(15, 1.5) == 23);
|
||||
assert(anode_scale_px(15, 2.0) == 30);
|
||||
assert(anode_scale_px(15, 0.75) == 11);
|
||||
assert(anode_parse_bool_str("true", 0) == 1);
|
||||
assert(anode_parse_bool_str("yes", 0) == 1);
|
||||
assert(anode_parse_bool_str("1", 0) == 1);
|
||||
assert(anode_parse_bool_str("false", 1) == 0);
|
||||
assert(anode_parse_bool_str("0", 1) == 0);
|
||||
assert(anode_parse_bool_str("unknown", 1) == 1);
|
||||
}
|
||||
|
||||
static void test_dns_validation(void) {
|
||||
char v4[ANODE_DNS_MAX_SERVERS][16];
|
||||
char v6[ANODE_DNS_MAX_SERVERS][46];
|
||||
int n4 = 0, n6 = 0;
|
||||
char csv[256] = {0};
|
||||
|
||||
int tot = anode_parse_dns_servers("1.1.1.1, 8.8.8.8, 1.1.1.1, 2606:4700:4700::1111",
|
||||
v4, &n4, ANODE_DNS_MAX_SERVERS,
|
||||
v6, &n6, ANODE_DNS_MAX_SERVERS,
|
||||
csv, sizeof(csv));
|
||||
assert(tot == 3);
|
||||
assert(n4 == 2);
|
||||
assert(n6 == 1);
|
||||
assert(strcmp(csv, "1.1.1.1,8.8.8.8,2606:4700:4700::1111") == 0);
|
||||
|
||||
assert(anode_parse_dns_servers("0.0.0.0", v4, &n4, 6, v6, &n6, 6, csv, sizeof(csv)) == -1);
|
||||
assert(anode_parse_dns_servers("224.0.0.1", v4, &n4, 6, v6, &n6, 6, csv, sizeof(csv)) == -1);
|
||||
assert(anode_parse_dns_servers("1.1.1.1; rm -rf /", v4, &n4, 6, v6, &n6, 6, csv, sizeof(csv)) == -1);
|
||||
assert(anode_dns_mode_valid("cloudflare"));
|
||||
assert(!anode_dns_mode_valid("evil"));
|
||||
|
||||
char sum[128] = {0};
|
||||
int c = anode_parse_resolv_conf("# comment\nnameserver 9.9.9.9\nnameserver 1.1.1.1\n", sum, sizeof(sum));
|
||||
assert(c == 2);
|
||||
assert(strcmp(sum, "9.9.9.9, 1.1.1.1") == 0);
|
||||
}
|
||||
|
||||
static void test_tz_validation(void) {
|
||||
assert(anode_tz_name_valid("UTC"));
|
||||
assert(anode_tz_name_valid("America/New_York"));
|
||||
assert(anode_tz_name_valid("Etc/GMT+2"));
|
||||
assert(!anode_tz_name_valid(""));
|
||||
assert(!anode_tz_name_valid("../etc/passwd"));
|
||||
assert(!anode_tz_name_valid("/America/New_York"));
|
||||
assert(!anode_tz_name_valid("America//New_York"));
|
||||
assert(!anode_tz_name_valid("UTC;id"));
|
||||
if (access("/usr/share/zoneinfo/UTC", R_OK) == 0) {
|
||||
assert(anode_tz_file_valid("/usr/share/zoneinfo", "UTC"));
|
||||
assert(!anode_tz_file_valid("/usr/share/zoneinfo", "No/SuchZone"));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_audio_parsers(void) {
|
||||
int vol = 0;
|
||||
bool muted = false;
|
||||
assert(anode_parse_wpctl_volume("Volume: 0.65 [MUTED]", &vol, &muted));
|
||||
assert(vol == 65 && muted == true);
|
||||
assert(anode_parse_wpctl_volume("Volume: 1.00", &vol, &muted));
|
||||
assert(vol == 100 && muted == false);
|
||||
|
||||
char sink[128], src[128];
|
||||
anode_parse_pactl_defaults("Server Name: Pulse\nDefault Sink: alsa_out.pci\nDefault Source: alsa_in.pci\n",
|
||||
sink, sizeof(sink), src, sizeof(src));
|
||||
assert(strcmp(sink, "alsa_out.pci") == 0);
|
||||
assert(strcmp(src, "alsa_in.pci") == 0);
|
||||
|
||||
const char *sinks_txt =
|
||||
"Sink #3\n"
|
||||
"\tState: RUNNING\n"
|
||||
"\tName: alsa_out.pci\n"
|
||||
"\tDescription: Built-in Analog\n"
|
||||
"\tMute: no\n"
|
||||
"\tVolume: front-left: 52428 / 80%\n";
|
||||
anode_audio_node_t nodes[8];
|
||||
int nn = anode_parse_pactl_nodes(sinks_txt, "Sink #", "alsa_out.pci", false, nodes, 8);
|
||||
assert(nn == 1);
|
||||
assert(nodes[0].index == 3);
|
||||
assert(nodes[0].is_default == true);
|
||||
assert(nodes[0].vol_pct == 80);
|
||||
assert(nodes[0].muted == false);
|
||||
|
||||
const char *am_txt = "Simple mixer control 'Master',0\nSimple mixer control 'Capture',0\n";
|
||||
int na = anode_parse_amixer_scontrols(am_txt, nodes, 8);
|
||||
assert(na == 2 && strcmp(nodes[0].name, "Master") == 0 && nodes[0].is_default);
|
||||
|
||||
const char *sn_txt = "output.level=0.72\noutput.mute=0\ninput.level=0.40\n";
|
||||
int ns = anode_parse_sndioctl(sn_txt, false, nodes, 8);
|
||||
assert(ns == 1 && nodes[0].vol_pct == 72);
|
||||
}
|
||||
|
||||
static void test_wifi_and_bt_parsers(void) {
|
||||
const char *nm =
|
||||
" :11\\:22\\:33\\:44\\:55\\:66:HomeNet:6:45:WPA2\n"
|
||||
"*:AA\\:BB\\:CC\\:DD\\:EE\\:FF:HomeNet:36:85:WPA2\n"
|
||||
" :00\\:11\\:22\\:33\\:44\\:55:CafeFree:11:60:--\n";
|
||||
anode_wifi_group_t grp[8];
|
||||
int ng = anode_parse_wifi_scan(nm, grp, 8);
|
||||
assert(ng == 2);
|
||||
assert(strcmp(grp[0].ssid, "HomeNet") == 0);
|
||||
assert(grp[0].in_use == true);
|
||||
assert(grp[0].best_chan == 36);
|
||||
assert(grp[0].ap_count == 2);
|
||||
assert(strcmp(grp[1].security, "Open") == 0);
|
||||
|
||||
const char *iw = "Connected to aa:bb:cc:dd:ee:ff\n\tSSID: LabWiFi\n\tfreq: 5180\n\tsignal: -55 dBm\n";
|
||||
char bssid[32], ssid[64];
|
||||
int ch = 0, sig = 0;
|
||||
assert(anode_parse_iw_link(iw, bssid, sizeof(bssid), ssid, sizeof(ssid), &ch, &sig));
|
||||
assert(strcmp(ssid, "LabWiFi") == 0 && ch == 36 && sig == 90);
|
||||
|
||||
anode_bt_dev_t devs[8];
|
||||
int nb = anode_parse_bt_devices("Device aa:bb:cc:dd:ee:ff Keyboard\nDevice 11:22:33:44:55:66 Speaker\n",
|
||||
"Device 11:22:33:44:55:66 Speaker\n",
|
||||
"Device 11:22:33:44:55:66 Speaker\n",
|
||||
devs, 8);
|
||||
assert(nb == 2);
|
||||
assert(devs[0].connected && strcmp(devs[0].name, "Speaker") == 0);
|
||||
}
|
||||
|
||||
static void test_power_policy_and_gestures(void) {
|
||||
anode_power_cfg_t cfg = anode_power_cfg_default();
|
||||
anode_pwr_state_t st = ANODE_PWR_ACTIVE;
|
||||
anode_power_actions_t act;
|
||||
|
||||
anode_power_policy_step(&cfg, &st, 10000, false, 80, true, false, &act);
|
||||
assert(st == ANODE_PWR_ACTIVE && !act.dim_now);
|
||||
|
||||
anode_power_policy_step(&cfg, &st, 65000, false, 80, true, false, &act);
|
||||
assert(st == ANODE_PWR_DIMMED && act.dim_now);
|
||||
|
||||
anode_power_policy_step(&cfg, &st, 1000, false, 80, true, false, &act);
|
||||
assert(st == ANODE_PWR_ACTIVE && act.restore_brightness);
|
||||
|
||||
anode_power_policy_step(&cfg, &st, 190000, false, 80, true, false, &act);
|
||||
assert(st == ANODE_PWR_LOCKED && act.lock_now);
|
||||
|
||||
anode_power_policy_step(&cfg, &st, 610000, false, 80, true, true, &act);
|
||||
assert(st == ANODE_PWR_SUSPENDED && act.suspend_now);
|
||||
|
||||
/* Critical low battery override on battery */
|
||||
st = ANODE_PWR_ACTIVE;
|
||||
anode_power_policy_step(&cfg, &st, 1000, false, 2, true, false, &act);
|
||||
assert(act.warn_low_batt && act.suspend_now);
|
||||
|
||||
/* Gestures at 1.0x and 2.0x scales */
|
||||
anode_touch_track_t tr = {0};
|
||||
anode_touch_begin(&tr, 1, 500, 1070, 1000);
|
||||
assert(anode_touch_finish(&tr, 500, 900, 1200, 1920, 1080, 1.0) == ANODE_GEST_VKBD_TOGGLE);
|
||||
|
||||
anode_touch_begin(&tr, 2, 1000, 15, 2000);
|
||||
assert(anode_touch_finish(&tr, 1000, 220, 2250, 3840, 2160, 2.0) == ANODE_GEST_LAUNCHER);
|
||||
|
||||
anode_touch_begin(&tr, 3, 1910, 500, 3000);
|
||||
assert(anode_touch_finish(&tr, 1750, 500, 3200, 1920, 1080, 1.0) == ANODE_GEST_CONTROL);
|
||||
}
|
||||
|
||||
static void test_platform_probe(void) {
|
||||
anode_net_iface_t ifs[ANODE_MAX_IFACES];
|
||||
int n = anode_list_net_ifaces(ifs, ANODE_MAX_IFACES);
|
||||
assert(n >= 0);
|
||||
anode_battery_info_t bat;
|
||||
anode_read_battery(&bat);
|
||||
(void)anode_detect_audio_backend();
|
||||
char buf[256];
|
||||
anode_runtime_dir(buf, sizeof(buf));
|
||||
assert(buf[0] == '/');
|
||||
anode_config_dir(buf, sizeof(buf));
|
||||
assert(buf[0] == '/');
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_scale_math();
|
||||
test_dns_validation();
|
||||
test_tz_validation();
|
||||
test_audio_parsers();
|
||||
test_wifi_and_bt_parsers();
|
||||
test_power_policy_and_gestures();
|
||||
test_platform_probe();
|
||||
printf("test_units: ALL PASSED\n");
|
||||
return 0;
|
||||
}
|
||||
Executable
+334
@@ -0,0 +1,334 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Headless Xvfb E2E integration tests across 1024x600, 1920x1080, and 3840x2160."""
|
||||
|
||||
import ctypes
|
||||
import ctypes.util
|
||||
import os
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||||
BUILD = os.path.join(ROOT, "build")
|
||||
|
||||
libx11_name = ctypes.util.find_library("X11") or "libX11.so.6"
|
||||
X11 = ctypes.CDLL(libx11_name)
|
||||
|
||||
Window = ctypes.c_ulong
|
||||
Atom = ctypes.c_ulong
|
||||
Display_p = ctypes.c_void_p
|
||||
|
||||
|
||||
class XWindowAttributes(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("x", ctypes.c_int), ("y", ctypes.c_int),
|
||||
("width", ctypes.c_int), ("height", ctypes.c_int),
|
||||
("border_width", ctypes.c_int), ("depth", ctypes.c_int),
|
||||
("visual", ctypes.c_void_p), ("root", Window),
|
||||
("class", ctypes.c_int), ("bit_gravity", ctypes.c_int),
|
||||
("win_gravity", ctypes.c_int), ("backing_store", ctypes.c_int),
|
||||
("backing_planes", ctypes.c_ulong), ("backing_pixel", ctypes.c_ulong),
|
||||
("save_under", ctypes.c_int), ("colormap", ctypes.c_ulong),
|
||||
("map_installed", ctypes.c_int), ("map_state", ctypes.c_int),
|
||||
("all_event_masks", ctypes.c_long), ("your_event_mask", ctypes.c_long),
|
||||
("do_not_propagate_mask", ctypes.c_long), ("override_redirect", ctypes.c_int),
|
||||
("screen", ctypes.c_void_p),
|
||||
]
|
||||
|
||||
|
||||
class XClientMessageData(ctypes.Union):
|
||||
_fields_ = [("b", ctypes.c_char * 20), ("s", ctypes.c_short * 10), ("l", ctypes.c_long * 5)]
|
||||
|
||||
|
||||
class XClientMessageEvent(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("type", ctypes.c_int), ("serial", ctypes.c_ulong), ("send_event", ctypes.c_int),
|
||||
("display", Display_p), ("window", Window), ("message_type", Atom),
|
||||
("format", ctypes.c_int), ("data", XClientMessageData),
|
||||
]
|
||||
|
||||
|
||||
class XWMHints(ctypes.Structure):
|
||||
_fields_ = [
|
||||
("flags", ctypes.c_long), ("input", ctypes.c_int), ("initial_state", ctypes.c_int),
|
||||
("icon_pixmap", ctypes.c_ulong), ("icon_window", Window),
|
||||
("icon_x", ctypes.c_int), ("icon_y", ctypes.c_int),
|
||||
("icon_mask", ctypes.c_ulong), ("window_group", Window),
|
||||
]
|
||||
|
||||
|
||||
X11.XOpenDisplay.argtypes = [ctypes.c_char_p]
|
||||
X11.XOpenDisplay.restype = Display_p
|
||||
X11.XCloseDisplay.argtypes = [Display_p]
|
||||
X11.XDefaultRootWindow.argtypes = [Display_p]
|
||||
X11.XDefaultRootWindow.restype = Window
|
||||
X11.XInternAtom.argtypes = [Display_p, ctypes.c_char_p, ctypes.c_int]
|
||||
X11.XInternAtom.restype = Atom
|
||||
X11.XGetSelectionOwner.argtypes = [Display_p, Atom]
|
||||
X11.XGetSelectionOwner.restype = Window
|
||||
X11.XGetWindowProperty.argtypes = [
|
||||
Display_p, Window, Atom, ctypes.c_long, ctypes.c_long, ctypes.c_int, Atom,
|
||||
ctypes.POINTER(Atom), ctypes.POINTER(ctypes.c_int),
|
||||
ctypes.POINTER(ctypes.c_ulong), ctypes.POINTER(ctypes.c_ulong),
|
||||
ctypes.POINTER(ctypes.POINTER(ctypes.c_ubyte)),
|
||||
]
|
||||
X11.XGetWindowProperty.restype = ctypes.c_int
|
||||
X11.XFree.argtypes = [ctypes.c_void_p]
|
||||
X11.XCreateSimpleWindow.argtypes = [
|
||||
Display_p, Window, ctypes.c_int, ctypes.c_int, ctypes.c_uint, ctypes.c_uint,
|
||||
ctypes.c_uint, ctypes.c_ulong, ctypes.c_ulong,
|
||||
]
|
||||
X11.XCreateSimpleWindow.restype = Window
|
||||
X11.XDestroyWindow.argtypes = [Display_p, Window]
|
||||
X11.XChangeProperty.argtypes = [
|
||||
Display_p, Window, Atom, Atom, ctypes.c_int, ctypes.c_int, ctypes.c_void_p, ctypes.c_int
|
||||
]
|
||||
X11.XSendEvent.argtypes = [Display_p, Window, ctypes.c_int, ctypes.c_long, ctypes.c_void_p]
|
||||
X11.XFlush.argtypes = [Display_p]
|
||||
X11.XSync.argtypes = [Display_p, ctypes.c_int]
|
||||
X11.XQueryTree.argtypes = [
|
||||
Display_p, Window, ctypes.POINTER(Window), ctypes.POINTER(Window),
|
||||
ctypes.POINTER(ctypes.POINTER(Window)), ctypes.POINTER(ctypes.c_uint),
|
||||
]
|
||||
X11.XQueryTree.restype = ctypes.c_int
|
||||
X11.XGetWindowAttributes.argtypes = [Display_p, Window, ctypes.POINTER(XWindowAttributes)]
|
||||
X11.XGetWindowAttributes.restype = ctypes.c_int
|
||||
X11.XGetWMHints.argtypes = [Display_p, Window]
|
||||
X11.XGetWMHints.restype = ctypes.POINTER(XWMHints)
|
||||
X11.XFetchName.argtypes = [Display_p, Window, ctypes.POINTER(ctypes.c_char_p)]
|
||||
X11.XFetchName.restype = ctypes.c_int
|
||||
|
||||
|
||||
def pick_display():
|
||||
for d in range(70, 120):
|
||||
if not os.path.exists(f"/tmp/.X{d}-lock") and not os.path.exists(f"/tmp/.X11-unix/X{d}"):
|
||||
return f":{d}"
|
||||
return ":99"
|
||||
|
||||
|
||||
def get_cardinal_prop(dpy, win, atom_name):
|
||||
atom = X11.XInternAtom(dpy, atom_name.encode(), 0)
|
||||
da = Atom()
|
||||
di = ctypes.c_int()
|
||||
n = ctypes.c_ulong()
|
||||
dl = ctypes.c_ulong()
|
||||
prop = ctypes.POINTER(ctypes.c_ubyte)()
|
||||
rc = X11.XGetWindowProperty(dpy, win, atom, 0, 16, 0, 0,
|
||||
ctypes.byref(da), ctypes.byref(di),
|
||||
ctypes.byref(n), ctypes.byref(dl), ctypes.byref(prop))
|
||||
if rc != 0 or not prop:
|
||||
return []
|
||||
vals = []
|
||||
if di.value == 32 and n.value > 0:
|
||||
arr = ctypes.cast(prop, ctypes.POINTER(ctypes.c_ulong))
|
||||
vals = [int(arr[i]) for i in range(n.value)]
|
||||
X11.XFree(prop)
|
||||
return vals
|
||||
|
||||
|
||||
def query_children(dpy, parent):
|
||||
r = Window()
|
||||
p = Window()
|
||||
ch = ctypes.POINTER(Window)()
|
||||
n = ctypes.c_uint()
|
||||
if X11.XQueryTree(dpy, parent, ctypes.byref(r), ctypes.byref(p), ctypes.byref(ch), ctypes.byref(n)):
|
||||
out = [int(ch[i]) for i in range(n.value)]
|
||||
if ch:
|
||||
X11.XFree(ch)
|
||||
return out
|
||||
return []
|
||||
|
||||
|
||||
def wait_until(pred, timeout=5.0):
|
||||
end = time.monotonic() + timeout
|
||||
while time.monotonic() < end:
|
||||
res = pred()
|
||||
if res:
|
||||
return res
|
||||
time.sleep(0.05)
|
||||
return None
|
||||
|
||||
|
||||
def terminate(proc):
|
||||
if proc and proc.poll() is None:
|
||||
proc.terminate()
|
||||
try:
|
||||
proc.wait(timeout=3)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
proc.wait(timeout=2)
|
||||
|
||||
|
||||
def test_resolution(res_str, scale_str, width, height):
|
||||
disp = pick_display()
|
||||
with tempfile.TemporaryDirectory() as home:
|
||||
env = dict(os.environ)
|
||||
env["DISPLAY"] = disp
|
||||
env["HOME"] = home
|
||||
env["XDG_CONFIG_HOME"] = os.path.join(home, ".config")
|
||||
env["ANODE_PREFIX"] = ROOT
|
||||
env["ANODE_NO_SIGNAL"] = "1"
|
||||
env["LD_LIBRARY_PATH"] = os.path.join(BUILD, "libgemui") + (":" + env["LD_LIBRARY_PATH"] if env.get("LD_LIBRARY_PATH") else "")
|
||||
env["PATH"] = (
|
||||
os.path.join(BUILD, "dwm") + ":" +
|
||||
os.path.join(BUILD, "dmenu") + ":" +
|
||||
os.path.join(BUILD, "st") + ":" +
|
||||
os.path.join(BUILD, "apps") + ":" +
|
||||
os.path.join(BUILD, "daemons") + ":" +
|
||||
os.path.join(ROOT, "scripts") + ":" +
|
||||
env.get("PATH", "")
|
||||
)
|
||||
|
||||
# Configure theme + scale in sandbox
|
||||
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), scale_str, "--touch=1"], env=env, check=True)
|
||||
|
||||
xvfb = subprocess.Popen(
|
||||
["Xvfb", disp, "-screen", "0", f"{res_str}x24", "-nolisten", "tcp"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
)
|
||||
dwm = None
|
||||
dpy = None
|
||||
procs = []
|
||||
try:
|
||||
dpy = wait_until(lambda: X11.XOpenDisplay(disp.encode()))
|
||||
assert dpy, f"Failed to open Xvfb {disp}"
|
||||
root = X11.XDefaultRootWindow(dpy)
|
||||
|
||||
dwm = subprocess.Popen([os.path.join(BUILD, "dwm", "dwm")], env=env)
|
||||
procs.append(dwm)
|
||||
|
||||
tray_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_S0", 0)
|
||||
tray_win = wait_until(lambda: X11.XGetSelectionOwner(dpy, tray_atom))
|
||||
assert tray_win, f"DWM failed to acquire _NET_SYSTEM_TRAY_S0 on {res_str}"
|
||||
|
||||
# Check initial _NET_WORKAREA and empty systray must be unmapped
|
||||
wa0 = wait_until(lambda: get_cardinal_prop(dpy, root, "_NET_WORKAREA"))
|
||||
assert len(wa0) >= 4 and wa0[2] == width and wa0[3] < height, f"Bad initial workarea: {wa0}"
|
||||
tray_attr = XWindowAttributes()
|
||||
X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr))
|
||||
assert tray_attr.map_state == 0, "Empty systray should stay unmapped!"
|
||||
|
||||
# Test XEmbed systray docking + _XEMBED_INFO unmap/remap + SIGUSR1 resize + undock
|
||||
icon = X11.XCreateSimpleWindow(dpy, root, 0, 0, 24, 24, 0, 0, 0xffffff)
|
||||
xembed_info = X11.XInternAtom(dpy, b"_XEMBED_INFO", 0)
|
||||
info_arr = (ctypes.c_ulong * 2)(0, 1) # version=0, XEMBED_MAPPED=1
|
||||
X11.XChangeProperty(dpy, icon, xembed_info, xembed_info, 32, 0, info_arr, 2)
|
||||
op_atom = X11.XInternAtom(dpy, b"_NET_SYSTEM_TRAY_OPCODE", 0)
|
||||
ev = XClientMessageEvent()
|
||||
ev.type = 33 # ClientMessage
|
||||
ev.display = dpy
|
||||
ev.window = tray_win
|
||||
ev.message_type = op_atom
|
||||
ev.format = 32
|
||||
ev.data.l[0] = 0
|
||||
ev.data.l[1] = 0 # SYSTEM_TRAY_REQUEST_DOCK
|
||||
ev.data.l[2] = icon
|
||||
X11.XSendEvent(dpy, tray_win, 0, 0, ctypes.byref(ev))
|
||||
X11.XSync(dpy, 0)
|
||||
|
||||
assert wait_until(lambda: icon in query_children(dpy, tray_win)), "Icon was not reparented into systray!"
|
||||
X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr))
|
||||
assert tray_attr.map_state == 2, "Non-empty systray must be mapped (IsViewable)"
|
||||
|
||||
# Toggle _XEMBED_INFO unmapped -> tray unmaps
|
||||
info_unmap = (ctypes.c_ulong * 2)(0, 0)
|
||||
X11.XChangeProperty(dpy, icon, xembed_info, xembed_info, 32, 0, info_unmap, 2)
|
||||
X11.XSync(dpy, 0)
|
||||
assert wait_until(lambda: (X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr)) or True) and tray_attr.map_state == 0), "Tray did not unmap when icon withdrew!"
|
||||
|
||||
# Remap via _XEMBED_INFO, reload scale via SIGUSR1, then destroy cleanly
|
||||
X11.XChangeProperty(dpy, icon, xembed_info, xembed_info, 32, 0, info_arr, 2)
|
||||
X11.XSync(dpy, 0)
|
||||
assert wait_until(lambda: (X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr)) or True) and tray_attr.map_state == 2)
|
||||
pre_h = tray_attr.height
|
||||
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), "2.00", "--touch=1"], env=env, check=True)
|
||||
dwm.send_signal(signal.SIGUSR1)
|
||||
time.sleep(0.25)
|
||||
X11.XGetWindowAttributes(dpy, tray_win, ctypes.byref(tray_attr))
|
||||
assert tray_attr.height >= pre_h, f"Tray height did not preserve/scale after SIGUSR1: {tray_attr.height} vs {pre_h}"
|
||||
subprocess.run([os.path.join(ROOT, "scripts", "anode-apply-scale"), scale_str, "--touch=1"], env=env, check=True)
|
||||
dwm.send_signal(signal.SIGUSR1)
|
||||
time.sleep(0.2)
|
||||
X11.XDestroyWindow(dpy, icon)
|
||||
X11.XSync(dpy, 0)
|
||||
assert wait_until(lambda: icon not in query_children(dpy, tray_win))
|
||||
|
||||
# Refresh wa0 after scale restore before testing anode-vkbd dock strut
|
||||
wa0 = wait_until(lambda: get_cardinal_prop(dpy, root, "_NET_WORKAREA"))
|
||||
vkbd = subprocess.Popen([os.path.join(BUILD, "apps", "anode-vkbd")], env=env)
|
||||
procs.append(vkbd)
|
||||
wa_vk = wait_until(lambda: (lambda w: w if w and len(w) >= 4 and w[3] < wa0[3] else None)(get_cardinal_prop(dpy, root, "_NET_WORKAREA")))
|
||||
assert wa_vk, f"anode-vkbd did not reserve workarea strut on {res_str} (wa0={wa0})"
|
||||
# Hide via SIGUSR1 -> workarea restores, then re-show via SIGUSR1 -> strut reserves again
|
||||
vkbd.send_signal(signal.SIGUSR1)
|
||||
assert wait_until(lambda: get_cardinal_prop(dpy, root, "_NET_WORKAREA") == wa0), "Workarea did not restore on vkbd hide"
|
||||
vkbd.send_signal(signal.SIGUSR1)
|
||||
assert wait_until(lambda: (lambda w: w if w and len(w) >= 4 and w[3] < wa0[3] else None)(get_cardinal_prop(dpy, root, "_NET_WORKAREA"))), "Workarea did not re-reserve on vkbd show"
|
||||
terminate(vkbd)
|
||||
|
||||
# Test anode-statusd updates root WM_NAME
|
||||
sd = subprocess.Popen([os.path.join(BUILD, "daemons", "anode-statusd")], env=env)
|
||||
procs.append(sd)
|
||||
def has_status():
|
||||
nm = ctypes.c_char_p()
|
||||
if X11.XFetchName(dpy, root, ctypes.byref(nm)) and nm.value:
|
||||
s = nm.value.decode("utf-8", errors="ignore")
|
||||
X11.XFree(nm)
|
||||
if "|" in s:
|
||||
return s
|
||||
return None
|
||||
assert wait_until(has_status), "anode-statusd did not publish status to root WM_NAME"
|
||||
terminate(sd)
|
||||
|
||||
# Test core + GemUI utilities launch, map cleanly inside screen, and exit cleanly
|
||||
for bin_path, extra_stdin in [
|
||||
(os.path.join(BUILD, "st", "st"), None),
|
||||
(os.path.join(BUILD, "dmenu", "dmenu"), b"alpha\nbeta\n"),
|
||||
(os.path.join(BUILD, "apps", "anode-themes"), None),
|
||||
(os.path.join(BUILD, "apps", "anode-power"), None),
|
||||
(os.path.join(BUILD, "apps", "anode-display"), None),
|
||||
(os.path.join(BUILD, "apps", "anode-audio"), None),
|
||||
(os.path.join(BUILD, "apps", "anode-datetime"), None),
|
||||
(os.path.join(BUILD, "apps", "anode-net"), None),
|
||||
]:
|
||||
before = set(query_children(dpy, root))
|
||||
if extra_stdin:
|
||||
p = subprocess.Popen([bin_path], env=env, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
p.stdin.write(extra_stdin)
|
||||
p.stdin.close()
|
||||
else:
|
||||
p = subprocess.Popen([bin_path], env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
procs.append(p)
|
||||
time.sleep(0.35)
|
||||
assert p.poll() is None, f"{os.path.basename(bin_path)} exited prematurely on {res_str} with code {p.returncode}"
|
||||
terminate(p)
|
||||
|
||||
finally:
|
||||
for p in reversed(procs):
|
||||
terminate(p)
|
||||
if dpy:
|
||||
X11.XCloseDisplay(dpy)
|
||||
terminate(xvfb)
|
||||
|
||||
|
||||
def main():
|
||||
if not shutil.which("Xvfb"):
|
||||
print("test_x11_xvfb: Xvfb not installed (skipping)")
|
||||
return 0
|
||||
cases = [
|
||||
("1024x600", "1.00", 1024, 600),
|
||||
("1920x1080", "1.25", 1920, 1080),
|
||||
("3840x2160", "2.00", 3840, 2160),
|
||||
]
|
||||
for res, sc, w, h in cases:
|
||||
test_resolution(res, sc, w, h)
|
||||
print(f"test_x11_xvfb: {res} @ {sc}x OK")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user