Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions tests/decision_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <nlohmann/json.hpp>
#include <string>
#include <vector>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace fs = std::filesystem;
using onebit::npu::DecisionHead;
Expand Down Expand Up @@ -74,7 +75,7 @@ nlohmann::json base_config() {
bool close(float a, float b, float eps = 1e-5f) { return std::fabs(a - b) <= eps; }

void test_load_and_logits() {
const fs::path dir = fs::temp_directory_path() / "onebit-decision-test";
const fs::path dir = ::onebit::test::tmp_root() / "onebit-decision-test";
fs::remove_all(dir);
fs::create_directories(dir);
// W = [[1,0,0],[0,1,0],[0,0,2]] rows A,B,C over a 3-wide hidden state.
Expand Down Expand Up @@ -113,7 +114,7 @@ void test_load_and_logits() {
}

void test_temperature_and_shape_errors() {
const fs::path dir = fs::temp_directory_path() / "onebit-decision-test2";
const fs::path dir = ::onebit::test::tmp_root() / "onebit-decision-test2";
fs::remove_all(dir);
fs::create_directories(dir);
const std::vector<float> w = {2, 0, 0, 2}; // two options over a 2-wide state
Expand Down Expand Up @@ -149,7 +150,7 @@ void test_temperature_and_shape_errors() {
}

void test_missing_pieces() {
const fs::path dir = fs::temp_directory_path() / "onebit-decision-test3";
const fs::path dir = ::onebit::test::tmp_root() / "onebit-decision-test3";
fs::remove_all(dir);
fs::create_directories(dir);
DecisionHead head;
Expand Down
3 changes: 2 additions & 1 deletion tests/gguf_meta_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <fstream>
#include <string>
#include <vector>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace {

Expand Down Expand Up @@ -66,7 +67,7 @@ void expect(const std::string& what, const std::string& got, const std::string&
} // namespace

int main() {
const auto dir = std::filesystem::temp_directory_path() / "onebit_gguf_meta_test";
const auto dir = ::onebit::test::tmp_root() / "onebit_gguf_meta_test";
std::filesystem::create_directories(dir);

Gguf first;
Expand Down
3 changes: 2 additions & 1 deletion tests/laya_bounds_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <vector>

#include <unistd.h>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace fs = std::filesystem;
using json = nlohmann::json;
Expand Down Expand Up @@ -69,7 +70,7 @@ void write_st(const fs::path& path, const std::vector<std::pair<std::string, std
} // namespace

int main() {
const fs::path root = fs::temp_directory_path() / ("laya_bounds_test." + std::to_string(::getpid()));
const fs::path root = ::onebit::test::tmp_root() / ("laya_bounds_test." + std::to_string(::getpid()));
fs::remove_all(root);
fs::create_directories(root);
std::vector<float> out;
Expand Down
3 changes: 2 additions & 1 deletion tests/mem_admit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <fstream>
#include <string>
#include <vector>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace fs = std::filesystem;
using namespace onebit;
Expand Down Expand Up @@ -94,7 +95,7 @@ void put(const fs::path& p, const std::string& text) {
} // namespace

int main() {
const fs::path dir = fs::temp_directory_path() / ("mem_admit_test_" + std::to_string(::getpid()));
const fs::path dir = ::onebit::test::tmp_root() / ("mem_admit_test_" + std::to_string(::getpid()));
fs::create_directories(dir);
const std::string d = dir.string();

Expand Down
3 changes: 2 additions & 1 deletion tests/moe_gguf_index_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <vector>

#include <unistd.h>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace fs = std::filesystem;
using onebit::moe::GgufIndex;
Expand Down Expand Up @@ -77,7 +78,7 @@ std::string open_error(const fs::path& path, Gguf g, size_t data = 64) {
} // namespace

int main() {
const fs::path root = fs::temp_directory_path() / ("moe_gguf_index_test." + std::to_string(::getpid()));
const fs::path root = ::onebit::test::tmp_root() / ("moe_gguf_index_test." + std::to_string(::getpid()));
fs::remove_all(root);
fs::create_directories(root);

Expand Down
3 changes: 2 additions & 1 deletion tests/npu_flm_head_import_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <fstream>
#include <string>
#include <vector>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace {

Expand Down Expand Up @@ -220,7 +221,7 @@ void test_refusal(const std::string& root) {

int main(int argc, char** argv) {
const std::string golden = argc > 1 ? argv[1] : "";
const std::string root = (fs::temp_directory_path() / "npu_flm_head_import_test").string();
const std::string root = (::onebit::test::tmp_root() / "npu_flm_head_import_test").string();
try {
if (!golden.empty()) test_golden(golden);
else std::printf("skip golden: no directory given\n");
Expand Down
3 changes: 2 additions & 1 deletion tests/npu_model_bounds_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <vector>

#include <unistd.h>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

using namespace onebit::npu;
namespace fs = std::filesystem;
Expand Down Expand Up @@ -120,7 +121,7 @@ std::vector<Entry> one_layer(std::vector<int64_t> q_shape = {1, 5120}, int64_t g
} // namespace

int main() {
const fs::path root = fs::temp_directory_path() / ("npu_model_bounds_test." + std::to_string(::getpid()));
const fs::path root = ::onebit::test::tmp_root() / ("npu_model_bounds_test." + std::to_string(::getpid()));
fs::remove_all(root);

{ // well-formed: loads and packs
Expand Down
3 changes: 2 additions & 1 deletion tests/npu_moe_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <vector>

#include <unistd.h>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

using namespace onebit::npu;
namespace fs = std::filesystem;
Expand Down Expand Up @@ -80,7 +81,7 @@ struct Crafted {
};

fs::path write_dir(const Crafted& m, const std::string& tag) {
fs::path dir = fs::temp_directory_path() / ("npu_moe_test_" + std::to_string(::getpid()) + tag);
fs::path dir = ::onebit::test::tmp_root() / ("npu_moe_test_" + std::to_string(::getpid()) + tag);
fs::remove_all(dir);
fs::create_directories(dir);
const uint64_t chunk = uint64_t(m.tiles) * kTileBytes;
Expand Down
41 changes: 21 additions & 20 deletions tests/npu_pack_import_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <stdexcept>
#include <string>
#include <vector>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace {

Expand Down Expand Up @@ -799,7 +800,7 @@ void test_external_import_success(const std::string& root) {
// alone, so what can go wrong is the test being too willing -- a truncated copy from an interrupted run, a leftover
// directory, a copy from a bigger pack. Those are the arms.
void test_canonical_copy_reusable() {
const fs::path dir = fs::temp_directory_path() / ("1bit-reuse-" + std::to_string(::getpid()));
const fs::path dir = ::onebit::test::tmp_root() / ("1bit-reuse-" + std::to_string(::getpid()));
std::error_code ec;
fs::remove_all(dir, ec);
fs::create_directories(dir);
Expand Down Expand Up @@ -836,7 +837,7 @@ void test_canonical_copy_reusable() {
// changes, so 699 files / 8.7 GiB of tmpfs (RAM) had built up on one box. The eviction rule is "same pack and geometry,
// different source identity", and what can go wrong is deleting one of the neighbours that must survive, so each is an arm.
void test_evict_stale_canonical_copies() {
const fs::path dir = fs::temp_directory_path() / ("1bit-evict-" + std::to_string(::getpid()));
const fs::path dir = ::onebit::test::tmp_root() / ("1bit-evict-" + std::to_string(::getpid()));
std::error_code ec;
fs::remove_all(dir, ec);
fs::create_directories(dir);
Expand Down Expand Up @@ -930,7 +931,7 @@ void test_evict_stale_canonical_copies() {
// again, and 17.0 GiB of copies left there by older binaries stayed in tmpfs (RAM). Every candidate is swept now; one that does
// not exist is not created.
void test_sweep_fconst_scratch_dirs() {
const fs::path root = fs::temp_directory_path() / ("1bit-sweep-" + std::to_string(::getpid()));
const fs::path root = ::onebit::test::tmp_root() / ("1bit-sweep-" + std::to_string(::getpid()));
std::error_code ec;
fs::remove_all(root, ec);
const fs::path written = root / "cache", other = root / "tmp", absent = root / "never-made";
Expand Down Expand Up @@ -996,8 +997,8 @@ void test_sweep_fconst_scratch_dirs() {
// override set only that directory is swept, so the second directory's copy must still be there.
void test_sweep_is_wired(const std::string& root) {
const fs::path dir = fs::path(root) / "sweep-wired";
const fs::path scratch = fs::temp_directory_path() / ("1bit-sweep-wired-" + std::to_string(::getpid()));
const fs::path cache_home = fs::temp_directory_path() / ("1bit-sweep-wired-xdg-" + std::to_string(::getpid()));
const fs::path scratch = ::onebit::test::tmp_root() / ("1bit-sweep-wired-" + std::to_string(::getpid()));
const fs::path cache_home = ::onebit::test::tmp_root() / ("1bit-sweep-wired-xdg-" + std::to_string(::getpid()));
std::error_code ec;
fs::remove_all(dir, ec);
fs::remove_all(scratch, ec);
Expand Down Expand Up @@ -1047,7 +1048,7 @@ void test_sweep_is_wired(const std::string& root) {
}
setenv("ONEBIT_FCONST_SCRATCH", scratch.c_str(), 1);
setenv("XDG_CACHE_HOME", cache_home.c_str(), 1);
const std::string out = (fs::temp_directory_path() / ("oga_pack_import_sweepwired." + std::to_string(::getpid()))).string();
const std::string out = (::onebit::test::tmp_root() / ("oga_pack_import_sweepwired." + std::to_string(::getpid()))).string();
fs::remove_all(out, ec);
pi::Options allow;
allow.allow_incomplete = true;
Expand Down Expand Up @@ -1794,7 +1795,7 @@ void test_tied_block32_head(const std::string& root) {
allow.allow_incomplete = true;
{ // arm 1: declared tied -> synthesised from the embedding, and the note says so
const fs::path dir = build(true, "tied-block32");
const std::string out = (fs::temp_directory_path() /
const std::string out = (::onebit::test::tmp_root() /
("oga_pack_import_tied32." + std::to_string(::getpid()))).string();
fs::remove_all(out);
bool threw = false;
Expand Down Expand Up @@ -1869,7 +1870,7 @@ void test_tied_block32_head(const std::string& root) {
}
{ // arm 2: the same pack without the declaration -> refused by name, nothing written
const fs::path dir = build(false, "untied-block32");
const std::string out = (fs::temp_directory_path() /
const std::string out = (::onebit::test::tmp_root() /
("oga_pack_import_untied32." + std::to_string(::getpid()))).string();
fs::remove_all(out);
bool threw = false;
Expand Down Expand Up @@ -2017,7 +2018,7 @@ void test_block32_tail_head(const std::string& root) {
const auto run = [&](const fs::path& dir, const char* tag) {
Run x;
const std::string out =
(fs::temp_directory_path() /
(::onebit::test::tmp_root() /
(std::string("oga_pack_import_b32tail_") + tag + "." + std::to_string(::getpid()))).string();
fs::remove_all(out);
pi::Options allow;
Expand Down Expand Up @@ -2204,7 +2205,7 @@ void test_final_norm_envelope(const std::string& root) {
(geom.why.empty() ? "" : ", why: " + geom.why) + ")");
pi::Options allow;
allow.allow_incomplete = true;
const std::string out = (fs::temp_directory_path() /
const std::string out = (::onebit::test::tmp_root() /
("oga_pack_import_norm." + std::to_string(::getpid()))).string();
fs::remove_all(out);
const pi::Report r = pi::import_pack(dir.string(), out, allow);
Expand Down Expand Up @@ -2355,7 +2356,7 @@ void test_pack(const std::string& pack, const std::string& golden_dir) {
// a fully representable pack imports without --allow-incomplete; a partial one writes nothing.
// Per-process scratch dir: two concurrent runs of this binary (or two ctest shards) otherwise write
// into the same directory and one dies with "cannot write .../model.q4nx" (measured 2026-11-03).
const std::string out = (fs::temp_directory_path() /
const std::string out = (::onebit::test::tmp_root() /
("oga_pack_import_test." + std::to_string(::getpid()))).string();
fs::remove_all(out);
const pi::Report r0 = pi::import_pack(pack, out, pi::Options{});
Expand Down Expand Up @@ -2745,7 +2746,7 @@ void test_import_fp32_params(const std::string& root) {
{pb::matmulnbits("lm_head", {"x", "lm_head_qweight", "lm_head_scales", "lm_head_zeros"},
H, V, 4, block)}));

const std::string out = (fs::temp_directory_path() /
const std::string out = (::onebit::test::tmp_root() /
("oga_pack_import_fp32." + std::to_string(::getpid()))).string();
fs::remove_all(out);
const pi::Report r = pi::import_pack(dir.string(), out, pi::Options{});
Expand Down Expand Up @@ -2852,7 +2853,7 @@ void test_import_fp32_params(const std::string& root) {
// than misread it (npu/forward/src/model.c). Q4nxNpuForward::init_impl converts first through
// npu/q4nx_device.cpp; this is that conversion, and the proof it changes only the parameter
// width: the device tiles are byte-identical to the old bf16 container's for the same weights.
const std::string cache = (fs::temp_directory_path() /
const std::string cache = (::onebit::test::tmp_root() /
("oga_q4nx_device_form." + std::to_string(::getpid()))).string();
fs::remove_all(cache);
{
Expand Down Expand Up @@ -3005,7 +3006,7 @@ void test_hybrid_pack_import(const std::string& root) {
int64_t(H) * H * 4)}, {}));
put_file((dir / "dd_metastate_Llm_Token_Token_crafted.fconst").string(), fc);

const std::string out = (fs::temp_directory_path() /
const std::string out = (::onebit::test::tmp_root() /
("oga_pack_import_hybrid." + std::to_string(::getpid()))).string();
fs::remove_all(out);
pi::Options allow;
Expand Down Expand Up @@ -3192,7 +3193,7 @@ void test_genre_a_projection_gap(const std::string& root) {
R"("rope_theta":10000.0,"tie_word_embeddings":false,"rms_norm_eps":1e-06})");
(void)groups;
};
const std::string out = (fs::temp_directory_path() / ("oga_pack_genre_a." + std::to_string(::getpid()))).string();
const std::string out = (::onebit::test::tmp_root() / ("oga_pack_genre_a." + std::to_string(::getpid()))).string();
auto names_down = [](const pi::Report& r) {
for (const auto& s : r.refused)
if (s.find("mlp.down_proj.weight") != std::string::npos && s.find("no quantised projection the decoder can pair") != std::string::npos)
Expand Down Expand Up @@ -3678,7 +3679,7 @@ void test_post_attn_norm_header(const std::string& root) {

pi::Options allow;
allow.allow_incomplete = true; // the crafted block has no tiles, so the payload legs are refused
const std::string out = (fs::temp_directory_path() /
const std::string out = (::onebit::test::tmp_root() /
("oga_pack_import_pa." + std::to_string(::getpid()))).string();
fs::remove_all(out);
try {
Expand Down Expand Up @@ -3749,7 +3750,7 @@ void test_kernel_set_refusal() {
// missing tokenizer -- the misleading report #1751 was written to remove. A file the pack has and cannot copy is refused
// BY NAME; a file the pack does not ship is not a failure.
void test_copy_text_artifacts() {
const fs::path base = fs::temp_directory_path() / ("1bit-textcopy-" + std::to_string(::getpid()));
const fs::path base = ::onebit::test::tmp_root() / ("1bit-textcopy-" + std::to_string(::getpid()));
std::error_code ec;
fs::remove_all(base, ec);
const fs::path pack = base / "pack", out = base / "out";
Expand Down Expand Up @@ -4498,7 +4499,7 @@ void test_per_layer_import(const std::string& root) {
put_file((dir / "genai_config.json").string(), R"({"model":{"embedding":{"filename":"embedding/model.onnx"}}})");

const std::string out =
(fs::temp_directory_path() / ("oga_pack_import_perlayer." + std::to_string(::getpid()))).string();
(::onebit::test::tmp_root() / ("oga_pack_import_perlayer." + std::to_string(::getpid()))).string();
fs::remove_all(out);
pi::Options allow;
allow.allow_incomplete = true;
Expand Down Expand Up @@ -4591,7 +4592,7 @@ void test_fconst_variable_stride(const std::string& root) {
put_file((dir / "model.onnx.data").string(), std::string(4096, '\x11'));
pi::Options allow;
allow.allow_incomplete = true;
const std::string out = (fs::temp_directory_path() / ("varstride_out." + std::to_string(::getpid()))).string();
const std::string out = (::onebit::test::tmp_root() / ("varstride_out." + std::to_string(::getpid()))).string();
fs::remove_all(out);
bool refused = false;
std::string what;
Expand Down Expand Up @@ -4813,7 +4814,7 @@ void test_header_witness_refusal() {
int main(int argc, char** argv) {
// engine#1907: every crafted 1.9 import writes a canonical copy into the scratch cache. Without this the suite left 0-byte
// copies in the user's real ~/.cache/1bit/fconst19 and in /tmp on every run. Give the run its own directory, removed at exit.
const fs::path run_scratch = fs::temp_directory_path() / ("1bit-pack-test-scratch-" + std::to_string(::getpid()));
const fs::path run_scratch = ::onebit::test::tmp_root() / ("1bit-pack-test-scratch-" + std::to_string(::getpid()));
if (!std::getenv("ONEBIT_FCONST_SCRATCH")) setenv("ONEBIT_FCONST_SCRATCH", run_scratch.c_str(), 1);
struct ScratchCleanup {
fs::path p;
Expand Down
5 changes: 3 additions & 2 deletions tests/npu_plan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <fstream>
#include <nlohmann/json.hpp>
#include <string>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace fs = std::filesystem;
using onebit::npu::plan::Plan;
Expand All @@ -42,7 +43,7 @@ void check(bool ok, const std::string& what) {
}

std::string write_plan(const std::string& name, const nlohmann::json& body) {
const fs::path p = fs::temp_directory_path() / ("npu_plan_test_" + name + ".json");
const fs::path p = ::onebit::test::tmp_root() / ("npu_plan_test_" + name + ".json");
std::ofstream f(p);
f << body.dump(2) << "\n";
f.close();
Expand Down Expand Up @@ -501,7 +502,7 @@ void test_artifacts() {
return p;
};
const Plan p = Plan::load(write_plan("artifacts", with_designs()));
const fs::path root = fs::temp_directory_path() / "npu_plan_test_artifacts";
const fs::path root = ::onebit::test::tmp_root() / "npu_plan_test_artifacts";
const fs::path kdir = root / "kernels";
std::error_code ec;
fs::remove_all(root, ec);
Expand Down
3 changes: 2 additions & 1 deletion tests/npu_private_route_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string>

#include <unistd.h>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace {

Expand Down Expand Up @@ -70,7 +71,7 @@ void no_addon_refuses_the_option() {
int main() {
no_addon_refuses_the_option();
namespace fs = std::filesystem;
const fs::path dir = fs::temp_directory_path() / ("npu_private_route_test." + std::to_string(::getpid()));
const fs::path dir = ::onebit::test::tmp_root() / ("npu_private_route_test." + std::to_string(::getpid()));
fs::create_directories(dir);
std::ofstream(dir / "config.json") << R"({"model_type": "qwen3_5_moe", "num_hidden_layers": 40})";
check("model_type_of reads config.json", model_type_of(dir.string()) == "qwen3_5_moe");
Expand Down
3 changes: 2 additions & 1 deletion tests/npu_target_caps_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <fstream>
#include <nlohmann/json.hpp>
#include <string>
#include "tmp_root.h" // engine#2029: scratch goes on disk, not in tmpfs

namespace fs = std::filesystem;
using onebit::npu::plan::Plan;
Expand Down Expand Up @@ -68,7 +69,7 @@ nlohmann::json base_plan() {
}

std::string write_plan(const std::string& name, const nlohmann::json& body) {
const fs::path p = fs::temp_directory_path() / ("npu_target_caps_test_" + name + ".json");
const fs::path p = ::onebit::test::tmp_root() / ("npu_target_caps_test_" + name + ".json");
std::ofstream f(p);
f << body.dump(2) << "\n";
f.close();
Expand Down
Loading
Loading