Files
Strata/engine/tests/core/stream_watch_test.cpp
T
Niko1221 4058aa782b Layout move for 0.2.16: the top level becomes app/, engine/, terminal/, docs/, tools/ and .github/
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
  changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
  Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
  repository paths inside tests.

engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.

No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
2026-11-17 13:19:21 +01:00

69 lines
2.9 KiB
C++

// #5718 follow-up: the stall report names the GPU streams a host may be waiting on and says, from a non-blocking query,
// whether their work is finished. No GPU: the query is faked per stream; this checks the list (RAII, slots), the line
// for each state, and that nothing is printed when no stream is watched.
#include "strata/core/stream_watch.hpp"
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <string>
using namespace strata::core;
namespace {
int failed = 0;
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
std::string report_text() {
std::FILE* f = std::tmpfile();
if (!f) return "<no tmpfile>";
stream_watch().report(f, [](void* s, int, std::string& why) {
const auto id = (std::uintptr_t) s;
if (id == 1) return StreamState::finished;
if (id == 2) return StreamState::working;
why = "invalid resource handle";
return StreamState::failed;
});
std::string out;
std::rewind(f);
char buf[512];
while (std::fgets(buf, sizeof buf, f)) out += buf;
std::fclose(f);
return out;
}
} // namespace
int main() {
CHECK(report_text().empty()); // nothing watched: no line
{
WatchedStream a("the prompt's GPU work", (void*) 1, 0);
CHECK(stream_watch().count() == 1);
{
WatchedStream b("the prompt's GPU work", (void*) 2, 1);
WatchedStream c("the prompt's GPU work", (void*) 3, 0);
const std::string t = report_text();
std::printf("%s", t.c_str());
CHECK(t.find(" the prompt's GPU work (GPU 0) had finished, but the engine was still waiting for it\n")
!= std::string::npos);
CHECK(t.find(" the prompt's GPU work (GPU 1) was still running\n") != std::string::npos);
CHECK(t.find(" the state of the prompt's GPU work could not be read: invalid resource handle\n")
!= std::string::npos); CHECK(stream_watch().count() == 3);
}
CHECK(stream_watch().count() == 1); // b and c left with their scopes
const std::string t = report_text();
CHECK(t.find("(GPU 1)") == std::string::npos);
}
CHECK(stream_watch().count() == 0);
CHECK(report_text().empty());
{ // all slots taken: the extra one is simply not listed, and nothing breaks when it goes
WatchedStream* many[StreamWatch::kSlots + 2];
for (auto& w : many) w = new WatchedStream("s", (void*) 1, 0);
CHECK(stream_watch().count() == StreamWatch::kSlots);
for (auto& w : many) delete w;
CHECK(stream_watch().count() == 0);
}
if (failed) { std::fprintf(stderr, "stream_watch_test: %d failed\n", failed); return 1; }
std::printf("stream_watch_test: ok\n");
return 0;
}