[infer][tests] avoid races in less hacky way

Reviewed By: jvillard

Differential Revision: D15555573

fbshipit-source-id: 40a9a0e31
master
Nikos Gorogiannis 6 years ago committed by Facebook Github Bot
parent 9b8a908ad3
commit 88d31a7a21

@ -156,14 +156,6 @@ endif
ifneq ($(BUCK),no) ifneq ($(BUCK),no)
BUILD_SYSTEMS_TESTS += buck genrule buck_javac_jar 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 endif
ifneq ($(MVN),no) ifneq ($(MVN),no)
BUILD_SYSTEMS_TESTS += mvn BUILD_SYSTEMS_TESTS += mvn
@ -172,13 +164,6 @@ endif
ifeq ($(BUILD_C_ANALYZERS)+$(BUILD_JAVA_ANALYZERS),yes+yes) ifeq ($(BUILD_C_ANALYZERS)+$(BUILD_JAVA_ANALYZERS),yes+yes)
BUILD_SYSTEMS_TESTS += make utf8_in_pwd waf 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 endif
ifeq ($(IS_INFER_RELEASE),no) ifeq ($(IS_INFER_RELEASE),no)

@ -197,3 +197,5 @@ endif
# print any variable for Makefile debugging # print any variable for Makefile debugging
print-%: print-%:
$(QUIET)echo '$*=$($*)' $(QUIET)echo '$*=$($*)'
TESTLOCK = $(INFER_DIR)/tests/testlock.py

@ -20,12 +20,12 @@ $(OBJECTS): $(JAVA_SOURCE_FILES)
$(QUIET)cd $(ROOT_DIR) && \ $(QUIET)cd $(ROOT_DIR) && \
$(call silent_on_success,Compiling Buck Java tests,\ $(call silent_on_success,Compiling Buck Java tests,\
INFER_BIN=$(INFER_BIN) \ 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) infer-out/report.json: $(JAVA_DEPS) $(JAVA_SOURCE_FILES)
$(QUIET)cd $(ROOT_DIR) && \ $(QUIET)cd $(ROOT_DIR) && \
$(REMOVE_DIR) buck-out && \ $(TESTLOCK) $(REMOVE_DIR) buck-out && \
$(call silent_on_success,Testing Buck Java integration,\ $(call silent_on_success,Testing Buck Java integration,\
INFER_BIN=$(INFER_BIN) \ 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)) $(BUCK) build --deep --no-cache $(BUCK_TARGET))

@ -17,10 +17,10 @@ CLEAN_EXTRA = buck-out
include $(TESTS_DIR)/infer.make include $(TESTS_DIR)/infer.make
$(OBJECTS): $(SOURCES) $(BUCKCONFIG) $(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) 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,\ $(call silent_on_success,Testing Buck Java integration with javac_jar,\
INFER_BIN=$(INFER_BIN) \ INFER_BIN=$(INFER_BIN) \
$(INFER_BIN) $(INFER_OPTIONS) -- $(BUCK) build $(TARGET)) $(TESTLOCK) $(INFER_BIN) $(INFER_OPTIONS) -- $(BUCK) build $(TARGET))

@ -22,7 +22,7 @@ include $(TESTS_DIR)/infer.make
$(OBJECTS): $(JAVA_SOURCE_FILES) $(OBJECTS): $(JAVA_SOURCE_FILES)
$(QUIET)cd $(ROOT_DIR) && \ $(QUIET)cd $(ROOT_DIR) && \
$(call silent_on_success,Compiling Buck genrule for Java sources,\ $(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 .PHONY: genrule
genrule: $(JSON_REPORT) genrule: $(JSON_REPORT)
@ -30,9 +30,9 @@ genrule: $(JSON_REPORT)
$(JSON_REPORT): $(JAVA_DEPS) $(JAVA_SOURCE_FILES) $(MAKEFILE_LIST) $(JSON_REPORT): $(JAVA_DEPS) $(JAVA_SOURCE_FILES) $(MAKEFILE_LIST)
$(QUIET)cd $(ROOT_DIR) && \ $(QUIET)cd $(ROOT_DIR) && \
$(REMOVE_DIR) buck-out && \ $(TESTLOCK) $(REMOVE_DIR) buck-out && \
$(call silent_on_success,Testing Buck genrule for Java integration,\ $(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 $@ $(QUIET)touch $@
report.json: $(JSON_REPORT) $(MAKEFILE_LIST) report.json: $(JSON_REPORT) $(MAKEFILE_LIST)

@ -14,6 +14,6 @@ include $(TESTS_DIR)/clang.make
infer-out/report.json: $(CLANG_DEPS) $(SOURCES) $(HEADERS) infer-out/report.json: $(CLANG_DEPS) $(SOURCES) $(HEADERS)
$(QUIET)$(call silent_on_success,Testing make clang and javac integration,\ $(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) make -C ../codetoanalyze/make clean all)
$(QUIET)$(call check_no_duplicates,infer-out/duplicates.txt) $(QUIET)$(call check_no_duplicates,infer-out/duplicates.txt)

@ -14,8 +14,7 @@ SOURCES = $(wildcard ../codetoanalyze/make/*.c)
include $(TESTS_DIR)/clang.make include $(TESTS_DIR)/clang.make
infer-out/report.json: $(CLANG_DEPS) $(SOURCES) infer-out/report.json: $(CLANG_DEPS) $(SOURCES)
$(QUIET)$(MAKE) -C ../codetoanalyze/make clean $(QUIET)$(call silent_on_success,Testing Waf clang integration,\
$(QUIET)cd ../codetoanalyze/make && \ $(TESTLOCK) sh -c "$(MAKE) -C ../codetoanalyze/make clean && \
$(call silent_on_success,Testing Waf clang integration,\ cd ../codetoanalyze/make && $(INFER_BIN) --dump-duplicate-symbols \
$(INFER_BIN) --dump-duplicate-symbols --results-dir $(CUR_DIR)/$(@D) -- \ --results-dir $(CUR_DIR)/$(@D) -- ./waf")
./waf)

@ -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)
Loading…
Cancel
Save