summaryrefslogtreecommitdiffstats
path: root/qadevOOo/runner/stats
diff options
context:
space:
mode:
Diffstat (limited to 'qadevOOo/runner/stats')
-rw-r--r--qadevOOo/runner/stats/InternalLogWriter.java101
-rw-r--r--qadevOOo/runner/stats/OutProducerFactory.java121
-rw-r--r--qadevOOo/runner/stats/SimpleLogWriter.java94
-rw-r--r--qadevOOo/runner/stats/SimpleOutProducer.java61
-rw-r--r--qadevOOo/runner/stats/Summarizer.java104
5 files changed, 481 insertions, 0 deletions
diff --git a/qadevOOo/runner/stats/InternalLogWriter.java b/qadevOOo/runner/stats/InternalLogWriter.java
new file mode 100644
index 000000000..a39e372a6
--- /dev/null
+++ b/qadevOOo/runner/stats/InternalLogWriter.java
@@ -0,0 +1,101 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package stats;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+/**
+ * Write all logs into a java.io.PrintWriter, i.e. a StringBuffer.
+ * Log is gathered there.
+ */
+public class InternalLogWriter implements share.LogWriter {
+ /** log active **/
+ private boolean active;
+ /** write all output to a StringBuffer **/
+ private StringWriter writer = new StringWriter();
+ private PrintWriter printWriter;
+
+ /**
+ * c'*tor
+ */
+ public InternalLogWriter() {
+ printWriter = new PrintWriter(writer);
+ active = true;
+ }
+
+ /**
+ * Initialization.
+ * @param entry The description entry.
+ * @param active Logging is active.
+ * @return True, if initialize worked.
+ */
+ public boolean initialize(share.DescEntry entry, boolean active) {
+ this.active = active;
+ return true;
+ }
+
+ /**
+ * Method to print a line that is added to the StringBuffer.
+ * @param msg The message that is printed.
+ */
+ public void println(String msg) {
+ if (active)
+ printWriter.println(msg);
+ }
+
+ /**
+ * Is used to sum up the information.
+ * The summary is also added to the StringBuffer.
+ * @param entry The description entry.
+ * @return True, if a summary could be created.
+ */
+ public boolean summary(share.DescEntry entry) {
+// linePrefix = "";
+ String header = "***** State for "+entry.longName+" ******";
+ printWriter.println(header);
+ if (entry.hasErrorMsg) {
+ printWriter.println(entry.ErrorMsg);
+ printWriter.println("Whole "+entry.EntryType+": "+entry.State);
+ } else {
+ printWriter.println("Whole "+entry.EntryType+": "+entry.State);
+ }
+ for (int i=0;i<header.length();i++) {
+ printWriter.print("*");
+ }
+ printWriter.println("");
+ return true;
+ }
+
+ /**
+ * Return all the written stuff.
+ * @return All that was written to the StringBuffer with the
+ * 'println()', 'print()' and 'summarize()' methods.
+ * The StringBuffer is emptied afterwards.
+ **/
+ public String getLog() {
+ String message = writer.getBuffer().toString();
+ writer = new StringWriter();
+ return message;
+ }
+
+ public void setWatcher(Object watcher) {
+ }
+
+}
+
diff --git a/qadevOOo/runner/stats/OutProducerFactory.java b/qadevOOo/runner/stats/OutProducerFactory.java
new file mode 100644
index 000000000..cb907a490
--- /dev/null
+++ b/qadevOOo/runner/stats/OutProducerFactory.java
@@ -0,0 +1,121 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package stats;
+
+import share.LogWriter;
+import java.util.HashMap;
+import util.DynamicClassLoader;
+
+/**
+ * A factory class for creating out producers.
+ */
+public class OutProducerFactory {
+
+ /**
+ * Create an out producer. The type that is created depends on the
+ * parameters given. These are:
+ * <ul>
+ * <li>DataBaseOut - If set to true, a database outproducer is created.
+ * <li>OutProducer - The value of this parameter names the class that is created.
+ * </ul>
+ * @param param Parameters of the test.
+ * @return The created out producer.
+ */
+ public static LogWriter createOutProducer(HashMap<String,Object> param) {
+ LogWriter dbOut = null;
+ boolean getDatabase = convertToBool(param.get("DataBaseOut"));
+ if (getDatabase) {
+ dbOut = createDataBaseOutProducer(param);
+ }
+ if (dbOut == null) {
+ DynamicClassLoader dcl = new DynamicClassLoader();
+ String outProducerName = (String)param.get("OutProducer");
+ if (outProducerName != null) {
+ try {
+ dbOut = (LogWriter)dcl.getInstance(outProducerName);
+ }
+ catch(IllegalArgumentException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ if (dbOut == null) {
+ dbOut = createSimpleOutProducer();
+ }
+ return dbOut;
+ }
+
+ /**
+ * Create a database out producer.
+ * @param param The test parameters
+ * @return The database out producer, or null if it couldn't be created.
+ */
+ private static LogWriter createDataBaseOutProducer(HashMap<String,Object> param) {
+ String dataProducerName = (String)param.get("DataBaseOutProducer");
+ if (dataProducerName == null) {
+ String testBaseName = (String)param.get("TestBase");
+ dataProducerName = testBaseName.substring(testBaseName.indexOf('_')+1);
+ dataProducerName = "stats." + makeFirstCharUpperCase(dataProducerName)
+ + "DataBaseOutProducer";
+ }
+ DynamicClassLoader dcl = new DynamicClassLoader();
+ LogWriter dbOut = null;
+ try {
+ dbOut = (LogWriter)dcl.getInstance(dataProducerName,
+ new Class[]{HashMap.class}, new Object[]{param});
+ }
+ catch(IllegalArgumentException e) {
+ e.printStackTrace();
+ }
+ return dbOut;
+ }
+
+ /**
+ * As a fallback, create a simple out producer, if all else failed.
+ * @return A simple out producer, writing to the screen.
+ */
+ private static LogWriter createSimpleOutProducer() {
+ return new SimpleOutProducer();
+ }
+
+ private static boolean convertToBool(Object val) {
+ if(val != null) {
+ if ( val instanceof String ) {
+ String sVal = (String)val;
+ if ( sVal.equalsIgnoreCase("true") || sVal.equalsIgnoreCase("yes") ) {
+ return true;
+ }
+
+ }
+ else if (val instanceof Boolean) {
+ return ((Boolean)val).booleanValue();
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Make the first character to an upper case char.
+ * @param name The String to change
+ * @return The String with an upper case first char.
+ */
+ private static String makeFirstCharUpperCase(String name) {
+ return name.substring(0,1).toUpperCase() + name.substring(1);
+ }
+
+}
diff --git a/qadevOOo/runner/stats/SimpleLogWriter.java b/qadevOOo/runner/stats/SimpleLogWriter.java
new file mode 100644
index 000000000..46e18527b
--- /dev/null
+++ b/qadevOOo/runner/stats/SimpleLogWriter.java
@@ -0,0 +1,94 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package stats;
+
+import share.LogWriter;
+
+import java.io.PrintWriter;
+import java.text.DecimalFormat;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+public class SimpleLogWriter extends PrintWriter implements LogWriter {
+
+ private boolean m_bLogging = false;
+ private share.DescEntry entry = null;
+ private share.Watcher ow = null;
+
+ public SimpleLogWriter() {
+ super(System.out);
+ Calendar cal = new GregorianCalendar();
+ DecimalFormat dfmt = new DecimalFormat("00");
+ super.println("LOG> Log started " +
+ dfmt.format(cal.get(Calendar.DAY_OF_MONTH)) + "." +
+ dfmt.format(cal.get(Calendar.MONTH)) + "." +
+ dfmt.format(cal.get(Calendar.YEAR)) + " - " +
+ dfmt.format(cal.get(Calendar.HOUR_OF_DAY)) + ":" +
+ dfmt.format(cal.get(Calendar.MINUTE)) + ":" +
+ dfmt.format(cal.get(Calendar.SECOND)));
+ super.flush();
+ }
+
+ public boolean initialize(share.DescEntry _entry, boolean _bLogging) {
+ m_bLogging = _bLogging;
+ entry = _entry;
+
+ return true;
+ }
+
+ @Override
+ public void println(String msg) {
+ if ((ow == null) && (entry != null))
+ {
+ this.ow = (share.Watcher) entry.UserDefinedParams.get("Watcher");
+ if (this.ow != null)
+ {
+ this.ow.ping();
+ }
+ }
+ else
+ {
+ if (ow != null)
+ {
+ this.ow.ping();
+ }
+ else
+ {
+ // special case: ow == null && entry == null
+ System.out.println(msg);
+ }
+ }
+
+ if (m_bLogging) {
+ super.println("LOG> " + msg);
+ super.flush();
+ }
+ }
+
+ public boolean summary(share.DescEntry entry) {
+ return true;
+ }
+
+ public void setWatcher(Object watcher)
+ {
+ if (watcher != null)
+ {
+ entry.UserDefinedParams.put("Watcher", watcher);
+ }
+ }
+}
diff --git a/qadevOOo/runner/stats/SimpleOutProducer.java b/qadevOOo/runner/stats/SimpleOutProducer.java
new file mode 100644
index 000000000..93ca0503c
--- /dev/null
+++ b/qadevOOo/runner/stats/SimpleOutProducer.java
@@ -0,0 +1,61 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package stats;
+
+import share.LogWriter;
+
+public class SimpleOutProducer implements LogWriter {
+
+
+ /** initialization, here a filename might be given
+ * or a dbUrL
+ */
+ public boolean initialize(share.DescEntry entry, boolean active) {
+ return true;
+ }
+
+ /** Method to print
+ */
+ public void println(String msg) {
+
+ }
+
+ /** will mostly be used by outproducers to sum up
+ * the information, maybe write them to a db
+ */
+ public boolean summary(share.DescEntry entry) {
+ String header = "***** State for "+entry.longName+" ******";
+ System.out.println(header);
+ if (entry.hasErrorMsg) {
+ System.out.println(entry.ErrorMsg);
+ System.out.println("Whole "+entry.EntryType+": "+entry.State);
+ } else {
+ System.out.println("Whole "+entry.EntryType+": "+entry.State);
+ }
+ for (int i=0;i<header.length();i++) {
+ System.out.print("*");
+ }
+ System.out.println("");
+ return true;
+ }
+
+ public void setWatcher(Object watcher) {
+ }
+
+}
diff --git a/qadevOOo/runner/stats/Summarizer.java b/qadevOOo/runner/stats/Summarizer.java
new file mode 100644
index 000000000..36addd5e6
--- /dev/null
+++ b/qadevOOo/runner/stats/Summarizer.java
@@ -0,0 +1,104 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+package stats;
+
+import java.util.ArrayList;
+
+import share.DescEntry;
+
+/**
+ *
+ * this class adds up the results of the subentries of a given DescEntry
+ * and fills the subentries in cases of SKIPPED states
+ */
+public class Summarizer
+{
+
+ /**
+ *
+ * gets the state for a SuperEntry according to its subentries
+ */
+ public void summarizeUp(DescEntry entry)
+ {
+ if ((entry.State != null) && !entry.State.equals("UNKNOWN"))
+ {
+ return;
+ }
+ int count = entry.SubEntryCount;
+ int knownIssues = 0;
+ ArrayList<String> failures = new ArrayList<String>();
+ ArrayList<String> states = new ArrayList<String>();
+ for (int i = 0; i < count; i++)
+ {
+ if (entry.SubEntries[i].State == null)
+ {
+ entry.SubEntries[i].State = "COMPLETED.FAILED";
+ }
+ if (entry.SubEntries[i].State.equals("known issue"))
+ {
+ entry.SubEntries[i].State = "COMPLETED.OK";
+ knownIssues++;
+ }
+ if (!entry.SubEntries[i].State.endsWith("OK"))
+ {
+ String sFailure = "[" + entry.SubEntries[i].longName + "]" + " is testcode: [" + entry.SubEntries[i].entryName + "]";
+ failures.add(sFailure);
+ states.add(entry.SubEntries[i].State);
+ }
+ }
+ if (failures.size() > 0)
+ {
+ StringBuilder errMsg = new StringBuilder();
+ String state = "COMPLETED.FAILED";
+ for (int j = 0; j < failures.size(); j++)
+ {
+ if (states.get(j).equals("not part of the job"))
+ {
+ state = "COMPLETED(some interfaces/services not tested).OK";
+ }
+ else
+ {
+ errMsg.append(failures.get(j)).append(" - ").append(states.get(j)).append("\r\n");
+ }
+ }
+ entry.hasErrorMsg = true;
+ entry.ErrorMsg = errMsg.toString();
+ entry.State = state;
+ }
+ else if (entry.EntryType.equals("component") && knownIssues > 0)
+ {
+ entry.State = "COMPLETED(with known issues).OK";
+ }
+ else
+ {
+ entry.State = "COMPLETED.OK";
+ }
+ }
+
+ public static void summarizeDown(DescEntry entry, String state)
+ {
+ if ((entry.State == null) || entry.State.equals("UNKNOWN"))
+ {
+ entry.State = state;
+ }
+ for (int i = 0; i < entry.SubEntryCount; i++)
+ {
+ summarizeDown(entry.SubEntries[i], entry.State);
+ }
+ }
+}