diff --git a/Makefile b/Makefile index da68ee555..6bee78a5c 100644 --- a/Makefile +++ b/Makefile @@ -156,14 +156,6 @@ endif ifneq ($(BUCK),no) BUILD_SYSTEMS_TESTS += buck genrule buck_javac_jar -# Introduce the dependency only if the two tests are going to be built in parallel, so that they do -# not run in parallel (otherwise Buck has a bad time). This works by checking if one of the main -# testing targets was passed as a goal on the command line. -ifneq ($(filter build_systems_tests config_tests test test-replace,${MAKECMDGOALS}),) -build_genrule_print: build_buck_print -build_genrule_replace: build_buck_replace -build_genrule_test: build_buck_test -endif endif ifneq ($(MVN),no) BUILD_SYSTEMS_TESTS += mvn @@ -172,13 +164,6 @@ endif ifeq ($(BUILD_C_ANALYZERS)+$(BUILD_JAVA_ANALYZERS),yes+yes) BUILD_SYSTEMS_TESTS += make utf8_in_pwd waf -# the waf test and the make test run the same `make` command; use the same trick as for -# "build_buck_test" to prevent make from running them in parallel -ifneq ($(filter build_systems_tests config_tests test test-replace,${MAKECMDGOALS}),) -build_waf_replace: build_make_replace -build_waf_print: build_make_print -build_waf_test: build_make_test -endif endif ifeq ($(IS_INFER_RELEASE),no) diff --git a/Makefile.config b/Makefile.config index a04262ad7..d94f38d1d 100644 --- a/Makefile.config +++ b/Makefile.config @@ -197,3 +197,5 @@ endif # print any variable for Makefile debugging print-%: $(QUIET)echo '$*=$($*)' + +TESTLOCK = $(INFER_DIR)/tests/testlock.py diff --git a/infer/tests/build_systems/buck/Makefile b/infer/tests/build_systems/buck/Makefile index 48e5e0262..4863ff554 100644 --- a/infer/tests/build_systems/buck/Makefile +++ b/infer/tests/build_systems/buck/Makefile @@ -20,12 +20,12 @@ $(OBJECTS): $(JAVA_SOURCE_FILES) $(QUIET)cd $(ROOT_DIR) && \ $(call silent_on_success,Compiling Buck Java tests,\ INFER_BIN=$(INFER_BIN) \ - $(BUCK) build --deep --no-cache $(BUCK_TARGET)) + $(TESTLOCK) $(BUCK) build --deep --no-cache $(BUCK_TARGET)) infer-out/report.json: $(JAVA_DEPS) $(JAVA_SOURCE_FILES) $(QUIET)cd $(ROOT_DIR) && \ - $(REMOVE_DIR) buck-out && \ + $(TESTLOCK) $(REMOVE_DIR) buck-out && \ $(call silent_on_success,Testing Buck Java integration,\ INFER_BIN=$(INFER_BIN) \ - $(INFER_BIN) $(INFER_OPTIONS) --results-dir $(CURDIR)/infer-out -- \ + $(TESTLOCK) $(INFER_BIN) $(INFER_OPTIONS) --results-dir $(CURDIR)/infer-out -- \ $(BUCK) build --deep --no-cache $(BUCK_TARGET)) diff --git a/infer/tests/build_systems/buck_javac_jar/Makefile b/infer/tests/build_systems/buck_javac_jar/Makefile index e06f63737..2b37f4465 100644 --- a/infer/tests/build_systems/buck_javac_jar/Makefile +++ b/infer/tests/build_systems/buck_javac_jar/Makefile @@ -17,10 +17,10 @@ CLEAN_EXTRA = buck-out include $(TESTS_DIR)/infer.make $(OBJECTS): $(SOURCES) $(BUCKCONFIG) - $(BUCK) build --config tools.javac_jar= $(TARGET) + $(TESTLOCK) $(BUCK) build --config tools.javac_jar= $(TARGET) infer-out/report.json: $(JAVA_DEPS) $(SOURCES) $(BUCKCONFIG) - $(REMOVE_DIR) buck-out && \ + $(TESTLOCK) $(REMOVE_DIR) buck-out && \ $(call silent_on_success,Testing Buck Java integration with javac_jar,\ INFER_BIN=$(INFER_BIN) \ - $(INFER_BIN) $(INFER_OPTIONS) -- $(BUCK) build $(TARGET)) + $(TESTLOCK) $(INFER_BIN) $(INFER_OPTIONS) -- $(BUCK) build $(TARGET)) diff --git a/infer/tests/build_systems/genrule/Makefile b/infer/tests/build_systems/genrule/Makefile index b68c31efb..4a422df3b 100644 --- a/infer/tests/build_systems/genrule/Makefile +++ b/infer/tests/build_systems/genrule/Makefile @@ -22,7 +22,7 @@ include $(TESTS_DIR)/infer.make $(OBJECTS): $(JAVA_SOURCE_FILES) $(QUIET)cd $(ROOT_DIR) && \ $(call silent_on_success,Compiling Buck genrule for Java sources,\ - $(BUCK) build --no-cache $(BUCK_TARGET)) + $(TESTLOCK) $(BUCK) build --no-cache $(BUCK_TARGET)) .PHONY: genrule genrule: $(JSON_REPORT) @@ -30,9 +30,9 @@ genrule: $(JSON_REPORT) $(JSON_REPORT): $(JAVA_DEPS) $(JAVA_SOURCE_FILES) $(MAKEFILE_LIST) $(QUIET)cd $(ROOT_DIR) && \ - $(REMOVE_DIR) buck-out && \ + $(TESTLOCK) $(REMOVE_DIR) buck-out && \ $(call silent_on_success,Testing Buck genrule for Java integration,\ - INFER_BIN="$(INFER_BIN)" PROJECT_ROOT="$(PWD)" $(BUCK) build --no-cache $(INFER_TARGET)) + INFER_BIN="$(INFER_BIN)" PROJECT_ROOT="$(PWD)" $(TESTLOCK) $(BUCK) build --no-cache $(INFER_TARGET)) $(QUIET)touch $@ report.json: $(JSON_REPORT) $(MAKEFILE_LIST) diff --git a/infer/tests/build_systems/make/Makefile b/infer/tests/build_systems/make/Makefile index 829abda98..2a1d553f8 100644 --- a/infer/tests/build_systems/make/Makefile +++ b/infer/tests/build_systems/make/Makefile @@ -14,6 +14,6 @@ include $(TESTS_DIR)/clang.make infer-out/report.json: $(CLANG_DEPS) $(SOURCES) $(HEADERS) $(QUIET)$(call silent_on_success,Testing make clang and javac integration,\ - $(INFER_BIN) --dump-duplicate-symbols --project-root $(TESTS_DIR) -- \ + $(TESTLOCK) $(INFER_BIN) --dump-duplicate-symbols --project-root $(TESTS_DIR) -- \ make -C ../codetoanalyze/make clean all) $(QUIET)$(call check_no_duplicates,infer-out/duplicates.txt) diff --git a/infer/tests/build_systems/waf/Makefile b/infer/tests/build_systems/waf/Makefile index faa00726f..6b063160f 100644 --- a/infer/tests/build_systems/waf/Makefile +++ b/infer/tests/build_systems/waf/Makefile @@ -14,8 +14,7 @@ SOURCES = $(wildcard ../codetoanalyze/make/*.c) include $(TESTS_DIR)/clang.make infer-out/report.json: $(CLANG_DEPS) $(SOURCES) - $(QUIET)$(MAKE) -C ../codetoanalyze/make clean - $(QUIET)cd ../codetoanalyze/make && \ - $(call silent_on_success,Testing Waf clang integration,\ - $(INFER_BIN) --dump-duplicate-symbols --results-dir $(CUR_DIR)/$(@D) -- \ - ./waf) + $(QUIET)$(call silent_on_success,Testing Waf clang integration,\ + $(TESTLOCK) sh -c "$(MAKE) -C ../codetoanalyze/make clean && \ + cd ../codetoanalyze/make && $(INFER_BIN) --dump-duplicate-symbols \ + --results-dir $(CUR_DIR)/$(@D) -- ./waf") diff --git a/infer/tests/testlock.mutex b/infer/tests/testlock.mutex new file mode 100644 index 000000000..e69de29bb diff --git a/infer/tests/testlock.py b/infer/tests/testlock.py new file mode 100755 index 000000000..6cefc5f50 --- /dev/null +++ b/infer/tests/testlock.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python2.7 + +# Copyright (c) 2019-present, Facebook, Inc. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +import os +import sys +import fcntl +import subprocess + +TESTS_DIR = os.path.dirname(os.path.realpath(__file__)) +LOCKFILE = os.path.join(TESTS_DIR, 'testlock.mutex') + +args = sys.argv[1:] + +with open(LOCKFILE, 'r') as lockfile: + fd = lockfile.fileno() + + fcntl.flock(fd, fcntl.LOCK_EX) + try: + subprocess.call(args) + finally: + fcntl.flock(fd, fcntl.LOCK_UN)