summaryrefslogtreecommitdiffstats
path: root/make/build-test.xml
blob: a791c7cae437cf43a1195fb61bf965bd0259a964 (plain)
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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
<?xml version="1.0" encoding="UTF-8"?>

<project name="GlueGenTest" basedir=".">

    <description>JUNIT Tests GlueGen</description>

    <property name="gluegen.root" value=".." />

    <property name="gluegen.basename" value="gluegen" /> <!-- if differs, ie jenkins jobname, must be set properly first -->
    <echo message="gluegen.basename: ${gluegen.basename}"/>
    <!---
    <property name="gluegen.abspath" location="${gluegen.root}" />
    <basename file="${gluegen.abspath}" property="gluegen.basename" /> -->

    <import file="gluegen-cpptasks.xml" />
    <import file="jogamp-archivetasks.xml" />
    <import file="jogamp-androidtasks.xml" />
    <import file="jogamp-env.xml" />

    <condition property="rootrel.build" value="build">
        <not>
          <isset property="rootrel.build"/>
        </not>
    </condition>

    <target name="init" depends="jogamp.env.init,gluegen.properties.load.user">

        <!-- Call the external config validator script to make sure the config is ok and consistent -->
        <ant antfile="validate-properties.xml" inheritall="true"/>

        <property name="make" value="." />

        <property name="test.base.dir"  value="${gluegen.root}/src/junit" />
        <property name="test.junit.rel" value="com/jogamp" />
        <property name="test.junit.util.rel" value="com/jogamp/junit/util" />
        <property name="test.junit.generation.rel" value="${test.junit.rel}/gluegen/test/junit/generation" />
        <property name="test.junit.generation.dir" value="${test.base.dir}/${test.junit.generation.rel}" />

        <property name="test.jcpp.base.dir" value="${project.root}/jcpp/src/test/java" />

        <property name="tempdir"      value="${project.root}/build-temp" />
        <property name="build"        location="${project.root}/${rootrel.build}" />
        <property name="test.dir"     value="${gluegen.root}/${rootrel.build}/test"/>
        <property name="results"      value="${test.dir}/results" />
        <property name="build_t"      value="${test.dir}/build" />
        <property name="build_t.gen"  value="${build_t}/gensrc"/>
        <property name="build_t.java" value="${build_t}/classes"/>
        <property name="build_t.java.path" location="${build_t.java}"/> <!-- absolute path -->
        <property name="build_t.obj"  value="${build_t}/obj"/>
        <property name="build_t.lib"  value="${build_t}/natives"/>

        <property name="batchtest.timeout"    value="1800000"/> <!-- 30 min -->

        <property name="build_t.gen.rootrel" value="${rootrel.build}/test/build/gensrc"/>

        <mkdir dir="${tempdir}" />
        <mkdir dir="${test.dir}"/>
        <mkdir dir="${results}"/>
        <mkdir dir="${build_t}"/>
        <mkdir dir="${build_t.gen}"/>
        <mkdir dir="${build_t.java}"/>
        <mkdir dir="${build_t.obj}"/>
        <mkdir dir="${build_t.lib}"/>

        <property name="gluegen.jar" location="${gluegen.root}/${rootrel.build}/gluegen.jar" />
        <property name="gluegen-rt.jar" location="${gluegen.root}/${rootrel.build}/gluegen-rt.jar" />
        <property name="gluegen.lib" value="${gluegen.root}/${rootrel.build}/obj" />

        <property name="gluegen-test-util.jar" location="${build}/gluegen-test-util.jar" />
        <property name="TestJarsInJar.jar" location="${gluegen.root}/make/lib/TestJarsInJar.jar" />
        <property name="gluegen-test.jar" location="${build_t}/gluegen-test.jar" />
        <property name="gluegen-test.apk" location="${build_t}/gluegen-test.apk" />

        <path id="gluegen.classpath">
          <pathelement location="${gluegen.jar}" />
          <pathelement location="${antlr.jar}" />
        </path>

        <path id="gluegen_rt.classpath">
            <pathelement location="${gluegen-rt.jar}" />
        </path>

        <path id="junit.compile.classpath">
            <pathelement location="${junit.jar}" />
            <pathelement location="${semver.jar}" />
            <pathelement location="${gluegen.jar}" />
        </path>

        <path id="junit.run.classpath">
            <pathelement location="${junit.jar}" />
            <pathelement location="${semver.jar}" />
            <pathelement location="${TestJarsInJar.jar}" />
            <pathelement location="${gluegen-rt.jar}" />
            <pathelement location="${gluegen.jar}" />
            <pathelement location="${gluegen-test-util.jar}" />
            <pathelement location="${gluegen-test.jar}" />
        </path>
        <property name="junit.run.jars" value="${junit.jar}${path.separator}${ant.jar}${path.separator}${semver.jar}${path.separator}${TestJarsInJar.jar}${path.separator}${gluegen.root}/${rootrel.build}/gluegen-rt.jar${path.separator}${gluegen.root}/${rootrel.build}/gluegen.jar${path.separator}${build}/gluegen-test-util.jar${path.separator}${build_t}/gluegen-test.jar"/>
        <property name="junit.run.remote.jars" value="${junit.jar}${path.separator}${env.TARGET_ANT_HOME}/lib/ant.jar${path.separator}${env.TARGET_ANT_HOME}/lib/ant-junit.jar${path.separator}${env.TARGET_ANT_HOME}/lib/ant-junit4.jar${path.separator}${semver.jar}${path.separator}${gluegen.root}/make/lib/TestJarsInJar.jar${path.separator}${gluegen.root}/${rootrel.build}/gluegen-rt.jar${path.separator}${gluegen.root}/${rootrel.build}/gluegen.jar${path.separator}${build}/gluegen-test-util.jar${path.separator}${build_t}/gluegen-test.jar"/>
        <property name="junit.run.remote.apks" value="${gluegen.root}/${rootrel.build}/jogamp-android-launcher.apk${path.separator}${ant-junit-all.apk}${path.separator}${gluegen.root}/${rootrel.build}/gluegen-rt-android-${android.abi}.apk${path.separator}${build_t}/gluegen-test.apk${path.separator}${gluegen.root}/make/lib/TestJarsInJar.apk"/>

        <property name="stub.includes.dir" value="stub_includes" /> <!-- NOTE:  this MUST be relative for FileSet -->

        <echo message="test.base.dir: ${test.base.dir} "/>
        <echo message="test.junit.generation.dir: ${test.junit.generation.dir} "/>
        <echo message="test.dir: ${test.dir} "/>
        <echo message="results: ${results} "/>
        <echo message="build_t: ${build_t} "/>
        <echo message="build_t.gen: ${build_t.gen} "/>
        <echo message="build_t.java: ${build_t.java} "/>
        <echo message="build_t.obj: ${build_t.obj} "/>
        <echo message="build_t.lib: ${build_t.lib} "/>

        <!-- Add the GlueGen tasks to ANT -->
        <taskdef name="gluegen" classname="com.jogamp.gluegen.ant.GlueGenTask"
                 classpathref="gluegen.classpath" />

        <property name="test.archive.name" value="${archive.name}-test-results-${build.node.name}"/>

    </target>

    <target name="java.build">
        <echo message=" - - - compiling all java files - - - "/>
        <echo message=" test.base.dir ${test.base.dir}"/>
        <echo message=" build_t.gen     ${build_t.gen}"/>

        <!-- Javac of Annotation Processor dependencies - First -->
        <!-- This has a hard Java8 target spec test: source, target + bootclasspath -->
        <javac destdir="${build_t.java}" 
               fork="yes"
               includeAntRuntime="false"
               memoryMaximumSize="${javac.memorymax}"
               encoding="UTF-8"
               source="${target.sourcelevel}" 
               target="${target.targetlevel}" 
               bootclasspath="${target.rt.jar}"
               debug="${javacdebug}" debuglevel="${javacdebuglevel}">
            <classpath refid="junit.compile.classpath"/>
            <compilerarg value="-proc:none"/>
            <src path="${test.base.dir}/com/jogamp/junit/util"/>
        </javac>

        <!-- Annotation Processor - Second -->
        <!-- This has a hard Java8 target spec test: source, target + bootclasspath -->
        <mkdir dir="${build_t.gen}/classes/com/jogamp/gluegen/test/junit/structgen"/>
        <javac destdir="${build_t.java}" 
               fork="yes"
               includeAntRuntime="false"
               memoryMaximumSize="${javac.memorymax}"
               encoding="UTF-8"
               source="${target.sourcelevel}" 
               target="${target.targetlevel}" 
               bootclasspath="${target.rt.jar}"
               debug="${javacdebug}" debuglevel="${javacdebuglevel}">
            <classpath refid="junit.compile.classpath"/>
            <compilerarg value="-proc:only"/>
            <!-- compilerarg value="-J-Djogamp.gluegen.structgen.debug"/ -->
            <compilerarg value="-J-Djogamp.gluegen.structgen.output=${build_t.gen}/classes"/>
            <src path="${test.base.dir}/com/jogamp/gluegen/test/junit/structgen"/>
            <src path="${build_t.gen}/classes/com/jogamp/gluegen/test/junit/structgen" />
        </javac>

        <!-- Javac All - Third -->
        <!-- This has a hard Java8 target spec test: source, target + bootclasspath -->
        <javac destdir="${build_t.java}" 
               fork="yes"
               includeAntRuntime="false"
               nativeheaderdir="${build_t.gen}/native/"
               memoryMaximumSize="${javac.memorymax}"
               encoding="UTF-8"
               source="${target.sourcelevel}" 
               target="${target.targetlevel}" 
               bootclasspath="${target.rt.jar}"
               debug="${javacdebug}" debuglevel="${javacdebuglevel}">
            <classpath refid="junit.compile.classpath"/>
            <compilerarg value="-proc:none"/>
            <src path="${test.base.dir}"/>
            <src path="${test.jcpp.base.dir}"/>
            <src path="${build_t.gen}" />
        </javac>
    </target>

    <target name="jar.build">
        <jar destfile="${gluegen-test-util.jar}">
          <fileset dir="${build_t.java}">
            <include name="${test.junit.util.rel}/**/*.class"/>
          </fileset>
        </jar>

        <jar destfile="${gluegen-test.jar}">
          <fileset dir="${build_t.java}">
            <include name="${test.junit.rel}/**/*.class"/>
            <exclude name="${test.junit.util.rel}/**"/>
          </fileset>
          <fileset dir="${build_t.lib}">
              <include name="*${native.library.suffix}" />
          </fileset>
          <fileset dir="resources/assets-test">
            <include name="**" />
          </fileset>
        </jar>
    </target>

    <target name="android.package" depends="java.generate,java.build,native.build,jar.build" if="isAndroid">
        <aapt.signed 
            assetsdir="resources/assets-test"
            jarbuilddir="${build_t}"
            jarbasename="gluegen-test"
            nativebuilddir="${build_t.lib}"
            nativebasename="test"
            android.abi="${android.abi}"
            androidmanifest.path="resources/android/AndroidManifest-Test.xml"
            androidresources.path="resources/android/res"
            version.code="${jogamp.version.int}"
            version.name="${jogamp.version}">
          <d8-classpaths>
            <arg line="--classpath ${junit.jar}"/>
            <arg line="--classpath ${semver.jar}"/>
            <arg line="--classpath ${gluegen.jar}"/>
            <arg line="--classpath ${gluegen-test-util.jar}"/>
          </d8-classpaths>
        </aapt.signed>
    </target>

    <target name="c.configure" depends="gluegen.cpptasks.detect.os,gluegen.cpptasks.setup.compiler">
        <property name="compiler.cfg.id" value="${compiler.cfg.id.base}" />
        <property name="linker.cfg.id"   value="${linker.cfg.id.base}" />
    </target>

    <macrodef name="c.build">
      <attribute name="c.compiler.src.files" />
      <attribute name="compiler.cfg.id" />
      <attribute name="linker.cfg.id" />
      <attribute name="output.lib.name" />
      <sequential>
        <echo message="Compiling @{output.lib.name}" />
        <echo message="   c.compiler.src.files @{c.compiler.src.files}" />
        <echo message="   compiler.cfg.id @{compiler.cfg.id}" />
        <echo message="   linker.cfg.id @{linker.cfg.id}" />
        <echo message="   output.lib.name @{output.lib.name}" />

        <!-- NOTE: the value of the debug and optimise attributes will not be overridden if already set externally -->
        <property name="c.compiler.debug"     value="false" /> 
        <!-- Optimise flags one of { none, size, speed, minimal, full, aggressive, extreme, unsafe } --> 
        <property name="c.compiler.optimise"  value="none" /> 

        <condition property="c.compiler.use-debug"><istrue value="${c.compiler.debug}"/></condition>

        <cc outtype="${output.lib.type}" 
            objdir="${build_t.obj}" 
            outfile="${build_t.lib}/@{output.lib.name}"
            optimize="${c.compiler.optimise}" 
            debug="${c.compiler.debug}"
            multithreaded="true" 
            exceptions="false" 
            rtti="false">   
  
          <fileset dir="${gluegen.root}"><patternset refid="@{c.compiler.src.files}"/></fileset>
  
          <compiler extends="@{compiler.cfg.id}" >
            <sysincludepath path="${java.includes.dir}"/>
            <sysincludepath path="${java.includes.dir.platform}"/>
            <sysincludepath path="${stub.includes.dir}/platform"/>
            <includepath path="${test.junit.generation.dir}"/>
            <includepath path="${build_t.gen}/native"/>
          </compiler>

          <linker extends="@{linker.cfg.id}">
            <syslibset dir="${java.lib.dir.platform}" libs="jawt" if="@{output.lib.name}.useLibJAWT"/>
            <syslibset dir="${java.lib.dir.platform}/server" libs="jvm" if="@{output.lib.name}.useLibJVM"/>
          </linker>
        </cc>
      </sequential>
    </macrodef>  

    <target name="junit.compile.check" depends="init">
      <uptodate property="junit.compile.skip">
        <srcfiles dir= "."                      includes="*.xml"/>
        <srcfiles dir= "${test.base.dir}"       includes="**"/>
        <srcfiles dir= "${test.jcpp.base.dir}"  includes="**"/>
        <srcfiles                               file="${gluegen.jar}" />
        <mapper type="merge" to="${gluegen-test.jar}"/>
      </uptodate>
    </target>

    <target name="junit.compile" depends="junit.compile.check" unless="junit.compile.skip">
      <mkdir dir="${build}/test/build/classes"/>
      <antcall target="android.package" inheritRefs="true"/> <!-- implies java.generate,java.build -->
      <antcall target="dump.localinfo" inheritRefs="true"/>
    </target>

    <target name="dump.localinfo">
        <echo message="Dump Local Info" />
        <java fork="false" failonerror="no" classname="com.jogamp.common.util.TestSystemPropsAndEnvs" classpath="${junit.run.jars}"/>  
    </target>

    <target name="junit.run.remote.ssh" if="isCrosscompilation" unless="isAndroid">
        <echo message="#! /bin/sh${line.separator}" append="false" file="${build_t}/targetcommand.sh" />
        <echo message="${line.separator}
