]> git.saurik.com Git - apple/xnu.git/blame - tools/tests/unit_tests/build_tests.sh
xnu-2422.1.72.tar.gz
[apple/xnu.git] / tools / tests / unit_tests / build_tests.sh
CommitLineData
39236c6e
A
1#!/usr/bin/env bash
2
3function run_test() {
4 local testname="$1"
5 local out_status=1
6 local out_str=" "
7
8 echo ""
9 echo "[TEST] ${testname} "
10 if [ -x "./${testname}" ]
11 then
12 echo "[BEGIN] Executing test ${testname}"
13 out_str=$(./"${testname}" 2>&1)
14 out_status="$?"
15 else
16 echo "[FAIL] Failed to execute test with name ${testname}"
17 out_status=1
18 fi
19
20 if [ "${out_status}" == "0" ]
21 then
22 echo "[PASS] Successfully finished ${testname}"
23 else
24 echo $out_str
25 echo "[FAIL] Test failed ${testname} exit value $out_status"
26 echo " *** FAILURE of test ${testname} *** "
27 echo ""
28 fi
29 return $out_status
30}
31
32function build_test(){
33 local testtarget="$1"
34 local out_str=" "
35 local out_status=1
36
37 echo "[MAKE] Building test ${testtarget}"
38 out_str=$(make ${MAKE_ARGS} ${testtarget} 2>&1)
39 out_status=$?
40 echo ${out_str} >> ${BUILD_LOG_FILEMAME}
41
42 if [ "${out_status}" == "0" ]
43 then
44 echo "[PASS][BUILD] Successfully built ${testtarget}"
45 else
46 echo ${out_str}
47 echo "[FAIL][BUILD] Failed to build ${testtarget}"
48 fi
49 return ${out_status}
50}
51
52CMD=build
53TARGET_MODE=$1
54TIMESTAMP=`date +%s`
55PROGNAME=$0
56TARGET_LIST_FILE="xnu_target_executables.list"
57BUILD_DIR="${PWD}/BUILD/"
58BUILD_LOG_FILEMAME="${BUILD_DIR}/build_${TIMESTAMP}.log"
59
60# load the list of targets to build/run
61if [ -f "$TARGET_LIST_FILE" ]
62then
63 TARGET_NAMES=`cat $TARGET_LIST_FILE`
64else
65 TARGET_NAMES=`make ${MAKE_ARGS} list_targets`
66fi
67
68if [ "$CMD" == "build" ]
69then
70
71 # setup make arguments based on target requirements
72 if [ "${TARGET_MODE}" == "embedded" ]
73 then
74 T_ios=`/usr/bin/xcodebuild -sdk iphoneos.internal -version Path`
75 T_ios_name=iphoneos.internal
76 if [ "$T_ios" == "" ]
77 then
78 T_ios=`/usr/bin/xcodebuild -sdk iphoneos -version Path`
79 T_ios_name=iphoneos
80 fi
81
82 if [ "$T_ios" == "" ]
83 then
84 echo "No iOS SDK found. Exiting."
85 exit 1
86 fi
87
88 MAKE_ARGS="SDKROOT=${T_ios_name}"
89 elif [ "${TARGET_MODE}" == "desktop" ]
90 then
91 MAKE_ARGS=""
92 else
93 echo "Usage: ${PROGNAME} <desktop|embedded>"
94 exit 1
95 fi
96
97 if [ -d "${BUILD_DIR}" ]
98 then
99 mkdir -p ${BUILD_DIR}
100 fi
101
102 echo " "
103 echo "=========== Building XNU Unit Tests ========="
104 echo " "
105
106 for testname_target in ${TARGET_NAMES}
107 do
108 build_test ${makefilename} ${testname_target}
109 echo ""
110 done
111
112 echo "Finished building tests. Saving list of targets in ${BUILD_DIR}/dst/${TARGET_LIST_FILE}"
113 echo "${TARGET_NAMES}" > ${BUILD_DIR}/dst/${TARGET_LIST_FILE}
114 cat "${PROGNAME}" | sed s/^CMD=build/CMD=run/g > ${BUILD_DIR}/dst/run_tests.sh
115 chmod +x ${BUILD_DIR}/dst/run_tests.sh
116 echo "Generated ${BUILD_DIR}/dst/run_tests.sh for running the tests."
117 exit 0
118
119fi
120# End of Build action
121
122#
123if [ "$CMD" == "run" ]
124then
125 echo " "
126 echo "=========== Running XNU Unit Tests ========="
127 echo " "
128 for testname_target in ${TARGET_NAMES}
129 do
130 run_test ${testname_target}
131 done
132 exit 0
133fi
134# End of Run action