lttng: Make GenerateTestValues output a valid Java file
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 24 Apr 2013 19:37:12 +0000 (15:37 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 25 Apr 2013 17:37:49 +0000 (13:37 -0400)
This way we can just copy-paste the output on top of the previous
TestValues.java file (which contains expected values for tests).

Java code that writes Java code, what can possibly go wrong...

Change-Id: I234959238d2c645ce40f4a9b5ed49d4399e08d4d
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/12169
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
IP-Clean: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.linuxtools.lttng2.kernel.core.tests/src/org/eclipse/linuxtools/lttng2/kernel/core/tests/headless/GenerateTestValues.java

index 280ac378d7d7e852ad8d39e874cd4ab77627db8a..a280a9ffcc051689af0cfc43ccd99c897158b04c 100644 (file)
@@ -29,7 +29,7 @@ import org.eclipse.linuxtools.tmf.core.tests.shared.CtfTmfTestTraces;
  * Small program to regenerate the values used in "TestValues.java" from the
  * current LTTng-kernel state provider.
  *
- * It will write its output the a file called 'test-values*.log' in your
+ * It will write its output the a file called 'TestValues<something>.java' in your
  * temporary files directory.
  *
  * @author Alexandre Montplaisir
@@ -38,6 +38,7 @@ public class GenerateTestValues {
 
     private static final int TRACE_INDEX = 1;
     private static final long targetTimestamp = 18670067372290L + 1331649577946812237L;
+    private static final String INDENT = "    ";
 
     /**
      * Run the program
@@ -56,7 +57,7 @@ public class GenerateTestValues {
         /* Prepare the files */
         File stateFile = File.createTempFile("test-values", ".ht");
         stateFile.deleteOnExit();
-        File logFile = File.createTempFile("test-values", ".log");
+        File logFile = File.createTempFile("TestValues", ".java");
         PrintWriter writer = new PrintWriter(new FileWriter(logFile), true);
 
         /* Build and query the state system */
@@ -64,22 +65,31 @@ public class GenerateTestValues {
         ITmfStateSystem ssq = StateSystemManager.loadStateHistory(stateFile, input, true);
         List<ITmfStateInterval> fullState = ssq.queryFullState(targetTimestamp);
 
-        /* Print the interval contents (with some convenience formatting) */
-        writer.println("Start times:");
+        /* Start printing the java file's contents */
+        writer.println("interface TestValues {");
+        writer.println();
+        writer.println(INDENT + "static final int size = " + fullState.size() +";");
+        writer.println();
+
+        /* Print the array contents */
+        writer.println(INDENT + "static final long[] startTimes = {");
         for (ITmfStateInterval interval : fullState) {
-            writer.println(String.valueOf(interval.getStartTime()) + "L,");
+            writer.println(INDENT + INDENT + String.valueOf(interval.getStartTime()) + "L,");
         }
+        writer.println(INDENT + "};");
         writer.println();
 
-        writer.println("End times:");
+        writer.println(INDENT + "static final long[] endTimes = {");
         for (ITmfStateInterval interval : fullState) {
-            writer.println(String.valueOf(interval.getEndTime())+ "L,");
+            writer.println(INDENT + INDENT + String.valueOf(interval.getEndTime())+ "L,");
         }
+        writer.println(INDENT + "};");
         writer.println();
 
-        writer.println("State values:");
+        writer.println(INDENT + "static final ITmfStateValue[] values = {");
         for (ITmfStateInterval interval : fullState) {
             ITmfStateValue val = interval.getStateValue();
+            writer.print(INDENT + INDENT);
 
             switch (val.getType()) {
             case NULL:
@@ -99,6 +109,10 @@ public class GenerateTestValues {
                 break;
             }
         }
+        writer.println(INDENT + "};");
+
+        writer.println("}");
+        writer.println();
 
         writer.close();
         System.exit(0);
This page took 0.028058 seconds and 5 git commands to generate.