1
1
package picard ;
2
2
3
3
import com .intel .gkl .compression .IntelDeflater ;
4
+ import com .intel .gkl .compression .IntelDeflaterFactory ;
4
5
import com .intel .gkl .compression .IntelInflater ;
6
+ import com .intel .gkl .compression .IntelInflaterFactory ;
7
+ import htsjdk .samtools .SAMFileWriterFactory ;
8
+ import htsjdk .samtools .SamReaderFactory ;
9
+ import htsjdk .samtools .util .zip .DeflaterFactory ;
10
+ import htsjdk .samtools .util .zip .InflaterFactory ;
5
11
import org .apache .commons .lang3 .SystemUtils ;
12
+ import org .broadinstitute .barclay .argparser .CommandLineProgramProperties ;
6
13
import org .testng .Assert ;
7
14
import org .testng .SkipException ;
8
15
import org .testng .annotations .Test ;
16
+ import picard .cmdline .CommandLineProgram ;
17
+ import picard .cmdline .programgroups .OtherProgramGroup ;
18
+ import picard .cmdline .programgroups .Testing ;
19
+
20
+ import java .lang .reflect .Field ;
9
21
10
22
/**
11
23
* Test that the Intel Inflater and Deflater can be loaded successfully.
@@ -25,6 +37,20 @@ public void testIntelDeflaterIsAvailable() {
25
37
"Intel shared library was not loaded. This could be due to a configuration error, or your system might not support it." );
26
38
}
27
39
40
+ @ Test
41
+ public void testIntelInflaterIsUsed (){
42
+ final InflaterDeflaterTester cmd = new InflaterDeflaterTester ();
43
+ cmd .instanceMain (new String []{});
44
+ Assert .assertEquals (cmd .inflaterFactory .getClass (), IntelInflaterFactory .class );
45
+ }
46
+
47
+ @ Test
48
+ public void testDeflaterIsUsed (){
49
+ final InflaterDeflaterTester cmd = new InflaterDeflaterTester ();
50
+ cmd .instanceMain (new String []{});
51
+ Assert .assertEquals (cmd .deflaterFactory .getClass (), IntelDeflaterFactory .class );
52
+ }
53
+
28
54
private void checkIntelSupported (final String componentName ) {
29
55
if (!SystemUtils .IS_OS_LINUX && !SystemUtils .IS_OS_MAC ) {
30
56
throw new SkipException (componentName + " is not available on this platform" );
@@ -34,4 +60,35 @@ private void checkIntelSupported(final String componentName) {
34
60
throw new SkipException (componentName + " is not available for this architecture" );
35
61
}
36
62
}
63
+
64
+
65
+ @ CommandLineProgramProperties (summary = "test program for checking if the intel optimized inflater/deflater are active" ,
66
+ oneLineSummary = "test program please ignore" ,
67
+ programGroup = Testing .class ,
68
+ omitFromCommandLine = true )
69
+ public static class InflaterDeflaterTester extends CommandLineProgram {
70
+ public InflaterFactory inflaterFactory ;
71
+ public DeflaterFactory deflaterFactory ;
72
+
73
+ @ Override
74
+ protected int doWork () {
75
+ final SamReaderFactory samReaderFactory = SamReaderFactory .makeDefault ();
76
+ inflaterFactory = getFieldValue (samReaderFactory , "inflaterFactory" , InflaterFactory .class );
77
+
78
+ final SAMFileWriterFactory samFileWriterFactory = new SAMFileWriterFactory ();
79
+ deflaterFactory = getFieldValue (samFileWriterFactory , "deflaterFactory" , DeflaterFactory .class );
80
+
81
+ return 0 ;
82
+ }
83
+
84
+ private <T ,R > R getFieldValue (final T obj ,final String fieldName , Class <R > clazz ) {
85
+ try {
86
+ final Field deflaterFactoryField = obj .getClass ().getDeclaredField (fieldName );
87
+ deflaterFactoryField .setAccessible (true );
88
+ return clazz .cast (deflaterFactoryField .get (obj ));
89
+ } catch (NoSuchFieldException | IllegalAccessException e ) {
90
+ throw new RuntimeException (e );
91
+ }
92
+ }
93
+ }
37
94
}
0 commit comments