mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jcambon
28.01.2009 bd458262d71f8a331082e8b4d00a2f47b0eaa3fd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !
 !      Copyright 2008 Sun Microsystems, Inc.
 ! -->
<project name="tests">
  <description>
    Execute the tests.
  </description>
 
  <target name="run">
    <tstamp>
      <format property="tests.run.time" pattern="yyyy.MM.dd-HH.mm.ss"/>
    </tstamp>
 
      <!-- clean up some -->
    <delete dir="${tests.tmp.dir}"/>
 
      <!-- make all the necessary directories for this test run -->
    <mkdir dir="${tests.tmp.dir}"/>
    <mkdir dir="${tests.run.dir}/${tests.run.time}"/>
    <mkdir dir="${tests.run.dir}/${tests.run.time}/config"/>
    <mkdir dir="${tests.run.dir}/${tests.run.time}/report"/>
      <!-- these will serve for after-the-fact archiving the logs -->
    <mkdir dir="${tests.run.dir}/${tests.run.time}/staf-logs"/>
    <mkdir dir="${tests.run.dir}/${tests.run.time}/server-logs"/>
    <mkdir dir="${tests.run.dir}/${tests.run.time}/coverage"/>
 
    <!--<delete file="${test.plan.default}"/>
    <for list="${test.plan.list}" param="item">
      <sequential>
      <echo file="${test.plan.default}" append="true">@{item}
</echo>
      </sequential>
    </for>-->
 
    <!-- generate the timestamped config file that will be used for this run -->
    <copy file="${tests.config.stubs}"
          tofile="${tests.run.dir}/${tests.run.time}/config/${tests.config.file}">
      <filterchain>
        <expandproperties/>
      </filterchain>
    </copy>
 
    <!-- this is a windows-specific measure to replace the windows file
         separator by a forward slash. Staf otherwise fails to find the files. -->
    <replace file="${tests.run.dir}/${tests.run.time}/config/${tests.config.file}" token="\" value="/"/>
 
    <property name="tests.request" value="EXECUTE FILE ${tests.xml} JOBNAME OpenDS_Functional_Tests SCRIPTFILE ${tests.run.dir}/${tests.run.time}/config/${tests.config.file} WAIT CLEARLOGS"/>
 
    <echo>While the tests are running you may tail the job logs at</echo>
    <echo>${staf.install.dir}/logs/MACHINE/${host.name}</echo>
    <echo>Running tests. This will take more than a while.</echo>
    <property name="CLASSPATH" value="${staf.lib.dir}/JSTAF.jar${path.separator}${e.CLASSPATH}"/>
    <exec
      dir="${staf.bin.dir}"
      executable="${staf.executable}"
      >
      <arg line="LOCAL STAX ${tests.request}"/>
      <env key="CLASSPATH" path="${staf.lib.dir}/JSTAF.jar${path.separator}${e.CLASSPATH}"/>
      <env key="LD_LIBRARY_PATH" value="${staf.lib.dir}"/>
      <env key="STAFCONVDIR" value="${staf.install.dir}/codepage"/>
      <env key="STAFCODEPAGE" value="LATIN_1"/>
    </exec>
 
    <symlink link="${tests.run.dir}/latest" resource="${tests.run.time}" overwrite="true"/>
    <if>
      <available file="${tests.tmp.dir}/${product.name}/logs"/>
      <then>
        <echo>Saving server logs</echo>
        <copy todir="${tests.run.dir}/${tests.run.time}/server-logs">
          <fileset dir="${tests.tmp.dir}/${product.name}/logs"/>
        </copy>
      </then>
    </if>
    <echo>Saving Staf/Stax logs</echo>
    <copy todir="${tests.run.dir}/${tests.run.time}/staf-logs">
      <fileset dir="${staf.install.dir}/logs"/>
    </copy>
    <delete dir="${staf.install.dir}/logs"/>
    <echo>Saving report</echo>
    <copy todir="${tests.run.dir}/${tests.run.time}/report">
      <fileset dir="${tests.tmp.dir}">
        <include name="r*"/>
      </fileset>
    </copy>
    <delete file="${tests.tmp.dir}/percentage.properties"/>
  </target>
 
  <target name="configure">
    <condition property="already.customized" value="true" else="false">
      <available file="${test.plan.custom}" />
    </condition>
    <if>
      <equals arg1="${already.customized}" arg2="true" />
      <then>
        <input message="A previously customized test plan was detected. Do you want to change the list of suites to run?" validargs="y,n" defaultvalue="n" addproperty="prompt.do" />
      </then>
      <else>
        <echo>No previous customized test plan found.</echo>
        <property name="prompt.do" value="y" />
      </else>
    </if>
    <if>
      <equals arg1="${prompt.do}" arg2="y" />
      <then>
        <delete file="${test.plan.custom}" />
 
        <for param="item">
          <dirset dir="${tests.dir}/testcases"
                  includes="*">
            <type type="dir"/>
          </dirset>
          <sequential>
            <var name="test" unset="true"/>
            <var name="answer" unset="true"/>
 
            <basename property="test" file="@{item}"/>
            <input message="Do you want to execute ${test}?" validargs="y,n" defaultvalue="y" addproperty="answer"/>
            <if>
              <equals arg1="${answer}" arg2="y" />
              <then>
                <echo file="${test.plan.custom}" append="true">${test}
