From 39ace3668c3c7cffec68d5fd124cb31b60793160 Mon Sep 17 00:00:00 2001 From: Cebtenzzre Date: Mon, 28 Aug 2023 01:57:57 -0400 Subject: [PATCH 1/4] tests : add a C compliance test --- Makefile | 3 +++ tests/CMakeLists.txt | 5 +++++ tests/test-c.c | 3 +++ 3 files changed, 11 insertions(+) create mode 100644 tests/test-c.c diff --git a/Makefile b/Makefile index a3400e491a0c1..a75c4d9898715 100644 --- a/Makefile +++ b/Makefile @@ -468,3 +468,6 @@ tests/test-sampling: tests/test-sampling.cpp build-info.h ggml.o llama.o common. tests/test-tokenizer-0: tests/test-tokenizer-0.cpp build-info.h ggml.o llama.o common.o $(OBJS) $(CXX) $(CXXFLAGS) $(filter-out %.txt,$^) -o $@ $(LDFLAGS) + +tests/test-c.o: tests/test-c.c llama.h + $(CC) $(CFLAGS) -c $(filter-out %.h,$^) -o $@ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ca1f39d31b081..483210d7b8906 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,3 +37,8 @@ llama_build_and_test_executable(test-grammar-parser.cpp) llama_build_and_test_executable(test-llama-grammar.cpp) llama_build_and_test_executable(test-grad0.cpp) # SLOW # llama_build_and_test_executable(test-opt.cpp) # SLOW + +# dummy executable - not installed +get_filename_component(TEST_TARGET test-c.c NAME_WE) +add_executable(${TEST_TARGET} test-c.c) +target_link_libraries(${TEST_TARGET} PRIVATE llama) diff --git a/tests/test-c.c b/tests/test-c.c new file mode 100644 index 0000000000000..a05071080a1df --- /dev/null +++ b/tests/test-c.c @@ -0,0 +1,3 @@ +#include "llama.h" + +int main(void) {} From 59fa94e44b2fce5856c56abc5867ad72c05f7812 Mon Sep 17 00:00:00 2001 From: Cebtenzzre Date: Mon, 28 Aug 2023 02:14:07 -0400 Subject: [PATCH 2/4] make : build C compliance test by default --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a75c4d9898715..8f9fe920efb5c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Define the default target now so that it is always the first target -BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch convert-llama2c-to-ggml simple server embd-input-test gguf llama-bench +BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch convert-llama2c-to-ggml simple server embd-input-test gguf llama-bench tests/test-c.o # Binaries only useful for tests 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 From 8445b8767f5fff9d736027aea79c7fe7c1b7177d Mon Sep 17 00:00:00 2001 From: Cebtenzzre Date: Mon, 28 Aug 2023 02:22:40 -0400 Subject: [PATCH 3/4] make : fix clean and make sure C test fails on clang --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8f9fe920efb5c..477b0ac68fdd1 100644 --- a/Makefile +++ b/Makefile @@ -369,7 +369,7 @@ libllama.so: llama.o ggml.o $(OBJS) $(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS) clean: - rm -vf *.o *.so *.dll main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state server simple vdot train-text-from-scratch convert-llama2c-to-ggml embd-input-test gguf llama-bench build-info.h $(TEST_TARGETS) + rm -vf *.o tests/*.o *.so *.dll main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state server simple vdot train-text-from-scratch convert-llama2c-to-ggml embd-input-test gguf llama-bench build-info.h $(TEST_TARGETS) # # Examples @@ -470,4 +470,4 @@ tests/test-tokenizer-0: tests/test-tokenizer-0.cpp build-info.h ggml.o llama.o c $(CXX) $(CXXFLAGS) $(filter-out %.txt,$^) -o $@ $(LDFLAGS) tests/test-c.o: tests/test-c.c llama.h - $(CC) $(CFLAGS) -c $(filter-out %.h,$^) -o $@ + $(CC) $(CFLAGS) -Werror=implicit-int -c $(filter-out %.h,$^) -o $@ From a9ed8652058ef456cf6b4cc1179df235c33dc034 Mon Sep 17 00:00:00 2001 From: Cebtenzzre Date: Tue, 29 Aug 2023 11:28:22 -0400 Subject: [PATCH 4/4] make : move -Werror=implicit-int to CFLAGS --- CMakeLists.txt | 1 + Makefile | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1eae2d670c0be..d6c1b3b33d6a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -402,6 +402,7 @@ if (LLAMA_ALL_WARNINGS) -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes + -Werror=implicit-int ) set(cxx_flags -Wall diff --git a/Makefile b/Makefile index 11a5e11677f58..44e68b7fc034f 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ endif # warnings CFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wdouble-promotion -Wshadow -Wstrict-prototypes -Wpointer-arith \ - -Wmissing-prototypes + -Wmissing-prototypes -Werror=implicit-int CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wno-multichar # OS specific @@ -491,4 +491,4 @@ tests/test-tokenizer-1: tests/test-tokenizer-1.cpp build-info.h ggml.o llama.o c $(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS) tests/test-c.o: tests/test-c.c llama.h - $(CC) $(CFLAGS) -Werror=implicit-int -c $(filter-out %.h,$^) -o $@ + $(CC) $(CFLAGS) -c $(filter-out %.h,$^) -o $@