From c9bac51b812ae1aae221ef6b9abe20d329994cb2 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 3 Nov 2016 09:46:05 -0700 Subject: [PATCH] [tests] make clang tests Makefile more functional Summary: This makes the tests depend on much fewer phony targets, thus reducing the need to rerun the tests when nothing has changed. Reviewed By: jberdine Differential Revision: D4118457 fbshipit-source-id: 664b6e3 --- .gitignore | 1 + infer/tests/clang.make | 46 ++++++++++++++++ infer/tests/codetoanalyze/Makefile.clang | 28 ---------- infer/tests/codetoanalyze/c/errors/Makefile | 18 +++---- .../tests/codetoanalyze/cpp/checkers/Makefile | 16 ++---- infer/tests/codetoanalyze/cpp/errors/Makefile | 46 ++++++++-------- .../tests/codetoanalyze/cpp/quandary/Makefile | 16 ++---- .../tests/codetoanalyze/objc/errors/Makefile | 52 +++++++++++++------ .../codetoanalyze/objc/errors/issues.exp | 1 - .../tests/codetoanalyze/objc/linters/Makefile | 19 +++---- .../codetoanalyze/objcpp/linters/Makefile | 17 ++---- 11 files changed, 134 insertions(+), 126 deletions(-) create mode 100644 infer/tests/clang.make delete mode 100644 infer/tests/codetoanalyze/Makefile.clang diff --git a/.gitignore b/.gitignore index 9d6da0491..e58e89e0b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ *.rej *.start *.exp.test +duplicates.txt infer/tests/codetoanalyze/java/*/codetoanalyze # Directories generated by Ocamlbuild diff --git a/infer/tests/clang.make b/infer/tests/clang.make new file mode 100644 index 000000000..e67b14196 --- /dev/null +++ b/infer/tests/clang.make @@ -0,0 +1,46 @@ +# Copyright (c) 2016 - present Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +ROOT_DIR = $(TESTS_DIR)/../.. +include $(ROOT_DIR)/Makefile.config + +INFERPRINT_OPTIONS = --issues-tests + +OBJECTS = $(foreach source,$(SOURCES),$(basename $(source)).o) + +CLEAN_EXTRA = + +default: compile + +infer-out/report.json: $(CLANG_DEPS) $(SOURCES) + $(call silent_on_success,\ + $(INFER_BIN) --check-duplicate-symbols $(INFER_OPTIONS) -a $(ANALYZER) -- clang $(CLANG_OPTIONS) $(SOURCES) 2>duplicates.txt) + grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 + +issues.exp.test: $(INFERPRINT_BIN) infer-out/report.json + $(INFERPRINT_BIN) -q -a $(ANALYZER) $(INFERPRINT_OPTIONS) issues.exp.test + LC_ALL=C sort -t, -k1,1 -k2,2 -k3n,3 -o issues.exp.test issues.exp.test + +$(OBJECTS): $(SOURCES) + clang $(CLANG_OPTIONS) $(SOURCES) + +.PHONY: compile +compile: $(OBJECTS) + +.PHONY: analyze +analyze: infer-out/report.json + +.PHONY: print +print: issues.exp.test + +.PHONY: test +test: issues.exp.test + diff -u issues.exp issues.exp.test + +.PHONY: clean +clean: + $(REMOVE_DIR) duplicates.txt issues.exp.test infer-out $(OBJECTS) $(CLEAN_EXTRA) diff --git a/infer/tests/codetoanalyze/Makefile.clang b/infer/tests/codetoanalyze/Makefile.clang deleted file mode 100644 index a93186e03..000000000 --- a/infer/tests/codetoanalyze/Makefile.clang +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) 2016 - present Facebook, Inc. -# All rights reserved. -# -# This source code is licensed under the BSD style license found in the -# LICENSE file in the root directory of this source tree. An additional grant -# of patent rights can be found in the PATENTS file in the same directory. - -ROOT_DIR = ../../../../.. -include $(ROOT_DIR)/Makefile.config - -ANALYZER = infer -INFERPRINT_OPTIONS = --issues-tests - -CLEAN_EXTRA = - -default: compile - -print: analyze - $(INFERPRINT_BIN) -q -a $(ANALYZER) $(INFERPRINT_OPTIONS) issues.exp.test - LC_ALL=C sort -t, -k1,1 -k2,2 -k3n,3 -o issues.exp.test issues.exp.test - -test: analyze print - $(MAKE) clean - diff -u issues.exp issues.exp.test - rm issues.exp.test - -clean: - rm -rf *.o infer-out $(CLEAN_EXTRA) duplicates.txt diff --git a/infer/tests/codetoanalyze/c/errors/Makefile b/infer/tests/codetoanalyze/c/errors/Makefile index 8c86b41d6..4a53dd281 100644 --- a/infer/tests/codetoanalyze/c/errors/Makefile +++ b/infer/tests/codetoanalyze/c/errors/Makefile @@ -5,16 +5,12 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -include ../../Makefile.clang +TESTS_DIR = ../../.. +include $(TESTS_DIR)/clang.make -OPTIONS = -c +ANALYZER = infer +CLANG_OPTIONS = -c +INFER_OPTIONS = --report-custom-error --developer-mode -FILES = \ - */*.c \ - -compile: - clang $(OPTIONS) $(FILES) - -analyze: - $(call silent_on_success,$(INFER_BIN) -a $(ANALYZER) --report-custom-error --check-duplicate-symbols --developer-mode -- clang $(OPTIONS) $(FILES) 2>duplicates.txt) - grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 +SOURCES = \ + $(wildcard */*.c) \ diff --git a/infer/tests/codetoanalyze/cpp/checkers/Makefile b/infer/tests/codetoanalyze/cpp/checkers/Makefile index b2643481b..ecfe43ddb 100644 --- a/infer/tests/codetoanalyze/cpp/checkers/Makefile +++ b/infer/tests/codetoanalyze/cpp/checkers/Makefile @@ -5,14 +5,15 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -include ../../Makefile.clang - -OPTIONS = -x c++ -std=c++11 -isystem$(MODELS_DIR)/cpp/include -isystem$(CLANG_INCLUDES)/c++/v1/ -c +TESTS_DIR = ../../.. +include $(TESTS_DIR)/clang.make ANALYZER = checkers +CLANG_OPTIONS = -x c++ -std=c++11 -isystem$(MODELS_DIR)/cpp/include -isystem$(CLANG_INCLUDES)/c++/v1/ -c +INFER_OPTIONS = --cxx --ml-buckets cpp INFERPRINT_OPTIONS = --issues-txt -FILES = \ +SOURCES = \ siof/const.cpp \ siof/const_use.cpp \ siof/pod_across_translation_units-1.cpp \ @@ -20,10 +21,3 @@ FILES = \ siof/pod_same_translation_unit.cpp \ siof/siof_across_translation_units-1.cpp \ siof/siof_across_translation_units-2.cpp \ - -compile: - clang $(OPTIONS) $(FILES) - -analyze: - $(INFER_BIN) -a $(ANALYZER) --cxx --ml-buckets cpp --check-duplicate-symbols -- clang $(OPTIONS) $(FILES) >/dev/null 2>duplicates.txt - grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 diff --git a/infer/tests/codetoanalyze/cpp/errors/Makefile b/infer/tests/codetoanalyze/cpp/errors/Makefile index ae69c4b37..876d6e4cb 100644 --- a/infer/tests/codetoanalyze/cpp/errors/Makefile +++ b/infer/tests/codetoanalyze/cpp/errors/Makefile @@ -5,36 +5,41 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -include ../../Makefile.clang +TESTS_DIR = ../../.. +include $(TESTS_DIR)/clang.make -OPTIONS = -x c++ -std=c++11 -isystem$(ROOT_DIR) -isystem$(CLANG_INCLUDES)/c++/v1/ -c +ANALYZER = infer -FILES = \ - c_tests/*.cpp \ +CLANG_OPTIONS = -x c++ -std=c++11 -isystem$(ROOT_DIR) -isystem$(CLANG_INCLUDES)/c++/v1/ -c + +INFER_OPTIONS = --cxx --ml-buckets cpp + +SOURCES = \ + $(wildcard c_tests/*.cpp) \ include_header/header.h \ include_header/include_templ.cpp \ - memory_leaks/*.cpp \ - models/*.cpp \ - npe/*.cpp \ - numeric/*.cpp \ - overwrite_attribute/*.cpp \ - resource_leaks/*.cpp \ - shared/attributes/*.cpp \ - shared/conditional/*.cpp \ + $(wildcard memory_leaks/*.cpp) \ + $(wildcard models/*.cpp) \ + $(wildcard npe/*.cpp) \ + $(wildcard numeric/*.cpp) \ + $(wildcard overwrite_attribute/*.cpp) \ + $(wildcard resource_leaks/*.cpp) \ + $(wildcard shared/attributes/*.cpp) \ + $(wildcard shared/conditional/*.cpp) \ shared/constructors/constructor_init.cpp \ shared/constructors/constructor_new.cpp \ shared/constructors/constructor_with_body.cpp \ shared/constructors/copy_move_constructor.cpp \ shared/constructors/temp_object.cpp \ shared/exceptions/Exceptions.cpp \ - shared/lambda/*.cpp \ + $(wildcard shared/lambda/*.cpp) \ shared/methods/conversion_operator.cpp \ shared/methods/static.cpp \ shared/namespace/function.cpp \ shared/namespace/global_variable.cpp \ shared/methods/virtual_methods.cpp \ shared/nestedoperators/var_decl_inside_if.cpp \ - shared/npe/*.cpp \ + $(wildcard shared/npe/*.cpp) \ shared/reference/reference_field.cpp \ shared/reference/reference_struct_e2e.cpp \ shared/reference/reference_type_e2e.cpp \ @@ -49,13 +54,6 @@ FILES = \ shared/types/struct_forward_declare.cpp \ shared/types/struct_pass_by_value.cpp \ shared/types/typeid_expr.cpp \ - smart_ptr/*.cpp \ - subtyping/*.cpp \ - vector/*.cpp \ - -compile: - clang $(OPTIONS) $(FILES) - -analyze: - $(call silent_on_success,$(INFER_BIN) -a $(ANALYZER) --cxx --ml-buckets cpp --check-duplicate-symbols -- clang $(OPTIONS) $(FILES) 2>duplicates.txt) - grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 + $(wildcard smart_ptr/*.cpp) \ + $(wildcard subtyping/*.cpp) \ + $(wildcard vector/*.cpp) \ diff --git a/infer/tests/codetoanalyze/cpp/quandary/Makefile b/infer/tests/codetoanalyze/cpp/quandary/Makefile index bc6e27a85..b6d2d79f6 100644 --- a/infer/tests/codetoanalyze/cpp/quandary/Makefile +++ b/infer/tests/codetoanalyze/cpp/quandary/Makefile @@ -5,20 +5,14 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -include ../../Makefile.clang - -OPTIONS = -x c++ -std=c++11 -isystem$(ROOT_DIR) -isystem$(CLANG_INCLUDES)/c++/v1/ -c +TESTS_DIR = ../../.. +include $(TESTS_DIR)/clang.make ANALYZER = quandary +CLANG_OPTIONS = -x c++ -std=c++11 -isystem$(ROOT_DIR) -isystem$(CLANG_INCLUDES)/c++/v1/ -c +INFER_OPTIONS = --cxx --ml-buckets cpp INFERPRINT_OPTIONS = --issues-txt -FILES = \ +SOURCES = \ basics.cpp \ execs.cpp \ - -compile: - clang $(OPTIONS) $(FILES) - -analyze: - $(call silent_on_success,$(INFER_BIN) -a $(ANALYZER) --cxx --ml-buckets cpp --check-duplicate-symbols -- clang $(OPTIONS) $(FILES) 2>duplicates.txt) - grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 diff --git a/infer/tests/codetoanalyze/objc/errors/Makefile b/infer/tests/codetoanalyze/objc/errors/Makefile index 6a22e7c02..ac9e345fb 100644 --- a/infer/tests/codetoanalyze/objc/errors/Makefile +++ b/infer/tests/codetoanalyze/objc/errors/Makefile @@ -5,18 +5,22 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -include ../../Makefile.clang +TESTS_DIR = ../../.. +include $(TESTS_DIR)/clang.make IPHONESIMULATOR_ISYSROOT_SUFFIX = /Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk XCODEROOT = $(shell xcode-select -p) -OPTIONS = -x objective-c \ +ANALYZER = infer +CLANG_OPTIONS = -x objective-c \ -isysroot $(XCODEROOT)$(IPHONESIMULATOR_ISYSROOT_SUFFIX) \ -mios-simulator-version-min=8.2 --target=x86_64-apple-darwin14 -c \ +CLEAN_EXTRA = infer-out-arc infer-out-all +INFER_OPTIONS = --cxx --check-duplicate-symbols -FILES = \ +SOURCES_DEFAULT = \ field_superclass/B.m \ memory_leaks_benchmark/FBViewExample.m \ memory_leaks_benchmark/MemoryLeakRaii.m \ @@ -47,7 +51,7 @@ FILES = \ taint/sources.m \ taint/viewController.m \ -FILES_BUCKET_ALL = \ +SOURCES_BUCKET_ALL = \ field_superclass/field.c \ global_const/global_const.m \ initialization/compound_literal.c \ @@ -71,7 +75,7 @@ FILES_BUCKET_ALL = \ shared/npe/npe_malloc.m \ warnings/ParameterNotNullableExample.m \ -FILES_ARC = \ +SOURCES_ARC = \ field_superclass/SubtypingExample.m \ initialization/struct_initlistexpr.c \ memory_leaks_benchmark/RetainReleaseExampleBucketingArc.m \ @@ -92,18 +96,36 @@ FILES_ARC = \ subtyping/KindOfClassExample.m \ variadic_methods/premature_nil_termination.m \ -compile: - clang $(OPTIONS) $(FILES) $(FILES_BUCKET_ALL) - clang $(OPTIONS) -fobjc-arc $(FILES_ARC) +SOURCES = $(SOURCES_DEFAULT) $(SOURCES_BUCKET_ALL) $(SOURCES_ARC) -CLEAN_EXTRA = infer-out-arc infer-out-all +OBJECTS_ARC = $(foreach source,$(SOURCES_ARC),$(basename $(source)).o) +OBJECTS_BUCKET_ALL = $(foreach source,$(SOURCES_BUCKET_ALL),$(basename $(source)).o) +OBJECTS_DEFAULT = $(foreach source,$(SOURCES_DEFAULT),$(basename $(source)).o) + +$(OBJECTS_ARC): $(SOURCES_ARC) + clang $(CLANG_OPTIONS) -fobjc-arc $< -o $@ + +$(OBJECTS_BASE) $(OBJECTS_BUCKETS_ALL): $(SOURCES_BASE) $(SOURCES_BUCKET_ALL) + clang $(CLANG_OPTIONS) $< -o $@ -analyze: - $(call silent_on_success,$(INFER_BIN) -a $(ANALYZER) --cxx --ml-buckets all --check-duplicate-symbols -o infer-out-all -- clang $(OPTIONS) $(FILES_BUCKET_ALL) 2>duplicates.txt) +infer-out-all/report.json: $(INFER_BIN) $(SOURCES_BUCKET_ALL) + $(call silent_on_success,\ + $(INFER_BIN) -a $(ANALYZER) $(INFER_OPTIONS) --ml-buckets all -o infer-out-all -- \ + clang $(CLANG_OPTIONS) $(SOURCES_BUCKET_ALL) 2>duplicates.txt) grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 - $(call silent_on_success,$(INFER_BIN) -a $(ANALYZER) --cxx --ml-buckets cf --check-duplicate-symbols -o infer-out -- clang $(OPTIONS) $(FILES) 2>duplicates.txt) + +infer-out-arc/report.json: $(INFER_BIN) $(SOURCES_ARC) + $(call silent_on_success,\ + $(INFER_BIN) -a $(ANALYZER) $(INFER_OPTIONS) --ml-buckets cf -o infer-out-arc -- \ + clang $(CLANG_OPTIONS) -fobjc-arc $(SOURCES_ARC) 2>duplicates.txt) grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 - $(call silent_on_success,$(INFER_BIN) -a $(ANALYZER) --cxx --ml-buckets cf --check-duplicate-symbols -o infer-out-arc -- clang $(OPTIONS) -fobjc-arc $(FILES_ARC) 2>duplicates.txt) + +infer-out-default/report.json: $(INFER_BIN) $(SOURCES_DEFAULT) + $(call silent_on_success,\ + $(INFER_BIN) -a $(ANALYZER) $(INFER_OPTIONS) --ml-buckets cf -o infer-out-default -- \ + clang $(CLANG_OPTIONS) $(SOURCES_DEFAULT) 2>duplicates.txt) grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 - cp infer-out-all/specs/* infer-out/specs - cp infer-out-arc/specs/* infer-out/specs + +infer-out/report.json: infer-out-all/report.json infer-out-arc/report.json infer-out-default/report.json + $(MKDIR_P) infer-out/specs + cp infer-out-{all,arc,default}/specs/* infer-out/specs diff --git a/infer/tests/codetoanalyze/objc/errors/issues.exp b/infer/tests/codetoanalyze/objc/errors/issues.exp index d8aed48c4..a1132408d 100644 --- a/infer/tests/codetoanalyze/objc/errors/issues.exp +++ b/infer/tests/codetoanalyze/objc/errors/issues.exp @@ -59,7 +59,6 @@ procdescs/main.c, call_nslog, 2, MEMORY_LEAK procdescs/main.c, call_nslog, 3, MEMORY_LEAK property/ExplicitIvarName.m, ExplicitIvarNameA_testDefaultName, 7, NULL_DEREFERENCE property/ExplicitIvarName.m, ExplicitIvarNameA_testExplicit, 6, NULL_DEREFERENCE -property/main.c, property_main, 2, MEMORY_LEAK property/main.c, property_main, 3, MEMORY_LEAK shared/assertions/NSAssert_example.m, NSAssert_addTarget:, 1, MEMORY_LEAK shared/assertions/NSAssert_example.m, NSAssert_initWithRequest:, 1, MEMORY_LEAK diff --git a/infer/tests/codetoanalyze/objc/linters/Makefile b/infer/tests/codetoanalyze/objc/linters/Makefile index f8b65bff9..bd33b56af 100644 --- a/infer/tests/codetoanalyze/objc/linters/Makefile +++ b/infer/tests/codetoanalyze/objc/linters/Makefile @@ -5,19 +5,12 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -include ../../Makefile.clang - -OPTIONS = -x objective-c -fobjc-arc -c +TESTS_DIR = ../../.. +include $(TESTS_DIR)/clang.make ANALYZER = linters +CLANG_OPTIONS = -x objective-c -fobjc-arc -c -FILES = \ - *.m \ - */*.m \ - -compile: - clang $(OPTIONS) $(FILES) - -analyze: - $(call silent_on_success,$(INFER_BIN) -a $(ANALYZER) --check-duplicate-symbols -- clang $(OPTIONS) $(FILES) 2>duplicates.txt) - grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 +SOURCES = \ + $(wildcard *.m) \ + $(wildcard */*.m) \ diff --git a/infer/tests/codetoanalyze/objcpp/linters/Makefile b/infer/tests/codetoanalyze/objcpp/linters/Makefile index 59ac64e32..1c89bbe9a 100644 --- a/infer/tests/codetoanalyze/objcpp/linters/Makefile +++ b/infer/tests/codetoanalyze/objcpp/linters/Makefile @@ -5,18 +5,11 @@ # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. -include ../../Makefile.clang - -OPTIONS = -x objective-c++ -std=c++11 -fobjc-arc -c +TESTS_DIR = ../../.. +include $(TESTS_DIR)/clang.make ANALYZER = linters +CLANG_OPTIONS = -x objective-c++ -std=c++11 -fobjc-arc -c -FILES = \ - */*.mm \ - -compile: - clang $(OPTIONS) $(FILES) - -analyze: - $(call silent_on_success,$(INFER_BIN) -a $(ANALYZER) --check-duplicate-symbols -- clang $(OPTIONS) $(FILES) 2>duplicates.txt) - grep "DUPLICATE_SYMBOLS" duplicates.txt; test $$? -ne 0 +SOURCES = \ + $(wildcard */*.mm) \