</echo>
              </then>
            </if>
          </sequential>
        </for>
      </then>
    </if>
  </target>
 
  <target name="send-mail-prepare">
    <condition property="test.successful">
      <available file="${tests.tmp.dir}/my-report.html"/>
    </condition>
    <condition property="email.send">
      <equals arg1="${email.enabled}" arg2="y"
              casesensitive="false" trim="true"/>
    </condition>
  </target>
  <target name="send-mail-get-percentage" depends="send-mail-prepare" if="test.successful">
    <echo>test report found.Proceeding...</echo>
    <delete file="${tests.tmp.dir}/percentage.properties"/>
    <copy file="${tests.tmp.dir}/my-report.html" tofile="${tests.tmp.dir}/percentage.properties">
      <filterchain>
        <linecontains>
          <contains value='font size="+2'/>
        </linecontains>
        <tokenfilter>
          <replaceregex pattern=".*font size=.+2..(.*\d+)%./font.*" replace="test.percentage=\1"/>
        </tokenfilter>
      </filterchain>
    </copy>
    <property file="${tests.tmp.dir}/percentage.properties"/>
    <echo>Test Success Rate: ${test.percentage}%</echo>
  </target>
  <target name="send-mail" if="email.send" depends="send-mail-get-percentage">
    <condition property="email.send.noauth">
      <or>
        <not>
          <isset property="email.server.user"/>
        </not>
        <not>
          <length string="${email.server.user}" when="greater"
                  trim="true" length="0"/>
        </not>
      </or>
    </condition>
    <condition property="email.file"
               value="${tests.tmp.dir}/my-report.html"
               else="staf-installer/failure.html">
      <available file="${tests.tmp.dir}/my-report.html"/>
    </condition>
    <condition property="email.subject"
               value="FT - Run - ${daily.date} - ${os.name} - ${os.arch} - ${test.percentage}%"
               else="FT - Failed -${daily.date} - ${os.name} - ${os.arch}">
      <available file="${tests.tmp.dir}/my-report.html"/>
    </condition>
    <antcall target="send-mail-noauth"/>
    <antcall target="send-mail-withauth"/>
  </target>
  <target name="send-mail-noauth" if="email.send.noauth">
    <mail from="${email.from}"
          tolist="${email.to}"
          subject="${email.subject}"
          mailhost="${email.server.host}"
          mailport="${email.server.port}"
          messagefile="${email.file}"
          messagemimetype="text/html" />
  </target>
  <target name="send-mail-withauth" unless="email.send.noauth">
    <mail from="${email.from}"
          tolist="${email.to}"
          subject="${email.subject}"
          mailhost="${email.server.host}"
          mailport="${email.server.port}"
          user="${email.server.user}"
          password="${email.server.pwd}"
          messagefile="${email.file}"
          messagemimetype="text/html" />
  </target>
  <target name="coverage-init">
    <path id="emma.lib">
      <pathelement location="${project.home}/ext/emma/lib/emma.jar"     />
      <pathelement location="${project.home}/ext/emma/lib/emma_ant.jar" />
    </path>
    <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
  </target>
  <target name="coverage-on" depends="coverage-init">
    <property name="coverage.on" value="true"/>
  </target>
  <target name="coverage-instrument" if="coverage.on">
    <delete dir="${tests.tmp.dir}/coverage-instr" />
    <mkdir dir="${tests.tmp.dir}/coverage-instr" />
    <!-- unzip the original package in a temporary location to make the
         changes necessary so that the coverage tool is called
     -->
    <unzip src="${product.package}"
           dest="${tests.tmp.dir}/coverage-instr"/>
 
    <!-- Add emma in the package along with the other librairies
         this has the advantage of being automatically picked up by the scripts
    -->
    <copy file="${project.home}/ext/emma/lib/emma.jar"
          tofile="${tests.tmp.dir}/coverage-instr/${product.name}/lib/emma.jar"/>
 
    <!-- move the original product package to make room for the coverage
         enabled package
     -->
    <move file="${product.package}" tofile="${product.package}.nocov"/>
 
    <!-- intrument the OpenDS java archive to gather coverage -->
    <java classpath="${tests.tmp.dir}${file.separator}coverage-instr${file.separator}${product.name}${file.separator}lib${file.separator}emma.jar"
          classname="emma" fork="true">
      <jvmarg value="-Demma.metadata.out.file=${tests.tmp.dir}${file.separator}coverage-instr${file.separator}${product.name}${file.separator}coverage.em" />
      <arg value="instr" />
      <arg value="-m" />
      <arg value="overwrite" />
      <arg value="-ip" />
      <arg value="${tests.tmp.dir}${file.separator}coverage-instr${file.separator}${product.name}${file.separator}lib${file.separator}OpenDS.jar:${tests.tmp.dir}${file.separator}coverage-instr${file.separator}${product.name}${file.separator}lib${file.separator}extensions${file.separator}snmp-mib2605.jar" />
    </java>
    <echo>Writing properties file</echo>
    <echo file="${tests.tmp.dir}/coverage-instr/${product.name}/classes/emma.properties">coverage.out.file=${tests.tmp.dir}/emma.coverage
    </echo>
    <!-- Repackage the product with coverage enabled scripts -->
    <zip basedir="${tests.tmp.dir}/coverage-instr" destfile="${product.package}">
      <zipfileset dir="${tests.tmp.dir}/coverage-instr"
                  includes="${product.name}/setup,${product.name}/uninstall,${product.name}/upgrade,${product.name}/bin/*,${product.name}/lib/*.sh"
           filemode="755" dirmode="755" />
    </zip>
    <!-- <delete dir="${tests.tmp.dir}/coverage-instr"/> -->
  </target>
  <target name="coverage-report" if="coverage.on">
    <delete dir="${tests.tmp.dir}/coverage/all" />
    <mkdir dir="${tests.tmp.dir}/coverage/all" />
    <emma enabled="${coverage.on}" >
      <report >
        <infileset dir="${tests.tmp.dir}" includes="**/*.em,**/*.ec" />
        <sourcepath>
          <dirset dir="${project.home}" >
            <include name="src" />
          </dirset>
        </sourcepath>
        <html outfile="${tests.tmp.dir}/coverage/all/index.html"
              columns="name, method, line"
              sort="+line, +name"
              metrics="line:80"
        />
      </report>
    </emma>
  </target>
  <target name="restore-pkg" if="coverage.on">
    <delete file="${product.package}"/>
    <move file="${product.package}.nocov" tofile="${product.package}"/>
  </target>
  <target name="testwithcoverage" depends="coverage-on,coverage-instrument,restore-pkg,coverage-report"/>
<!-- Run tests section - bottom -->
 
</project>