LLM inference in C/C++
C++ ggml
tests : avoid building get-model.cpp many times (#26317)
Georgi Gerganov47f686f53f2a
diff --git a/common/common.cpp b/common/common.cppindex 9d5d2834ac..1a0aeef4ec 100644--- a/common/common.cpp+++ b/common/common.cpp@@ -1476,6 +1476,20 @@ std::string common_get_model_endpoint() {return model_endpoint;}+char * common_get_model_or_exit(int argc, char * argv[]) {+ if (argc > 1) {+ return argv[1];+ }++ char * path = getenv("LLAMACPP_TEST_MODELFILE");+ if (!path || strlen(path) == 0) {+ fprintf(stderr, "\033[33mWARNING: No model file provided. Skipping this test. Set LLAMACPP_TEST_MODELFILE=<gguf_model_path> to silence this warning and run this test.\n\033[0m");+ exit(EXIT_SUCCESS);+ }++ return path;+}+common_context_seq_rm_type common_context_can_seq_rm(llama_context * ctx) {auto * mem = llama_get_memory(ctx);if (mem == nullptr) {diff --git a/common/common.h b/common/common.hindex 14889193d9..919c0ea103 100644--- a/common/common.h+++ b/common/common.h@@ -930,6 +930,9 @@ void common_set_adapter_lora(struct llama_context * ctx, std::vector<common_adap// model endpoint from envstd::string common_get_model_endpoint();+// for testing purposes+char * common_get_model_or_exit(int, char*[]);+//// Context utils//diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txtindex 805b744726..881e55c75a 100644--- a/tests/CMakeLists.txt+++ b/tests/CMakeLists.txt@@ -87,7 +87,7 @@ function(llama_build_and_test source)set(multiValueArgs ARGS)cmake_parse_arguments(LLAMA_TEST "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})- set(TEST_SOURCES ${source} ${LLAMA_TEST_UNPARSED_ARGUMENTS} get-model.cpp)+ set(TEST_SOURCES ${source} ${LLAMA_TEST_UNPARSED_ARGUMENTS})if (NOT DEFINED LLAMA_TEST_LABEL)set(LLAMA_TEST_LABEL "main")@@ -148,7 +148,7 @@ if (LLAMA_LLGUIDANCE)llama_build_and_test(test-grammar-llguidance.cpp ARGS ${PROJECT_SOURCE_DIR}/models/ggml-vocab-llama-bpe.gguf)endif ()-llama_build(test-recurrent-state-rollback.cpp get-model.cpp)+llama_build(test-recurrent-state-rollback.cpp)if (NOT WIN32 OR NOT BUILD_SHARED_LIBS)# these tests are disabled on Windows because they use internal functions not exported with LLAMA_API (when building with shared libraries)@@ -279,8 +279,9 @@ llama_build_and_test(test-save-load-state.cpp LABEL "model" ARGS -m "${MODEL_DESset_tests_properties(test-save-load-state PROPERTIES FIXTURES_REQUIRED test-download-model)if (APPLE)- llama_build(test-rset-release.cpp get-model.cpp)+ llama_build(test-rset-release.cpp)endif()+if (NOT GGML_BACKEND_DL)# these tests use the backends directly and cannot be built with dynamic loadingllama_build_and_test(test-barrier.cpp)diff --git a/tests/get-model.cpp b/tests/get-model.cppdeleted file mode 100644index 4edb685f0f..0000000000--- a/tests/get-model.cpp+++ /dev/null@@ -1,21 +0,0 @@-#include <cstdio>-#include <cstdlib>-#include <cstring>--#include "get-model.h"--char * get_model_or_exit(int argc, char *argv[]) {- char * model_path;- if (argc > 1) {- model_path = argv[1];-- } else {- model_path = getenv("LLAMACPP_TEST_MODELFILE");- if (!model_path || strlen(model_path) == 0) {- fprintf(stderr, "\033[33mWARNING: No model file provided. Skipping this test. Set LLAMACPP_TEST_MODELFILE=<gguf_model_path> to silence this warning and run this test.\n\033[0m");- exit(EXIT_SUCCESS);- }- }-- return model_path;-}diff --git a/tests/get-model.h b/tests/get-model.hdeleted file mode 100644index 81a3a0fefd..0000000000--- a/tests/get-model.h+++ /dev/null@@ -1,2 +0,0 @@-#pragma once-char * get_model_or_exit(int, char*[]);diff --git a/tests/snapshots/qwen3.5-27b.schema b/tests/snapshots/qwen3.6-27b.schemasimilarity index 100%rename from tests/snapshots/qwen3.5-27b.schemarename to tests/snapshots/qwen3.6-27b.schemadiff --git a/tests/test-autorelease.cpp b/tests/test-autorelease.cppindex ca87c56a8f..370428809f 100644--- a/tests/test-autorelease.cpp+++ b/tests/test-autorelease.cpp@@ -1,15 +1,13 @@// ref: https://github.com/ggml-org/llama.cpp/issues/4952#issuecomment-1892864763-#include <cstdio>-#include <string>#include <thread>#include "llama.h"-#include "get-model.h"+#include "common.h"// This creates a new context inside a pthread and then tries to exit cleanly.int main(int argc, char ** argv) {- auto * model_path = get_model_or_exit(argc, argv);+ auto * model_path = common_get_model_or_exit(argc, argv);std::thread([&model_path]() {llama_backend_init();diff --git a/tests/test-backend-sampler.cpp b/tests/test-backend-sampler.cppindex 61ddf91fea..c24076e313 100644--- a/tests/test-backend-sampler.cpp+++ b/tests/test-backend-sampler.cpp@@ -1,7 +1,6 @@#include "ggml.h"#include "llama.h"#include "llama-cpp.h"-#include "get-model.h"#include "common.h"#ifdef NDEBUG@@ -1136,7 +1135,7 @@ int main(int argc, char ** argv) {test_args args = parse_cli(argc, argv);if (args.model.empty()) {- args.model = get_model_or_exit(1, argv);+ args.model = common_get_model_or_exit(1, argv);}{diff --git a/tests/test-model-load-cancel.cpp b/tests/test-model-load-cancel.cppindex ecc3022711..f8139b26d7 100644--- a/tests/test-model-load-cancel.cpp+++ b/tests/test-model-load-cancel.cpp@@ -1,10 +1,10 @@#include "llama.h"-#include "get-model.h"+#include "common.h"#include <cstdlib>int main(int argc, char *argv[] ) {- auto * model_path = get_model_or_exit(argc, argv);+ auto * model_path = common_get_model_or_exit(argc, argv);auto * file = fopen(model_path, "r");if (file == nullptr) {fprintf(stderr, "no model at '%s' found\n", model_path);diff --git a/tests/test-quant-type-selection.cpp b/tests/test-quant-type-selection.cppindex 3c8983360e..9a5f5e53e1 100644--- a/tests/test-quant-type-selection.cpp+++ b/tests/test-quant-type-selection.cpp@@ -216,18 +216,18 @@ static std::string snapshot_file_from_name(const std::string & name) {}static const remote_model_spec model_specs[] = {- { "ggml-org/Qwen3-0.6B-GGUF", "Q8_0" },- { "ggml-org/GLM-4.6V-GGUF", "Q8_0" },- { "ggml-org/Step-3.5-Flash-GGUF", "Q4_K" },- { "ggml-org/Qwen3-Coder-Next-GGUF", "Q8_0" },- { "ggml-org/Qwen3-14B-GGUF", "Q8_0" },- { "ggml-org/Nemotron-Nano-3-30B-A3B-GGUF", "Q8_0" },- { "ggml-org/gpt-oss-120b-GGUF", "mxfp4" },- { "ggml-org/gemma-3-4b-it-GGUF", "Q8_0" },- { "bartowski/Meta-Llama-3.1-70B-Instruct-GGUF", "Q4_K_M" },- { "bartowski/deepseek-ai_DeepSeek-V3.1-GGUF", "IQ1_M" },- { "bartowski/Qwen_Qwen3.5-397B-A17B-GGUF", "IQ1_S" }, // TODO: swap with ggml-org if/when it's released- { "bartowski/Qwen_Qwen3.5-27B-GGUF", "Q8_0" }, // TODO: swap with ggml-org if/when it's released+ { "ggml-org/Qwen3-0.6B-GGUF", "Q8_0" },+ { "ggml-org/GLM-4.6V-GGUF", "Q8_0" },+ { "ggml-org/Step-3.5-Flash-GGUF", "Q4_K" },+ { "ggml-org/Qwen3-Coder-Next-GGUF", "Q8_0" },+ { "ggml-org/Qwen3-14B-GGUF", "Q8_0" },+ { "ggml-org/NVIDIA-Nemotron-Nano-3-30B-A3B-GGUF", "Q8_0" },+ { "ggml-org/gpt-oss-120b-GGUF", "mxfp4" },+ { "ggml-org/gemma-3-4b-it-GGUF", "Q8_0" },+ { "bartowski/Meta-Llama-3.1-70B-Instruct-GGUF", "Q4_K_M" },+ { "bartowski/deepseek-ai_DeepSeek-V3.1-GGUF", "IQ1_M" },+ //{ "bartowski/Qwen_Qwen3.5-397B-A17B-GGUF", "IQ1_S" }, // TODO: swap with ggml-org if/when it's released+ { "ggml-org/Qwen3.6-27B-GGUF", "Q8_0" },};static const int n_model_specs = (int) (sizeof(model_specs) / sizeof(model_specs[0]));diff --git a/tests/test-rset-release.cpp b/tests/test-rset-release.cppindex bf03c5e8bd..c60801c115 100644--- a/tests/test-rset-release.cpp+++ b/tests/test-rset-release.cpp@@ -3,14 +3,14 @@// thus, this test is not run by default// example model to run with: google/gemma-4-E4B-it-qat-q4_0-gguf+#include "llama.h"+#include "common.h"+#include <cstdint>#include <mach/mach.h>#include <mach/mach_host.h>#include <unistd.h>-#include "llama.h"-#include "get-model.h"-static uint64_t wired_memory() {vm_statistics64_data_t vmstat;mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;@@ -21,7 +21,7 @@ static uint64_t wired_memory() {}int main(int argc, char ** argv) {- auto * model_path = get_model_or_exit(argc, argv);+ auto * model_path = common_get_model_or_exit(argc, argv);llama_backend_init();