1 package org.apache.maven.surefire.its.jiras;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.surefire.its.fixture.OutputValidator;
23 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
24 import org.apache.maven.surefire.its.fixture.SurefireLauncher;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.Parameterized;
28 import org.junit.runners.Parameterized.Parameter;
29 import org.junit.runners.Parameterized.Parameters;
30
31 import java.util.Iterator;
32
33 import static java.util.Arrays.asList;
34 import static java.util.concurrent.TimeUnit.SECONDS;
35 import static org.apache.commons.lang3.SystemUtils.IS_OS_LINUX;
36 import static org.apache.commons.lang3.SystemUtils.IS_OS_MAC_OSX;
37 import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS_7;
38 import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS_8;
39 import static org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS_10;
40 import static org.apache.maven.surefire.its.jiras.Surefire1295AttributeJvmCrashesToTestsIT.ForkMode.DEFAULT;
41 import static org.apache.maven.surefire.its.jiras.Surefire1295AttributeJvmCrashesToTestsIT.ForkMode.ONE_FORK_NO_REUSE;
42 import static org.apache.maven.surefire.its.jiras.Surefire1295AttributeJvmCrashesToTestsIT.ForkMode.ONE_FORK_REUSE;
43 import static org.fest.assertions.Assertions.assertThat;
44 import static org.junit.Assert.fail;
45 import static org.junit.Assume.assumeTrue;
46
47
48
49
50
51
52
53
54 @RunWith( Parameterized.class )
55 public class Surefire1295AttributeJvmCrashesToTestsIT
56 extends SurefireJUnit4IntegrationTestCase
57 {
58 public enum ForkMode
59 {
60 DEFAULT,
61 ONE_FORK_NO_REUSE,
62 ONE_FORK_REUSE
63 }
64
65 @Parameters
66 public static Iterable<Object[]> parameters()
67 {
68 return asList(new Object[][] {
69
70
71 { "exit", DEFAULT },
72 { "exit", ONE_FORK_NO_REUSE },
73 { "exit", ONE_FORK_REUSE },
74 { "abort", DEFAULT },
75 { "abort", ONE_FORK_NO_REUSE },
76 { "abort", ONE_FORK_REUSE },
77 { "segfault", DEFAULT },
78 { "segfault", ONE_FORK_NO_REUSE },
79 { "segfault", ONE_FORK_REUSE }
80 });
81 }
82
83 @Parameter( 0 )
84 public static String crashStyle;
85
86 @Parameter( 1 )
87 public static ForkMode forkStyle;
88
89 @Test
90 public void test()
91 throws Exception
92 {
93 assumeTrue( IS_OS_LINUX || IS_OS_MAC_OSX || IS_OS_WINDOWS_7 || IS_OS_WINDOWS_8 || IS_OS_WINDOWS_10 );
94
95 SurefireLauncher launcher =
96 unpack( "crash-during-test", "_" + crashStyle + "_" + forkStyle.ordinal() )
97 .setForkJvm();
98
99 switch ( forkStyle )
100 {
101 case DEFAULT:
102 break;
103 case ONE_FORK_NO_REUSE:
104 launcher.forkCount( 1 )
105 .reuseForks( false );
106 break;
107 case ONE_FORK_REUSE:
108 launcher.forkPerThread()
109 .reuseForks( true )
110 .threadCount( 1 );
111 break;
112 default:
113 fail();
114 }
115
116 checkCrash( launcher.addGoal( "-DcrashType=" + crashStyle ) );
117 }
118
119 private static void checkCrash( SurefireLauncher launcher ) throws Exception
120 {
121 OutputValidator validator = launcher.maven()
122 .withFailure()
123 .executeTest()
124 .verifyTextInLog( "The forked VM terminated without properly saying "
125 + "goodbye. VM crash or System.exit called?" )
126 .verifyTextInLog( "Crashed tests:" );
127
128
129
130 SECONDS.sleep( 1L );
131
132 for ( Iterator<String> it = validator.loadLogLines().iterator(); it.hasNext(); )
133 {
134 String line = it.next();
135 if ( line.contains( "Crashed tests:" ) )
136 {
137 line = it.next();
138 if ( it.hasNext() )
139 {
140 assertThat( line )
141 .contains( "junit44.environment.Test1CrashedTest" );
142 }
143 else
144 {
145 fail( "Could not find any line after 'Crashed tests:'." );
146 }
147 }
148 }
149 }
150 }