feat: improve session switching, fractional DPI/GTK theming, XDG launcher, CPU/RAM status, and power policy
This commit is contained in:
1 parent
72b05b650e
commit
07d9134d2d
28 files changed
+2670
-302
No files matched your search
+57
-3
@@ -13,6 +13,7 @@
|
||||
#include "anode_bt_list.h"
|
||||
#include "anode_power_policy.h"
|
||||
#include "anode_xkb_parse.h"
|
||||
#include "anode_sys_parse.h"
|
||||
#include "anode-touch-gesture.h"
|
||||
|
||||
static void test_scale_math(void) {
|
||||
@@ -152,16 +153,20 @@ static void test_power_policy_and_gestures(void) {
|
||||
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);
|
||||
anode_power_policy_step(&cfg, &st, 305000, 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);
|
||||
anode_power_policy_step(&cfg, &st, 610000, 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);
|
||||
/* Waking from ANODE_PWR_LOCKED must also restore dimmed brightness */
|
||||
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, 1810000, false, 80, true, true, &act);
|
||||
assert(st == ANODE_PWR_SUSPENDED && act.suspend_now);
|
||||
|
||||
/* Critical low battery override on battery */
|
||||
@@ -225,6 +230,45 @@ static void test_xkb_layout_parser(void) {
|
||||
assert(!anode_xkb_layout_from_group_name("!!!", buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
static void test_sys_parsers(void) {
|
||||
anode_cpu_sample_t prev = {0, 0}, cur = {0, 0};
|
||||
const char *stat1 =
|
||||
"cpu 100 0 50 850 0 0 0 0 0 0\n"
|
||||
"cpu0 50 0 25 425 0 0 0 0 0 0\n";
|
||||
const char *stat_25 =
|
||||
"cpu 300 0 100 1550 50 0 0 0 0 0\n"
|
||||
"cpu0 150 0 50 775 25 0 0 0 0 0\n";
|
||||
const char *stat_idle = "cpu 300 0 100 2550 50 0 0 0 0 0\n";
|
||||
const char *stat_full = "cpu 1300 0 100 2550 50 0 0 0 0 0\n";
|
||||
|
||||
assert(anode_parse_proc_stat_cpu(stat1, &prev));
|
||||
assert(prev.total == 1000 && prev.idle == 850);
|
||||
assert(anode_parse_proc_stat_cpu(stat_25, &cur));
|
||||
assert(cur.total == 2000 && cur.idle == 1600);
|
||||
assert(anode_cpu_usage_pct(&prev, &cur) == 25);
|
||||
assert(anode_cpu_usage_pct(&cur, &cur) == 0);
|
||||
assert(anode_cpu_usage_pct(&cur, &prev) == 0);
|
||||
|
||||
anode_cpu_sample_t idle_s = {0, 0}, full_s = {0, 0};
|
||||
assert(anode_parse_proc_stat_cpu(stat_idle, &idle_s));
|
||||
assert(anode_cpu_usage_pct(&cur, &idle_s) == 0);
|
||||
assert(anode_parse_proc_stat_cpu(stat_full, &full_s));
|
||||
assert(anode_cpu_usage_pct(&idle_s, &full_s) == 100);
|
||||
assert(!anode_parse_proc_stat_cpu("intr 1 2 3\n", &cur));
|
||||
assert(!anode_parse_proc_stat_cpu("cpu 10 20\n", &cur));
|
||||
|
||||
int ram = -1;
|
||||
assert(anode_parse_proc_meminfo_pct(
|
||||
"MemTotal: 1000000 kB\nMemFree: 100000 kB\nMemAvailable: 250000 kB\n", &ram));
|
||||
assert(ram == 75);
|
||||
assert(anode_parse_proc_meminfo_pct(
|
||||
"MemTotal: 1000000 kB\nMemFree: 100000 kB\nBuffers: 100000 kB\n"
|
||||
"Cached: 300000 kB\nSReclaimable: 100000 kB\n", &ram));
|
||||
assert(ram == 40);
|
||||
assert(!anode_parse_proc_meminfo_pct("MemFree: 100 kB\n", &ram));
|
||||
assert(!anode_parse_proc_meminfo_pct("MemTotal: 0 kB\nMemFree: 0 kB\n", &ram));
|
||||
}
|
||||
|
||||
static void test_platform_probe(void) {
|
||||
anode_net_iface_t ifs[ANODE_MAX_IFACES];
|
||||
int n = anode_list_net_ifaces(ifs, ANODE_MAX_IFACES);
|
||||
@@ -232,6 +276,15 @@ static void test_platform_probe(void) {
|
||||
anode_battery_info_t bat;
|
||||
anode_read_battery(&bat);
|
||||
(void)anode_detect_audio_backend();
|
||||
anode_cpu_sample_t cpu = {0, 0};
|
||||
int ram_pct = -1;
|
||||
#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
|
||||
assert(anode_read_cpu_sample(&cpu) && cpu.total > 0);
|
||||
assert(anode_read_mem_usage_pct(&ram_pct) && ram_pct >= 0 && ram_pct <= 100);
|
||||
#else
|
||||
(void)anode_read_cpu_sample(&cpu);
|
||||
(void)anode_read_mem_usage_pct(&ram_pct);
|
||||
#endif
|
||||
char buf[256];
|
||||
anode_runtime_dir(buf, sizeof(buf));
|
||||
assert(buf[0] == '/');
|
||||
@@ -247,6 +300,7 @@ int main(void) {
|
||||
test_wifi_and_bt_parsers();
|
||||
test_power_policy_and_gestures();
|
||||
test_xkb_layout_parser();
|
||||
test_sys_parsers();
|
||||
test_platform_probe();
|
||||
printf("test_units: ALL PASSED\n");
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user