1#! bash -f 2#--------------------------------------------------------------------------- 3# Project: TwlSDK - tools 4# File: make_utest_main__ 5# 6# Copyright 2007 Nintendo. All rights reserved. 7# 8# These coded instructions, statements, and computer programs contain 9# proprietary information of Nintendo of America Inc. and/or Nintendo 10# Company Ltd., and are protected by Federal copyright law. They may 11# not be disclosed to third parties or copied or duplicated in any form, 12# in whole or in part, without the prior written consent of Nintendo. 13# 14# $Date:: 2007-12-28#$ 15# $Rev: 3324 $ 16# $Author: okubata_ryoma $ 17#--------------------------------------------------------------------------- 18 19(shopt -s igncr) 2>/dev/null && eval 'shopt -s igncr';# 20 21#-------------------------- 22# Decode Command Line 23# -o [outfile] infiles 24#-------------------------- 25UTEST_IN= 26UTEST_OUT=utest_main__.c # default outfile 27 28for i in `getopt 'c:' $*` 29do 30 case "$i" in \ 31 -* ) 32 opt=$i 33 ;; 34 * ) 35 case "$opt" in \ 36 -c ) 37 UTEST_OUT="$i" 38 ;; 39 * ) 40 UTEST_IN="$UTEST_IN $i" 41 ;; 42 esac 43 esac 44done 45 46if [ "$UTEST_IN" == "" ] 47then 48 echo "Usage: `basename $0` [-c output_c_source] objfile..." > /dev/stderr 49 exit -1; 50fi 51 52#echo $UTEST_IN > /dev/stderr 53#echo $UTEST_OUT > /dev/stderr 54 55#-------------------------- 56# Generate test code 57# nm & perl 58#-------------------------- 59/bin/nm -Ap $UTEST_IN | 60/bin/perl -e ' 61 %filename = (); 62 %callback_begin = (); 63 %callback_end = (); 64 @namelist = (); 65 while ( <> ) { 66 # Search UTESTBEGIN_XXXX 67 if ( ($file,$name) = /^(.+):00000000 T (UTESTBEGIN_[A-Za-z0-9_]+)$/ ) { 68 if ( ! exists $callback_begin{$file} ){ 69 $callback_begin{$file} = $name; 70 } 71 else { 72 print STDERR "Warning: Initializer($name) redefined...\n"; 73 print STDERR " in $file (skipped)\n"; 74 } 75 } 76 # Search UTESTEND_XXXX 77 elsif ( ($file,$name) = /^(.+):00000000 T (UTESTEND_[A-Za-z0-9_]+)$/ ) { 78 if ( ! exists $callback_end{$file} ){ 79 $callback_end{$file} = $name; 80 } 81 else { 82 print STDERR "Warning: Initializer($name) redefined...\n"; 83 print STDERR " in $file (skipped)\n"; 84 } 85 } 86 # Search UTEST_XXXX 87 elsif ( ($file,$name) = /^(.+):00000000 T (UTEST_[A-Za-z0-9_]+)$/ ) { 88 if ( ! exists $filename{$name} ){ 89 $filename{$name} = $file; 90 unshift(@namelist,$name); 91 } 92 else { 93 print STDERR "Warning: $name redefined...\n"; 94 print STDERR " in $filename{$name}\n"; 95 print STDERR " and $file (skipped)\n"; 96 } 97 } 98 } 99 100 if ( $#namelist < 0 ){ 101 print STDERR "No test modules.\n"; 102 exit 1; 103 } 104 105 # 106 # include files 107 # 108 print "#include <nitro/utest.h>\n\n"; 109 110 # 111 # prototypes 112 # 113 foreach $name ( values( %callback_begin ) ){ 114 print "void $name(void);\n"; 115 } 116 foreach $name ( values( %callback_end ) ){ 117 print "void $name(void);\n"; 118 } 119 foreach $name ( @namelist ){ 120 print "void $name(void);\n"; 121 } 122 print "\n"; 123 124 # 125 # list of test modules 126 # 127 print "static UTiModule Modules[] =\n"; 128 print "{\n"; 129 foreach $name ( @namelist ){ 130 $file = $filename{$name}; 131 $cb_begin = exists $callback_begin{$file} ? $callback_begin{$file} : "0"; 132 $cb_end = exists $callback_end{$file} ? $callback_end{$file} : "0"; 133 print " {\n"; 134 print " \"$file\",\n"; 135 print " \"$name\",\n"; 136 print " $name,\n"; 137 print " $cb_begin,\n"; 138 print " $cb_end,\n"; 139 print " },\n"; 140 } 141 print "};\n"; 142 print "\n"; 143 144 # 145 # number of test modules 146 # 147 print "static int NumModule = sizeof(Modules)/sizeof(UTiModule);\n"; 148 print "\n"; 149 150 # 151 # NitroMain 152 # 153 print "void NitroMain(void);\n"; 154 print "void NitroMain(void)\n"; 155 print "{\n"; 156 print " UTi_Main(NumModule, Modules);\n"; 157 print "}\n"; 158 print "\n"; 159' > $UTEST_OUT && echo "Create... $UTEST_OUT" || rm $UTEST_OUT 160 161# 162# Because the return value is always TRUE, advancement to the next process should be determined based on whether or not $UTEST_OUT can be done. 163# 164# 165 166#===== End of makeutest ===== 167