2026-11-22 10:49:59 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""Verify zero-poll daemon design and Geminux power/lid-suspend policy logic."""
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
import shutil
|
|
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
|
DAEMON_DIR = os.path.join(BASE_DIR, "src", "geminux-daemons")
|
2026-11-22 22:31:41 +02:00
|
|
|
APPS_DIR = os.path.join(BASE_DIR, "src", "geminux-apps")
|
2026-11-22 10:49:59 +02:00
|
|
|
POLICY_C = os.path.join(DAEMON_DIR, "geminux-power-policy.c")
|
2026-11-22 16:16:22 +02:00
|
|
|
GESTURE_C = os.path.join(DAEMON_DIR, "geminux-touch-gesture.c")
|
2026-11-22 22:31:41 +02:00
|
|
|
WIFI_NVRAM_C = os.path.join(DAEMON_DIR, "geminux-wifi-nvram-core.c")
|
2026-11-22 10:49:59 +02:00
|
|
|
|
|
|
|
|
DAEMON_FILES = {
|
|
|
|
|
"geminux-powerd.c": "epoll_wait",
|
|
|
|
|
"geminux-statusd.c": "epoll_wait",
|
2026-11-22 16:16:22 +02:00
|
|
|
"geminux-touchd.c": "epoll_wait",
|
2026-11-22 10:49:59 +02:00
|
|
|
"geminux-ccci-daemon.c": "epoll_wait",
|
|
|
|
|
"geminux-modem-ctl.c": "epoll_wait",
|
|
|
|
|
"geminux-bt-obex.c": "g_main_loop_run",
|
|
|
|
|
"geminux-leds.c": "epoll_wait",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
C_TEST = r"""
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "geminux-power-policy.h"
|
2026-11-22 16:16:22 +02:00
|
|
|
#include "geminux-touch-gesture.h"
|
2026-11-22 22:31:41 +02:00
|
|
|
#include "geminux-wifi-nvram-core.h"
|
|
|
|
|
#include "geminux-wifi-list.h"
|
|
|
|
|
#include "geminux-bt-list.h"
|
|
|
|
|
#include "geminux-audio-parse.h"
|
2026-11-22 23:34:44 +02:00
|
|
|
#include "geminux-tz-valid.h"
|
2026-11-23 12:46:34 +02:00
|
|
|
#include "geminux-dns-valid.h"
|
2026-11-23 06:38:06 +02:00
|
|
|
#include "geminux-cam-bayer.h"
|
|
|
|
|
#include "geminux-leds-core.h"
|
2026-11-22 16:16:22 +02:00
|
|
|
|
|
|
|
|
static int count_decision(const geminux_gesture_action_t *a, int mode) {
|
|
|
|
|
int c = 0;
|
|
|
|
|
for (int i = 0; i < a->decision_count; i++) {
|
|
|
|
|
if (a->decisions[i].allow_mode == mode) c++;
|
|
|
|
|
}
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void test_touch_gestures(void) {
|
|
|
|
|
geminux_gesture_state_t gs;
|
|
|
|
|
geminux_gesture_action_t act;
|
|
|
|
|
|
|
|
|
|
/* 1. 1-finger tap -> REJECT passthrough, no synthetic click */
|
|
|
|
|
geminux_gesture_init(&gs, true);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 100, 500.0, 400.0, 0, &act);
|
|
|
|
|
assert(gs.phase == GESTURE_PENDING_1F);
|
|
|
|
|
assert(act.decision_count == 0);
|
|
|
|
|
assert(act.next_timer_ms == GEMINUX_LONGPRESS_MS);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 100, 504.0, 403.0, 90, &act);
|
|
|
|
|
assert(act.decision_count == 1);
|
|
|
|
|
assert(act.decisions[0].devid == 2 && act.decisions[0].touchid == 100);
|
|
|
|
|
assert(act.decisions[0].allow_mode == GEMINUX_ALLOW_REJECT);
|
|
|
|
|
assert(act.click_button == 0);
|
|
|
|
|
assert(gs.phase == GESTURE_IDLE);
|
|
|
|
|
|
|
|
|
|
/* 2. 1-finger drag -> held during 45ms grace, REJECTed on timer */
|
|
|
|
|
geminux_gesture_init(&gs, true);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 101, 500.0, 400.0, 1000, &act);
|
|
|
|
|
geminux_gesture_on_update(&gs, 2, 101, 550.0, 400.0, 1020, &act);
|
|
|
|
|
assert(gs.phase == GESTURE_PENDING_1F);
|
|
|
|
|
assert(act.decision_count == 0);
|
|
|
|
|
assert(act.next_timer_ms == 25);
|
|
|
|
|
geminux_gesture_on_timer(&gs, 1045, &act);
|
|
|
|
|
assert(gs.phase == GESTURE_PASSTHROUGH_1F);
|
|
|
|
|
assert(count_decision(&act, GEMINUX_ALLOW_REJECT) == 1);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 101, 600.0, 400.0, 1150, &act);
|
|
|
|
|
assert(act.click_button == 0);
|
|
|
|
|
assert(gs.phase == GESTURE_IDLE);
|
|
|
|
|
|
|
|
|
|
/* 3. 1-finger 500ms stationary hold -> ACCEPT + Button3 right-click */
|
|
|
|
|
geminux_gesture_init(&gs, true);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 102, 700.0, 300.0, 2000, &act);
|
|
|
|
|
geminux_gesture_on_timer(&gs, 2500, &act);
|
|
|
|
|
assert(gs.phase == GESTURE_ACCEPTED_1F_HOLD);
|
|
|
|
|
assert(count_decision(&act, GEMINUX_ALLOW_ACCEPT) == 1);
|
|
|
|
|
assert(act.click_button == 3);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 102, 705.0, 302.0, 2600, &act);
|
|
|
|
|
assert(act.click_button == 0);
|
|
|
|
|
assert(gs.phase == GESTURE_IDLE);
|
|
|
|
|
|
|
|
|
|
/* 4. 2-finger tap -> ACCEPT both + Button3 right-click on release */
|
|
|
|
|
geminux_gesture_init(&gs, true);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 201, 600.0, 400.0, 3000, &act);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 202, 680.0, 410.0, 3015, &act);
|
|
|
|
|
assert(gs.phase == GESTURE_ACCEPTED_MULTI);
|
|
|
|
|
assert(count_decision(&act, GEMINUX_ALLOW_ACCEPT) == 2);
|
|
|
|
|
assert(act.next_timer_ms == 0);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 201, 604.0, 402.0, 3110, &act);
|
|
|
|
|
assert(act.click_button == 0);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 202, 684.0, 412.0, 3120, &act);
|
|
|
|
|
assert(act.click_button == 3);
|
|
|
|
|
assert(gs.phase == GESTURE_IDLE);
|
|
|
|
|
|
|
|
|
|
/* 5. 3-finger tap -> ACCEPT all 3 + Button2 middle-click on release */
|
|
|
|
|
geminux_gesture_init(&gs, true);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 301, 500.0, 400.0, 4000, &act);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 302, 600.0, 400.0, 4010, &act);
|
|
|
|
|
assert(count_decision(&act, GEMINUX_ALLOW_ACCEPT) == 2);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 303, 700.0, 400.0, 4025, &act);
|
|
|
|
|
assert(count_decision(&act, GEMINUX_ALLOW_ACCEPT) == 1);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 301, 505.0, 402.0, 4120, &act);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 302, 605.0, 402.0, 4135, &act);
|
|
|
|
|
assert(act.click_button == 0);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 303, 705.0, 402.0, 4150, &act);
|
|
|
|
|
assert(act.click_button == 2);
|
|
|
|
|
assert(gs.phase == GESTURE_IDLE);
|
|
|
|
|
|
|
|
|
|
/* 6. 2-finger drag -> natural vertical & horizontal scroll ticks, no tap click */
|
|
|
|
|
int total_v = 0, total_h = 0;
|
|
|
|
|
geminux_gesture_init(&gs, true);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 401, 600.0, 300.0, 5000, &act);
|
|
|
|
|
geminux_gesture_on_begin(&gs, 2, 402, 680.0, 300.0, 5010, &act);
|
|
|
|
|
geminux_gesture_on_update(&gs, 2, 401, 730.0, 410.0, 5080, &act);
|
|
|
|
|
total_v += act.wheel_v;
|
|
|
|
|
total_h += act.wheel_h;
|
|
|
|
|
geminux_gesture_on_update(&gs, 2, 402, 810.0, 410.0, 5081, &act);
|
|
|
|
|
total_v += act.wheel_v;
|
|
|
|
|
total_h += act.wheel_h;
|
|
|
|
|
assert(gs.scrolled);
|
|
|
|
|
assert(total_v == 2);
|
|
|
|
|
assert(total_h == 2);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 401, 730.0, 410.0, 5140, &act);
|
|
|
|
|
geminux_gesture_on_end(&gs, 2, 402, 810.0, 410.0, 5150, &act);
|
|
|
|
|
assert(act.click_button == 0);
|
|
|
|
|
assert(gs.phase == GESTURE_IDLE);
|
|
|
|
|
}
|
2026-11-22 10:49:59 +02:00
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
|
geminux_power_policy_t pol;
|
|
|
|
|
geminux_policy_init(&pol);
|
|
|
|
|
assert(pol.profile == POWER_PROFILE_BALANCED);
|
|
|
|
|
assert(pol.lid_suspend_enabled);
|
|
|
|
|
assert(!geminux_should_suspend_on_lid(&pol));
|
|
|
|
|
|
|
|
|
|
/* Closing lid on battery should trigger S3 suspend */
|
|
|
|
|
pol.lid_closed = true;
|
|
|
|
|
assert(geminux_should_suspend_on_lid(&pol));
|
|
|
|
|
|
|
|
|
|
/* Active voice call inhibitor blocks lid suspend */
|
|
|
|
|
assert(geminux_policy_add_inhibit(&pol, "call"));
|
|
|
|
|
assert(!geminux_should_suspend_on_lid(&pol));
|
|
|
|
|
assert(geminux_policy_del_inhibit(&pol, "call"));
|
|
|
|
|
assert(geminux_should_suspend_on_lid(&pol));
|
|
|
|
|
|
|
|
|
|
/* Connected external HDMI display blocks lid suspend */
|
|
|
|
|
pol.hdmi_connected = true;
|
|
|
|
|
assert(!geminux_should_suspend_on_lid(&pol));
|
|
|
|
|
pol.hdmi_connected = false;
|
|
|
|
|
assert(geminux_should_suspend_on_lid(&pol));
|
|
|
|
|
|
|
|
|
|
/* Profile parameters: eco disables A72 big cluster, balanced/perf enable A72 */
|
|
|
|
|
geminux_profile_params_t eco = geminux_policy_params(POWER_PROFILE_ECO, false);
|
|
|
|
|
assert(strcmp(eco.governor, "schedutil") == 0);
|
|
|
|
|
assert(!eco.a72_online);
|
2026-11-24 11:05:18 +02:00
|
|
|
assert(eco.a53_ll_max_khz == 715000UL);
|
|
|
|
|
assert(eco.a53_max_khz == 962000UL);
|
2026-11-22 10:49:59 +02:00
|
|
|
assert(eco.suspend_timeout_s > 0);
|
|
|
|
|
|
|
|
|
|
geminux_profile_params_t bal = geminux_policy_params(POWER_PROFILE_BALANCED, false);
|
|
|
|
|
assert(strcmp(bal.governor, "schedutil") == 0);
|
|
|
|
|
assert(bal.a72_online);
|
2026-11-24 11:05:18 +02:00
|
|
|
assert(bal.a53_ll_max_khz == 897000UL);
|
|
|
|
|
assert(bal.a53_max_khz == 1209000UL);
|
2026-11-23 20:00:17 +02:00
|
|
|
|
|
|
|
|
geminux_profile_params_t bal_ac = geminux_policy_params(POWER_PROFILE_BALANCED, true);
|
|
|
|
|
assert(strcmp(bal_ac.governor, "schedutil") == 0);
|
2026-11-24 11:05:18 +02:00
|
|
|
assert(bal_ac.a53_ll_max_khz == 1547000UL);
|
|
|
|
|
assert(bal_ac.a53_max_khz == 1846000UL);
|
2026-11-22 10:49:59 +02:00
|
|
|
|
|
|
|
|
geminux_profile_params_t perf = geminux_policy_params(POWER_PROFILE_PERFORMANCE, true);
|
2026-11-24 11:05:18 +02:00
|
|
|
assert(strcmp(perf.governor, "performance") == 0);
|
2026-11-22 10:49:59 +02:00
|
|
|
assert(perf.a72_online);
|
2026-11-23 20:00:17 +02:00
|
|
|
assert(perf.a53_ll_max_khz == 1547000UL);
|
|
|
|
|
assert(perf.a53_max_khz == 1846000UL);
|
2026-11-22 10:49:59 +02:00
|
|
|
assert(perf.suspend_timeout_s == 0);
|
2026-11-22 16:16:22 +02:00
|
|
|
|
2026-11-23 09:31:00 +02:00
|
|
|
/* Idle screensaver timing from last active input (battery balanced: dim=120s, suspend=300s) */
|
|
|
|
|
pol.lid_closed = false;
|
|
|
|
|
pol.hdmi_connected = false;
|
|
|
|
|
pol.on_ac_power = false;
|
|
|
|
|
uint64_t next_wait = 999999;
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_ACTIVE, 0, &next_wait) == IDLE_ACT_NONE);
|
|
|
|
|
assert(next_wait == 120000);
|
|
|
|
|
/* User typed at t=100s, so when initial 120s timer fires (elapsed=20s) it re-arms for 100s */
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_ACTIVE, 20000, &next_wait) == IDLE_ACT_NONE);
|
|
|
|
|
assert(next_wait == 100000);
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_ACTIVE, 120000, &next_wait) == IDLE_ACT_DIM);
|
|
|
|
|
assert(next_wait == 180000);
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_DIMMED, 200000, &next_wait) == IDLE_ACT_NONE);
|
|
|
|
|
assert(next_wait == 100000);
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_DIMMED, 300000, &next_wait) == IDLE_ACT_SUSPEND);
|
|
|
|
|
assert(next_wait == 0);
|
|
|
|
|
|
|
|
|
|
/* AC balanced (dim=300s, suspend=0): acts as lock + blank screensaver without auto-suspend */
|
|
|
|
|
pol.lid_closed = false;
|
|
|
|
|
pol.on_ac_power = true;
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_ACTIVE, 299000, &next_wait) == IDLE_ACT_NONE);
|
|
|
|
|
assert(next_wait == 1000);
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_ACTIVE, 300000, &next_wait) == IDLE_ACT_LOCK_BLANK);
|
|
|
|
|
assert(next_wait == 0);
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_LOCKED_BLANK, 450000, &next_wait) == IDLE_ACT_NONE);
|
|
|
|
|
assert(next_wait == 0);
|
|
|
|
|
|
|
|
|
|
/* Inhibitors, HDMI, and closed lid suppress idle screensaver timers */
|
|
|
|
|
assert(geminux_policy_add_inhibit(&pol, "video"));
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_ACTIVE, 400000, &next_wait) == IDLE_ACT_NONE);
|
|
|
|
|
assert(next_wait == 0);
|
|
|
|
|
assert(geminux_policy_del_inhibit(&pol, "video"));
|
|
|
|
|
pol.hdmi_connected = true;
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_ACTIVE, 400000, &next_wait) == IDLE_ACT_NONE);
|
|
|
|
|
assert(next_wait == 0);
|
|
|
|
|
pol.hdmi_connected = false;
|
|
|
|
|
pol.lid_closed = true;
|
|
|
|
|
assert(geminux_policy_eval_idle(&pol, IDLE_STAGE_ACTIVE, 400000, &next_wait) == IDLE_ACT_NONE);
|
|
|
|
|
assert(next_wait == 0);
|
|
|
|
|
pol.lid_closed = false;
|
|
|
|
|
pol.on_ac_power = false;
|
|
|
|
|
|
2026-11-22 16:16:22 +02:00
|
|
|
test_touch_gestures();
|
2026-11-22 22:31:41 +02:00
|
|
|
|
|
|
|
|
/* Wi-Fi NVRAM record validation, scan, and deterministic MAC fallback */
|
|
|
|
|
static unsigned char blob[1024];
|
|
|
|
|
unsigned char rec[GEMINUX_WIFI_STORAGE_BYTES];
|
|
|
|
|
unsigned char out_rec[GEMINUX_WIFI_STORAGE_BYTES];
|
|
|
|
|
bool have_mac = false;
|
|
|
|
|
|
|
|
|
|
memset(blob, 0xff, sizeof(blob));
|
|
|
|
|
memset(rec, 0, sizeof(rec));
|
|
|
|
|
rec[0] = 0x06;
|
|
|
|
|
rec[1] = 0x01;
|
|
|
|
|
rec[197] = 1;
|
|
|
|
|
rec[262] = 1;
|
|
|
|
|
rec[512] = 0xaa;
|
|
|
|
|
rec[513] = geminux_wifi_nvram_checksum(rec);
|
|
|
|
|
assert(geminux_wifi_nvram_valid_record(rec, sizeof(rec), false));
|
|
|
|
|
assert(!geminux_wifi_nvram_valid_record(rec, sizeof(rec), true));
|
|
|
|
|
|
|
|
|
|
memcpy(blob + 128, rec, sizeof(rec));
|
|
|
|
|
assert(geminux_wifi_nvram_scan_blob(blob, sizeof(blob), out_rec, &have_mac));
|
|
|
|
|
assert(!have_mac);
|
|
|
|
|
|
|
|
|
|
geminux_wifi_nvram_apply_fallback_mac(out_rec, "test-unit-seed");
|
|
|
|
|
assert(geminux_wifi_nvram_valid_record(out_rec, sizeof(out_rec), true));
|
|
|
|
|
assert((out_rec[4] & 0x03) == 0x02);
|
|
|
|
|
memcpy(blob + 256, out_rec, sizeof(out_rec));
|
|
|
|
|
assert(geminux_wifi_nvram_scan_blob(blob, sizeof(blob), out_rec, &have_mac));
|
|
|
|
|
assert(have_mac);
|
|
|
|
|
|
|
|
|
|
/* Wi-Fi mesh grouping, DFS avoidance, 5GHz tie-break, and escaped colons */
|
|
|
|
|
const char *scan =
|
|
|
|
|
" :11\\:22\\:33\\:44\\:55\\:01::6:100:WPA2\n"
|
|
|
|
|
" :11\\:22\\:33\\:44\\:55\\:02:My\\:Mesh\\\\Home:52:95:WPA2\n"
|
|
|
|
|
" :11\\:22\\:33\\:44\\:55\\:03:My\\:Mesh\\\\Home:2:80:WPA2\n"
|
|
|
|
|
" :11\\:22\\:33\\:44\\:55\\:04:My\\:Mesh\\\\Home:44:80:WPA2 WPA3\n"
|
|
|
|
|
" :11\\:22\\:33\\:44\\:55\\:05:My\\:Mesh\\\\Home:11:65:WPA2\n"
|
|
|
|
|
" :11\\:22\\:33\\:44\\:55\\:06:My\\:Mesh\\\\Home:9:50:WPA2\n"
|
|
|
|
|
" :11\\:22\\:33\\:44\\:55\\:07:My\\:Mesh\\\\Home:157:40:WPA2\n"
|
|
|
|
|
" :11\\:22\\:33\\:44\\:55\\:08:My\\:Mesh\\\\Home:1:30:WPA2\n"
|
|
|
|
|
" :11\\:22\\:33\\:44\\:55\\:09:My\\:Mesh\\\\Home:161:20:WPA2\n"
|
|
|
|
|
" :aa\\:bb\\:cc\\:dd\\:ee\\:01:CafeOpen:6:90:--\n"
|
|
|
|
|
"*:aa\\:bb\\:cc\\:dd\\:ee\\:02:CurrentNet:36:55:WPA2\n"
|
|
|
|
|
" :aa\\:bb\\:cc\\:dd\\:ee\\:03:StrongOther:1:92:\n";
|
|
|
|
|
geminux_wifi_group_t groups[GEMINUX_MAX_WIFI_GROUPS];
|
|
|
|
|
int ng = geminux_parse_wifi_scan(scan, groups, GEMINUX_MAX_WIFI_GROUPS);
|
|
|
|
|
assert(ng == 4);
|
|
|
|
|
assert(strcmp(groups[0].ssid, "CurrentNet") == 0);
|
|
|
|
|
assert(groups[0].in_use);
|
|
|
|
|
assert(strcmp(groups[1].ssid, "StrongOther") == 0);
|
|
|
|
|
assert(strcmp(groups[1].security, "Open") == 0);
|
|
|
|
|
assert(strcmp(groups[2].ssid, "CafeOpen") == 0);
|
|
|
|
|
assert(strcmp(groups[2].security, "Open") == 0);
|
|
|
|
|
assert(strcmp(groups[3].ssid, "My:Mesh\\Home") == 0);
|
|
|
|
|
assert(groups[3].ap_count == 8);
|
|
|
|
|
assert(groups[3].best_chan == 44);
|
|
|
|
|
assert(groups[3].best_signal == 80);
|
|
|
|
|
assert(groups[3].best_joinable);
|
|
|
|
|
assert(strcmp(groups[3].best_bssid, "11:22:33:44:55:04") == 0);
|
|
|
|
|
|
|
|
|
|
/* Bluetooth device list parsing & priority sort */
|
|
|
|
|
const char *bt_all =
|
|
|
|
|
"Waiting to connect to bluetoothd...\n"
|
|
|
|
|
"\x1b[0;93mDevice aa:bb:cc:dd:ee:03 Keychron K3\x1b[0m\n"
|
|
|
|
|
"Device aa:bb:cc:dd:ee:01 Sony WH-1000XM5\n"
|
|
|
|
|
"Device aa:bb:cc:dd:ee:02 Logitech MX Anywhere 3\n";
|
|
|
|
|
const char *bt_pair = "Device AA:BB:CC:DD:EE:02 Logitech MX Anywhere 3\n"
|
|
|
|
|
"Device AA:BB:CC:DD:EE:03 Keychron K3\n";
|
|
|
|
|
const char *bt_conn = "Device AA:BB:CC:DD:EE:03 Keychron K3\n";
|
|
|
|
|
geminux_bt_dev_t bt_devs[GEMINUX_MAX_BT_DEVS];
|
|
|
|
|
int nbt = geminux_parse_bt_devices(bt_all, bt_pair, bt_conn, bt_devs, GEMINUX_MAX_BT_DEVS);
|
|
|
|
|
assert(nbt == 3);
|
|
|
|
|
assert(bt_devs[0].connected && strcmp(bt_devs[0].name, "Keychron K3") == 0);
|
|
|
|
|
assert(bt_devs[1].paired && !bt_devs[1].connected && strcmp(bt_devs[1].mac, "AA:BB:CC:DD:EE:02") == 0);
|
|
|
|
|
assert(!bt_devs[2].paired && strcmp(bt_devs[2].name, "Sony WH-1000XM5") == 0);
|
|
|
|
|
|
|
|
|
|
/* PipeWire wpctl / pactl parsing */
|
|
|
|
|
int vpct = 0;
|
|
|
|
|
bool vmuted = false;
|
|
|
|
|
assert(geminux_parse_wpctl_volume("Volume: 0.65 [MUTED]\n", &vpct, &vmuted));
|
|
|
|
|
assert(vpct == 65 && vmuted);
|
|
|
|
|
|
|
|
|
|
char def_sink[128], def_src[128];
|
|
|
|
|
geminux_parse_pactl_defaults("Server Name: PulseAudio (on PipeWire 1.6.11)\n"
|
|
|
|
|
"Default Sink: alsa_output.platform-sound.stereo-fallback\n"
|
|
|
|
|
"Default Source: alsa_input.platform-sound.stereo-fallback\n",
|
|
|
|
|
def_sink, sizeof(def_sink), def_src, sizeof(def_src));
|
|
|
|
|
assert(strcmp(def_sink, "alsa_output.platform-sound.stereo-fallback") == 0);
|
|
|
|
|
assert(strcmp(def_src, "alsa_input.platform-sound.stereo-fallback") == 0);
|
|
|
|
|
|
|
|
|
|
const char *sinks_txt =
|
|
|
|
|
"Sink #50\n"
|
|
|
|
|
"\tState: SUSPENDED\n"
|
|
|
|
|
"\tName: alsa_output.platform-sound.stereo-fallback\n"
|
|
|
|
|
"\tDescription: Built-in Audio Stereo\n"
|
|
|
|
|
"\tMute: no\n"
|
|
|
|
|
"\tVolume: front-left: 26214 / 40% / -23.87 dB, front-right: 26214 / 40% / -23.87 dB\n"
|
|
|
|
|
"\tBase Volume: 65536 / 100% / 0.00 dB\n";
|
|
|
|
|
geminux_audio_node_t nodes[GEMINUX_MAX_AUDIO_NODES];
|
|
|
|
|
int ns = geminux_parse_pactl_nodes(sinks_txt, "Sink #", def_sink, false, nodes, GEMINUX_MAX_AUDIO_NODES);
|
|
|
|
|
assert(ns == 1 && nodes[0].index == 50 && nodes[0].is_default && nodes[0].vol_pct == 40 && !nodes[0].muted);
|
|
|
|
|
|
|
|
|
|
const char *cards_txt =
|
|
|
|
|
"Card #44\n"
|
|
|
|
|
"\tName: bluez_card.11_22_33_44_55_66\n"
|
|
|
|
|
"\tProperties:\n"
|
|
|
|
|
"\t\tdevice.description = \"WH-1000XM5\"\n"
|
|
|
|
|
"\tProfiles:\n"
|
|
|
|
|
"\t\toff: Off (sinks: 0, sources: 0, priority: 0, available: yes)\n"
|
|
|
|
|
"\t\ta2dp-sink-sbc: High Fidelity Playback (A2DP Sink, codec SBC-XQ) (sinks: 1, sources: 0, priority: 32, available: yes)\n"
|
|
|
|
|
"\t\theadset-head-unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 1, available: yes)\n"
|
|
|
|
|
"\tActive Profile: a2dp-sink-sbc\n";
|
|
|
|
|
geminux_audio_profile_t profs[GEMINUX_MAX_AUDIO_PROFILES];
|
|
|
|
|
int np = geminux_parse_pactl_cards(cards_txt, profs, GEMINUX_MAX_AUDIO_PROFILES);
|
|
|
|
|
assert(np == 3);
|
|
|
|
|
assert(strcmp(profs[1].card_label, "WH-1000XM5") == 0);
|
|
|
|
|
assert(profs[1].active && profs[1].available);
|
|
|
|
|
assert(!profs[2].active && strcmp(profs[2].profile_name, "headset-head-unit") == 0);
|
2026-11-22 23:34:44 +02:00
|
|
|
|
|
|
|
|
assert(geminux_tz_name_valid("UTC"));
|
|
|
|
|
assert(geminux_tz_name_valid("Europe/Berlin"));
|
|
|
|
|
assert(geminux_tz_name_valid("America/Argentina/Buenos_Aires"));
|
|
|
|
|
assert(geminux_tz_name_valid("Etc/GMT+2"));
|
|
|
|
|
assert(!geminux_tz_name_valid(""));
|
|
|
|
|
assert(!geminux_tz_name_valid("/UTC"));
|
|
|
|
|
assert(!geminux_tz_name_valid("Europe/"));
|
|
|
|
|
assert(!geminux_tz_name_valid("../etc/passwd"));
|
|
|
|
|
assert(!geminux_tz_name_valid("Europe//Berlin"));
|
|
|
|
|
assert(!geminux_tz_name_valid("UTC;id"));
|
|
|
|
|
|
|
|
|
|
char tzdir[128];
|
|
|
|
|
snprintf(tzdir, sizeof(tzdir), "/tmp/geminux-tz-test-%ld", (long)getpid());
|
|
|
|
|
mkdir(tzdir, 0755);
|
|
|
|
|
char okp[256], badp[256];
|
|
|
|
|
snprintf(okp, sizeof(okp), "%s/GoodZone", tzdir);
|
|
|
|
|
snprintf(badp, sizeof(badp), "%s/BadZone", tzdir);
|
|
|
|
|
FILE *zf = fopen(okp, "wb");
|
|
|
|
|
assert(zf != NULL);
|
|
|
|
|
fwrite("TZif2\0", 1, 6, zf);
|
|
|
|
|
fclose(zf);
|
|
|
|
|
zf = fopen(badp, "wb");
|
|
|
|
|
assert(zf != NULL);
|
|
|
|
|
fwrite("BAD!\0", 1, 5, zf);
|
|
|
|
|
fclose(zf);
|
|
|
|
|
assert(geminux_tz_file_valid(tzdir, "GoodZone"));
|
|
|
|
|
assert(!geminux_tz_file_valid(tzdir, "BadZone"));
|
|
|
|
|
assert(!geminux_tz_file_valid(tzdir, "MissingZone"));
|
|
|
|
|
unlink(okp);
|
|
|
|
|
unlink(badp);
|
|
|
|
|
rmdir(tzdir);
|
2026-11-23 06:38:06 +02:00
|
|
|
|
|
|
|
|
/* MTISP 10-bit packed Bayer unpack + bilinear demosaic (0 and 90 deg) */
|
|
|
|
|
const uint8_t packed4[5] = {0x40, 0x00, 0x01, 0x04, 0x10};
|
|
|
|
|
uint16_t unpacked4[4] = {0};
|
|
|
|
|
geminux_mtisp_unpack_row10(packed4, unpacked4, 4);
|
|
|
|
|
for (int i = 0; i < 4; i++) assert(unpacked4[i] == 64);
|
|
|
|
|
|
|
|
|
|
uint8_t raw8x8[8 * 10];
|
|
|
|
|
memset(raw8x8, 0, sizeof(raw8x8));
|
|
|
|
|
for (int y = 0; y < 8; y++) {
|
|
|
|
|
/* Encode uniform value 512 (pedestal-subtracted 448) across 8 pixels (2 blocks) */
|
|
|
|
|
for (int blk = 0; blk < 2; blk++) {
|
|
|
|
|
uint8_t *p = raw8x8 + y * 10 + blk * 5;
|
|
|
|
|
p[0] = 0x00; p[1] = 0x02; p[2] = 0x08; p[3] = 0x20; p[4] = 0x80;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
geminux_bayer10_isp_t cam_isp;
|
|
|
|
|
memset(&cam_isp, 0, sizeof(cam_isp));
|
|
|
|
|
uint16_t raw16[8 * 8];
|
|
|
|
|
uint8_t rgb[8 * 8 * 3];
|
|
|
|
|
uint32_t argb[8 * 8];
|
|
|
|
|
int lin_avg = 0;
|
|
|
|
|
geminux_bayer10_to_buffers(&cam_isp, raw8x8, 10, 8, 8, true, 0, false, raw16, rgb, argb, &lin_avg);
|
|
|
|
|
assert(lin_avg > 350);
|
|
|
|
|
assert(rgb[0] > 150 && rgb[1] > 150 && rgb[2] > 150);
|
|
|
|
|
geminux_bayer10_to_buffers(&cam_isp, raw8x8, 10, 8, 8, true, 90, false, raw16, rgb, argb, &lin_avg);
|
|
|
|
|
assert((argb[0] >> 24) == 0xff && rgb[(8 * 8 - 1) * 3 + 1] > 150);
|
|
|
|
|
|
|
|
|
|
/* AW9120 multicolor back strip selection, formatting, and power_supply uevent filter */
|
|
|
|
|
assert(geminux_led_is_back_strip("rgb:indicator-1"));
|
|
|
|
|
assert(geminux_led_is_back_strip("rgb:indicator-2"));
|
|
|
|
|
assert(geminux_led_is_back_strip("rgb:indicator-3"));
|
|
|
|
|
assert(geminux_led_is_back_strip("rgb:indicator-4"));
|
|
|
|
|
assert(geminux_led_is_back_strip("rgb:indicator-5"));
|
|
|
|
|
assert(!geminux_led_is_back_strip("rgb:indicator-6"));
|
|
|
|
|
assert(!geminux_led_is_back_strip("red:indicator-7"));
|
|
|
|
|
assert(!geminux_led_is_back_strip("blue:indicator-7"));
|
|
|
|
|
assert(!geminux_led_is_back_strip("input1::capslock"));
|
|
|
|
|
assert(!geminux_led_is_back_strip(NULL));
|
|
|
|
|
|
|
|
|
|
assert(geminux_led_is_cover_rgb("rgb:indicator-6"));
|
|
|
|
|
assert(!geminux_led_is_cover_rgb("rgb:indicator-7"));
|
|
|
|
|
assert(!geminux_led_is_cover_rgb("rgb:indicator-0"));
|
|
|
|
|
assert(!geminux_led_is_cover_rgb("red:indicator-7"));
|
|
|
|
|
assert(!geminux_led_is_cover_rgb("blue:indicator-7"));
|
|
|
|
|
|
|
|
|
|
char ibuf[32];
|
|
|
|
|
int lbri = -1;
|
|
|
|
|
assert(geminux_led_format_mc("red green blue\n", 32, 16, 0, ibuf, sizeof(ibuf), &lbri) == 0);
|
|
|
|
|
assert(strcmp(ibuf, "32 16 0\n") == 0 && lbri == 255);
|
|
|
|
|
assert(geminux_led_format_mc("blue green red\n", 32, 16, 5, ibuf, sizeof(ibuf), &lbri) == 0);
|
|
|
|
|
assert(strcmp(ibuf, "5 16 32\n") == 0 && lbri == 255);
|
|
|
|
|
assert(geminux_led_format_mc("red green blue\n", 0, 0, 0, ibuf, sizeof(ibuf), &lbri) == 0);
|
|
|
|
|
assert(strcmp(ibuf, "0 0 0\n") == 0 && lbri == 0);
|
|
|
|
|
assert(geminux_led_format_mc(NULL, -10, 300, 128, ibuf, sizeof(ibuf), &lbri) == 0);
|
|
|
|
|
assert(strcmp(ibuf, "0 255 128\n") == 0 && lbri == 255);
|
|
|
|
|
|
|
|
|
|
const char uev_ps[] = "change@/devices/platform/charger\0SUBSYSTEM=power_supply\0ACTION=change\0";
|
|
|
|
|
const char uev_in[] = "change@/devices/platform/input\0SUBSYSTEM=input\0ACTION=change\0";
|
|
|
|
|
const char uev_pfx[] = "change@/devices/platform/charger\0SUBSYSTEM=power_supply2\0";
|
2026-11-23 20:00:17 +02:00
|
|
|
const char uev_drm[] = "change@/devices/platform/drm\0SUBSYSTEM=drm\0ACTION=change\0";
|
|
|
|
|
const char uev_net[] = "add@/devices/platform/wlan0\0SUBSYSTEM=net\0ACTION=add\0";
|
2026-11-23 06:38:06 +02:00
|
|
|
assert(geminux_uevent_is_power_supply(uev_ps, sizeof(uev_ps)));
|
|
|
|
|
assert(!geminux_uevent_is_power_supply(uev_in, sizeof(uev_in)));
|
|
|
|
|
assert(!geminux_uevent_is_power_supply(uev_pfx, sizeof(uev_pfx)));
|
2026-11-23 20:00:17 +02:00
|
|
|
assert(geminux_uevent_has_subsystem(uev_ps, sizeof(uev_ps), "power_supply"));
|
|
|
|
|
assert(geminux_uevent_has_subsystem(uev_in, sizeof(uev_in), "input"));
|
|
|
|
|
assert(geminux_uevent_has_subsystem(uev_drm, sizeof(uev_drm), "drm"));
|
|
|
|
|
assert(geminux_uevent_has_subsystem(uev_net, sizeof(uev_net), "net"));
|
|
|
|
|
assert(!geminux_uevent_has_subsystem(uev_in, sizeof(uev_in), "inputs"));
|
|
|
|
|
assert(!geminux_uevent_has_subsystem(uev_pfx, sizeof(uev_pfx), "power_supply"));
|
|
|
|
|
assert(!geminux_uevent_has_subsystem("", 0, "input"));
|
|
|
|
|
assert(!geminux_uevent_has_subsystem(NULL, 10, "input"));
|
|
|
|
|
assert(!geminux_uevent_has_subsystem(uev_ps, sizeof(uev_ps), NULL));
|
|
|
|
|
assert(!geminux_uevent_has_subsystem(uev_ps, sizeof(uev_ps), ""));
|
2026-11-23 12:46:34 +02:00
|
|
|
|
|
|
|
|
/* Wi-Fi active connection preservation (iw link + merge into empty/partial scan) */
|
|
|
|
|
char iw_bssid[24], iw_ssid[96];
|
|
|
|
|
int iw_chan = 0, iw_sig = 0;
|
|
|
|
|
const char *iw_sample =
|
|
|
|
|
"Connected to 11:22:33:44:55:66 (on wlan0)\n"
|
|
|
|
|
"\tSSID: OfficeNet\n"
|
|
|
|
|
"\tfreq: 5220.0\n"
|
|
|
|
|
"\tsignal: -42 dBm\n";
|
|
|
|
|
assert(geminux_parse_iw_link(iw_sample, iw_bssid, sizeof(iw_bssid),
|
|
|
|
|
iw_ssid, sizeof(iw_ssid), &iw_chan, &iw_sig));
|
|
|
|
|
assert(strcmp(iw_bssid, "11:22:33:44:55:66") == 0);
|
|
|
|
|
assert(strcmp(iw_ssid, "OfficeNet") == 0);
|
|
|
|
|
assert(iw_chan == 44 && iw_sig == 100);
|
|
|
|
|
assert(!geminux_parse_iw_link("Not connected.\n", iw_bssid, sizeof(iw_bssid),
|
|
|
|
|
iw_ssid, sizeof(iw_ssid), &iw_chan, &iw_sig));
|
|
|
|
|
|
|
|
|
|
geminux_wifi_group_t active_only[4];
|
|
|
|
|
int na = geminux_merge_active_wifi(active_only, 0, 4, "OfficeNet",
|
|
|
|
|
"11:22:33:44:55:66", 44, 96, "WPA2");
|
|
|
|
|
assert(na == 1 && active_only[0].in_use);
|
|
|
|
|
assert(strcmp(active_only[0].ssid, "OfficeNet") == 0);
|
|
|
|
|
assert(active_only[0].best_chan == 44 && active_only[0].best_signal == 96);
|
|
|
|
|
|
|
|
|
|
geminux_wifi_group_t partial[4];
|
|
|
|
|
int np2 = geminux_parse_wifi_scan(" :aa\\:bb\\:cc\\:dd\\:ee\\:03:StrongOther:1:92:WPA2\n", partial, 4);
|
|
|
|
|
np2 = geminux_merge_active_wifi(partial, np2, 4, "OfficeNet",
|
|
|
|
|
"11:22:33:44:55:66", 44, 82, "WPA2");
|
|
|
|
|
assert(np2 == 2);
|
|
|
|
|
assert(strcmp(partial[0].ssid, "OfficeNet") == 0 && partial[0].in_use);
|
|
|
|
|
assert(strcmp(partial[1].ssid, "StrongOther") == 0 && !partial[1].in_use);
|
|
|
|
|
|
|
|
|
|
/* Mark existing entry active when nmcli scan missed '*' flag */
|
|
|
|
|
geminux_wifi_group_t unmarked[4];
|
|
|
|
|
int nu = geminux_parse_wifi_scan(" :aa\\:bb\\:cc\\:dd\\:ee\\:03:StrongOther:1:92:WPA2\n"
|
|
|
|
|
" :aa\\:bb\\:cc\\:dd\\:ee\\:04:OfficeNet:36:60:WPA2\n",
|
|
|
|
|
unmarked, 4);
|
|
|
|
|
nu = geminux_merge_active_wifi(unmarked, nu, 4, "OfficeNet", NULL, 0, 0, NULL);
|
|
|
|
|
assert(nu == 2 && unmarked[0].in_use && strcmp(unmarked[0].ssid, "OfficeNet") == 0);
|
|
|
|
|
assert(!unmarked[1].in_use);
|
|
|
|
|
|
|
|
|
|
/* DNS preset & custom nameserver parsing/validation */
|
|
|
|
|
assert(geminux_dns_mode_valid("default"));
|
|
|
|
|
assert(geminux_dns_mode_valid("cloudflare"));
|
|
|
|
|
assert(geminux_dns_mode_valid("google"));
|
|
|
|
|
assert(geminux_dns_mode_valid("radicaldns"));
|
|
|
|
|
assert(geminux_dns_mode_valid("quad9"));
|
|
|
|
|
assert(geminux_dns_mode_valid("custom"));
|
|
|
|
|
assert(!geminux_dns_mode_valid("evil;rm"));
|
|
|
|
|
assert(!geminux_dns_mode_valid(""));
|
|
|
|
|
|
|
|
|
|
char dv4[6][16], dv6[6][46], dnorm[192];
|
|
|
|
|
int dn4 = 0, dn6 = 0;
|
|
|
|
|
int dtot = geminux_parse_dns_servers(" 2a01:4f8:1c0c:82c0::1, 88.198.92.222 192.71.166.92, 88.198.92.222 ",
|
|
|
|
|
dv4, &dn4, 6, dv6, &dn6, 6, dnorm, sizeof(dnorm));
|
|
|
|
|
assert(dtot == 3 && dn4 == 2 && dn6 == 1);
|
|
|
|
|
assert(strcmp(dnorm, "88.198.92.222,192.71.166.92,2a01:4f8:1c0c:82c0::1") == 0);
|
|
|
|
|
assert(geminux_parse_dns_servers("", dv4, &dn4, 6, dv6, &dn6, 6, dnorm, sizeof(dnorm)) < 0);
|
|
|
|
|
assert(geminux_parse_dns_servers("1.1.1.1;id", dv4, &dn4, 6, dv6, &dn6, 6, dnorm, sizeof(dnorm)) < 0);
|
|
|
|
|
assert(geminux_parse_dns_servers("0.0.0.0", dv4, &dn4, 6, dv6, &dn6, 6, dnorm, sizeof(dnorm)) < 0);
|
|
|
|
|
assert(geminux_parse_dns_servers("224.0.0.1", dv4, &dn4, 6, dv6, &dn6, 6, dnorm, sizeof(dnorm)) < 0);
|
|
|
|
|
assert(geminux_parse_dns_servers("999.1.1.1", dv4, &dn4, 6, dv6, &dn6, 6, dnorm, sizeof(dnorm)) < 0);
|
|
|
|
|
assert(geminux_parse_dns_servers("1.1.1.1,1.0.0.1,8.8.8.8,8.8.4.4,9.9.9.9,88.198.92.222,192.71.166.92",
|
|
|
|
|
dv4, &dn4, 6, dv6, &dn6, 6, dnorm, sizeof(dnorm)) < 0);
|
|
|
|
|
|
|
|
|
|
char rsum[128];
|
|
|
|
|
int rc_cnt = geminux_parse_resolv_conf("# Generated\nnameserver 88.198.92.222\nnameserver 192.71.166.92 # rad\n",
|
|
|
|
|
rsum, sizeof(rsum));
|
|
|
|
|
assert(rc_cnt == 2 && strcmp(rsum, "88.198.92.222, 192.71.166.92") == 0);
|
2026-11-24 11:05:18 +02:00
|
|
|
|
|
|
|
|
/* MT6351 fuel-gauge persisted state serialization & bounds validation */
|
|
|
|
|
char fg_buf[128];
|
|
|
|
|
uint32_t fg_r = 0, fg_full = 0;
|
|
|
|
|
assert(geminux_fg_state_format(245000U, 3812000U, fg_buf, sizeof(fg_buf)) == 0);
|
|
|
|
|
assert(strcmp(fg_buf, "learned_resistance_uohm=245000\nlearned_full_uah=3812000\n") == 0);
|
|
|
|
|
assert(geminux_fg_state_parse(fg_buf, &fg_r, &fg_full));
|
|
|
|
|
assert(fg_r == 245000U && fg_full == 3812000U);
|
|
|
|
|
assert(geminux_fg_state_parse("learned_full_uah=3500000\n learned_resistance_uohm=180000 \r\n", &fg_r, &fg_full));
|
|
|
|
|
assert(fg_r == 180000U && fg_full == 3500000U);
|
|
|
|
|
assert(!geminux_fg_state_parse("learned_resistance_uohm=49999\nlearned_full_uah=3500000\n", &fg_r, &fg_full));
|
|
|
|
|
assert(!geminux_fg_state_parse("learned_resistance_uohm=1500001\nlearned_full_uah=3500000\n", &fg_r, &fg_full));
|
|
|
|
|
assert(!geminux_fg_state_parse("learned_resistance_uohm=200000\nlearned_full_uah=999999\n", &fg_r, &fg_full));
|
|
|
|
|
assert(!geminux_fg_state_parse("learned_resistance_uohm=200000\n", &fg_r, &fg_full));
|
|
|
|
|
assert(geminux_fg_state_format(10000U, 3800000U, fg_buf, sizeof(fg_buf)) < 0);
|
|
|
|
|
|
|
|
|
|
/* Verify 16x16 tiled 32bpp 90/180/270 rotation math on asymmetric geometry + sub-rects */
|
|
|
|
|
{
|
|
|
|
|
enum { SRC_W = 120, SRC_H = 110, CRTC_X = 7, CRTC_Y = 11, W = 53, H = 97 };
|
|
|
|
|
static uint32_t src_fb[SRC_H * SRC_W];
|
|
|
|
|
static uint32_t dst_fast[H * W];
|
|
|
|
|
static uint32_t dst_ref[H * W];
|
|
|
|
|
for (int y = 0; y < SRC_H; y++) {
|
|
|
|
|
for (int x = 0; x < SRC_W; x++) {
|
|
|
|
|
src_fb[y * SRC_W + x] = ((uint32_t)(y + 1) << 16) | (uint32_t)(x + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const int rots[3] = { 90, 180, 270 };
|
|
|
|
|
const int bx1[3] = { 0, 13, 32 };
|
|
|
|
|
const int by1[3] = { 0, 15, 48 };
|
|
|
|
|
const int bx2[3] = { W, 51, 53 };
|
|
|
|
|
const int by2[3] = { H, 81, 97 };
|
|
|
|
|
for (int ri = 0; ri < 3; ri++) {
|
|
|
|
|
int deg = rots[ri];
|
|
|
|
|
memset(dst_fast, 0xaa, sizeof(dst_fast));
|
|
|
|
|
memset(dst_ref, 0xaa, sizeof(dst_ref));
|
|
|
|
|
for (int bi = 0; bi < 3; bi++) {
|
|
|
|
|
int x1 = bx1[bi], y1 = by1[bi], x2 = bx2[bi], y2 = by2[bi];
|
|
|
|
|
for (int dy = y1; dy < y2; dy++) {
|
|
|
|
|
for (int dx = x1; dx < x2; dx++) {
|
|
|
|
|
int sx = CRTC_X + ((deg == 270) ? dy : (deg == 90) ? (H - 1 - dy) : (W - 1 - dx));
|
|
|
|
|
int sy = CRTC_Y + ((deg == 270) ? (W - 1 - dx) : (deg == 90) ? dx : (H - 1 - dy));
|
|
|
|
|
dst_ref[dy * W + dx] = src_fb[sy * SRC_W + sx];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (deg == 270) {
|
|
|
|
|
for (int ty = y1; ty < y2; ty += 16) {
|
|
|
|
|
int bh = (y2 - ty < 16) ? (y2 - ty) : 16;
|
|
|
|
|
for (int tx = x1; tx < x2; tx += 16) {
|
|
|
|
|
int bw = (x2 - tx < 16) ? (x2 - tx) : 16;
|
|
|
|
|
uint32_t tile[16][16];
|
|
|
|
|
for (int bx = 0; bx < bw; bx++) {
|
|
|
|
|
const uint32_t *srow = src_fb + (size_t)(CRTC_Y + W - 1 - (tx + bx)) * SRC_W + (size_t)(CRTC_X + ty);
|
|
|
|
|
for (int by = 0; by < bh; by++) tile[by][bx] = srow[by];
|
|
|
|
|
}
|
|
|
|
|
for (int by = 0; by < bh; by++) {
|
|
|
|
|
memcpy(dst_fast + (size_t)(ty + by) * W + tx, tile[by], (size_t)bw * sizeof(uint32_t));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else if (deg == 90) {
|
|
|
|
|
for (int ty = y1; ty < y2; ty += 16) {
|
|
|
|
|
int bh = (y2 - ty < 16) ? (y2 - ty) : 16;
|
|
|
|
|
for (int tx = x1; tx < x2; tx += 16) {
|
|
|
|
|
int bw = (x2 - tx < 16) ? (x2 - tx) : 16;
|
|
|
|
|
uint32_t tile[16][16];
|
|
|
|
|
for (int bx = 0; bx < bw; bx++) {
|
|
|
|
|
const uint32_t *srow = src_fb + (size_t)(CRTC_Y + tx + bx) * SRC_W + (size_t)(CRTC_X + H - ty - bh);
|
|
|
|
|
for (int k = 0; k < bh; k++) tile[bh - 1 - k][bx] = srow[k];
|
|
|
|
|
}
|
|
|
|
|
for (int by = 0; by < bh; by++) {
|
|
|
|
|
memcpy(dst_fast + (size_t)(ty + by) * W + tx, tile[by], (size_t)bw * sizeof(uint32_t));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int dy = y1; dy < y2; dy++) {
|
|
|
|
|
const uint32_t *srow = src_fb + (size_t)(CRTC_Y + H - 1 - dy) * SRC_W + (size_t)(CRTC_X + W - 1);
|
|
|
|
|
uint32_t *drow = dst_fast + (size_t)dy * W;
|
|
|
|
|
for (int dx = x1; dx < x2; dx++) drow[dx] = srow[-dx];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
assert(memcmp(dst_fast, dst_ref, sizeof(dst_ref)) == 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-22 10:49:59 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
for fname, required_loop in DAEMON_FILES.items():
|
|
|
|
|
path = os.path.join(DAEMON_DIR, fname)
|
|
|
|
|
with open(path, "r", encoding="utf-8") as handle:
|
|
|
|
|
src = handle.read()
|
|
|
|
|
for bad in (r"\bsleep\s*\(", r"\busleep\s*\(", r"\bnanosleep\s*\("):
|
|
|
|
|
if re.search(bad, src):
|
|
|
|
|
raise AssertionError(f"Busy-wait sleep call ({bad}) detected in {fname}")
|
|
|
|
|
if required_loop not in src:
|
|
|
|
|
raise AssertionError(f"Expected event loop primitive {required_loop} missing in {fname}")
|
|
|
|
|
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix="geminux-power-test-") as tmp:
|
|
|
|
|
src = os.path.join(tmp, "test_power.c")
|
|
|
|
|
bin_path = os.path.join(tmp, "test_power")
|
|
|
|
|
with open(src, "w", encoding="utf-8") as handle:
|
|
|
|
|
handle.write(C_TEST)
|
|
|
|
|
|
|
|
|
|
gcc = shutil.which("gcc")
|
|
|
|
|
if gcc:
|
|
|
|
|
subprocess.run(
|
|
|
|
|
[gcc, "-std=c11", "-Wall", "-Wextra", "-Werror",
|
2026-11-22 22:31:41 +02:00
|
|
|
"-I", DAEMON_DIR, "-I", APPS_DIR, src, POLICY_C, GESTURE_C, WIFI_NVRAM_C, "-lm", "-o", bin_path],
|
2026-11-22 10:49:59 +02:00
|
|
|
check=True,
|
|
|
|
|
)
|
|
|
|
|
subprocess.run([bin_path], check=True)
|
|
|
|
|
else:
|
|
|
|
|
subprocess.run(
|
|
|
|
|
["docker", "run", "--rm", "-v", f"{BASE_DIR}:/geminux:ro",
|
|
|
|
|
"-v", f"{tmp}:/work", "alpine:3.24", "sh", "-eu", "-c",
|
|
|
|
|
"apk add --no-cache build-base >/dev/null && "
|
2026-11-22 22:31:41 +02:00
|
|
|
"gcc -std=c11 -Wall -Wextra -Werror -I/geminux/src/geminux-daemons -I/geminux/src/geminux-apps "
|
2026-11-22 10:49:59 +02:00
|
|
|
"/work/test_power.c /geminux/src/geminux-daemons/geminux-power-policy.c "
|
2026-11-22 22:31:41 +02:00
|
|
|
"/geminux/src/geminux-daemons/geminux-touch-gesture.c "
|
|
|
|
|
"/geminux/src/geminux-daemons/geminux-wifi-nvram-core.c -lm "
|
2026-11-22 10:49:59 +02:00
|
|
|
"-o /work/test_power && /work/test_power"],
|
|
|
|
|
check=True,
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-23 20:00:17 +02:00
|
|
|
overlay_dir = os.path.join(BASE_DIR, "overlay", "rootfs")
|
|
|
|
|
required_overlay_needles = {
|
|
|
|
|
os.path.join(overlay_dir, "etc", "bluetooth", "main.conf"): (
|
|
|
|
|
"AutoEnable = false",
|
|
|
|
|
"FastConnectable = false",
|
|
|
|
|
),
|
|
|
|
|
os.path.join(overlay_dir, "etc", "pipewire", "pipewire.conf.d", "10-geminux-power.conf"): (
|
|
|
|
|
"default.clock.min-quantum = 1024",
|
|
|
|
|
),
|
|
|
|
|
os.path.join(overlay_dir, "etc", "conf.d", "geminux-hwinit"): (
|
|
|
|
|
'GEMINUX_ENABLE_CPUFREQ="yes"',
|
|
|
|
|
'GEMINUX_ENABLE_SENSORS="no"',
|
|
|
|
|
'GEMINUX_GATE_UNUSED_CLOCKS="yes"',
|
2026-11-24 11:05:18 +02:00
|
|
|
'GEMINUX_ENABLE_SPM_SLEEP="yes"',
|
2026-11-23 20:00:17 +02:00
|
|
|
),
|
|
|
|
|
os.path.join(overlay_dir, "etc", "modprobe.d", "geminux.conf"): (
|
|
|
|
|
"blacklist stk3310",
|
|
|
|
|
"softdep cpufreq_dt pre: clk_mt6797_mcusys",
|
2026-11-24 11:05:18 +02:00
|
|
|
"options mt6797_spm_sleep sodi_idle=0 pmic_modes=1 timer_sec=600",
|
|
|
|
|
"options mt6797_wlan power_save=0",
|
|
|
|
|
),
|
|
|
|
|
os.path.join(BASE_DIR, "patches", "kernel", "series"): (
|
|
|
|
|
"0009-mt6797-wlan-drop-free-stability.patch",
|
2026-11-23 20:00:17 +02:00
|
|
|
),
|
|
|
|
|
os.path.join(overlay_dir, "etc", "profile.d", "10-geminux-env.sh"): (
|
|
|
|
|
"export NO_AT_BRIDGE=1",
|
|
|
|
|
),
|
|
|
|
|
}
|
|
|
|
|
for path, needles in required_overlay_needles.items():
|
|
|
|
|
with open(path, "r", encoding="utf-8") as handle:
|
|
|
|
|
txt = handle.read()
|
|
|
|
|
for needle in needles:
|
|
|
|
|
if needle not in txt:
|
|
|
|
|
raise AssertionError(f"Expected {needle!r} in {path}")
|
|
|
|
|
|
|
|
|
|
with open(os.path.join(overlay_dir, "etc", "modprobe.d", "geminux.conf"), "r", encoding="utf-8") as handle:
|
|
|
|
|
modprobe_txt = handle.read()
|
|
|
|
|
for line in modprobe_txt.splitlines():
|
|
|
|
|
if line.startswith("softdep clk_mt6797_mcusys") or line.startswith("softdep cpufreq_dt"):
|
|
|
|
|
if "mt6797_a72" in line:
|
|
|
|
|
raise AssertionError(f"CPUfreq softdep must not depend on mt6797_a72: {line}")
|
|
|
|
|
|
|
|
|
|
with open(os.path.join(DAEMON_DIR, "geminux-powerd.c"), "r", encoding="utf-8") as handle:
|
|
|
|
|
powerd_src = handle.read()
|
|
|
|
|
trig_idx = powerd_src.find("static void trigger_suspend(powerd_ctx_t *ctx) {")
|
|
|
|
|
assert trig_idx >= 0, "trigger_suspend missing in geminux-powerd.c"
|
|
|
|
|
trig_src = powerd_src[trig_idx:]
|
|
|
|
|
prep_idx = trig_src.find("prepare_consys_for_suspend(")
|
2026-11-24 11:05:18 +02:00
|
|
|
cpu_prep_idx = trig_src.find("prepare_cpus_for_suspend(")
|
2026-11-23 20:00:17 +02:00
|
|
|
susp_idx = trig_src.find('"/sys/power/state"')
|
2026-11-24 11:05:18 +02:00
|
|
|
cpu_rest_idx = trig_src.find("restore_cpus_after_resume(")
|
2026-11-23 20:00:17 +02:00
|
|
|
rest_idx = trig_src.find("restore_consys_after_resume(")
|
2026-11-24 11:05:18 +02:00
|
|
|
if min(prep_idx, cpu_prep_idx, susp_idx, cpu_rest_idx, rest_idx) < 0 or not (
|
|
|
|
|
prep_idx < cpu_prep_idx < susp_idx < cpu_rest_idx < rest_idx):
|
|
|
|
|
raise AssertionError("trigger_suspend must quiesce CONSYS and CPUs before /sys/power/state and restore after")
|
2026-11-23 20:00:17 +02:00
|
|
|
if '"mt6797_consys"' not in powerd_src or '"mt6797-consys"' not in powerd_src:
|
|
|
|
|
raise AssertionError("geminux-powerd.c must unload mt6797_consys and reload mt6797-consys")
|
|
|
|
|
|
2026-11-24 11:05:18 +02:00
|
|
|
with open(os.path.join(APPS_DIR, "geminux-control.c"), "r", encoding="utf-8") as handle:
|
|
|
|
|
ctrl_src = handle.read()
|
|
|
|
|
if "st->bl_path" not in ctrl_src or "flush_vol_helper(" not in ctrl_src:
|
|
|
|
|
raise AssertionError("geminux-control.c must write backlight directly via bl_path and throttle wpctl")
|
|
|
|
|
with open(os.path.join(BASE_DIR, "src", "libgemui", "gemui.c"), "r", encoding="utf-8") as handle:
|
|
|
|
|
gemui_src = handle.read()
|
|
|
|
|
if "XPeekEvent(" not in gemui_src:
|
|
|
|
|
raise AssertionError("gemui.c must coalesce consecutive MotionNotify events with XPeekEvent")
|
|
|
|
|
|
2026-11-22 16:16:22 +02:00
|
|
|
print("[PASS] Zero-poll daemon loops, power/lid policy, and touch gestures verified")
|
2026-11-22 10:49:59 +02:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
sys.exit(main())
|