Browse Source

Use simpler clang setup for fuzzing.

Thanks to https://github.com/openssl/openssl/commit/404c76f4ee1dc51c0d200e2b60a6340aadb44e38
Stefan Profanter 6 years ago
parent
commit
5b2b18b376

+ 24 - 0
.travis-apt-pin.preferences

@@ -0,0 +1,24 @@
+Package: clang-3.9
+Pin: release o=Ubuntu
+Pin-Priority: -1
+
+Package: libclang-common-3.9-dev
+Pin: release o=Ubuntu
+Pin-Priority: -1
+
+Package: libclang1-3.9
+Pin: release o=Ubuntu
+Pin-Priority: -1
+
+Package: libllvm3.9v4
+Pin: release o=Ubuntu
+Pin-Priority: -1
+
+Package: clang-tidy-3.9
+Pin: release o=Ubuntu
+Pin-Priority: -1
+
+Package: libfuzzer-3.9-dev
+Pin: release o=Ubuntu
+Pin-Priority: -1
+

+ 0 - 2
.travis.yml

@@ -55,8 +55,6 @@ addons:
       - binutils-mingw-w64-i686
       - build-essential
       - check
-      - clang-3.9
-      - clang-tidy-3.9
       - cmake
       - cppcheck
       - gcc-multilib

+ 5 - 8
tests/fuzz/CMakeLists.txt

@@ -13,12 +13,11 @@ if(NOT "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
 endif()
 
 if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)
-    MESSAGE(WARNING "You should use at least clang version 5.0 for fuzzing support")
-endif()
-
-if(NOT $ENV{LIB_FUZZER_DIR} STREQUAL "")
-    # specific settings for travis
-    link_directories($ENV{LIB_FUZZER_DIR})
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
+else()
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=trace-pc-guard")
+    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=trace-pc-guard")
 endif()
 
 set(LIBS Fuzzer ${open62541_LIBRARIES})
@@ -29,8 +28,6 @@ set(LIBS Fuzzer ${open62541_LIBRARIES})
 
 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/fuzz)
 
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fsanitize-coverage=trace-pc-guard")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-coverage=trace-pc-guard")
 
 
 # Use different plugins for testing

+ 12 - 12
tools/travis/travis_linux_before_install.sh

@@ -2,22 +2,22 @@
 set -ev
 
 
-if ! [ -z ${FUZZER+x} ]; then
-	# we need libfuzzer 5.0, all the older versions do not work on travis.
-	sudo apt-get --yes install git
-	git clone https://github.com/google/fuzzer-test-suite.git FTS
-	./FTS/tutorial/install-deps.sh  # Get deps
-	./FTS/tutorial/install-clang.sh # Get fresh clang binaries
-	# Get libFuzzer sources and build it
-	svn co http://llvm.org/svn/llvm-project/llvm/trunk/lib/Fuzzer
-	Fuzzer/build.sh
-	exit 0
-fi
-
 if [ -z ${DOCKER+x} ]; then
 	# Only on non-docker builds required
 
 	echo "=== Installing from external package sources ===" && echo -en 'travis_fold:start:before_install.external\\r'
+
+	if [ "$CC" = "clang" ]; then
+		# the ubuntu repo has a somehow broken clang-3.9 compiler. We want to use the one from the llvm repo
+		# See https://github.com/openssl/openssl/commit/404c76f4ee1dc51c0d200e2b60a6340aadb44e38
+		sudo cp .travis-apt-pin.preferences /etc/apt/preferences.d/no-ubuntu-clang
+		curl -sSL "http://apt.llvm.org/llvm-snapshot.gpg.key" | sudo -E apt-key add -
+		echo "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main" | sudo tee -a /etc/apt/sources.list > /dev/null
+		sudo -E apt-add-repository -y "ppa:ubuntu-toolchain-r/test"
+		sudo -E apt-get -yq update
+		sudo -E apt-get -yq --no-install-suggests --no-install-recommends --force-yes install clang-3.9 clang-tidy-3.9 libfuzzer-3.9-dev
+	fi
+
 	sudo add-apt-repository -y ppa:lttng/ppa
 	sudo apt-get update -qq
 	sudo apt-get install -y liburcu4 liburcu-dev

+ 3 - 5
tools/travis/travis_linux_script.sh

@@ -14,12 +14,10 @@ fi
 # Fuzzer build test
 if ! [ -z ${FUZZER+x} ]; then
 	mkdir -p build && cd build
-	export CC=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin/clang
-	export CXX=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin/clang++
-	# libFuzzer.a is in the build dir.
-	export LIB_FUZZER_DIR=$TRAVIS_BUILD_DIR
+	export CC=clang-3.9
+	export CXX=clang++-3.9
 	cmake -DUA_ENABLE_DISCOVERY=ON -DUA_ENABLE_DISCOVERY_MULTICAST=ON -DUA_BUILD_FUZZING=ON ..
-	make VERBOSE=1 && make run_fuzzer
+	make && make run_fuzzer
 	if [ $? -ne 0 ] ; then exit 1 ; fi
 	cd .. && rm build -rf
     exit 0