Home | History | Annotate | Line # | Download | only in cc
t_hello.sh revision 1.1
      1 #	$NetBSD: t_hello.sh,v 1.1 2012/03/17 17:15:29 jruoho Exp $
      2 #
      3 # Copyright (c) 2011 The NetBSD Foundation, Inc.
      4 # All rights reserved.
      5 #
      6 # Redistribution and use in source and binary forms, with or without
      7 # modification, are permitted provided that the following conditions
      8 # are met:
      9 # 1. Redistributions of source code must retain the above copyright
     10 #    notice, this list of conditions and the following disclaimer.
     11 # 2. Redistributions in binary form must reproduce the above copyright
     12 #    notice, this list of conditions and the following disclaimer in the
     13 #    documentation and/or other materials provided with the distribution.
     14 #
     15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25 # POSSIBILITY OF SUCH DAMAGE.
     26 #
     27 
     28 atf_test_case hello
     29 hello_head() {
     30 	atf_set "descr" "compile and run \"hello world\""
     31 	atf_set "require.progs" "cc"
     32 }
     33 
     34 atf_test_case hello_pic
     35 hello_pic_head() {
     36 	atf_set "descr" "compile and run PIC \"hello world\""
     37 	atf_set "require.progs" "cc"
     38 }
     39 
     40 atf_test_case hello32
     41 hello32_head() {
     42 	atf_set "descr" "compile and run \"hello world\" for/in netbsd32 emulation"
     43 	atf_set "require.progs" "cc file diff cat"
     44 }
     45 
     46 hello_body() {
     47 	cat > test.c << EOF
     48 #include <stdio.h>
     49 #include <stdlib.h>
     50 int main(void) {printf("hello world\n");exit(0);}
     51 EOF
     52 	atf_check -s exit:0 -o ignore -e ignore cc -o hello test.c
     53 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     54 }
     55 
     56 hello_pic_body() {
     57 	cat > test.c << EOF
     58 #include <stdlib.h>
     59 int main(void) {callpic();exit(0);}
     60 EOF
     61 	cat > pic.c << EOF
     62 #include <stdio.h>
     63 int callpic(void) {printf("hello world\n");}
     64 EOF
     65 
     66 	atf_check -s exit:0 -o ignore -e ignore \
     67 	    cc -fPIC -dPIC -shared -o libtest.so pic.c
     68 	atf_check -s exit:0 -o ignore -e ignore \
     69 	    cc -o hello test.c -L. -ltest
     70 
     71 	export LD_LIBRARY_PATH=.
     72 	atf_check -s exit:0 -o inline:"hello world\n" ./hello
     73 }
     74 
     75 hello32_body() {
     76 	# check whether this arch is 64bit
     77 	if ! cc -dM -E - < /dev/null | fgrep -q _LP64; then
     78 		atf_skip "this is not a 64 bit architecture"
     79 	fi
     80 	if ! cc -m32 -dM -E - < /dev/null 2>/dev/null > ./def32; then
     81 		atf_skip "cc -m32 not supported on this architecture"
     82 	else
     83 		if fgrep -q _LP64 ./def32; then
     84 			atf_fail "cc -m32 does not generate netbsd32 binaries"
     85 		fi
     86 	fi
     87 
     88 	cat > test.c << EOF
     89 #include <stdio.h>
     90 #include <stdlib.h>
     91 int main(void) {printf("hello world\n");exit(0);}
     92 EOF
     93 	atf_check -s exit:0 -o ignore -e ignore cc -o hello32 -m32 test.c
     94 	atf_check -s exit:0 -o ignore -e ignore cc -o hello64 test.c
     95 	file -b ./hello32 > ./ftype32
     96 	file -b ./hello64 > ./ftype64
     97 	if diff ./ftype32 ./ftype64 >/dev/null; then
     98 		atf_fail "generated binaries do not differ"
     99 	fi
    100 	echo "32bit binaries on this platform are:"
    101 	cat ./ftype32
    102 	echo "While native (64bit) binaries are:"
    103 	cat ./ftype64
    104 	atf_check -s exit:0 -o inline:"hello world\n" ./hello32
    105 
    106 	# do another test with static 32bit binaries
    107 	cat > test.c << EOF
    108 #include <stdio.h>
    109 #include <stdlib.h>
    110 int main(void) {printf("hello static world\n");exit(0);}
    111 EOF
    112 	atf_check -s exit:0 -o ignore -e ignore cc -o hello -m32 \
    113 	    -static test.c
    114 	atf_check -s exit:0 -o inline:"hello static world\n" ./hello
    115 }
    116 
    117 atf_init_test_cases()
    118 {
    119 
    120 	atf_add_test_case hello
    121 	atf_add_test_case hello_pic
    122 	atf_add_test_case hello32
    123 }
    124