PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ksh/api/tetapi.ksh

#
Korn Shell | 339 lines | 170 code | 37 blank | 132 comment | 21 complexity | ecc67595d90c18fc9dc575ff2118cd66 MD5 | raw file
  1. #
  2. # SCCS: @(#)tetapi.ksh 1.3 (96/10/11)
  3. #
  4. # UniSoft Ltd., London, England
  5. #
  6. # (C) Copyright 1996 X/Open Company Limited
  7. #
  8. # All rights reserved. No part of this source code may be reproduced,
  9. # stored in a retrieval system, or transmitted, in any form or by any
  10. # means, electronic, mechanical, photocopying, recording or otherwise,
  11. # except as stated in the end-user licence agreement, without the prior
  12. # permission of the copyright owners.
  13. # A copy of the end-user licence agreement is contained in the file
  14. # Licence which accompanies this distribution.
  15. #
  16. # X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
  17. # the UK and other countries.
  18. #
  19. # ************************************************************************
  20. # Copyright 1990 Open Software Foundation (OSF)
  21. # Copyright 1990 Unix International (UI)
  22. # Copyright 1990 X/Open Company Limited (X/Open)
  23. # Copyright 1991 Hewlett-Packard Co. (HP)
  24. #
  25. # Permission to use, copy, modify, and distribute this software and its
  26. # documentation for any purpose and without fee is hereby granted, provided
  27. # that the above copyright notice appear in all copies and that both that
  28. # copyright notice and this permission notice appear in supporting
  29. # documentation, and that the name of HP, OSF, UI or X/Open not be used in
  30. # advertising or publicity pertaining to distribution of the software
  31. # without specific, written prior permission. HP, OSF, UI and X/Open make
  32. # no representations about the suitability of this software for any purpose.
  33. # It is provided "as is" without express or implied warranty.
  34. #
  35. # HP, OSF, UI and X/Open DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  36. # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  37. # EVENT SHALL HP, OSF, UI or X/Open BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  38. # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  39. # USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  40. # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  41. # PERFORMANCE OF THIS SOFTWARE.
  42. #
  43. # ***********************************************************************
  44. #
  45. # SCCS: @(#)tetapi.sh 1.8 03/09/92
  46. # NAME: Shell API Support Routines
  47. # PRODUCT: TET (Test Environment Toolkit)
  48. # as supplied with TETware release 3.3
  49. # AUTHOR: Andrew Dingwall, UniSoft Ltd.
  50. # DATE CREATED: 1 November 1990
  51. #
  52. # DESCRIPTION:
  53. # This file contains shell functions for use with the shell API.
  54. # It is sourced automatically by the shell TCM.
  55. # In addition it should be sourced by test purposes that are written as
  56. # separate shell scripts, by means of the shell . command.
  57. #
  58. # The following functions are provided:
  59. #
  60. # tet_setcontext
  61. # tet_setblock
  62. # tet_infoline
  63. # tet_result
  64. # tet_delete
  65. # tet_reason
  66. #
  67. # MODIFICATIONS:
  68. #
  69. # Kevin Currey Friday, November 15, 1991
  70. # For HP-PA OSF/1 and Domain/OS and HP-UX
  71. # converted to ksh bindings
  72. #
  73. # Geoff Clare, 29 Jan 1992
  74. # Rewrite tet_setcontext() so context number will change.
  75. #
  76. # Andrew Josey, UNIX System Labs, Inc. October 1993.
  77. # ETET1.10.2 Update.
  78. # TET TP numbering as per ETET scheme, which has consistency
  79. # between APIs and the TET specification.
  80. #
  81. # Andrew Josey, UNIX System Labs, Inc. November 1993.
  82. # ETET1.10.2'
  83. # Fix tet_xres handling
  84. #
  85. # Andrew Josey, Novell UNIX System Labs, February 1994
  86. # Add TET_EXTENDED=T/F handling.
  87. #
  88. # Geoff Clare, UniSoft Ltd., 3 Sept 1996
  89. # Use $$ as context number whenever possible.
  90. #
  91. # Andrew Dingwall, UniSoft Ltd., October 1996
  92. # Port to NT
  93. #
  94. # ***********************************************************************
  95. #
  96. # publicly available shell API functions
  97. #
  98. # set current context and reset block and sequence
  99. # usage: tet_setcontext
  100. # Note that when tet_setcontext is called in a subshell started using
  101. # "( ... )" we cannot use $$ because it has the same value as in the parent.
  102. tet_setcontext(){
  103. if test $$ != "$TET_CONTEXT"
  104. then
  105. TET_CONTEXT=$$
  106. else
  107. # obtain a new, unused PID without generating a zombie process.
  108. TET_CONTEXT=`(:)& echo $!`
  109. fi
  110. TET_BLOCK=1
  111. TET_SEQUENCE=1
  112. }
  113. # increment the current block ID, reset the sequence number to 1
  114. # usage: tet_setblock
  115. tet_setblock(){
  116. let TET_BLOCK=${TET_BLOCK:?}+1
  117. TET_SEQUENCE=1
  118. }
  119. # print an information line to the execution results file
  120. # and increment the sequence number
  121. # usage: tet_infoline args [...]
  122. tet_infoline(){
  123. tet_output 520 "${TET_TPNUMBER:?} ${TET_CONTEXT:?} ${TET_BLOCK:?} ${TET_SEQUENCE:?}" "$*"
  124. let TET_SEQUENCE=TET_SEQUENCE+1
  125. }
  126. # record a test result for later emmision to the execution results file
  127. # by tet_tpend
  128. # usage: tet_result result_name
  129. # (note that a result name is expected, not a result code number)
  130. tet_result(){
  131. TET_ARG1="${1:?}"
  132. if tet_getcode "$TET_ARG1"
  133. then
  134. : ok
  135. else
  136. tet_error "invalid result name \"$TET_ARG1\"" \
  137. "passed to tet_result"
  138. TET_ARG1=NORESULT
  139. fi
  140. echo $TET_ARG1 >> ${TET_TMPRES:?}
  141. unset TET_ARG1
  142. }
  143. # mark a test purpose as deleted
  144. # usage: tet_delete test_name reason [...]
  145. tet_delete(){
  146. TET_ARG1=${1:?}
  147. shift
  148. TET_ARG2N="$*"
  149. if test -z "$TET_ARG2N"
  150. then
  151. tet_undelete $TET_ARG1
  152. return
  153. fi
  154. case $TET_OSNAME in
  155. Windows_NT|Windows_95|DOS)
  156. TET_DEVNULL=nul
  157. ;;
  158. *)
  159. TET_DEVNULL=/dev/null
  160. ;;
  161. esac
  162. if tet_reason $TET_ARG1 > $TET_DEVNULL
  163. then
  164. tet_undelete $TET_ARG1
  165. fi
  166. echo "$TET_ARG1 $TET_ARG2N" >> ${TET_DELETES:?}
  167. unset TET_ARG1 TET_ARG2N
  168. }
  169. # print the reason why a test purpose has been deleted
  170. # return 0 if the test purpose has been deleted, 1 otherwise
  171. # usage: tet_reason test_name
  172. tet_reason(){
  173. : ${1:?}
  174. let TET_return=1
  175. while read TET_A TET_B
  176. do
  177. if test X"$TET_A" = X"$1"
  178. then
  179. echo "$TET_B"
  180. let TET_return=0
  181. break
  182. fi
  183. done < ${TET_DELETES:?}
  184. return $TET_return
  185. }
  186. # ******************************************************************
  187. #
  188. # "private" functions for internal use by the shell API
  189. # these are not published interfaces and may go away one day
  190. #
  191. # tet_getcode
  192. # look up a result code name in the result code definition file
  193. # return 0 if successful with the result number in TET_RESNUM and TET_ABORT
  194. # set to YES or NO
  195. # otherwise return 1 if the code could not be found
  196. tet_getcode(){
  197. TET_ABORT=NO
  198. TET_RESNUM=-1
  199. : ${TET_CODE:?}
  200. TET_A="${1:?}"
  201. while read TET_B
  202. do
  203. eval set -- $TET_B
  204. if test X$2 = X$TET_A
  205. then
  206. TET_RESNUM=$1
  207. TET_ABACTION=$3
  208. break
  209. fi
  210. done < $TET_CODE
  211. case "$TET_RESNUM" in
  212. -1)
  213. unset TET_ABACTION
  214. return 1
  215. ;;
  216. esac
  217. case "$TET_ABACTION" in
  218. ""|Continue)
  219. TET_ABORT=NO
  220. ;;
  221. Abort)
  222. TET_ABORT=YES
  223. ;;
  224. *)
  225. tet_error "invalid action field \"$TET_ABACTION\" in file" \
  226. $TET_CODE
  227. TET_ABORT=NO
  228. ;;
  229. esac
  230. unset TET_ABACTION
  231. return 0
  232. }
  233. # tet_undelete - undelete a test purpose
  234. tet_undelete(){
  235. echo "g/^${1:?} /d
  236. w
  237. q" | ed - ${TET_DELETES:?}
  238. }
  239. # tet_error - print an error message to stderr and on TCM Message line
  240. tet_error(){
  241. echo "$TET_PNAME: $*" 1>&2
  242. if [ "$TET_EXTENDED" != "T" ]
  243. then
  244. echo "510|${TET_ACTIVITY:-0}|$*" >> ${TET_RESFILE:?}
  245. else
  246. echo "510|${TET_ACTIVITY:-0}|$*" >> ${TET_JOURNAL_PATH}
  247. fi
  248. }
  249. # tet_output - print a line to the execution results file
  250. tet_output(){
  251. > ${TET_STDERR:?}
  252. TET_arg1=${1:?}
  253. TET_arg2=$2
  254. TET_arg3=$3
  255. TET_activity=${TET_ACTIVITY:-0}
  256. if test ${#TET_arg2} -gt 0
  257. then TET_sp=" "
  258. else TET_sp=""
  259. fi
  260. TET_line="${TET_arg1}|${TET_activity}${TET_sp}${TET_arg2}|$TET_arg3"
  261. # ensure no newline characters in data
  262. TET_tmp="
  263. "
  264. if test ${#TET_line} -ne 0
  265. then TET_nline=${TET_line##*${TET_tmp}*}
  266. if test ${#TET_nline} -eq 0
  267. then TET_x=$TET_line
  268. unset TET_n
  269. unset TET_nx
  270. TET_n=${TET_x##*$TET_tmp}
  271. while test ${#TET_n} -ne ${#TET_x}
  272. do
  273. TET_x=${TET_x%%${TET_tmp}$TET_n}
  274. TET_nx=${TET_n}' '$TET_nx
  275. TET_n=${TET_x##*$TET_tmp}
  276. done
  277. TET_line=${TET_n}' '$TET_nx
  278. fi
  279. fi
  280. # journal lines must not exceed 512 bytes
  281. if test ${#TET_line} -gt 511
  282. then TET_nline=${TET_line%${TET_line#???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????}}
  283. TET_line=$TET_nline
  284. print -R "warning: results file line truncated: prefix: ${TET_arg1}|${TET_activity}${TET_sp}${TET_arg2}|" > $TET_STDERR
  285. fi
  286. # line is now OK to print
  287. if [ "$TET_EXTENDED" != "T" ]
  288. then
  289. print -R "$TET_line" >> ${TET_RESFILE:?}
  290. else
  291. print -R "$TET_line" >> ${TET_JOURNAL_PATH:?}
  292. fi
  293. if test -s $TET_STDERR
  294. then unset TET_error_line
  295. while read TET_i
  296. do
  297. TET_error_line=${TET_error_line}${TET_i}
  298. done < $TET_STDERR
  299. tet_error "$TET_error_line"
  300. > $TET_STDERR
  301. fi
  302. }