Skip to content

Commit 8494089

Browse files
authored
tests : add a C compliance test (#2848)
* tests : add a C compliance test * make : build C compliance test by default * make : fix clean and make sure C test fails on clang * make : move -Werror=implicit-int to CFLAGS
1 parent 06abf8e commit 8494089

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ if (LLAMA_ALL_WARNINGS)
402402
-Wstrict-prototypes
403403
-Wpointer-arith
404404
-Wmissing-prototypes
405+
-Werror=implicit-int
405406
)
406407
set(cxx_flags
407408
-Wall

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Define the default target now so that it is always the first target
2-
BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch convert-llama2c-to-ggml simple save-load-state server embd-input-test gguf llama-bench baby-llama beam_search
2+
BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch convert-llama2c-to-ggml simple save-load-state server embd-input-test gguf llama-bench baby-llama beam_search tests/test-c.o
33

44
# Binaries only useful for tests
55
TEST_TARGETS = tests/test-llama-grammar tests/test-grammar-parser tests/test-double-float tests/test-grad0 tests/test-opt tests/test-quantize-fns tests/test-quantize-perf tests/test-sampling tests/test-tokenizer-0-llama tests/test-tokenizer-0-falcon tests/test-tokenizer-1
@@ -64,7 +64,7 @@ endif
6464

6565
# warnings
6666
CFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith \
67-
-Wmissing-prototypes
67+
-Wmissing-prototypes -Werror=implicit-int
6868
CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wno-multichar
6969

7070
# OS specific
@@ -369,7 +369,7 @@ libllama.so: llama.o ggml.o $(OBJS)
369369
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
370370

371371
clean:
372-
rm -vf *.o *.so *.dll benchmark-matmult build-info.h $(BUILD_TARGETS) $(TEST_TARGETS)
372+
rm -vf *.o tests/*.o *.so *.dll benchmark-matmult build-info.h $(BUILD_TARGETS) $(TEST_TARGETS)
373373

374374
#
375375
# Examples
@@ -489,3 +489,6 @@ tests/test-tokenizer-0-llama: tests/test-tokenizer-0-llama.cpp build-info.h ggml
489489

490490
tests/test-tokenizer-1: tests/test-tokenizer-1.cpp build-info.h ggml.o llama.o common.o $(OBJS)
491491
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
492+
493+
tests/test-c.o: tests/test-c.c llama.h
494+
$(CC) $(CFLAGS) -c $(filter-out %.h,$^) -o $@

tests/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ llama_build_and_test_executable(test-grammar-parser.cpp)
3737
llama_build_and_test_executable(test-llama-grammar.cpp)
3838
llama_build_and_test_executable(test-grad0.cpp) # SLOW
3939
# llama_build_and_test_executable(test-opt.cpp) # SLOW
40+
41+
# dummy executable - not installed
42+
get_filename_component(TEST_TARGET test-c.c NAME_WE)
43+
add_executable(${TEST_TARGET} test-c.c)
44+
target_link_libraries(${TEST_TARGET} PRIVATE llama)

tests/test-c.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "llama.h"
2+
3+
int main(void) {}

0 commit comments

Comments
 (0)