1+ package org .uiuc ;
2+
3+ import com .anubhavshukla .p2y .converter .PropertiesToYamlConverter ;
4+ import com .google .gson .Gson ;
5+ import org .apache .commons .io .FileUtils ;
6+
7+ import java .io .*;
8+ import java .nio .charset .Charset ;
9+ import java .nio .file .Files ;
10+ import java .nio .file .Paths ;
11+ import java .util .ArrayList ;
12+ import java .util .LinkedHashMap ;
13+ import java .util .List ;
14+ import java .util .Map ;
15+ import java .util .stream .Collectors ;
16+ import java .util .stream .Stream ;
17+
18+ import static org .uiuc .AppConstants .*;
19+
20+ public class Main {
21+ public static void main (String [] args ) throws IOException {
22+
23+ String configDestDir = args [0 ];
24+ String testToConfigMapperInputFile = args [1 ];
25+ String generatedValueListFile = args [2 ];
26+ String resultDir = args [3 ];
27+
28+ List <String > arrList = new ArrayList <>();
29+ try (Stream <String > lines = Files .lines (Paths .get (generatedValueListFile ), Charset .defaultCharset ())) {
30+ lines .forEachOrdered (line -> {
31+ if (!line .isEmpty ()) {
32+ String [] split = line .split ("\t " );
33+ if (!line .contains ("SKIP" )) {
34+ arrList .add (split [0 ] + "=" + split [1 ]);
35+ arrList .add (split [0 ] + "=" + split [2 ]);
36+ }
37+ }
38+ });
39+ }
40+ System .out .println (arrList );
41+ FileWriter writer = new FileWriter (configDestDir + "/output.txt" );
42+ for (String str : arrList ) {
43+ writer .write (str + System .lineSeparator ());
44+ }
45+ writer .close ();
46+
47+ List <String > overrideConfigFileList = new ArrayList <>();
48+ int i = 0 ;
49+ try (Stream <String > lines = Files .lines (Paths .get (configDestDir + "/output.txt" ), Charset .defaultCharset ())) {
50+ lines .forEachOrdered (line -> {
51+ try {
52+ File file = new File ("config" + i + ".txt" );
53+ FileUtils .writeStringToFile (file , line , Charset .forName ("UTF-8" ));
54+ PropertiesToYamlConverter p = new PropertiesToYamlConverter ();
55+ String yaml = p .fileToYamlString (file );
56+ if (yaml .contains ("[" )) {
57+ yaml = yaml .replaceFirst ("\\ [[^\\ ]]+\\ ]" , "" ).trim ().replace ("\n " , "\n " + " -" );
58+ }
59+ System .out .println (yaml );
60+ FileUtils .writeStringToFile (new File (configDestDir + "/" + line ), yaml , Charset .forName ("UTF-8" ));
61+ overrideConfigFileList .add (line );
62+ } catch (IOException e ) {
63+ throw new RuntimeException (e );
64+ }
65+ });
66+ }
67+
68+ StringBuffer mapperInputStr = new StringBuffer ();
69+ try (Stream <String > lines = Files .lines (Paths .get (testToConfigMapperInputFile ), Charset .defaultCharset ())) {
70+ lines .forEachOrdered (line ->
71+ mapperInputStr .append (line )
72+ );
73+ }
74+ System .out .println (mapperInputStr );
75+
76+ Gson gson = new Gson ();
77+ Map <String , List <String >> testToConfigList = gson .fromJson (mapperInputStr .toString (), Map .class );
78+ System .out .println (testToConfigList );
79+
80+ Map <String , String > testCaseToModuleMap = testCases .stream ()
81+ .collect (Collectors .toMap (x -> x .split (">" )[1 ], y -> y .split (">" )[0 ]));
82+
83+ List <String > finalReport = new ArrayList <>();
84+ Map <String , List <String >> finalParamToTestReport = new LinkedHashMap <>();
85+ testToConfigList .forEach ((testCase , configList ) -> {
86+ configList .forEach (config -> {
87+ List <String > allMatchingFiles = overrideConfigFileList .stream ().filter (x -> x .split ("=" )[0 ].equals (config )).collect (Collectors .toList ());
88+ allMatchingFiles .forEach (c -> {
89+ System .out .println ("Module : " + testCaseToModuleMap .get (testCase ) + " TestCase : " + testCase + " destFileName : " + c );
90+ try {
91+ runTest (configDestDir , c , testCaseToModuleMap .get (testCase ), testCase , finalReport , finalParamToTestReport );
92+ } catch (Exception e ) {
93+ throw new RuntimeException (e );
94+ }
95+ });
96+ });
97+ });
98+
99+ System .out .println (finalReport );
100+ FileWriter writer2 = new FileWriter (resultDir + "/test_result.tsv" );
101+ for (String str : finalReport ) {
102+ writer2 .write (str + System .lineSeparator ());
103+ }
104+ writer2 .close ();
105+
106+ String finalCtestJson = gson .toJson (finalParamToTestReport );
107+ System .out .println (finalCtestJson );
108+ FileWriter writer3 = new FileWriter (resultDir + "/ctests-skywalking.json" );
109+ writer3 .write (finalCtestJson );
110+ writer3 .close ();
111+
112+ }
113+
114+ private static void runTest (String sourceDir , String sourceFileName , String module , String testCase ,
115+ List <String > finalReport , Map <String , List <String >> finalParamToTestReport ) throws IOException , InterruptedException {
116+
117+ long startTime = System .nanoTime ();
118+
119+ String destFileName = moduleToFileNameMap .get (module );
120+
121+ System .out .println ("copying < " + sourceFileName + " > from < " + sourceDir + " > to < " + moduleToDirMap .get (module ) + " >" );
122+
123+ try {
124+ Runtime .getRuntime ().exec ("cp " + sourceDir + "/" + sourceFileName + " " + moduleToDirMap .get (module ) + "/" + destFileName );
125+ } catch (IOException e ) {
126+ System .err .println (ERROR_MSG );
127+ e .printStackTrace ();
128+ }
129+
130+ Process p = null ;
131+ try {
132+ p = Runtime .getRuntime ().exec ("mvn test -pl " + module + " -Dtest=" + testCase + " -DfailIfNoTests=false" );
133+ } catch (IOException e ) {
134+ System .err .println (ERROR_MSG );
135+ e .printStackTrace ();
136+ }
137+
138+ OutputStream output = new OutputStream () {
139+ private final StringBuilder string = new StringBuilder ();
140+
141+ @ Override
142+ public void write (int b ) {
143+ this .string .append ((char ) b );
144+ }
145+
146+ public String toString () {
147+ return this .string .toString ();
148+ }
149+ };
150+
151+ copy (p .getInputStream (), output );
152+ BufferedReader bufReader = new BufferedReader (new StringReader (output .toString ()));
153+ String next = bufReader .readLine ();
154+ String parameter = sourceFileName .split ("=" )[0 ];
155+ long endTime = System .nanoTime ();
156+ long execTime = (endTime - startTime );
157+ while (next != null ) {
158+ System .out .println (next );
159+ if (next .contains ("BUILD FAILURE" )) {
160+ finalReport .add (parameter + "\t " + testCase + "\t " + sourceFileName .split ("=" )[1 ] + "\t " + "f" + "\t " + execTime );
161+ } else if (next .contains ("BUILD SUCCESS" )) {
162+ finalReport .add (parameter + "\t " + testCase + "\t " + sourceFileName .split ("=" )[1 ] + "\t " + "p" + "\t " + execTime );
163+ if (!finalParamToTestReport .containsKey (parameter )) {
164+ List <String > testList = new ArrayList <>();
165+ testList .add (testCase );
166+ finalParamToTestReport .put (parameter , testList );
167+ } else {
168+ finalParamToTestReport .get (parameter ).add (testCase );
169+ }
170+ }
171+ next = bufReader .readLine ();
172+ }
173+
174+ p .waitFor ();
175+ }
176+
177+
178+ public static void copy (InputStream in , OutputStream out ) throws IOException {
179+ while (true ) {
180+ int c = in .read ();
181+ if (c == -1 )
182+ break ;
183+ out .write ((char ) c );
184+ }
185+ }
186+ }
0 commit comments