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 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);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
geminux_profile_params_t perf = geminux_policy_params(POWER_PROFILE_PERFORMANCE, true);
|
|
|
|
|
assert(strcmp(perf.governor, "schedutil") == 0);
|
|
|
|
|
assert(perf.a72_online);
|
|
|
|
|
assert(perf.suspend_timeout_s == 0);
|
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";
|
|
|
|
|
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-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-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())
|