// Exercise the actual renderers with a synthetic driver response; no IOKit. // The TUI is a modern btop-style layout (rounded borders, Braille chart, // sub-cell bars, truecolor gradients). Assertions check structural invariants // and the documented n/a panels. #define main mtop_program_main #include "../amdgpu_mtop/main.cpp" #undef main #include namespace mtop { std::vector discover(std::string &) { return {}; } } // Strip ANSI escapes so we can assert on visible text. static std::string strip(const std::string &s) { std::string out; for (size_t i = 0; i < s.size(); ++i) { if (s[i] == '\033' && i + 1 < s.size() && s[i + 1] == '[') { i += 2; while (i < s.size() && !(s[i] >= '@' && s[i] <= '~')) ++i; continue; } out += s[i]; } return out; } int main() { using namespace amdgpu; using namespace vram_accounting; // Minimal device: just the identity fields. The dashboard handles // missing sensors gracefully (renders n/a rows). mtop::Device d; d.registry = 1; d.build = 195; d.stage = 15; d.gfx[0] = 11; d.gfx[1] = 0; d.gfx[2] = 0; // No accounting/clock/telemetry: the dashboard renders n/a rows. const auto now=clock_gettime_nsec_np(CLOCK_UPTIME_RAW); // Telemetry: power, temp, fan, clocks. d.telemetrySupported=true; d.metrics.version=kSMUMetricsSnapshotVersion;d.metrics.size=sizeof(d.metrics); d.metrics.driverInterface=metrics::kCompatibleInterface; d.metrics.flags=kSMUMetricsValid|kSMUMetricsLinuxCompatible; d.metrics.collectedAtNs=now; d.metrics.validFields=(uint64_t(1)<= 4 text rows), and every // panel from the e8e7c49 rework is visible in the 50-row frame. --- captured.str(""); captured.clear(); previous = std::cout.rdbuf(captured.rdbuf()); mtop::Frame fit50; ui.sort.kind = mtop::tui::Sort::Vram; dashboard({d}, selected, {}, true, false, &histories, mtop::RefreshMode{true}, 120, 50, now, mtop::Graphics::Text, &fit50, false, &ui); std::cout.rdbuf(previous); auto fit50Visible = strip(captured.str()); // Frame is exactly 50 lines, footer last. assert(fit50.previous.size() == 50); assert(strip(fit50.previous.back()).find("[q] Quit") != std::string::npos); assert(strip(fit50.previous.back()).find("Interval: 10ms") != std::string::npos); // Sort label reflects the ui state. assert(fit50Visible.find("sort: VRAM") != std::string::npos); // Both charts are present with their axis captions. assert(fit50Visible.find("GPU CORE LOAD") != std::string::npos); assert(fit50Visible.find("SMU MEMORY ACTIVITY (UMC)") != std::string::npos); assert(fit50Visible.find("100%") != std::string::npos); assert(fit50Visible.find("0%") != std::string::npos); assert(fit50Visible.find("0s") != std::string::npos); // Every panel below the charts is still on screen. assert(fit50Visible.find("VRAM USAGE") != std::string::npos); assert(fit50Visible.find("POWER & SENSOR STATE") != std::string::npos); assert(fit50Visible.find("PERFORMANCE COUNTERS (GRBM / GRBM2)") != std::string::npos); assert(fit50Visible.find("[GRBM2 Status]") != std::string::npos); assert(fit50Visible.find("Primitive Assembly (PA)") != std::string::npos); assert(fit50Visible.find("GPU PROCESSES (fdinfo)") != std::string::npos); // --- Tall terminal (80 rows): charts grow back toward the ceiling, all // panels remain present, footer is the last row. --- captured.str(""); captured.clear(); previous = std::cout.rdbuf(captured.rdbuf()); mtop::Frame fit80; dashboard({d}, selected, {}, true, false, &histories, mtop::RefreshMode{true}, 120, 80, now, mtop::Graphics::Text, &fit80, false, &ui); std::cout.rdbuf(previous); auto fit80Visible = strip(captured.str()); assert(fit80.previous.size() == 80); assert(strip(fit80.previous.back()).find("[q] Quit") != std::string::npos); assert(fit80Visible.find("GPU CORE LOAD") != std::string::npos); assert(fit80Visible.find("SMU MEMORY ACTIVITY (UMC)") != std::string::npos); assert(fit80Visible.find("VRAM USAGE") != std::string::npos); assert(fit80Visible.find("PERFORMANCE COUNTERS (GRBM / GRBM2)") != std::string::npos); assert(fit80Visible.find("GPU PROCESSES (fdinfo)") != std::string::npos); // --- Engine toggle: 'r' hides the GRBM section --- ui.enginesVisible = false; captured.str(""); captured.clear(); previous = std::cout.rdbuf(captured.rdbuf()); dashboard({d}, selected, {}, false, false, &histories, {}, 120, 50, now, mtop::Graphics::Text, &layout, false, &ui); std::cout.rdbuf(previous); auto hiddenVisible = strip(captured.str()); assert(hiddenVisible.find("(hidden; press r to toggle)") != std::string::npos); assert(hiddenVisible.find("Graphics Pipe (GFX)") == std::string::npos); // --- Unavailable sensors: stale telemetry clears the headline --- d.metrics.collectedAtNs = now - kSMUMetricsStaleAfterNs - 1; captured.str(""); captured.clear(); previous = std::cout.rdbuf(captured.rdbuf()); dashboard({d}, selected, {}, false, false, &histories, {}, 120, 50, now, mtop::Graphics::Text, &layout, false, &ui); std::cout.rdbuf(previous); auto staleVisible = strip(captured.str()); // Power should be n/a when stale. assert(staleVisible.find("Pwr: n/a") != std::string::npos); return 0; }