okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3342e0644
main
1// draft_vocab_test: the DFlash2-alone start's draft-vocabulary choice (include/strata/spec/draft_vocab.hpp). 2#include "strata/spec/draft_vocab.hpp" 3 4#include <cstdio> 5#include <set> 6#include <string> 7 8using strata::spec::df2_vocab_resolve ; 9 10static int g_fail = 0 ; 11#define CHECK (c ) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++g_fail; } } while (0) 12 13int main () { 14const std::set < std::string > files = {"/mtp/with/draft_vocab.bin" ,"/given.bin" ,"/pkg/data/draft_vocab.bin" }; 15auto exists = [& ](const std::string & p ) {return files .count (p )> 0 ; }; 16 17// the MTP folder has the subset: it is used, packaged default or not 18for (const char * pkg : {"" ,"/pkg/data/draft_vocab.bin" }) { 19auto r = df2_vocab_resolve ("/mtp/with" ,"" ,pkg , false,exists ); 20CHECK (r .ok && r .path == "/mtp/with/draft_vocab.bin" && !r .packaged && !r .whole_head ); 21 } 22// a file the person named wins over the folder's 23 {auto r = df2_vocab_resolve ("/mtp/with" ,"/given.bin" ,"/pkg/data/draft_vocab.bin" , false,exists );CHECK (r .ok && r .path == "/given.bin" && !r .packaged ); } 24// the Mac: the MTP folder has none, the build ships its default: that is used (what Metal did before the merge) 25 {auto r = df2_vocab_resolve ("/mtp/empty" ,"" ,"/pkg/data/draft_vocab.bin" , false,exists );CHECK (r .ok && r .packaged && r .path == "/pkg/data/draft_vocab.bin" ); } 26// CUDA / HIP / SYCL (no packaged default named): a missing file is the error it was 27 {auto r = df2_vocab_resolve ("/mtp/empty" ,"" ,"" , false,exists );CHECK (!r .ok && r .why .find ("/mtp/empty/draft_vocab.bin" )!= std::string::npos ); } 28// no subset can be found at all (the build's default is missing too): the error, on every backend 29 {auto r = df2_vocab_resolve ("/mtp/empty" ,"" ,"/nowhere/draft_vocab.bin" , false,exists );CHECK (!r .ok && !r .packaged ); } 30// a file the person named that does not exist is their mistake: no silent fallback to the default 31 {auto r = df2_vocab_resolve ("/mtp/with" ,"/typo.bin" ,"/pkg/data/draft_vocab.bin" , false,exists );CHECK (!r .ok && r .why .find ("/typo.bin" )!= std::string::npos ); } 32// the whole head asked for on purpose (STRATA_METAL_DRAFT_VOCAB=full) is not an error 33 {auto r = df2_vocab_resolve ("/mtp/empty" ,"" ,"" , true,exists );CHECK (r .ok && r .whole_head ); } 34 35if (g_fail == 0 ) std::printf ("draft_vocab_test: all checks passed\n" ); 36return g_fail == 0 ?0 :1 ; 37}