rsync -av --delete --delete-after --delete-excluded \${line.separator}
      --exclude 'build-x86*/' --exclude 'build-linux-x*/' --exclude 'build-android*/' --exclude 'build-win*/' --exclude 'build-mac*/' \${line.separator}
      --exclude 'classes/' --exclude 'src/java/' --exclude 'src/native/' --exclude '.git/' --exclude 'gluegen-java-src.zip' \${line.separator}
      ${env.HOST_UID}@${env.HOST_IP}::${env.HOST_RSYNC_ROOT}/${gluegen.basename} ${env.TARGET_ROOT} ${line.separator}
cd ${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/make ${line.separator}
export ${system.env.library.path}=${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/${rootrel.build}/obj:${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/${rootrel.build}/test/build/natives ${line.separator}
" append="true" file="${build_t}/targetcommand.sh" />

        <for param="test.class.path.m" keepgoing="true">
            <!-- results in absolute path -->
            <fileset dir="${build_t.java}">
                <include name="${test.junit.rel}/**/*Test*"/>
                <exclude name="**/*$$*"/>
            </fileset>
          <sequential>
            <var name="test.class.path" unset="true"/>
            <property name="test.class.path" basedir="${build_t.java}" relative="true" location="@{test.class.path.m}"/>
            <var name="test.class.fqn" unset="true"/>
            <pathconvert property="test.class.fqn">
              <fileset file="${build_t.java}${file.separator}${test.class.path}"/>
              <chainedmapper>
                  <globmapper    from="${build_t.java.path}${file.separator}*" to="*"/> <!-- rel. -->
                  <packagemapper from="*.class"           to="*"/> <!-- FQCN -->
              </chainedmapper>
            </pathconvert>
            <var name="test.class.result.file" value="${results}/TEST-${test.class.fqn}.xml"/>
            <echo message="Testing ${test.class.fqn} -- ${test.class.result.file}"/>
            <echo message="${line.separator}
java \${line.separator}
${junit.run.arg0}\${line.separator}
${junit.run.arg1}\${line.separator}
${jvmDataModel.arg}\${line.separator}
-Djava.library.path=${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/${rootrel.build}/obj${path.separator}${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/${rootrel.build}/test/build/natives\${line.separator}
-cp ${junit.run.remote.jars}\${line.separator}
-Dgluegen.root=${gluegen.root} \${line.separator}
-Drootrel.build=${rootrel.build} \${line.separator}
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner \${line.separator}
${test.class.fqn} \${line.separator}
filtertrace=true \${line.separator}
haltOnError=false \${line.separator}
haltOnFailure=false \${line.separator}
showoutput=true \${line.separator}
outputtoformatters=true \${line.separator}
logfailedtests=true \${line.separator}
logtestlistenerevents=true \${line.separator}
formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter \${line.separator}
formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.class.result.file} ${line.separator}
${line.separator}
" append="true" file="${build_t}/targetcommand.sh" />
          </sequential>
        </for>
        <exec dir="." executable="sh" logError="true" failonerror="true" failifexecutionfails="true">
            <arg line='-x -c "
            chmod 0755 ${build_t}/targetcommand.sh ;
            scp ${build_t}/targetcommand.sh ${env.TARGET_UID}@${env.TARGET_IP}:${env.TARGET_ROOT}/gluegen-targetcommand.sh ;
            ssh -x ${env.TARGET_UID}@${env.TARGET_IP} ${env.TARGET_ROOT}/gluegen-targetcommand.sh ;
            scp -pr ${env.TARGET_UID}@${env.TARGET_IP}:${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/make/${results}/* ${results}/ "'/>
        </exec>
    </target>

<!--
rsync:
    -a == -rlptgoD
    -rt 
-->

    <target name="junit.run.remote.adb" if="isAndroidARMv7">
        <echo message="#! /system/bin/sh${line.separator}" append="false" file="${build_t}/targetcommand.sh" />
        <echo message="${line.separator}
rsync -rtv --delete --delete-after --delete-excluded \${line.separator}
      --exclude 'build-x86*/' --exclude 'build-linux*/' --exclude 'build-win*/' --exclude 'build-mac*/' \${line.separator}
      --exclude 'classes/' --exclude 'src/' --exclude '.git/' --exclude 'gluegen-java-src.zip' \${line.separator}
      --exclude 'gensrc/' --exclude 'doc/' --exclude 'jnlp-files' --exclude 'archive/' \${line.separator}
      --exclude 'android-sdk/' --exclude 'resources/' --exclude 'scripts/' \${line.separator}
      --exclude 'stub_includes/' --exclude 'nbproject/' --exclude '*.log' --exclude '*.zip' --exclude '*.7z' \${line.separator}
      ${env.HOST_UID}@${env.HOST_IP}::${env.HOST_RSYNC_ROOT}/${gluegen.basename} ${env.TARGET_ROOT} ${line.separator}
mkdir ${env.TARGET_ROOT}/tmp ${line.separator}
cd ${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/make ${line.separator}
export ${system.env.library.path}=/system/lib:${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/${rootrel.build}/obj:${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/${rootrel.build}/test/build/natives ${line.separator}
# export BOOTCLASSPATH=/system/framework/core.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar ${line.separator}
# export BOOTCLASSPATH=/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/filterfw.jar ${line.separator}
" append="true" file="${build_t}/targetcommand.sh" />

        <for param="test.class.path.m" keepgoing="true">
            <!-- results in absolute path -->
            <fileset dir="${build_t.java}">
                <include name="${test.junit.rel}/**/*Test*"/>
                <exclude name="**/*$$*"/>
            </fileset>
          <sequential>
            <var name="test.class.path" unset="true"/>
            <property name="test.class.path" basedir="${build_t.java}" relative="true" location="@{test.class.path.m}"/>
            <var name="test.class.fqn" unset="true"/>
            <pathconvert property="test.class.fqn">
              <fileset file="${build_t.java}${file.separator}${test.class.path}"/>
              <chainedmapper>
                  <globmapper    from="${build_t.java.path}${file.separator}*" to="*"/> <!-- rel. -->
                  <packagemapper from="*.class"           to="*"/> <!-- FQCN -->
              </chainedmapper>
            </pathconvert>
            <var name="test.class.result.file" value="${results}/TEST-${test.class.fqn}.xml"/>
            <echo message="Testing ${test.class.fqn} -- ${test.class.result.file}"/>
            <echo message="${line.separator}
dalvikvm \${line.separator}
-Xjnigreflimit:2000 \${line.separator}
-cp ${junit.run.remote.apks} \${line.separator}
-Djava.io.tmpdir=${env.TARGET_ROOT}/tmp \${line.separator}
-Dgluegen.root=${gluegen.root} \${line.separator}
-Drootrel.build=${rootrel.build} \${line.separator}
com.android.internal.util.WithFramework \${line.separator}
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner \${line.separator}
${test.class.fqn} \${line.separator}
filtertrace=true \${line.separator}
haltOnError=false \${line.separator}
haltOnFailure=false \${line.separator}
showoutput=true \${line.separator}
outputtoformatters=true \${line.separator}
logfailedtests=true \${line.separator}
logtestlistenerevents=true \${line.separator}
formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter \${line.separator}
formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.class.result.file} ${line.separator}
${line.separator}
" append="true" file="${build_t}/targetcommand.sh" />
          </sequential>
        </for>

        <echo message="${line.separator}
chmod 644 ${results}/* \${line.separator}
" append="true" file="${build_t}/targetcommand.sh" />

        <exec dir="." executable="sh" logError="true" failonerror="true" failifexecutionfails="true">
            <arg line='-x -c "
            chmod 0755 ${build_t}/targetcommand.sh ;
            adb connect ${env.TARGET_IP}:${env.TARGET_ADB_PORT} ;
            adb -s ${env.TARGET_IP}:${env.TARGET_ADB_PORT} push ${build_t}/targetcommand.sh ${env.TARGET_ROOT}/gluegen-targetcommand.sh ;
            adb -s ${env.TARGET_IP}:${env.TARGET_ADB_PORT} shell su -c ${env.TARGET_ROOT}/gluegen-targetcommand.sh ;
            adb -s ${env.TARGET_IP}:${env.TARGET_ADB_PORT} pull ${env.TARGET_ROOT}/${gluegen.basename}/${env.NODE_LABEL}/make/${results}/ ${results}/ "'/>
        </exec>
    </target>

    <target name="junit.run.local" unless="isCrosscompilation">
        <!-- Perform the junit tests-->
        <junit forkmode="once" showoutput="true" fork="true" timeout="${batchtest.timeout}">
            <env key="${system.env.library.path}" path="${gluegen.lib.abs}${path.separator}${build_t.lib.abs}"/>
            <jvmarg value="${junit.run.arg0}"/>
            <jvmarg value="${junit.run.arg1}"/>
            <jvmarg value="${jvmDataModel.arg}"/>
            <jvmarg value="-Djava.library.path=${gluegen.lib.abs}${path.separator}${build_t.lib.abs}"/>
            <jvmarg value="-Dgluegen.root=${gluegen.root}"/>
            <jvmarg value="-Drootrel.build=${rootrel.build}"/>
            <!--
            <jvmarg value="-Djogamp.debug.NativeLibrary=true"/>
            <jvmarg value="-Djogamp.debug.JNILibLoader=true"/>
            <jvmarg value="-Djogamp.debug.TempFileCache=true"/>
            <jvmarg value="-Djogamp.debug.JarUtil=true"/>
            <jvmarg value="-Djogamp.debug.TempJarCache=true"/>
            <jvmarg value="-Djogamp.debug.ProcAddressHelper=true"/>
            <jvmarg value="-verbose:jni"/> 
            <jvmarg value="-client"/>
            -->
            <formatter usefile="false" type="plain"/>
            <formatter usefile="true" type="xml"/>
            <classpath refid="junit.run.classpath"/>

            <batchtest todir="${results}">
              <fileset dir="${build_t.java}">
                  <include name="${test.junit.rel}/**/*Test*"/>
                  <exclude name="**/*$$*"/>
              </fileset>
              <formatter usefile="false" type="brief"/>
              <formatter usefile="true" type="xml"/>
            </batchtest>
        </junit>
        <move todir="${results}">
            <fileset dir="." includes="hs_err_pid*.log" />
        </move>
    </target>

    <target name="junit.run.settings" depends="init, gluegen.cpptasks.detect.os">
        <!-- Use absolute path -->
        <property name="gluegen.lib.abs" location="${gluegen.lib}" />
        <property name="build_t.lib.abs" location="${build_t.lib}" />

        <delete quiet="true">
            <fileset dir="${build}/test/results" includes="**"/>
            <fileset dir="${build}/test/results-x32" includes="**"/>
            <fileset file="${build}/${test.archive.name}.7z"/>
        </delete>
        <mkdir dir="${build}/test/results"/>
    </target>

    <target name="junit.run.local.osx.d32" if="use.macosx32">
        <var name="jvmDataModel.arg" unset="true"/>
        <var name="jvmDataModel.arg" value="-d32"/>

        <antcall target="junit.run.local" inheritRefs="true" inheritAll="true"/>

        <mkdir dir="${build}/test/results-x32"/>
        <move todir="${build}/test/results-x32">
            <fileset dir="${build}/test/results" includes="**" />
        </move>
        <mkdir dir="${build}/test/results"/>

        <var name="jvmDataModel.arg" unset="true"/>
        <var name="jvmDataModel.arg" value="-d64"/>
    </target>

    <target name="junit.run.tests" depends="junit.run.local.osx.d32, junit.run.local, junit.run.remote.ssh, junit.run.remote.adb"/>

    <target name="junit.run.if.enabled" unless="junit.is.disabled">
        <antcall target="junit.run.tests"      inheritRefs="true" inheritAll="true"/>
    </target>
    <target name="junit.run.if.disabled" if="junit.is.disabled">
        <copy todir="${build}/test/results" file="${gluegen.root}/make/lib/TEST-com.jogamp.junit.DisabledTest.xml"/>
    </target>

    <target name="junit.run" depends="junit.run.settings, junit.run.if.enabled, junit.run.if.disabled">
        <antcall target="test-zip-archive" inheritRefs="true" />
    </target>

    <!-- 

        Hook all junit.test* ..

      -->

    <target name="java.generate" depends="junit.test1.java.generate, junit.test2.java.generate"/>

    <target name="native.build" depends="c.configure, junit.test1.c.build, junit.test2.c.build" unless="build.javaonly">
      <antcall target="gluegen.cpptasks.striplibs" inheritRefs="true">
          <param name="libdir" value="${build_t.lib}"/>
      </antcall>
    </target>

    <target name="java.generate.copy2temp">
        <copy todir="${tempdir}">
            <fileset dir="${build_t}"
                     includes="gensrc/classes/**" />
        </copy>
    </target>

    <!-- 

        junit.test1

      -->


    <target name="junit.test1.java.generate">
        <echo message=" - - - junit.test1.java.generate" />

        <dirset id="stub.includes.fileset.test" dir=".">
            <include name="${test.junit.generation.dir}/**"/>
            <include name="${stub.includes.dir}/gluegen" />
            <include name="${stub.includes.dir}/macosx" />
            <include name="${stub.includes.dir}/unix" />
            <include name="${stub.includes.dir}/windows" />
        </dirset>

        <gluegen src="${test.junit.generation.dir}/test1-gluegen.c"
                 outputRootDir="${build_t.gen}"
                 config="${test.junit.generation.dir}/test1-gluegen.cfg"
                 literalInclude="${test.junit.generation.dir}"
                 includeRefid="stub.includes.fileset.test"
                 emitter="com.jogamp.gluegen.JavaEmitter"
                 dumpCPP="false"
                 debug="false"
                 logLevel="WARNING">
            <classpath refid="gluegen.classpath" />
        </gluegen>
        <antcall target="java.generate.copy2temp" inheritRefs="true" />

        <gluegen src="${test.junit.generation.dir}/test1-gluegen.c"
                 outputRootDir="${build_t.gen}"
                 config="${test.junit.generation.dir}/test1p1-gluegen.cfg"
                 literalInclude="${test.junit.generation.dir}"
                 includeRefid="stub.includes.fileset.test"
                 emitter="com.jogamp.gluegen.JavaEmitter"
                 dumpCPP="false"
                 debug="false"
                 logLevel="WARNING">
            <classpath refid="gluegen.classpath" />
        </gluegen>

        <gluegen src="${test.junit.generation.dir}/test1-gluegen.c"
                 outputRootDir="${build_t.gen}"
                 config="${test.junit.generation.dir}/test1p2-gluegen.cfg"
                 literalInclude="${test.junit.generation.dir}"
                 includeRefid="stub.includes.fileset.test"
                 emitter="com.jogamp.gluegen.procaddress.ProcAddressEmitter"
                 dumpCPP="false"
                 debug="false"
                 logLevel="WARNING">
            <classpath refid="gluegen.classpath" />
        </gluegen>
    </target>

    <target name="junit.test1.c.build" depends="junit.test1i.c.build, junit.test1p1.c.build, junit.test1p2.c.build" unless="build.javaonly" />

    <!-- this is the test1 implementation -->
    <target name="junit.test1i.c.build">
        <patternset id="junit.test1i.c.src.files">
          <include name="src/junit/${test.junit.generation.rel}/test1.c"/>
        </patternset>

        <!-- Windows hacks ro make a proper DLL -->
        <linker id="linker.test1.dll.cfg.id" extends="${linker.cfg.id}">
        </linker>

        <c.build c.compiler.src.files="junit.test1i.c.src.files"
                 output.lib.name="test1"
                 compiler.cfg.id="${compiler.cfg.id}"
                 linker.cfg.id="linker.test1.dll.cfg.id"/>

    </target>

    <!-- this is a fixed binding to the test1 implementation -->
    <target name="junit.test1p1.c.build">
        <linker id="linker.test1.fixed.cfg.id" extends="${linker.cfg.id}">
            <syslibset dir="${build_t.lib}" libs="test1"/>
        </linker>

        <patternset id="junit.test1p1.c.src.files">
          <include name="${build_t.gen.rootrel}/native/Bindingtest1p1Impl_JNI.c"/>
          <include name="${build_t.gen.rootrel}/native/TK_Engine_JNI.c"/>
          <include name="${build_t.gen.rootrel}/native/TK_Surface_JNI.c"/>
          <include name="${build_t.gen.rootrel}/native/TK_ModelConst_JNI.c"/>
          <include name="${build_t.gen.rootrel}/native/TK_ModelMutable_JNI.c"/>
        </patternset>

        <c.build c.compiler.src.files="junit.test1p1.c.src.files"
                 output.lib.name="Bindingtest1p1"
                 compiler.cfg.id="${compiler.cfg.id}"
                 linker.cfg.id="linker.test1.fixed.cfg.id"/>
    </target>

    <!-- this is a dynamic lookup binding to the test1 implementation -->
    <target name="junit.test1p2.c.build">
        <linker id="linker.test1.runtime.cfg.id" extends="${linker.cfg.id}">
        </linker>

        <patternset id="junit.test1p2.c.src.files">
          <include name="${build_t.gen.rootrel}/native/Bindingtest1p2Impl_JNI.c"/>
          <include name="${build_t.gen.rootrel}/native/TK_Engine_JNI.c"/>
          <include name="${build_t.gen.rootrel}/native/TK_Surface_JNI.c"/>
          <include name="${build_t.gen.rootrel}/native/TK_ModelConst_JNI.c"/>
          <include name="${build_t.gen.rootrel}/native/TK_ModelMutable_JNI.c"/>
        </patternset>

        <c.build c.compiler.src.files="junit.test1p2.c.src.files"
                 output.lib.name="Bindingtest1p2"
                 compiler.cfg.id="${compiler.cfg.id}"
                 linker.cfg.id="linker.test1.runtime.cfg.id"/>
    </target>

    <!-- 

        junit.test2

      -->

    <target name="junit.test2.java.generate">
        <echo message=" - - - junit.test2.java.generate" />

        <dirset id="stub.includes.fileset.test" dir=".">
            <include name="${test.junit.generation.dir}/**"/>
            <include name="${stub.includes.dir}/gluegen" />
            <include name="${stub.includes.dir}/macosx" />
            <include name="${stub.includes.dir}/unix" />
            <include name="${stub.includes.dir}/windows" />
        </dirset>

        <gluegen src="${test.junit.generation.dir}/test2.h"
                 outputRootDir="${build_t.gen}"
                 config="${test.junit.generation.dir}/test2.cfg"
                 literalInclude="${test.junit.generation.dir}"
                 includeRefid="stub.includes.fileset.test"
                 emitter="com.jogamp.gluegen.procaddress.ProcAddressEmitter"
                 dumpCPP="false"
                 debug="false"
                 logLevel="WARNING">
            <classpath refid="gluegen.classpath" />
        </gluegen>
        <antcall target="java.generate.copy2temp" inheritRefs="true" />
    </target>

    <target name="junit.test2.c.build">
        <!-- this is the test2 implementation -->
        <patternset id="junit.test2.implc.src.files">
          <include name="src/junit/${test.junit.generation.rel}/test2.c"/>
        </patternset>

        <!-- Windows hacks ro make a proper DLL -->
        <linker id="linker.test2.dll.cfg.id" extends="${linker.cfg.id}">
        </linker>

        <c.build c.compiler.src.files="junit.test2.implc.src.files"
                 output.lib.name="test2"
                 compiler.cfg.id="${compiler.cfg.id}"
                 linker.cfg.id="linker.test2.dll.cfg.id"/>

        <!-- this is a dynamic lookup binding to the test1 implementation -->
        <linker id="linker.test2.runtime.cfg.id" extends="${linker.cfg.id}">
        </linker>

        <patternset id="junit.test2.jnic.src.files">
          <include name="${build_t.gen.rootrel}/native/Bindingtest2Impl_JNI.c"/>
          <include name="${build_t.gen.rootrel}/native/T2_InitializeOptions_JNI.c"/>
        </patternset>

        <c.build c.compiler.src.files="junit.test2.jnic.src.files"
                 output.lib.name="Bindingtest2"
                 compiler.cfg.id="${compiler.cfg.id}"
                 linker.cfg.id="linker.test2.runtime.cfg.id"/>
    </target>


    <!-- updates / create the test results zip file -->
    <target name="test-zip-archive" depends="init">
        <archive.7z destfile="${build}/${test.archive.name}.7z"
                    basedir="${project.root}" 
                    includes="${rootrel.build}/test/results ${rootrel.build}/test/results-x64 ${rootrel.build}/test/results-x32" />
    </target>


</project>