[llvm-commits] [compiler-rt] r156547 - in /compiler-rt/trunk/lib/tsan: Makefile.old analyze_libtsan.sh check_analyze.sh output_tests/test_output.sh rtl/Makefile.old

Kostya Serebryany kcc at google.com
Thu May 10 08:10:03 PDT 2012


Author: kcc
Date: Thu May 10 10:10:03 2012
New Revision: 156547

URL: http://llvm.org/viewvc/llvm-project?rev=156547&view=rev
Log:
[tsan] old-dstyle Makefile for tests; two helper scripts that analyze the assembly code of the hot functions

Added:
    compiler-rt/trunk/lib/tsan/Makefile.old
    compiler-rt/trunk/lib/tsan/analyze_libtsan.sh   (with props)
    compiler-rt/trunk/lib/tsan/check_analyze.sh   (with props)
Modified:
    compiler-rt/trunk/lib/tsan/output_tests/test_output.sh
    compiler-rt/trunk/lib/tsan/rtl/Makefile.old

Added: compiler-rt/trunk/lib/tsan/Makefile.old
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/Makefile.old?rev=156547&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/Makefile.old (added)
+++ compiler-rt/trunk/lib/tsan/Makefile.old Thu May 10 10:10:03 2012
@@ -0,0 +1,95 @@
+DEBUG=0
+LDFLAGS=-ldl -lpthread -pie
+CXXFLAGS = -fPIE -g -Wall -Werror  -DTSAN_DEBUG=$(DEBUG)
+ifeq ($(DEBUG), 0)
+	CXXFLAGS += -O3
+endif
+
+
+LIBTSAN=rtl/libtsan.a
+GTEST_ROOT=third_party/googletest
+GTEST_INCLUDE=-I$(GTEST_ROOT)/include
+GTEST_BUILD_DIR=$(GTEST_ROOT)/build
+GTEST_LIB=$(GTEST_BUILD_DIR)/gtest-all.o
+
+RTL_TEST_SRC=$(wildcard rtl_tests/*.cc)
+RTL_TEST_OBJ=$(patsubst %.cc,%.o,$(RTL_TEST_SRC))
+UNIT_TEST_SRC=$(wildcard unit_tests/*_test.cc)
+UNIT_TEST_OBJ=$(patsubst %.cc,%.o,$(UNIT_TEST_SRC))
+UNIT_TEST_HDR=$(wildcard rtl/*.h)
+
+INCLUDES=-Irtl $(GTEST_INCLUDE)
+
+all: $(LIBTSAN) test
+
+help:
+	@ echo "A little help is always welcome!"
+	@ echo "The most useful targets are:"
+	@ echo "  make install_deps  # Install third-party dependencies required for building"
+	@ echo "  make presubmit     # Run it every time before committing"
+	@ echo "  make lint          # Run the style checker"
+	@ echo
+	@ echo "For more info, see http://code.google.com/p/data-race-test/wiki/ThreadSanitizer2"
+
+$(LIBTSAN):
+	$(MAKE) -C rtl -f Makefile.old DEBUG=$(DEBUG)
+
+unit_tests/%_test.o: unit_tests/%_test.cc $(UNIT_TEST_HDR)
+	$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ -c $<
+
+rtl_tests/%.o: rtl_tests/%.cc $(LIBTSAN_HEADERS)
+	$(CXX) $(CXXFLAGS) $(INCLUDES) -o $@ -c $<
+
+#%.o: %.c $(LIBTSAN_HEADERS)
+#	$(CC) $(CXXFLAGS) $(INCLUDES) -c $<
+
+tsan_test: $(TEST_OBJ) $(UNIT_TEST_OBJ) $(RTL_TEST_OBJ) $(LIBTSAN) $(GTEST_LIB)
+	$(CXX) $^ -o $@ $(LDFLAGS)
+
+test: $(LIBTSAN) tsan_test
+
+run: all
+	(ulimit -s 8192; ./tsan_test)
+
+presubmit:
+	$(MAKE) -f Makefile.old lint -j 4
+	# Debug build with clang.
+	$(MAKE) -f Makefile.old clean
+	$(MAKE) -f Makefile.old run DEBUG=1 -j 16 CC=clang CXX=clang++
+	./output_tests/test_output.sh
+	# Release build gcc
+	$(MAKE) -f Makefile.old clean
+	$(MAKE) -f Makefile.old run DEBUG=0 -j 16 CC=gcc CXX=g++
+	./check_analyze.sh
+	./output_tests/test_output.sh
+	@ echo PRESUBMIT PASSED
+
+RTL_LINT_FITLER=-legal/copyright,-build/include,-readability/casting,-build/header_guard
+
+lint: lint_tsan lint_tests
+lint_tsan:
+	third_party/cpplint/cpplint.py --filter=$(RTL_LINT_FITLER) rtl/*.{cc,h}
+lint_tests:
+	third_party/cpplint/cpplint.py --filter=$(RTL_LINT_FITLER) rtl_tests/*.{cc,h}
+
+install_deps:
+	rm -rf third_party
+	mkdir third_party
+	(cd third_party && \
+	svn co -r613 http://googletest.googlecode.com/svn/trunk googletest && \
+	svn co -r82 http://google-styleguide.googlecode.com/svn/trunk/cpplint cpplint \
+        )
+
+# Remove verbose printf from lint. Not strictly necessary.
+hack_cpplint:
+	sed -i "s/  sys.stderr.write('Done processing.*//g" third_party/cpplint/cpplint.py
+
+$(GTEST_LIB):
+	mkdir -p $(GTEST_BUILD_DIR) && \
+	cd $(GTEST_BUILD_DIR) && \
+	$(MAKE) -f ../make/Makefile CXXFLAGS="$(CXXFLAGS)" CFLAGS="$(CFLAGS)" CC=$(CC) CXX=$(CXX)
+
+clean:
+	rm -f asm_*.s libtsan.nm libtsan.objdump */*.o tsan_test
+	rm -rf $(GTEST_BUILD_DIR)
+	$(MAKE) clean -C rtl -f Makefile.old

Added: compiler-rt/trunk/lib/tsan/analyze_libtsan.sh
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/analyze_libtsan.sh?rev=156547&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/analyze_libtsan.sh (added)
+++ compiler-rt/trunk/lib/tsan/analyze_libtsan.sh Thu May 10 10:10:03 2012
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+set -e
+set -u
+
+get_asm() {
+  grep tsan_$1.: -A 10000 libtsan.objdump | \
+    awk "/[^:]$/ {print;} />:/ {c++; if (c == 2) {exit}}"
+}
+
+list="write1 \
+      write2 \
+      write4 \
+      write8 \
+      read1 \
+      read2 \
+      read4 \
+      read8 \
+      func_entry \
+      func_exit"
+
+BIN=`dirname $0`/tsan_test
+objdump -d $BIN  > libtsan.objdump
+nm -S $BIN | grep "__tsan_" > libtsan.nm
+
+for f in $list; do
+  file=asm_$f.s
+  get_asm $f > $file
+  tot=$(wc -l < $file)
+  size=$(grep $f$ libtsan.nm | awk --non-decimal-data '{print ("0x"$2)+0}')
+  rsp=$(grep '(%rsp)' $file | wc -l)
+  push=$(grep 'push' $file | wc -l)
+  pop=$(grep 'pop' $file | wc -l)
+  call=$(grep 'call' $file | wc -l)
+  load=$(egrep 'mov .*\,.*\(.*\)|cmp .*\,.*\(.*\)' $file | wc -l)
+  store=$(egrep 'mov .*\(.*\),' $file | wc -l)
+  mov=$(grep 'mov' $file | wc -l)
+  lea=$(grep 'lea' $file | wc -l)
+  sh=$(grep 'shr\|shl' $file | wc -l)
+  cmp=$(grep 'cmp\|test' $file | wc -l)
+  printf "%10s tot %3d; size %4d; rsp %d; push %d; pop %d; call %d; load %2d; store %2d; sh %3d; mov %3d; lea %3d; cmp %3d\n" \
+    $f $tot $size $rsp $push $pop $call $load $store $sh $mov $lea $cmp;
+done

Propchange: compiler-rt/trunk/lib/tsan/analyze_libtsan.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: compiler-rt/trunk/lib/tsan/check_analyze.sh
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/check_analyze.sh?rev=156547&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/check_analyze.sh (added)
+++ compiler-rt/trunk/lib/tsan/check_analyze.sh Thu May 10 10:10:03 2012
@@ -0,0 +1,43 @@
+#!/bin/bash
+set -u
+
+RES=$(./analyze_libtsan.sh)
+PrintRes() {
+  printf "%s\n" "$RES"
+}
+
+PrintRes
+
+mops="write1 \
+      write2 \
+      write4 \
+      write8 \
+      read1 \
+      read2 \
+      read4 \
+      read8"
+func="func_entry \
+      func_exit"
+
+check() {
+  res=$(PrintRes | egrep "$1 .* $2 $3; ")
+  if [ "$res" == "" ]; then
+    echo FAILED $1 must contain $2 $3
+    exit 1
+  fi
+}
+
+for f in $mops; do
+  check $f rsp 1   # To read caller pc.
+  check $f push 0
+  check $f pop 0
+done
+
+for f in $func; do
+  check $f rsp 0
+  check $f push 0
+  check $f pop 0
+  check $f call 1  # TraceSwitch()
+done
+
+echo LGTM

Propchange: compiler-rt/trunk/lib/tsan/check_analyze.sh
------------------------------------------------------------------------------
    svn:executable = *

Modified: compiler-rt/trunk/lib/tsan/output_tests/test_output.sh
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/output_tests/test_output.sh?rev=156547&r1=156546&r2=156547&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/output_tests/test_output.sh (original)
+++ compiler-rt/trunk/lib/tsan/output_tests/test_output.sh Thu May 10 10:10:03 2012
@@ -11,7 +11,7 @@
 
 # TODO: add testing for all of -O0...-O3
 CFLAGS="-fthread-sanitizer -fPIE -O1 -g -fno-builtin -Wall -Werror=return-type"
-LDFLAGS="-pie -lpthread -ldl $ROOTDIR/tsan/libtsan.a"
+LDFLAGS="-pie -lpthread -ldl $ROOTDIR/rtl/libtsan.a"
 if [ "$LLDB" != "" ]; then
   LDFLAGS+=" -L$LLDB -llldb"
 fi

Modified: compiler-rt/trunk/lib/tsan/rtl/Makefile.old
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/Makefile.old?rev=156547&r1=156546&r2=156547&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/Makefile.old (original)
+++ compiler-rt/trunk/lib/tsan/rtl/Makefile.old Thu May 10 10:10:03 2012
@@ -1,10 +1,6 @@
-CXXFLAGS=-Wall -fPIE -Werror -g $(CFLAGS) -fno-builtin
-DEBUG=1
-
+CXXFLAGS = -fPIE -g -Wall -Werror -fno-builtin -DTSAN_DEBUG=$(DEBUG)
 ifeq ($(DEBUG), 0)
-	CXXFLAGS+=-DTSAN_DEBUG=0 -O3
-else
-	CXXFLAGS+=-DTSAN_DEBUG=1
+	CXXFLAGS += -O3
 endif
 
 # For interception. FIXME: move interception one level higher.





More information about the llvm-commits mailing list