Home | History | Annotate | Line # | Download | only in cc
t_hello.sh revision 1.6.10.2
      1  1.6.10.2    martin #	$NetBSD: t_hello.sh,v 1.6.10.2 2020/04/08 14:09:13 martin Exp $
      2       1.1    jruoho #
      3       1.1    jruoho # Copyright (c) 2011 The NetBSD Foundation, Inc.
      4       1.1    jruoho # All rights reserved.
      5       1.1    jruoho #
      6       1.1    jruoho # Redistribution and use in source and binary forms, with or without
      7       1.1    jruoho # modification, are permitted provided that the following conditions
      8       1.1    jruoho # are met:
      9       1.1    jruoho # 1. Redistributions of source code must retain the above copyright
     10       1.1    jruoho #    notice, this list of conditions and the following disclaimer.
     11       1.1    jruoho # 2. Redistributions in binary form must reproduce the above copyright
     12       1.1    jruoho #    notice, this list of conditions and the following disclaimer in the
     13       1.1    jruoho #    documentation and/or other materials provided with the distribution.
     14       1.1    jruoho #
     15       1.1    jruoho # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16       1.1    jruoho # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17       1.1    jruoho # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18       1.1    jruoho # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19       1.1    jruoho # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20       1.1    jruoho # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21       1.1    jruoho # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22       1.1    jruoho # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23       1.1    jruoho # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24       1.1    jruoho # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25       1.1    jruoho # POSSIBILITY OF SUCH DAMAGE.
     26       1.1    jruoho #
     27       1.1    jruoho 
     28       1.1    jruoho atf_test_case hello
     29       1.1    jruoho hello_head() {
     30       1.1    jruoho 	atf_set "descr" "compile and run \"hello world\""
     31       1.1    jruoho 	atf_set "require.progs" "cc"
     32       1.1    jruoho }
     33       1.1    jruoho 
     34       1.5    martin atf_test_case hello_profile
     35  1.6.10.1  christos hello_profile_head() {
     36       1.5    martin 	atf_set "descr" "compile and run \"hello world\" with profiling option"
     37       1.5    martin 	atf_set "require.progs" "cc"
     38       1.5    martin }
     39       1.5    martin 
     40       1.1    jruoho atf_test_case hello_pic
     41       1.1    jruoho hello_pic_head() {
     42       1.1    jruoho 	atf_set "descr" "compile and run PIC \"hello world\""
     43       1.1    jruoho 	atf_set "require.progs" "cc"
     44       1.1    jruoho }
     45       1.1    jruoho 
     46       1.2    martin atf_test_case hello_pie
     47       1.2    martin hello_pie_head() {
     48       1.3      gson 	atf_set "descr" "compile and run position independent (PIE) \"hello world\""
     49       1.2    martin 	atf_set "require.progs" "cc"
     50       1.2    martin }
     51       1.2    martin 
     52       1.1    jruoho atf_test_case hello32
     53       1.1    jruoho hello32_head() {
     54       1.1    jruoho 	atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
     55       1.1    jruoho 	atf_set "require.progs" "cc file diff cat"
     56       1.1    jruoho }
     57       1.1    jruoho 
     58       1.1    jruoho hello_body() {
     59       1.1    jruoho 	cat > test.c << EOF
     60       1.1    jruoho #include <stdio.h>
     61       1.1    jruoho #include <stdlib.h>
     62       1.1    jruoho int main(void) {printf("hello world\n");exit(0);}
     63       1.1    jruoho EOF
     64       1.1    jruoho 	atf_check -s exit:0 -o ignore -e ignore cc -o hello test.c
     65       1.1    jruoho 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     66       1.1    jruoho }
     67       1.1    jruoho 
     68       1.5    martin hello_profile_body() {
     69       1.5    martin 	cat > test.c << EOF
     70       1.5    martin #include <stdio.h>
     71       1.5    martin #include <stdlib.h>
     72       1.5    martin int main(void) {printf("hello world\n");exit(0);}
     73       1.5    martin EOF
     74       1.5    martin 	atf_check -s exit:0 -o ignore -e ignore cc -o hello -pg test.c
     75  1.6.10.2    martin 	case `uname -p` in
     76  1.6.10.2    martin 	aarch64)
     77  1.6.10.2    martin 		atf_expect_fail 'cc -pg is busted on aarch64'
     78  1.6.10.2    martin 		;;
     79  1.6.10.2    martin 	esac
     80       1.5    martin 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     81  1.6.10.1  christos 	atf_check -s exit:0 -o ignore -e ignore cc -o hello2 -fprofile-generate test.c
     82  1.6.10.1  christos 	atf_check -s exit:0 -o inline:"hello world\n" ./hello2
     83       1.5    martin }
     84       1.5    martin 
     85       1.1    jruoho hello_pic_body() {
     86       1.1    jruoho 	cat > test.c << EOF
     87       1.1    jruoho #include <stdlib.h>
     88       1.4     kamil int callpic(void);
     89       1.1    jruoho int main(void) {callpic();exit(0);}
     90       1.1    jruoho EOF
     91       1.1    jruoho 	cat > pic.c << EOF
     92       1.1    jruoho #include <stdio.h>
     93       1.4     kamil int callpic(void) {printf("hello world\n");return 0;}
     94       1.1    jruoho EOF
     95       1.1    jruoho 
     96       1.1    jruoho 	atf_check -s exit:0 -o ignore -e ignore \
     97       1.4     kamil 	    cc -fPIC -shared -o libtest.so pic.c
     98       1.1    jruoho 	atf_check -s exit:0 -o ignore -e ignore \
     99       1.1    jruoho 	    cc -o hello test.c -L. -ltest
    100       1.1    jruoho 
    101       1.1    jruoho 	export LD_LIBRARY_PATH=.
    102       1.1    jruoho 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    103       1.1    jruoho }
    104       1.1    jruoho 
    105       1.2    martin hello_pie_body() {
    106       1.2    martin 	# check whether this arch supports -pie
    107       1.2    martin 	if ! cc -pie -dM -E - < /dev/null 2>/dev/null >/dev/null; then
    108       1.2    martin 		atf_skip "cc -pie not supported on this architecture"
    109       1.2    martin 	fi
    110       1.2    martin 	cat > test.c << EOF
    111       1.2    martin #include <stdio.h>
    112       1.2    martin #include <stdlib.h>
    113       1.2    martin int main(void) {printf("hello world\n");exit(0);}
    114       1.2    martin EOF
    115       1.2    martin 	atf_check -s exit:0 -o ignore -e ignore cc -fpie -pie -o hello test.c
    116       1.2    martin 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
    117       1.2    martin }
    118       1.2    martin 
    119       1.1    jruoho hello32_body() {
    120       1.1    jruoho 	# check whether this arch is 64bit
    121       1.1    jruoho 	if ! cc -dM -E - < /dev/null | fgrep -q _LP64; then
    122       1.1    jruoho 		atf_skip "this is not a 64 bit architecture"
    123       1.1    jruoho 	fi
    124       1.1    jruoho 	if ! cc -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
    125       1.1    jruoho 		atf_skip "cc -m32 not supported on this architecture"
    126       1.1    jruoho 	else
    127       1.1    jruoho 		if fgrep -q _LP64 ./def32; then
    128       1.1    jruoho 			atf_fail "cc -m32 does not generate netbsd32 binaries"
    129       1.1    jruoho 		fi
    130       1.1    jruoho 	fi
    131       1.1    jruoho 
    132       1.1    jruoho 	cat > test.c << EOF
    133       1.1    jruoho #include <stdio.h>
    134       1.1    jruoho #include <stdlib.h>
    135       1.1    jruoho int main(void) {printf("hello world\n");exit(0);}
    136       1.1    jruoho EOF
    137       1.1    jruoho 	atf_check -s exit:0 -o ignore -e ignore cc -o hello32 -m32 test.c
    138       1.1    jruoho 	atf_check -s exit:0 -o ignore -e ignore cc -o hello64 test.c
    139       1.1    jruoho 	file -b ./hello32 > ./ftype32
    140       1.1    jruoho 	file -b ./hello64 > ./ftype64
    141       1.1    jruoho 	if diff ./ftype32 ./ftype64 >/dev/null; then
    142       1.1    jruoho 		atf_fail "generated binaries do not differ"
    143       1.1    jruoho 	fi
    144       1.1    jruoho 	echo "32bit binaries on this platform are:"
    145       1.1    jruoho 	cat ./ftype32
    146       1.1    jruoho 	echo "While native (64bit) binaries are:"
    147       1.1    jruoho 	cat ./ftype64
    148       1.1    jruoho 	atf_check -s exit:0 -o inline:"hello world\n" ./hello32
    149       1.1    jruoho 
    150       1.1    jruoho 	# do another test with static 32bit binaries
    151       1.1    jruoho 	cat > test.c << EOF
    152       1.1    jruoho #include <stdio.h>
    153       1.1    jruoho #include <stdlib.h>
    154       1.1    jruoho int main(void) {printf("hello static world\n");exit(0);}
    155       1.1    jruoho EOF
    156       1.1    jruoho 	atf_check -s exit:0 -o ignore -e ignore cc -o hello -m32 \
    157       1.1    jruoho 	    -static test.c
    158       1.1    jruoho 	atf_check -s exit:0 -o inline:"hello static world\n" ./hello
    159       1.6    martin 
    160       1.6    martin 	# and another test with profile 32bit binaries
    161       1.6    martin 	cat > test.c << EOF
    162       1.6    martin #include <stdio.h>
    163       1.6    martin #include <stdlib.h>
    164       1.6    martin int main(void) {printf("hello 32bit profile world\n");exit(0);}
    165       1.6    martin EOF
    166       1.6    martin 	atf_check -s exit:0 -o ignore -e ignore cc -o hello -m32 \
    167       1.6    martin 	    -pg test.c
    168       1.6    martin 	atf_check -s exit:0 -o inline:"hello 32bit profile world\n" ./hello
    169       1.1    jruoho }
    170       1.1    jruoho 
    171       1.1    jruoho atf_init_test_cases()
    172       1.1    jruoho {
    173       1.1    jruoho 
    174       1.1    jruoho 	atf_add_test_case hello
    175       1.5    martin 	atf_add_test_case hello_profile
    176       1.1    jruoho 	atf_add_test_case hello_pic
    177       1.2    martin 	atf_add_test_case hello_pie
    178       1.1    jruoho 	atf_add_test_case hello32
    179       1.1    jruoho }
    180