* Here we listen to keystrokes while console frame is being displayed and if magic "test" word is typed

* we launch a functional test on real hardware, same as Jenkins runs within continues integration
This commit is contained in:
rusefi 2019-12-21 14:08:38 -05:00
parent 435211b161
commit 48ad5716a4
4 changed files with 72 additions and 15 deletions

View File

@ -17,9 +17,8 @@ public class RealHwTest {
public static void main(String[] args) throws InterruptedException {
System.out.println("Sleeping " + STARTUP_SLEEP + " seconds to give OS time to connect VCP driver");
Thread.sleep(STARTUP_SLEEP * SECOND);
long start = System.currentTimeMillis();
boolean isSuccess = runHardwareTest(args, start);
boolean isSuccess = runHardwareTest(args);
if (!isSuccess)
System.exit(-1);
FileLog.MAIN.logLine("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
@ -31,20 +30,28 @@ public class RealHwTest {
/**
* @return true if test is a SUCCESS, false if a FAILURE
*/
public static boolean runHardwareTest(String[] args, long start) {
public static boolean runHardwareTest(String[] args) {
String port = startRealHardwareTest(args);
if (port == null) {
return false;
} else {
try {
runRealHardwareTest(port);
} catch (Throwable e) {
e.printStackTrace();
return false;
}
long time = (System.currentTimeMillis() - start) / 1000;
FileLog.MAIN.logLine("Done in " + time + "secs");
return runHardwareTest(port);
}
}
/**
* @return true if test is a SUCCESS, false if a FAILURE
*/
public static boolean runHardwareTest(String port) {
long start = System.currentTimeMillis();
try {
runRealHardwareTest(port);
} catch (Throwable e) {
e.printStackTrace();
return false;
}
long time = (System.currentTimeMillis() - start) / 1000;
FileLog.MAIN.logLine("Done in " + time + "secs");
return true;
}
@ -59,6 +66,7 @@ public class RealHwTest {
if (args.length == 1 || args.length == 2) {
port = args[0];
} else if (args.length == 0) {
// todo: reuse 'PortDetector.autoDetectPort' here?
port = LinkManager.getDefaultPort();
} else {
System.out.println("Only one optional argument expected: port number");

View File

@ -182,6 +182,7 @@ public class LinkManager {
return null;
}
String port = ports[ports.length - 1];
// todo: reuse 'PortDetector.autoDetectPort' here?
System.out.println("Using last of " + ports.length + " port(s)");
System.out.println("All ports: " + Arrays.toString(ports));
return port;

View File

@ -14,17 +14,16 @@ import org.putgemin.VerticalFlowLayout;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
import static com.rusefi.ui.util.UiUtils.getAllComponents;
import static com.rusefi.ui.util.UiUtils.setToolTip;
import static javax.swing.JOptionPane.YES_NO_OPTION;
/**
* This frame is used on startup to select the port we would be using
@ -217,6 +216,43 @@ public class StartupFrame {
frame.pack();
frame.setVisible(true);
UiUtils.centerWindow(frame);
KeyListener hwTestEasterEgg = functionalTestEasterEgg();
for (Component component : getAllComponents(frame)) {
component.addKeyListener(hwTestEasterEgg);
}
}
/**
* Here we listen to keystrokes while console frame is being displayed and if magic "test" word is typed
* we launch a functional test on real hardware, same as Jenkins runs within continues integration
*/
@NotNull
private KeyListener functionalTestEasterEgg() {
return new KeyAdapter() {
private final static String TEST = "test";
private String recentKeyStrokes = "";
@Override
public void keyTyped(KeyEvent e) {
recentKeyStrokes = recentKeyStrokes + e.getKeyChar();
if (recentKeyStrokes.toLowerCase().endsWith(TEST) && showTestConfirmation()) {
runFunctionalHardwareTest();
}
}
private boolean showTestConfirmation() {
return JOptionPane.showConfirmDialog(StartupFrame.this.frame, "Want to run functional test? This would freeze UI for the duration of the test",
"Better do not run while connected to vehicle!!!", YES_NO_OPTION) == JOptionPane.YES_OPTION;
}
private void runFunctionalHardwareTest() {
String autoDetectedPort = PortDetector.autoDetectPort(null);
boolean isSuccess = RealHwTest.runHardwareTest(autoDetectedPort);
JOptionPane.showMessageDialog(null, "Function test passed: " + isSuccess + "\nSee log folder for details.");
}
};
}
private Component createShowDeviceManagerButton() {

View File

@ -12,6 +12,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
import static com.rusefi.ui.util.LocalizedMessages.CLEAR;
import static com.rusefi.ui.util.LocalizedMessages.PAUSE;
@ -99,6 +100,17 @@ public class UiUtils {
component.repaint();
}
public static java.util.List<Component> getAllComponents(final Container c) {
Component[] comps = c.getComponents();
java.util.List<Component> compList = new ArrayList<>();
for (Component comp : comps) {
compList.add(comp);
if (comp instanceof Container)
compList.addAll(getAllComponents((Container) comp));
}
return compList;
}
/**
* Utility method for multi-line tooltips
*/