TEST.mk 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * regression test support
  3. *
  4. * @(#)TEST.mk (AT&T Research) 2010-05-19
  5. *
  6. * test management is still in the design phase
  7. */
  8. /*
  9. * three forms for :TEST:
  10. *
  11. * :TEST: xxx yyy ...
  12. *
  13. * $(REGRESS) $(REGRESSFLAGS) xxx.tst
  14. * $(REGRESS) $(REGRESSFLAGS) yyy.tst
  15. *
  16. * :TEST: xxx.tst yyy ...
  17. *
  18. * $(REGRESS) $(REGRESSFLAGS) xxx.tst yyy ...
  19. *
  20. * :TEST: xxx.c [ :: test-prereq ... :: ] [ args [ : args ... ] ]
  21. *
  22. * :TEST: xxx.sh [ :: test-prereq ... :: ] [ args [ : args ... ] ]
  23. *
  24. * xxx :TEST: prereq ...
  25. * [ action ]
  26. *
  27. * $(*) if no action
  28. */
  29. ":TEST:" : .MAKE .OPERATOR
  30. local B G P S T
  31. test : .INSERT .TESTINIT
  32. if "$("tests":T=FD)"
  33. .SOURCE : tests
  34. end
  35. P := $(>:O=1)
  36. if "$(P:N=*.tst)" && ! "$(@:V)"
  37. B := $(P:B)
  38. if ! ( T = "$(<:V)" )
  39. T := $(B)
  40. end
  41. test : - test.$(T)
  42. eval
  43. test.$$(T) : $$(B).tst
  44. $$(REGRESS) $$(REGRESSFLAGS) $$(*) $(>:V:O>1)
  45. :SAVE: $$(B).tst
  46. end
  47. elif "$(P:N=*@(.sh|$(.SUFFIX.c:/ /|/G)|$(.SUFFIX.C:/ /|/G)))"
  48. B := $(P:B)
  49. if ! ( T = "$(<:V)" )
  50. T := $(B)
  51. end
  52. :INSTALLDIR: $(B)
  53. $(B) :: $(P) $(*:-l*|*$(CC.SUFFIX.ARCHIVE))
  54. if "$(P:N=*.sh)"
  55. TESTCC == $(CC)
  56. $(B) : (TESTCC)
  57. end
  58. test : - test.$(T)
  59. if "$(@:V)"
  60. eval
  61. test.$$(T) : $$(B) $(>:V:O>1)
  62. set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
  63. $(@:V)
  64. end
  65. elif "$(>:V:O>1)"
  66. local I A V X S R=0
  67. for A $(>:V:O>1)
  68. if A == "::"
  69. let R = !R
  70. elif A == ":"
  71. let I = I + 1
  72. test.$(T).$(I) := $(V:V)
  73. V =
  74. X := $(X:V)$(S)$$(*) $$(test.$(T).$(I):T=*)
  75. S = $("\n")
  76. elif A != "-l*|*$(CC.SUFFIX.ARCHIVE)"
  77. if R
  78. test.$(A) : .VIRTUAL .FORCE
  79. test.$(T) : test.$(A)
  80. else
  81. V += $(A:V)
  82. end
  83. end
  84. end
  85. if V
  86. let I = I + 1
  87. test.$(T).$(I) := $(V:V)
  88. X := $(X:V)$(S)$$(*) $$(test.$(T).$(I):T=*)
  89. end
  90. eval
  91. test.$$(T) : $$(B)
  92. set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
  93. $(X:V)
  94. end
  95. else
  96. eval
  97. test.$$(T) : $$(B)
  98. set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
  99. $$(*)
  100. end
  101. end
  102. elif ! "$(<:V)"
  103. G = 1
  104. for B $(>)
  105. if B == "-|--"
  106. let G = !G
  107. else
  108. if ! G
  109. T =
  110. elif ! ( T = "$(B:A=.COMMAND)" ) && ! "$(B:A=.TARGET)"
  111. for S .c .sh
  112. if "$(B:B:S=$(S):T=F)"
  113. :INSTALLDIR: $(B)
  114. $(B) :: $(B:B:S=$(S))
  115. T := $(B)
  116. break
  117. end
  118. end
  119. end
  120. test : - test.$(B)
  121. test.$(B) : $(T) - $(B).tst
  122. $(REGRESS) $(REGRESSFLAGS) $(*:N=*.tst) $(*:N!=*.tst)
  123. :SAVE: $(B).tst
  124. end
  125. end
  126. else
  127. if "$(>:V)" || "$(@:V)"
  128. P := $(>)
  129. T := $(P:O=1)
  130. B := $(T:B)
  131. if "$(T)" != "$(B)" && "$(T:G=$(B))"
  132. :INSTALLDIR: $(B)
  133. $(B) :: $(T) $(P:O>1:N=-*)
  134. T := $(B)
  135. P := $(B) $(P:O>1:N!=-*)
  136. end
  137. if "$(<:V)"
  138. T := $(<:V)
  139. end
  140. test : - test.$(T)
  141. if "$(@:V)"
  142. eval
  143. test.$$(T) : $$(P) $(>:V:O>1)
  144. set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
  145. $(@:V)
  146. end
  147. else
  148. test.$(T) : $(P)
  149. set +x; (ulimit -c 0) >/dev/null 2>&1 && ulimit -c 0; set -x
  150. $(*)
  151. end
  152. else
  153. test : - test.$(<)
  154. test.$(<) : $(<).tst $(<:A=.COMMAND)
  155. $(REGRESS) $(REGRESSFLAGS) $(*)
  156. end
  157. end
  158. .TESTINIT : .MAKE .VIRTUAL .FORCE .REPEAT
  159. if VARIANT == "DLL"
  160. error 1 :DLL: tests skipped
  161. exit 0
  162. end
  163. set keepgoing
  164. REGRESSFLAGS &= $(TESTS:@/ /|/G:/.*/--test=&/:@Q)
  165. .SCAN.tst : .SCAN
  166. $(@.SCAN.sh)
  167. I| INCLUDE@ % |
  168. .ATTRIBUTE.%.tst : .SCAN.tst
  169. MKTEST = mktest
  170. MKTESTFLAGS = --style=regress
  171. /*
  172. * test scripts are only regenerated from *.rt when --force
  173. * is specified or the .rt file is newer than the script
  174. * otherwise the script is accepted if it exists
  175. *
  176. * this avoids the case where a fresh build with no state
  177. * would regenerate the test script and capture current
  178. * behavior instead of expected behavior
  179. */
  180. %.tst : %.rt
  181. if [[ "$(-force)" || "$(>)" -nt "$(^|<)" ]]
  182. then $(MKTEST) $(MKTESTFLAGS) $(>) > $(<)
  183. fi
  184. test%.sh test%.out : %.rt
  185. if [[ "$(-force)" || "$(>)" -nt "$(^|<:O=1)" ]]
  186. then $(MKTEST) --style=shell $(>) > $(<:N=*.sh)
  187. $(SHELL) $(<:N=*.sh) --accept > $(<:N=*.out)
  188. fi