Skip to content

Commit 5c42d3a

Browse files
committed
tests: Very basic test parsing to run individual tests in test-memory
This may be too much infrastructure for a single unit test, but it makes it a lot easier to complex single tests without getting lost in the noice of the other tests that already work. Branch: HybridCache Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
1 parent 9d0b137 commit 5c42d3a

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

tests/test-memory.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*------------------------------------------------------------------------------
2+
* Unit tests for llama-memory.h and derived memory implementations. It contains
3+
* a number of tests which can be run all together or separately.
4+
*
5+
* USAGE: ./bin/test-memory <test_name1> <test_name2>
6+
*
7+
* When adding a new test, do the following:
8+
*
9+
* 1. Add the new test_<memory_type>_description function under the
10+
* appropriate memory type section
11+
*
12+
* 2. Add `RUN_TEST(test_<memory_type>_description);` to main
13+
*----------------------------------------------------------------------------*/
14+
115
#include "../src/llama-arch.h"
216
#include "../src/llama-hparams.h"
317
#include "../src/llama-impl.h"
@@ -61,13 +75,22 @@ struct log_scope {
6175
}
6276
};
6377

64-
#define LOG_SCOPE() log_scope __log_scope(__func__)
78+
#define RUN_TEST(test_name) \
79+
do { \
80+
bool run_test = argc < 2; \
81+
std::vector<std::string> args(argv + 1, argv + argc); \
82+
if (std::find(args.begin(), args.end(), #test_name) != args.end()) \
83+
run_test = true; \
84+
if (run_test) { \
85+
log_scope __log_scope(#test_name); \
86+
test_name(); \
87+
} \
88+
} while (0)
6589

6690
/*- Unified Cache ------------------------------------------------------------*/
6791

6892
/* Test that the unified cache can be constructed and destructed safely */
6993
static void test_llama_kv_cache_unified_constructor() {
70-
LOG_SCOPE();
7194
auto model = _make_model();
7295
llama_kv_cache_unified cache(
7396
/* model */ *model,
@@ -84,7 +107,6 @@ static void test_llama_kv_cache_unified_constructor() {
84107

85108
/* Test that the recurrent cache can be constructed and destructed safely */
86109
static void test_llama_kv_cache_recurrent_constructor() {
87-
LOG_SCOPE();
88110
auto model = _make_model(LLM_ARCH_MAMBA);
89111
llama_kv_cache_recurrent cache(
90112
/* model */ *model,
@@ -99,7 +121,6 @@ static void test_llama_kv_cache_recurrent_constructor() {
99121

100122
/* Test that the hybrid cache can be constructed and destructed safely */
101123
static void test_llama_kv_cache_hybrid_constructor() {
102-
LOG_SCOPE();
103124
auto model = _make_model(
104125
/* arch =*/ LLM_ARCH_LLAMA,
105126
/* n_layer =*/ 4,
@@ -159,12 +180,13 @@ static void test_llama_kv_cache_hybrid_constructor() {
159180

160181
/*- Main ---------------------------------------------------------------------*/
161182

162-
int main() {
183+
int main(int argc, char* argv[]) {
163184
// Unified Cache Tests
164-
test_llama_kv_cache_unified_constructor();
185+
RUN_TEST(test_llama_kv_cache_unified_constructor);
186+
RUN_TEST(test_llama_kv_cache_unified_single_seq);
165187
// Recurrent Cache Tests
166-
test_llama_kv_cache_recurrent_constructor();
188+
RUN_TEST(test_llama_kv_cache_recurrent_constructor);
167189
// Hybrid Cache Tests
168-
test_llama_kv_cache_hybrid_constructor();
190+
RUN_TEST(test_llama_kv_cache_hybrid_constructor);
169191
return 0;
170192
}

0 commit comments

Comments
 (0)