Files
DroidDeck/tools/tests/test_framegen_hang_breaker.py
T
Kurt Himebauch bc8a970520 Stop re-arming frame generation after repeated GPU loss (#3659)
Disable frame generation after repeated startup device losses, while preserving recovery for engines that had been working. Keep the current ZeroFG-compatible submission path.
2026-12-04 09:41:39 -05:00

70 lines
2.5 KiB
Python

import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
from tools.tests.test_vk_pending_completion import function
class FramegenHangBreakerTest(unittest.TestCase):
def run_c(self, body):
compiler = shutil.which(os.environ.get('CC', 'cc'))
if not compiler:
self.skipTest('A host C compiler is required')
root = Path(__file__).resolve().parents[2]
source = (root / 'app/src/main/cpp/waylandcomp/src/framegen_bridge.c').read_text()
code = '#include <assert.h>\n#include <stdatomic.h>\n#include <stdint.h>\n'
code += '#define FG_PROVEN_FRAMES 120\n#define FG_HANG_STRIKES 2\n'
code += 'static _Atomic int g_hang_strikes, g_dev_lost;\n'
code += 'static int g_submitted_since_ready;\nstatic uint64_t g_total_generated, g_generated_at_ready;\n'
code += function(source, 'framegen_loss_strike')
code += function(source, 'framegen_count_loss')
code += 'int main(void) {\n' + body + '\n}\n'
with tempfile.TemporaryDirectory() as tmp:
folder = Path(tmp)
probe = folder / 'breaker.c'
binary = folder / 'breaker'
probe.write_text(code)
subprocess.run([compiler, '-std=c11', str(probe), '-o', str(binary)], check=True,
capture_output=True, text=True)
subprocess.run([str(binary)], check=True, capture_output=True, timeout=10)
def test_losses_before_any_generated_frame_completes_switch_generation_off(self):
self.run_c('''
assert(framegen_loss_strike(1, 0) == 0);
assert(framegen_loss_strike(1, 0) == 1);
assert(framegen_loss_strike(1, 0) == 0);
''')
def test_a_loss_after_generation_worked_keeps_it_armed(self):
self.run_c('''
assert(framegen_loss_strike(1, 0) == 0);
assert(framegen_loss_strike(1, 500) == 0);
assert(framegen_loss_strike(1, 0) == 0);
''')
def test_a_loss_without_generation_work_is_not_a_strike(self):
self.run_c('''
assert(framegen_loss_strike(1, 0) == 0);
assert(framegen_loss_strike(0, 0) == 0);
assert(framegen_loss_strike(1, 0) == 0);
''')
def test_a_loss_reported_twice_counts_once(self):
self.run_c('''
for (int loss = 0; loss < 2; loss++) {
g_dev_lost = 0;
g_submitted_since_ready = 1;
int first = framegen_count_loss();
int again = framegen_count_loss();
assert(again == 0);
assert(first == (loss == 1));
}
''')
if __name__ == '__main__':
unittest.main()