cheatah
Source

tests/purrc/memory_cheatah_e2e_test.cpp

1// Copyright (c) 2026 BigBrain LLC. MIT-licensed (see LICENSE).
2// Original work; see ACKNOWLEDGMENTS.md for the open-source ideas we build upon.
3// memory cheatah-surface e2e (suite MemoryCheatah) — runs the REAL cheatah `.purr` programs in
4// stdlib/memory/tests/ and checks exact stdout. These are actual cheatah programs exercising the
5// memory surface (own / rwrite / rread / acquire / read / write / valid / expired), verified to parse
6// + codegen + compile.
7//
8// The Owner engine is implemented, so these are real GREEN output checks in the gate: purrc builds
9// the module + program, cheatah runs it, and stdout must match exactly.
11#include <string>
13#include "e2e_harness.hpp"
15namespace {
16void expect_purr(const char* file, const std::string& expected) {
17 int rc = -1;
18 const std::string path = std::string(MEMORY_PURR_DIR) + "/" + file;
19 const std::string out = e2e::run_purr_file(std::string("mem_") + file, path, rc);
20 EXPECT_EQ(rc, 0) << file << ": exited non-zero";
21 EXPECT_EQ(out, expected) << file << ": stdout mismatch";
23} // namespace
25TEST(MemoryCheatah, ScalarWriteReadModifyWrite) { expect_purr("cheatah_scalar.purr", "5\n7\n12\n"); }
26TEST(MemoryCheatah, StructPerFieldWrites) { expect_purr("cheatah_struct.purr", "0 0\n3 4\n7\n"); }
27TEST(MemoryCheatah, AccumulateDeterministic) { expect_purr("cheatah_accumulate.purr", "1000\n0\n"); }
28TEST(MemoryCheatah, StringOwnerGrows) { expect_purr("cheatah_string.purr", "5\nhello world\n11\n"); }
29TEST(MemoryCheatah, ReadLeaseValidState) { expect_purr("cheatah_lease_state.purr", "True\nFalse\n42\n"); }
30TEST(MemoryCheatah, OwnerOfNdArrayElements) { expect_purr("cheatah_ndarray.purr", "True\nTrue\nTrue\n"); }
31TEST(MemoryCheatah, TwoOwnersInvariantPreserved){ expect_purr("cheatah_interleaved.purr", "50 50\n100\n"); }
32// Real cheatah CONCURRENCY: N threads (thread.spawn) share one pinned Owner; the deterministic-final
33// total proves the engine's drain-before-write exclusion end-to-end through the language.
34TEST(MemoryCheatah, ConcurrentSumOverSharedOwner) { expect_purr("cheatah_concurrent_sum.purr", "20000\n"); }