Skip to content

Commit e03d958

Browse files
pdillingerfacebook-github-bot
authored andcommitted
Clean up variables for temporary directory (facebook#9961)
Summary: Having all of TMPD, TMPDIR and TEST_TMPDIR as configuration parameters is confusing. This change simplifies a number of things by standardizing on TEST_TMPDIR, while still recognizing the old names also. In detail: * crash_test.mk also needs to use TEST_TMPDIR for crash test, so put in shared common.mk (an upgrade of python.mk) * Always exporting TEST_TMPDIR eliminates the need to propagate TMPD or export TEST_TMPDIR in selective places. * Use --tmpdir option to gnu_parallel so that it doesn't need TMPDIR environment variable * Remove obsolete parloop and parallel_check Makefile targets * Remove undefined, unused function ResetTmpDirForDirectIO() Pull Request resolved: facebook#9961 Test Plan: manual + CI Reviewed By: riversand963 Differential Revision: D36212178 Pulled By: pdillinger fbshipit-source-id: b76c1876c4f4d38b37789c2779eaa7c3026824dd
1 parent 00889cf commit e03d958

File tree

5 files changed

+43
-78
lines changed

5 files changed

+43
-78
lines changed

Makefile

+12-63
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
BASH_EXISTS := $(shell which bash)
1010
SHELL := $(shell which bash)
11-
include python.mk
11+
include common.mk
1212

1313
CLEAN_FILES = # deliberately empty, so we can append below.
1414
CFLAGS += ${EXTRA_CFLAGS}
@@ -842,18 +842,6 @@ coverage: clean
842842
# Delete intermediate files
843843
$(FIND) . -type f \( -name "*.gcda" -o -name "*.gcno" \) -exec rm -f {} \;
844844

845-
ifneq (,$(filter check parallel_check,$(MAKECMDGOALS)),)
846-
# Use /dev/shm if it has the sticky bit set (otherwise, /tmp),
847-
# and create a randomly-named rocksdb.XXXX directory therein.
848-
# We'll use that directory in the "make check" rules.
849-
ifeq ($(TMPD),)
850-
TMPDIR := $(shell echo $${TMPDIR:-/tmp})
851-
TMPD := $(shell f=/dev/shm; test -k $$f || f=$(TMPDIR); \
852-
perl -le 'use File::Temp "tempdir";' \
853-
-e 'print tempdir("'$$f'/rocksdb.XXXX", CLEANUP => 0)')
854-
endif
855-
endif
856-
857845
# Run all tests in parallel, accumulating per-test logs in t/log-*.
858846
#
859847
# Each t/run-* file is a tiny generated bourne shell script that invokes one of
@@ -893,7 +881,7 @@ $(parallel_tests):
893881
TEST_SCRIPT=t/run-$$TEST_BINARY-$${TEST_NAME//\//-}; \
894882
printf '%s\n' \
895883
'#!/bin/sh' \
896-
"d=\$(TMPD)$$TEST_SCRIPT" \
884+
"d=\$(TEST_TMPDIR)$$TEST_SCRIPT" \
897885
'mkdir -p $$d' \
898886
"TEST_TMPDIR=\$$d $(DRIVER) ./$$TEST_BINARY --gtest_filter=$$TEST_NAME" \
899887
> $$TEST_SCRIPT; \
@@ -953,7 +941,6 @@ endif
953941

954942
.PHONY: check_0
955943
check_0:
956-
$(AM_V_GEN)export TEST_TMPDIR=$(TMPD); \
957944
printf '%s\n' '' \
958945
'To monitor subtest <duration,pass/fail,name>,' \
959946
' run "make watch-log" in a separate window' ''; \
@@ -964,7 +951,8 @@ check_0:
964951
| $(prioritize_long_running_tests) \
965952
| grep -E '$(tests-regexp)' \
966953
| grep -E -v '$(EXCLUDE_TESTS_REGEX)' \
967-
| build_tools/gnu_parallel -j$(J) --plain --joblog=LOG --eta --gnu '{} $(parallel_redir)' ; \
954+
| build_tools/gnu_parallel -j$(J) --plain --joblog=LOG --eta --gnu \
955+
--tmpdir=$(TEST_TMPDIR) '{} $(parallel_redir)' ; \
968956
parallel_retcode=$$? ; \
969957
awk '{ if ($$7 != 0 || $$8 != 0) { if ($$7 == "Exitval") { h = $$0; } else { if (!f) print h; print; f = 1 } } } END { if(f) exit 1; }' < LOG ; \
970958
awk_retcode=$$?; \
@@ -975,7 +963,6 @@ valgrind-exclude-regexp = InlineSkipTest.ConcurrentInsert|TransactionStressTest.
975963
.PHONY: valgrind_check_0
976964
valgrind_check_0: test_log_prefix := valgrind_
977965
valgrind_check_0:
978-
$(AM_V_GEN)export TEST_TMPDIR=$(TMPD); \
979966
printf '%s\n' '' \
980967
'To monitor subtest <duration,pass/fail,name>,' \
981968
' run "make watch-log" in a separate window' ''; \
@@ -987,10 +974,11 @@ valgrind_check_0:
987974
| grep -E '$(tests-regexp)' \
988975
| grep -E -v '$(valgrind-exclude-regexp)' \
989976
| build_tools/gnu_parallel -j$(J) --plain --joblog=LOG --eta --gnu \
990-
'(if [[ "{}" == "./"* ]] ; then $(DRIVER) {}; else {}; fi) \
977+
--tmpdir=$(TEST_TMPDIR) \
978+
'(if [[ "{}" == "./"* ]] ; then $(DRIVER) {}; else {}; fi) \
991979
$(parallel_redir)' \
992980

993-
CLEAN_FILES += t LOG $(TMPD)
981+
CLEAN_FILES += t LOG $(TEST_TMPDIR)
994982

995983
# When running parallel "make check", you can monitor its progress
996984
# from another window.
@@ -1013,12 +1001,12 @@ check: all
10131001
&& (build_tools/gnu_parallel --gnu --help 2>/dev/null) | \
10141002
grep -q 'GNU Parallel'; \
10151003
then \
1016-
$(MAKE) T="$$t" TMPD=$(TMPD) check_0; \
1004+
$(MAKE) T="$$t" check_0; \
10171005
else \
10181006
for t in $(TESTS); do \
10191007
echo "===== Running $$t (`date`)"; ./$$t || exit 1; done; \
10201008
fi
1021-
rm -rf $(TMPD)
1009+
rm -rf $(TEST_TMPDIR)
10221010
ifneq ($(PLATFORM), OS_AIX)
10231011
$(PYTHON) tools/check_all_python.py
10241012
ifeq ($(filter -DROCKSDB_LITE,$(OPT)),)
@@ -1115,11 +1103,11 @@ valgrind_test_some:
11151103
valgrind_check: $(TESTS)
11161104
$(MAKE) DRIVER="$(VALGRIND_VER) $(VALGRIND_OPTS)" gen_parallel_tests
11171105
$(AM_V_GEN)if test "$(J)" != 1 \
1118-
&& (build_tools/gnu_parallel --gnu --help 2>/dev/null) | \
1106+
&& (build_tools/gnu_parallel --gnu --help 2>/dev/null) | \
11191107
grep -q 'GNU Parallel'; \
11201108
then \
1121-
$(MAKE) TMPD=$(TMPD) \
1122-
DRIVER="$(VALGRIND_VER) $(VALGRIND_OPTS)" valgrind_check_0; \
1109+
$(MAKE) \
1110+
DRIVER="$(VALGRIND_VER) $(VALGRIND_OPTS)" valgrind_check_0; \
11231111
else \
11241112
for t in $(filter-out %skiplist_test options_settable_test,$(TESTS)); do \
11251113
$(VALGRIND_VER) $(VALGRIND_OPTS) ./$$t; \
@@ -1139,52 +1127,13 @@ valgrind_check_some: $(ROCKSDBTESTS_SUBSET)
11391127
fi; \
11401128
done
11411129

1142-
ifneq ($(PAR_TEST),)
1143-
parloop:
1144-
ret_bad=0; \
1145-
for t in $(PAR_TEST); do \
1146-
echo "===== Running $$t in parallel $(NUM_PAR) (`date`)";\
1147-
if [ $(db_test) -eq 1 ]; then \
1148-
seq $(J) | v="$$t" build_tools/gnu_parallel --gnu --plain 's=$(TMPD)/rdb-{}; export TEST_TMPDIR=$$s;' \
1149-
'timeout 2m ./db_test --gtest_filter=$$v >> $$s/log-{} 2>1'; \
1150-
else\
1151-
seq $(J) | v="./$$t" build_tools/gnu_parallel --gnu --plain 's=$(TMPD)/rdb-{};' \
1152-
'export TEST_TMPDIR=$$s; timeout 10m $$v >> $$s/log-{} 2>1'; \
1153-
fi; \
1154-
ret_code=$$?; \
1155-
if [ $$ret_code -ne 0 ]; then \
1156-
ret_bad=$$ret_code; \
1157-
echo $$t exited with $$ret_code; \
1158-
fi; \
1159-
done; \
1160-
exit $$ret_bad;
1161-
endif
1162-
11631130
test_names = \
11641131
./db_test --gtest_list_tests \
11651132
| perl -n \
11661133
-e 's/ *\#.*//;' \
11671134
-e '/^(\s*)(\S+)/; !$$1 and do {$$p=$$2; break};' \
11681135
-e 'print qq! $$p$$2!'
11691136

1170-
parallel_check: $(TESTS)
1171-
$(AM_V_GEN)if test "$(J)" > 1 \
1172-
&& (build_tools/gnu_parallel --gnu --help 2>/dev/null) | \
1173-
grep -q 'GNU Parallel'; \
1174-
then \
1175-
echo Running in parallel $(J); \
1176-
else \
1177-
echo "Need to have GNU Parallel and J > 1"; exit 1; \
1178-
fi; \
1179-
ret_bad=0; \
1180-
echo $(J);\
1181-
echo Test Dir: $(TMPD); \
1182-
seq $(J) | build_tools/gnu_parallel --gnu --plain 's=$(TMPD)/rdb-{}; rm -rf $$s; mkdir $$s'; \
1183-
$(MAKE) PAR_TEST="$(shell $(test_names))" TMPD=$(TMPD) \
1184-
J=$(J) db_test=1 parloop; \
1185-
$(MAKE) PAR_TEST="$(filter-out db_test, $(TESTS))" \
1186-
TMPD=$(TMPD) J=$(J) db_test=0 parloop;
1187-
11881137
analyze: clean
11891138
USE_CLANG=1 $(MAKE) analyze_incremental
11901139

common.mk

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
ifndef PYTHON
2+
3+
# Default to python3. Some distros like CentOS 8 do not have `python`.
4+
ifeq ($(origin PYTHON), undefined)
5+
PYTHON := $(shell which python3 || which python || echo python3)
6+
endif
7+
export PYTHON
8+
9+
endif
10+
11+
# To setup tmp directory, first recognize some old variables for setting
12+
# test tmp directory or base tmp directory. TEST_TMPDIR is usually read
13+
# by RocksDB tools though Env/FileSystem::GetTestDirectory.
14+
ifeq ($(TEST_TMPDIR),)
15+
TEST_TMPDIR := $(TMPD)
16+
endif
17+
ifeq ($(TEST_TMPDIR),)
18+
ifeq ($(BASE_TMPDIR),)
19+
BASE_TMPDIR :=$(TMPDIR)
20+
endif
21+
ifeq ($(BASE_TMPDIR),)
22+
BASE_TMPDIR :=/tmp
23+
endif
24+
# Use /dev/shm if it has the sticky bit set (otherwise, /tmp or other
25+
# base dir), and create a randomly-named rocksdb.XXXX directory therein.
26+
TEST_TMPDIR := $(shell f=/dev/shm; test -k $$f || f=$(BASE_TMPDIR); \
27+
perl -le 'use File::Temp "tempdir";' \
28+
-e 'print tempdir("'$$f'/rocksdb.XXXX", CLEANUP => 0)')
29+
endif
30+
export TEST_TMPDIR

crash_test.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# build DB_STRESS_CMD so it must exist prior.
66
DB_STRESS_CMD?=./db_stress
77

8-
include python.mk
8+
include common.mk
99

1010
CRASHTEST_MAKE=$(MAKE) -f crash_test.mk
1111
CRASHTEST_PY=$(PYTHON) -u tools/db_crashtest.py --stress_cmd=$(DB_STRESS_CMD)

python.mk

-9
This file was deleted.

test_util/testutil.h

-5
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,6 @@ bool IsPrefetchSupported(const std::shared_ptr<FileSystem>& fs,
819819
// Return the number of lines where a given pattern was found in a file.
820820
size_t GetLinesCount(const std::string& fname, const std::string& pattern);
821821

822-
// TEST_TMPDIR may be set to /dev/shm in Makefile,
823-
// but /dev/shm does not support direct IO.
824-
// Tries to set TEST_TMPDIR to a directory supporting direct IO.
825-
void ResetTmpDirForDirectIO();
826-
827822
Status CorruptFile(Env* env, const std::string& fname, int offset,
828823
int bytes_to_corrupt, bool verify_checksum = true);
829824
Status TruncateFile(Env* env, const std::string& fname, uint64_t length);

0 commit comments

Comments
 (0)