MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / fuzz_test_template

Function fuzz_test_template

subprojects/llama.cpp/tests/test-jinja.cpp:1903–1920  ·  view source on GitHub ↗

Helper to execute a fuzz test case - returns true if no crash occurred

Source from the content-addressed store, hash-verified

1901
1902// Helper to execute a fuzz test case - returns true if no crash occurred
1903static bool fuzz_test_template(const std::string & tmpl, const json & vars) {
1904 try {
1905 // printf("Fuzz testing template: %s\n", tmpl.c_str());
1906 jinja::lexer lexer;
1907 auto lexer_res = lexer.tokenize(tmpl);
1908 jinja::program ast = jinja::parse_from_tokens(lexer_res);
1909 jinja::context ctx(tmpl);
1910 jinja::global_from_json(ctx, vars, true);
1911 jinja::runtime runtime(ctx);
1912 const jinja::value results = runtime.execute(ast);
1913 runtime.gather_string_parts(results);
1914 return true; // success
1915 } catch (const std::exception &) {
1916 return true; // exception is acceptable, not a crash
1917 } catch (...) {
1918 return true; // any exception is acceptable, not a crash
1919 }
1920}
1921
1922static void test_fuzzing(testing & t) {
1923 const int num_iterations = JINJA_FUZZ_ITERATIONS;

Callers 1

test_fuzzingFunction · 0.85

Calls 5

parse_from_tokensFunction · 0.85
global_from_jsonFunction · 0.85
gather_string_partsMethod · 0.80
tokenizeMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected