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

Jean-Noel Rouvignac
04.20.2013 c64b052d2fc60dcadbc8afcf1ef5b82b6857e512
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
<!--
 ! 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-2010 Sun Microsystems, Inc.
 ! -->
<project name="tests">
 
  <description>
    Execute the tests.
  </description>
 
  <target name="specs">
    <javac srcdir="${shared.dir}/java/parsingtool"
           destdir="${shared.dir}/java/parsingtool"
           debug="true"
           debuglevel="lines,vars,source"
           verbose="yes"
           />
    <delete dir="${logs.dir}/specs" failonerror="false"/>
    <mkdir dir="${logs.dir}/specs"/>
    <java classpath="${shared.dir}/java/parsingtool"
          classname="GenerateOpenDSTestSpecs" fork="true">
        <!-- uncomment "agentlib" if need debugger waiting for you
        <jvmarg value="-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address=7778"/>
        -->
        <arg value="${tests.dir}"/>
        <arg value="${logs.dir}/specs"/>
        <arg value="xml" />
    </java>
  </target>
 
  <target name="run">
    <tstamp>
      <format property="tests.timestamp" pattern="yyyyMMdd-HHmmss"/>
    </tstamp>
    <var name="tests.run.time" value="${remote.hostname}-${tests.timestamp}"/>
 
    <!-- clean up tmp dir -->
    <if>
      <equals arg1="${tests.mode}" arg2="local"/>
      <then>
        <delete dir="${tests.tmp.dir}"/>
        <mkdir dir="${tests.tmp.dir}"/>
      </then>
    </if>
 
    <!-- make all the necessary directories for this test run -->
    <mkdir dir="${tests.run.dir}/${tests.run.time}"/>
    <mkdir dir="${tests.run.dir}/${tests.run.time}/config"/>
    <!-- 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}/logs"/>
 
    <if>
      <equals arg1="${test.plan.custom}" arg2=""/>
      <then>
        <if>
          <equals arg1="${tests.type}" arg2="functional-tests"/>
          <then>
            <var name="test.plan.custom" value="${test.plan.functional.default}"/>
          </then>
          <else>
            <var name="test.plan.custom" value="${test.plan.stress.default}"/>
          </else>
        </if>
      </then>
    </if>
 
    <!-- generate the 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>
 
    <!-- generate the topology files that will be used for this run -->
    <copy todir="${tests.run.dir}/${tests.run.time}/config">
      <fileset dir="${tests.topology.dir}">
        <include name="**/*.txt"/>
      </fileset>
      <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 OpenDJ_${tests.type} 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}/${staf.name}/data-${host.name}/service/log/MACHINE/${host.name}/GLOBAL</echo>
    <echo>Running tests. This will take more than a while.</echo>
    <property name="CLASSPATH" value="${staf.lib.dir}/JSTAF.jar:."/>
    <exec
      dir="${staf.bin.dir}"
      executable="${staf.executable}"
      >
      <arg line="LOCAL STAX ${tests.request}"/>
      <env key="CLASSPATH" path="${staf.lib.dir}/JSTAF.jar:."/>
      <env key="LD_LIBRARY_PATH" value="${staf.lib.dir}"/>
      <env key="STAFCONVDIR" value="${staf.install.dir}/${staf.name}/codepage"/>
      <env key="STAFCODEPAGE" value="LATIN_1"/>
    </exec>
 
    <symlink link="${tests.run.dir}/${remote.hostname}-latest" resource="${tests.run.time}" overwrite="true"/>
    <echo>Report is available at</echo>
    <echo>${tests.run.dir}/${remote.hostname}-latest</echo>
  </target>
 
  <target name="configure">
    <echo>* Tests configuration</echo>
 
    <input message="   Run the tests on the local machine or on a remote machine?"
           defaultvalue="local"
           validargs="local,remote"
           addproperty="tests.mode.input"/>
 
    <input message="   Enter local hostname:"
               defaultvalue="${local.hostname}"
               addproperty="local.hostname.input"/>
 
    <if>
      <equals arg1="${tests.mode.input}" arg2="remote"/>
      <then>
        <input message="   Enter remote hostname:"
               defaultvalue=""
               addproperty="remote.hostname.input"/>
 
        <!-- Tests-defined values -->
        <if>
          <available file="${basedir}/${tests.type}-${local.hostname.input}-${remote.hostname.input}.properties"/>
          <then>
            <var file="${basedir}/${tests.type}-${local.hostname.input}-${remote.hostname.input}.properties"/>
          </then>
        </if>
      </then>
      <else>
        <property name="remote.hostname.input" value="${local.hostname.input}"/>
 
        <!-- Tests-defined values -->
        <if>
          <available file="${basedir}/${tests.type}-${local.hostname.input}.properties"/>
          <then>
            <var file="${basedir}/${tests.type}-${local.hostname.input}.properties"/>
          </then>
        </if>
      </else>
    </if>
 
    <if>
      <equals arg1="${tests.type}" arg2="stress-tests"/>
      <then>
        <input message="   Enter client hostname:"
               defaultvalue="${client.hostname}"
               addproperty="client.hostname.input"/>
 
        <input message="   Enter ldclt path (on client machine):"
               defaultvalue="${ldclt.dir}"
               addproperty="ldclt.dir.input"/>
      </then>
      <else>
        <property name="client.hostname.input" value="${client.hostname}"/>
        <property name="ldclt.dir.input" value="${ldclt.dir}"/>
      </else>
    </if>
 
    <input message="   Enter path to logs directory:"
           defaultvalue="${logs.dir}"
           addproperty="logs.dir.input"/>
 
    <input message="   Enter path to OpenDS archive:"
           defaultvalue="${opends.dir}"
           addproperty="opends.dir.input"/>
           
    <input message="   Enter OpenDS name:"
           defaultvalue="${opends.name}"
           addproperty="opends.name.input"/>
 
    <input message="   Enter java home:"
           defaultvalue="${local.javahome}"
           addproperty="local.javahome.input"/>
 
    <if>
      <equals arg1="${tests.mode.input}" arg2="remote" />
      <then>
        <input message="   Enter java home (on remote machine):"
               defaultvalue="${remote.javahome}"
               addproperty="remote.javahome.input"/>
      </then>
      <else>
        <property name="remote.javahome.input" value="${local.javahome.input}"/>
      </else>
    </if>
 
    <if>
      <equals arg1="${tests.mode.input}" arg2="remote" />
      <then>
        <input message="   Enter directory instance directory (on remote machine):"
           defaultvalue="${instance.dir}"
           addproperty="instance.dir.input"/>
      </then>
      <else>
        <input message="   Enter directory instance directory:"
           defaultvalue="${instance.dir}"
           addproperty="instance.dir.input"/>
      </else>
    </if>
 
    <input message="   Enter OpenDMK lib directory:"
           defaultvalue="${snmp.opendmk.lib.dir}"
           addproperty="snmp.opendmk.lib.dir.input"/>
 
    <input message="   Use default directory instance?"
           defaultvalue="${tests.default}"
           validargs="true,false"
           addproperty="tests.default.input"/>
    <if>
      <equals arg1="${tests.default.input}" arg2="false"/>
      <then>
        <input message="   Enter OpenDS ldap port:"
               defaultvalue="${opends.port.ldap}"
               addproperty="opends.port.ldap.input"/>
        <input message="   Enter OpenDS admin port:"
               defaultvalue="${opends.port.admin}"
               addproperty="opends.port.admin.input"/>
        <input message="   Enter OpenDS secure ldap port:"
               defaultvalue="${opends.port.ldaps}"
               addproperty="opends.port.ldaps.input"/>
        <input message="   Enter OpenDS admin DN (also called root DN):"
               defaultvalue="${opends.admin.dn}"
               addproperty="opends.admin.dn.input"/>
        <input message="   Enter OpenDS admin password:"
               defaultvalue="${opends.admin.pwd}"
               addproperty="opends.admin.pwd.input"/>
      </then>
      <else>
        <property name="opends.port.ldap.input" value="${opends.port.ldap}"/>
        <property name="opends.port.admin.input" value="${opends.port.admin}"/>
        <property name="opends.port.ldaps.input" value="${opends.port.ldaps}"/>
        <property name="opends.admin.dn.input" value="${opends.admin.dn}"/>
        <property name="opends.admin.pwd.input" value="${opends.admin.pwd}"/>
      </else>
    </if>
 
    <input message="   Run tests using verbose mode?"
           defaultvalue="${verbose.mode}"
           validargs="true,false"
           addproperty="verbose.mode.input"/>
 
    <echo>* Test plan configuration</echo>
    <if>
      <equals arg1="${test.plan.custom}" arg2=""/>
      <then>
        <echo>   No previous customized test plan found.</echo>
        <property name="prompt" value="y"/>
      </then>
      <else>
        <echo>   A previously customized test plan was detected:</echo>
        <echo>   ${test.plan.custom}</echo>
        <echo></echo>
        <input message="   Do you want to change the list of suites to run?"
               validargs="y,n"
               defaultvalue="n"
               addproperty="prompt"/>
      </else>
    </if>
    <if>
      <equals arg1="${prompt}" arg2="y" />
      <then>
        <var name="test.plan.custom" value=""/>
        <input message="   Do you want to execute all the tests?"
               validargs="y,n"
               defaultvalue="y"
               addproperty="answer"/>
        <if>
          <equals arg1="${answer}" arg2="y" />
          <then>
            <if>
              <equals arg1="${tests.type}" arg2="functional-tests"/>
              <then>
                <var name="test.plan.custom" value="${test.plan.functional.default}"/>
              </then>
              <else>
                <var name="test.plan.custom" value="${test.plan.stress.default}"/>
              </else>
            </if>
          </then>
          <else>
            <for param="item">
              <dirset dir="${tests.dir}/testcases"
                      includes="*"
                      excludes="quickstart,sample">
                <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>
                    <if>
                      <equals arg1="${test.plan.custom}" arg2=""/>
                      <then>
                        <var name="test.plan.custom" value="${test}"/>
                      </then>
                      <else>
                        <var name="test.plan.custom" value="${test.plan.custom},${test}"/>
                      </else>
                    </if>
                  </then>
                </if>
              </sequential>
            </for>
          </else>
        </if>
      </then>
    </if>
 
    <echo>Saving ...</echo>
    <if>
      <equals arg1="${tests.mode.input}" arg2="remote"/>
      <then>
        <property name="property.file" value="${tests.type}-${local.hostname.input}-${remote.hostname.input}.properties"/>
      </then>
      <else>
        <property name="property.file" value="${tests.type}-${local.hostname.input}.properties"/>
      </else>
    </if>
    <echo file="${basedir}/${property.file}"># Tests-defined values
# This file is generated by "build tests-configure" command
tests.mode=${tests.mode.input}
local.hostname=${local.hostname.input}
local.javahome=${local.javahome.input}
remote.hostname=${remote.hostname.input}
remote.javahome=${remote.javahome.input}
client.hostname=${client.hostname.input}
logs.dir=${logs.dir.input}
opends.dir=${opends.dir.input}
opends.name=${opends.name.input}
tests.tmp.dir=${instance.dir.input}
tests.default=${tests.default.input}
instance.bin=${instance.dir.input}
instance.dir=${instance.dir.input}
opends.port.ldap=${opends.port.ldap.input}
opends.port.admin=${opends.port.admin.input}
opends.port.ldaps=${opends.port.ldaps.input}
opends.admin.dn=${opends.admin.dn.input}
opends.admin.pwd=${opends.admin.pwd.input}
snmp.opendmk.lib.dir=${snmp.opendmk.lib.dir.input}
ldclt.dir=${ldclt.dir.input}
verbose.mode=${verbose.mode.input}
wc.type=tomcat
test.plan.custom=${test.plan.custom}
original.archive=${opends.dir.input}/${opends.name.input}.zip</echo>
  </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="${temp.dir}/coverage-instr" />
    <mkdir dir="${temp.dir}/coverage-instr/opends" />
    <mkdir dir="${temp.dir}/coverage-instr/dsml" />
 
    <!-- unzip the original package in a temporary location to make the
         changes necessary so that the coverage tool is called
     -->
    <unzip src="${opends.dir}/${opends.name}.zip"
           dest="${temp.dir}/coverage-instr/opends"/>
    <if>
      <matches string="${product.name}" pattern="^OpenDS ."/>
      <then>
        <!-- The war file is not in the opends archive -->
        <unzip src="${opends.dir}/${opends.name}-DSML.war"
               dest="${temp.dir}/coverage-instr/dsml"/>
      </then>
      <else>
        <!-- The war file is in the opends archive -->
        <unzip src="${temp.dir}/coverage-instr/opends/${opends.name}/addons/DSML.war"
               dest="${temp.dir}/coverage-instr/dsml"/>
      </else>
    </if>
 
    <!-- 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="${temp.dir}/coverage-instr/opends/${opends.name}/lib/emma.jar"/>
    <copy file="${project.home}/ext/emma/lib/emma.jar"
          tofile="${temp.dir}/coverage-instr/dsml/WEB-INF/lib/emma.jar"/>
 
    <!-- move the original product package to make room for the coverage
         enabled package
     -->
    <move file="${opends.dir}/${opends.name}.zip" tofile="${opends.dir}/${opends.name}.zip.nocov"/>
    <if>
      <matches string="${product.name}" pattern="^OpenDS ."/>
      <then>
        <!-- The war file is not in the opends archive, so we need to backup the original package -->
        <move file="${opends.dir}/${opends.name}-DSML.war" tofile="${opends.dir}/${opends.name}-DSML.war.nocov"/>
      </then>
    </if>
 
    <!-- intrument the OpenDS java archive to gather coverage -->
    <java classpath="${temp.dir}/coverage-instr/opends/${opends.name}/lib/emma.jar"
          classname="emma" fork="true">
        <jvmarg value="-Demma.metadata.out.file=${temp.dir}/coverage-instr/opends/${opends.name}/coverage.em" />
        <arg value="instr" />
        <arg value="-m" />
        <arg value="overwrite" />
        <arg value="-ix" />
        <arg value="-org.opends.guitools.*" />
        <arg value="-ix" />
        <arg value="-org.opends.quicksetup.*" />
        <arg value="-ix" />
        <arg value="org.*" />
        <arg value="-ix" />
        <arg value="com.*" />
        <arg value="-ip" />
        <arg value="${temp.dir}/coverage-instr/opends/${opends.name}/lib/OpenDS.jar:${temp.dir}/coverage-instr/opends/${opends.name}/lib/extensions/snmp-mib2605.jar" />
    </java>
 
    <java classpath="${temp.dir}/coverage-instr/dsml/WEB-INF/lib/emma.jar"
          classname="emma" fork="true">
        <jvmarg value="-Demma.metadata.out.file=${temp.dir}/coverage-instr/opends/${opends.name}/coverage.em" />
        <arg value="instr" />
        <arg value="-merge" />
        <arg value="yes" />
        <arg value="-m" />
        <arg value="overwrite" />
        <arg value="-ix" />
        <arg value="-org.opends.guitools.*" />
        <arg value="-ix" />
        <arg value="-org.opends.quicksetup.*" />
        <arg value="-ix" />
        <arg value="org.*" />
        <arg value="-ix" />
        <arg value="com.*" />
        <arg value="-ip" />
        <arg value="${temp.dir}/coverage-instr/dsml/WEB-INF/classes" />
    </java>
 
    <!-- Repackage DSML Gateway the product with coverage enabled scripts -->
    <if>
      <matches string="${product.name}" pattern="^OpenDS ."/>
      <then>
        <!-- The war file is not in the opends archive, so we need to repackage the war file -->
        <zip basedir="${temp.dir}/coverage-instr/dsml" destfile="${opends.dir}/${opends.name}-DSML.war"/>
      </then>
      <else>
        <!-- The war file is in the opends archive, so we need to replace the war file -->
        <delete file="${temp.dir}/coverage-instr/opends/${opends.name}/addons/DSML.war"/>
        <zip basedir="${temp.dir}/coverage-instr/dsml" destfile="${temp.dir}/coverage-instr/opends/${opends.name}/addons/DSML.war"/>
      </else>
    </if>
 
    <!-- Repackage OpenDS the product with coverage enabled scripts -->
    <zip basedir="${temp.dir}/coverage-instr/opends"
         destfile="${opends.dir}/${opends.name}.zip"
         excludes="${opends.name}/setup,${opends.name}/uninstall,${opends.name}/upgrade,${opends.name}/bin/*,${opends.name}/lib/*.sh">
      <zipfileset dir="${temp.dir}/coverage-instr/opends"
                  includes="${opends.name}/setup,${opends.name}/uninstall,${opends.name}/upgrade,${opends.name}/bin/*,${opends.name}/lib/*.sh"
                  filemode="755" dirmode="755"/>
    </zip>
 
    <delete dir="${temp.dir}/coverage-instr"/>
  </target>
 
  <target name="restore-pkg" if="coverage.on">
    <delete file="${opends.dir}/${opends.name}.zip"/>
    <move file="${opends.dir}/${opends.name}.zip.nocov" tofile="${opends.dir}/${opends.name}.zip"/>
    <if>
      <matches string="${product.name}" pattern="^OpenDS ."/>
      <then>
        <!-- The war file is not in the opends archive, so we need to restore the original package -->
        <delete file="${opends.dir}/${opends.name}-DSML.war"/>
        <move file="${opends.dir}/${opends.name}-DSML.war.nocov" tofile="${opends.dir}/${opends.name}-DSML.war"/>
      </then>
    </if>
 
  </target>
 
  <target name="testwithcoverage" depends="coverage-on,coverage-instrument,run,restore-pkg"/>
 
</project>