t_msan_allocated_memory.sh revision 1.1
11.1Skamil# Copyright (c) 2018 The NetBSD Foundation, Inc. 21.1Skamil# All rights reserved. 31.1Skamil# 41.1Skamil# This code is derived from software contributed to The NetBSD Foundation 51.1Skamil# by Yang Zheng. 61.1Skamil# 71.1Skamil# Redistribution and use in source and binary forms, with or without 81.1Skamil# modification, are permitted provided that the following conditions 91.1Skamil# are met: 101.1Skamil# 1. Redistributions of source code must retain the above copyright 111.1Skamil# notice, this list of conditions and the following disclaimer. 121.1Skamil# 2. Redistributions in binary form must reproduce the above copyright 131.1Skamil# notice, this list of conditions and the following disclaimer in the 141.1Skamil# documentation and/or other materials provided with the distribution. 151.1Skamil# 161.1Skamil# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 171.1Skamil# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 181.1Skamil# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 191.1Skamil# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201.1Skamil# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211.1Skamil# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221.1Skamil# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231.1Skamil# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241.1Skamil# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251.1Skamil# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261.1Skamil# POSSIBILITY OF SUCH DAMAGE. 271.1Skamil# 281.1Skamil 291.1Skamiltest_target() 301.1Skamil{ 311.1Skamil SUPPORT='n' 321.1Skamil if uname -m | grep -q "amd64" && command -v c++ >/dev/null 2>&1 && \ 331.1Skamil ! echo __clang__ | c++ -E - | grep -q __clang__; then 341.1Skamil # only clang with major version newer than 7 is supported 351.1Skamil CLANG_MAJOR=`echo __clang_major__ | c++ -E - | grep -o '^[[:digit:]]'` 361.1Skamil if [ "$CLANG_MAJOR" -ge "7" ]; then 371.1Skamil SUPPORT='y' 381.1Skamil fi 391.1Skamil fi 401.1Skamil} 411.1Skamil 421.1Skamilatf_test_case allocated_memory 431.1Skamilallocated_memory_head() { 441.1Skamil atf_set "descr" "Test memory sanitizer for __msan_allocated_memory interface" 451.1Skamil atf_set "require.progs" "c++ paxctl" 461.1Skamil} 471.1Skamil 481.1Skamilatf_test_case allocated_memory_profile 491.1Skamilallocated_memory_profile_head() { 501.1Skamil atf_set "descr" "Test memory sanitizer for __msan_allocated_memory with profiling option" 511.1Skamil atf_set "require.progs" "c++ paxctl" 521.1Skamil} 531.1Skamilatf_test_case allocated_memory_pic 541.1Skamilallocated_memory_pic_head() { 551.1Skamil atf_set "descr" "Test memory sanitizer for __msan_allocated_memory with position independent code (PIC) flag" 561.1Skamil atf_set "require.progs" "c++ paxctl" 571.1Skamil} 581.1Skamilatf_test_case allocated_memory_pie 591.1Skamilallocated_memory_pie_head() { 601.1Skamil atf_set "descr" "Test memory sanitizer for __msan_allocated_memory with position independent execution (PIE) flag" 611.1Skamil atf_set "require.progs" "c++ paxctl" 621.1Skamil} 631.1Skamil 641.1Skamilallocated_memory_body(){ 651.1Skamil cat > test.cc << EOF 661.1Skamil#include <stdio.h> 671.1Skamil#include <sanitizer/msan_interface.h> 681.1Skamil 691.1Skamilint main() { 701.1Skamil int x = 0; 711.1Skamil __msan_allocated_memory(&x, sizeof(x)); 721.1Skamil return x; 731.1Skamil} 741.1SkamilEOF 751.1Skamil 761.1Skamil c++ -fsanitize=memory -o test test.cc 771.1Skamil paxctl +a test 781.1Skamil atf_check -s ignore -o ignore -e match:"WARNING: MemorySanitizer: use-of-uninitialized-value" ./test 791.1Skamil} 801.1Skamil 811.1Skamilallocated_memory_profile_body(){ 821.1Skamil cat > test.cc << EOF 831.1Skamil#include <stdio.h> 841.1Skamil#include <sanitizer/msan_interface.h> 851.1Skamil 861.1Skamilint main() { 871.1Skamil int x = 0; 881.1Skamil __msan_allocated_memory(&x, sizeof(x)); 891.1Skamil return x; 901.1Skamil} 911.1SkamilEOF 921.1Skamil 931.1Skamil c++ -fsanitize=memory -o test -pg test.cc 941.1Skamil paxctl +a test 951.1Skamil atf_check -s ignore -o ignore -e match:"WARNING: MemorySanitizer: use-of-uninitialized-value" ./test 961.1Skamil} 971.1Skamil 981.1Skamilallocated_memory_pic_body(){ 991.1Skamil cat > test.cc << EOF 1001.1Skamil#include <stdio.h> 1011.1Skamil#include <stdlib.h> 1021.1Skamilint help(int); 1031.1Skamilint main(int argc, char **argv) {return help(argc);} 1041.1SkamilEOF 1051.1Skamil 1061.1Skamil cat > pic.cc << EOF 1071.1Skamil#include <stdio.h> 1081.1Skamil#include <sanitizer/msan_interface.h> 1091.1Skamil 1101.1Skamilint help(int argc) { 1111.1Skamil int x = 0; 1121.1Skamil __msan_allocated_memory(&x, sizeof(x)); 1131.1Skamil return x; 1141.1Skamil} 1151.1SkamilEOF 1161.1Skamil 1171.1Skamil c++ -fsanitize=memory -fPIC -shared -o libtest.so pic.cc 1181.1Skamil c++ -o test test.cc -fsanitize=memory -L. -ltest 1191.1Skamil paxctl +a test 1201.1Skamil 1211.1Skamil export LD_LIBRARY_PATH=. 1221.1Skamil atf_check -s ignore -o ignore -e match:"WARNING: MemorySanitizer: use-of-uninitialized-value" ./test 1231.1Skamil} 1241.1Skamilallocated_memory_pie_body(){ 1251.1Skamil 1261.1Skamil #check whether -pie flag is supported on this architecture 1271.1Skamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 1281.1Skamil atf_set_skip "c++ -pie not supported on this architecture" 1291.1Skamil fi 1301.1Skamil cat > test.cc << EOF 1311.1Skamil#include <stdio.h> 1321.1Skamil#include <sanitizer/msan_interface.h> 1331.1Skamil 1341.1Skamilint main() { 1351.1Skamil int x = 0; 1361.1Skamil __msan_allocated_memory(&x, sizeof(x)); 1371.1Skamil return x; 1381.1Skamil} 1391.1SkamilEOF 1401.1Skamil 1411.1Skamil c++ -fsanitize=memory -o test -fpie -pie test.cc 1421.1Skamil paxctl +a test 1431.1Skamil atf_check -s ignore -o ignore -e match:"WARNING: MemorySanitizer: use-of-uninitialized-value" ./test 1441.1Skamil} 1451.1Skamil 1461.1Skamilatf_test_case target_not_supported 1471.1Skamiltarget_not_supported_head() 1481.1Skamil{ 1491.1Skamil atf_set "descr" "Test forced skip" 1501.1Skamil} 1511.1Skamil 1521.1Skamilatf_init_test_cases() 1531.1Skamil{ 1541.1Skamil test_target 1551.1Skamil test $SUPPORT = 'n' && { 1561.1Skamil atf_add_test_case target_not_supported 1571.1Skamil return 0 1581.1Skamil } 1591.1Skamil atf_add_test_case allocated_memory 1601.1Skamil atf_add_test_case allocated_memory_profile 1611.1Skamil atf_add_test_case allocated_memory_pie 1621.1Skamil atf_add_test_case allocated_memory_pic 1631.1Skamil} 164