t_hello.sh revision 1.1
11.1Skamil# $NetBSD: t_hello.sh,v 1.1 2017/05/14 00:07:07 kamil Exp $ 21.1Skamil# 31.1Skamil# Copyright (c) 2011 The NetBSD Foundation, Inc. 41.1Skamil# All rights reserved. 51.1Skamil# 61.1Skamil# Redistribution and use in source and binary forms, with or without 71.1Skamil# modification, are permitted provided that the following conditions 81.1Skamil# are met: 91.1Skamil# 1. Redistributions of source code must retain the above copyright 101.1Skamil# notice, this list of conditions and the following disclaimer. 111.1Skamil# 2. Redistributions in binary form must reproduce the above copyright 121.1Skamil# notice, this list of conditions and the following disclaimer in the 131.1Skamil# documentation and/or other materials provided with the distribution. 141.1Skamil# 151.1Skamil# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 161.1Skamil# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 171.1Skamil# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 181.1Skamil# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 191.1Skamil# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 201.1Skamil# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 211.1Skamil# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 221.1Skamil# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 231.1Skamil# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 241.1Skamil# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 251.1Skamil# POSSIBILITY OF SUCH DAMAGE. 261.1Skamil# 271.1Skamil 281.1Skamilatf_test_case hello 291.1Skamilhello_head() { 301.1Skamil atf_set "descr" "compile and run \"hello world\"" 311.1Skamil atf_set "require.progs" "c++" 321.1Skamil} 331.1Skamil 341.1Skamilatf_test_case hello_pic 351.1Skamilhello_pic_head() { 361.1Skamil atf_set "descr" "compile and run PIC \"hello world\"" 371.1Skamil atf_set "require.progs" "c++" 381.1Skamil} 391.1Skamil 401.1Skamilatf_test_case hello_pie 411.1Skamilhello_pie_head() { 421.1Skamil atf_set "descr" "compile and run position independent (PIE) \"hello world\"" 431.1Skamil atf_set "require.progs" "c++" 441.1Skamil} 451.1Skamil 461.1Skamilatf_test_case hello32 471.1Skamilhello32_head() { 481.1Skamil atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation" 491.1Skamil atf_set "require.progs" "c++ file diff cat" 501.1Skamil} 511.1Skamil 521.1Skamilhello_body() { 531.1Skamil cat > test.cpp << EOF 541.1Skamil#include <stdio.h> 551.1Skamil#include <stdlib.h> 561.1Skamilint main(void) {printf("hello world\n");exit(0);} 571.1SkamilEOF 581.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello test.cpp 591.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 601.1Skamil} 611.1Skamil 621.1Skamilhello_pic_body() { 631.1Skamil cat > test.cpp << EOF 641.1Skamil#include <stdlib.h> 651.1Skamilint callpic(void); 661.1Skamilint main(void) {callpic();exit(0);} 671.1SkamilEOF 681.1Skamil cat > pic.cpp << EOF 691.1Skamil#include <stdio.h> 701.1Skamilint callpic(void) {printf("hello world\n");return 0;} 711.1SkamilEOF 721.1Skamil 731.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 741.1Skamil c++ -fPIC -shared -o libtest.so pic.cpp 751.1Skamil atf_check -s exit:0 -o ignore -e ignore \ 761.1Skamil c++ -o hello test.cpp -L. -ltest 771.1Skamil 781.1Skamil export LD_LIBRARY_PATH=. 791.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 801.1Skamil} 811.1Skamil 821.1Skamilhello_pie_body() { 831.1Skamil # check whether this arch supports -pie 841.1Skamil if ! c++ -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then 851.1Skamil atf_skip "c++ -pie not supported on this architecture" 861.1Skamil fi 871.1Skamil cat > test.cpp << EOF 881.1Skamil#include <stdio.h> 891.1Skamil#include <stdlib.h> 901.1Skamilint main(void) {printf("hello world\n");exit(0);} 911.1SkamilEOF 921.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -fpie -pie -o hello test.cpp 931.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello 941.1Skamil} 951.1Skamil 961.1Skamilhello32_body() { 971.1Skamil # check whether this arch is 64bit 981.1Skamil if ! c++ -dM -E - < /dev/null | fgrep -q _LP64; then 991.1Skamil atf_skip "this is not a 64 bit architecture" 1001.1Skamil fi 1011.1Skamil if ! c++ -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then 1021.1Skamil atf_skip "c++ -m32 not supported on this architecture" 1031.1Skamil else 1041.1Skamil if fgrep -q _LP64 ./def32; then 1051.1Skamil atf_fail "c++ -m32 does not generate netbsd32 binaries" 1061.1Skamil fi 1071.1Skamil fi 1081.1Skamil 1091.1Skamil cat > test.cpp << EOF 1101.1Skamil#include <stdio.h> 1111.1Skamil#include <stdlib.h> 1121.1Skamilint main(void) {printf("hello world\n");exit(0);} 1131.1SkamilEOF 1141.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello32 -m32 test.cpp 1151.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello64 test.cpp 1161.1Skamil file -b ./hello32 > ./ftype32 1171.1Skamil file -b ./hello64 > ./ftype64 1181.1Skamil if diff ./ftype32 ./ftype64 >/dev/null; then 1191.1Skamil atf_fail "generated binaries do not differ" 1201.1Skamil fi 1211.1Skamil echo "32bit binaries on this platform are:" 1221.1Skamil cat ./ftype32 1231.1Skamil echo "While native (64bit) binaries are:" 1241.1Skamil cat ./ftype64 1251.1Skamil atf_check -s exit:0 -o inline:"hello world\n" ./hello32 1261.1Skamil 1271.1Skamil # do another test with static 32bit binaries 1281.1Skamil cat > test.cpp << EOF 1291.1Skamil#include <stdio.h> 1301.1Skamil#include <stdlib.h> 1311.1Skamilint main(void) {printf("hello static world\n");exit(0);} 1321.1SkamilEOF 1331.1Skamil atf_check -s exit:0 -o ignore -e ignore c++ -o hello -m32 \ 1341.1Skamil -static test.cpp 1351.1Skamil atf_check -s exit:0 -o inline:"hello static world\n" ./hello 1361.1Skamil} 1371.1Skamil 1381.1Skamilatf_init_test_cases() 1391.1Skamil{ 1401.1Skamil 1411.1Skamil atf_add_test_case hello 1421.1Skamil atf_add_test_case hello_pic 1431.1Skamil atf_add_test_case hello_pie 1441.1Skamil atf_add_test_case hello32 1451.1Skamil} 146