1 package autotest.moblab;
2 
3 import autotest.common.ui.TabView;
4 import autotest.moblab.rpc.MoblabRpcCallbacks;
5 import autotest.moblab.rpc.MoblabRpcCallbacks.RunSuiteCallback;
6 import autotest.moblab.rpc.MoblabRpcHelper;
7 import autotest.moblab.rpc.ConnectedBoard;
8 import com.google.gwt.event.dom.client.ChangeEvent;
9 import com.google.gwt.event.dom.client.ChangeHandler;
10 import com.google.gwt.event.dom.client.ClickEvent;
11 import com.google.gwt.event.dom.client.ClickHandler;
12 import com.google.gwt.user.client.Window;
13 import com.google.gwt.user.client.ui.Button;
14 import com.google.gwt.user.client.ui.HasVerticalAlignment;
15 import com.google.gwt.user.client.ui.HorizontalPanel;
16 import com.google.gwt.user.client.ui.Label;
17 import com.google.gwt.user.client.ui.ListBox;
18 import com.google.gwt.user.client.ui.SimplePanel;
19 import com.google.gwt.user.client.ui.TextArea;
20 import com.google.gwt.user.client.ui.TextBox;
21 import com.google.gwt.user.client.ui.VerticalPanel;
22 import com.google.gwt.user.client.ui.Widget;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.HashMap;
26 
27 
28 /**
29  * Implement a tab to make a very easy way to run the most common moblab suites.
30  */
31 public class SuiteRunnerView extends TabView {
32 
33   private VerticalPanel suiteRunnerMainPanel;
34   private ListBox boardSelector;
35   private ListBox buildSelector;
36   private ListBox suiteSelector;
37   private ListBox rwFirmwareSelector;
38   private ListBox roFirmwareSelector;
39   private ListBox poolSelector;
40   private Button actionButton;
41   private TextArea suiteArgsTextArea;
42   private HorizontalPanel thirdOptionalLine;
43 
44   private TextBox bugIdTextBox;
45   private HorizontalPanel fourthOptionalLine;
46 
47   private TextBox partIdTextBox;
48   private HorizontalPanel fifthOptionalLine;
49 
50   private TextArea testArgsTextArea;
51   private HorizontalPanel sixthOptionalLine;
52   private static String TEST_ARGS_PLACEHOLDER =
53     "line delimited test arguments\nexample:\nmyarg=myval\nmyarg2=myval2";
54 
55   private HashMap<String, String> modelBoardMap;
56 
57   private static List<String> suiteNames = Arrays.asList(
58     "au_fsi",
59     "bvt-cq",
60     "bvt-inline",
61     "bvt-tast-cq",
62     "check_setup_cts_N",
63     "check_setup_storage_qual",
64     "cts_N",
65     "cts_P",
66     "gts",
67     "hardware_memoryqual",
68     "hardware_storagequal",
69     "hardware_storagequal_quick",
70     "power_idle",
71     "power_loadtest",
72     "power_loadtest_1hour",
73     "power_loadtest_fast",
74     "power_measurement_wrapper",
75     "power_sanity",
76     "usb-camera",
77     "wifi_matfunc",
78     "wifi_perf"
79   );
80 
81   private static String TEST_LIST_PLACEHOLDER = "arm.CtsAnimationTestCases, x86.CtsDeqpTestCases";
82 
83   @Override
getElementId()84   public String getElementId() {
85     return "suite_run";
86   }
87 
88   @Override
refresh()89   public void refresh() {
90     super.refresh();
91     boardSelector.clear();
92     buildSelector.clear();
93     suiteSelector.clear();
94     rwFirmwareSelector.clear();
95     roFirmwareSelector.clear();
96     poolSelector.clear();
97     suiteArgsTextArea.setText("");
98     bugIdTextBox.setText("");
99     partIdTextBox.setText("");
100 
101     buildSelector.addItem("Select the build");
102     suiteSelector.addItem("Select the suite");
103     poolSelector.addItem("Select the pool");
104 
105     rwFirmwareSelector.addItem("Select the RW Firmware (Faft only) (Optional)");
106     roFirmwareSelector.addItem("Select the RO Firmware (Faft only) (Optional)");
107 
108     for (String suite : suiteNames) {
109       suiteSelector.addItem(suite);
110     }
111 
112     loadBoards();
113     loadPools();
114     addWidget(suiteRunnerMainPanel, "view_suite_run");
115   };
116 
117   @Override
initialize()118   public void initialize() {
119     super.initialize();
120 
121     boardSelector = new ListBox();
122     buildSelector = new ListBox();
123     suiteSelector = new ListBox();
124     rwFirmwareSelector = new ListBox();
125     roFirmwareSelector = new ListBox();
126     poolSelector = new ListBox();
127     suiteArgsTextArea = new TextArea();
128     suiteArgsTextArea.getElement().setPropertyString("placeholder", TEST_LIST_PLACEHOLDER);
129 
130     bugIdTextBox = new TextBox();
131     partIdTextBox = new TextBox();
132 
133     testArgsTextArea = new TextArea();
134     testArgsTextArea.getElement().setPropertyString("placeholder",
135       TEST_ARGS_PLACEHOLDER);
136 
137     boardSelector.addChangeHandler(new ChangeHandler() {
138       @Override
139       public void onChange(ChangeEvent event) {
140         boardSelected();
141       }
142     });
143     boardSelector.setStyleName("run_suite_selector");
144 
145     buildSelector.setEnabled(false);
146     buildSelector.addChangeHandler(new ChangeHandler() {
147       @Override
148       public void onChange(ChangeEvent event) {
149          buildSelected();
150       }
151     });
152     buildSelector.setStyleName("run_suite_selector");
153 
154     suiteSelector.setEnabled(false);
155     suiteSelector.addChangeHandler(new ChangeHandler() {
156       @Override
157       public void onChange(ChangeEvent event) {
158         suiteSelected();
159       }
160     });
161     suiteSelector.setStyleName("run_suite_selector");
162 
163     rwFirmwareSelector.setEnabled(false);
164     rwFirmwareSelector.setStyleName("run_suite_selector");
165     roFirmwareSelector.setEnabled(false);
166     roFirmwareSelector.setStyleName("run_suite_selector");
167     poolSelector.setEnabled(false);
168     poolSelector.setStyleName("run_suite_selector");
169 
170     suiteArgsTextArea.setStyleName("run_suite_test_args");
171     testArgsTextArea.setStyleName("run_suite_test_args");
172     bugIdTextBox.setStyleName("run_suite_avl_args");
173     partIdTextBox.setStyleName("run_suite_avl_args");
174 
175     HorizontalPanel firstLine = createHorizontalLineItem("Select board:", boardSelector);
176     HorizontalPanel secondLine = createHorizontalLineItem("Select build:", buildSelector);
177     HorizontalPanel thirdLine = createHorizontalLineItem("Select suite:", suiteSelector);
178     thirdOptionalLine = createHorizontalLineItem("Only run specified tests (Optional):",
179                                                  suiteArgsTextArea);
180     thirdOptionalLine.setVisible(false);
181     fourthOptionalLine = createHorizontalLineItem("AVL process bug ID:",
182                                                  bugIdTextBox);
183     fourthOptionalLine.setVisible(false);
184     fifthOptionalLine = createHorizontalLineItem("AVL part number:",
185                                                  partIdTextBox);
186     fifthOptionalLine.setVisible(false);
187     sixthOptionalLine = createHorizontalLineItem("Test args:",
188                                                   testArgsTextArea);
189     sixthOptionalLine.setVisible(false);
190     HorizontalPanel fourthLine = createHorizontalLineItem("RW Firmware (Optional):", rwFirmwareSelector);
191     HorizontalPanel fifthLine = createHorizontalLineItem("RO Firmware (Optional):", roFirmwareSelector);
192     HorizontalPanel sixthLine = createHorizontalLineItem("Pool (Optional):", poolSelector);
193 
194     actionButton = new Button("Run Suite", new ClickHandler() {
195       public void onClick(ClickEvent event) {
196         int boardSelection = boardSelector.getSelectedIndex();
197         int buildSelection = buildSelector.getSelectedIndex();
198         int suiteSelection = suiteSelector.getSelectedIndex();
199         int poolSelection = poolSelector.getSelectedIndex();
200         int rwFirmwareSelection = rwFirmwareSelector.getSelectedIndex();
201         int roFirmwareSelection = roFirmwareSelector.getSelectedIndex();
202         if (boardSelection != 0 && buildSelection != 0 && suiteSelection != 0) {
203           String poolLabel = new String();
204           if (poolSelection != 0) {
205             poolLabel = poolSelector.getItemText(poolSelection);
206           }
207           String rwFirmware = new String();
208           if (rwFirmwareSelection != 0) {
209             rwFirmware = rwFirmwareSelector.getItemText(rwFirmwareSelection);
210           }
211           String roFirmware = new String();
212           if (roFirmwareSelection != 0) {
213             roFirmware = roFirmwareSelector.getItemText(roFirmwareSelection);
214           }
215           runSuite(getSelectedBoard(),
216               boardSelector.getItemText(boardSelection),
217               buildSelector.getItemText(buildSelection),
218               suiteSelector.getItemText(suiteSelection),
219               poolLabel,
220               rwFirmware,
221               roFirmware,
222               suiteArgsTextArea.getText(),
223               testArgsTextArea.getText(),
224               bugIdTextBox.getText(),
225               partIdTextBox.getText());
226         } else {
227           Window.alert("You have to select a valid board, build and suite.");
228         }
229       }});
230 
231     actionButton.setEnabled(false);
232     actionButton.setStyleName("run_suite_button");
233     HorizontalPanel seventhLine = createHorizontalLineItem("", actionButton);
234 
235     suiteRunnerMainPanel = new VerticalPanel();
236 
237     suiteRunnerMainPanel.add(firstLine);
238     suiteRunnerMainPanel.add(secondLine);
239     suiteRunnerMainPanel.add(thirdLine);
240     suiteRunnerMainPanel.add(thirdOptionalLine);
241     suiteRunnerMainPanel.add(fourthOptionalLine);
242     suiteRunnerMainPanel.add(fifthOptionalLine);
243     suiteRunnerMainPanel.add(sixthOptionalLine);
244     suiteRunnerMainPanel.add(fourthLine);
245     suiteRunnerMainPanel.add(fifthLine);
246     suiteRunnerMainPanel.add(sixthLine);
247     suiteRunnerMainPanel.add(seventhLine);
248   }
249 
createHorizontalLineItem(String label, Widget item)250   private HorizontalPanel createHorizontalLineItem(String label, Widget item) {
251     HorizontalPanel panel = new HorizontalPanel();
252     panel.add(contstructLabel(label));
253     panel.add(item);
254     return panel;
255   }
256 
contstructLabel(String labelName)257   private Label contstructLabel(String labelName) {
258     Label label = new Label(labelName);
259     label.setStyleName("run_suite_label");
260     return label;
261   }
262 
suiteSelected()263   private void suiteSelected() {
264     int selectedIndex = suiteSelector.getSelectedIndex();
265     if (selectedIndex != 0) {
266       actionButton.setEnabled(true);
267     }
268     // Account for their being an extra item in the drop down
269     int listIndex = selectedIndex - 1;
270     if (listIndex  == suiteNames.indexOf("faft_setup") ||
271       listIndex == suiteNames.indexOf("faft_bios") ||
272       listIndex == suiteNames.indexOf("faft_ec")) {
273       loadFirmwareBuilds(getSelectedBoard());
274     } else {
275       rwFirmwareSelector.setEnabled(false);
276       roFirmwareSelector.setEnabled(false);
277       rwFirmwareSelector.setSelectedIndex(0);
278       roFirmwareSelector.setSelectedIndex(0);
279     }
280 
281     if (listIndex  == suiteNames.indexOf("gts") ||
282       listIndex == suiteNames.indexOf("cts_N") ||
283       listIndex == suiteNames.indexOf("cts_P")) {
284       thirdOptionalLine.setVisible(true);
285       fourthOptionalLine.setVisible(false);
286       fifthOptionalLine.setVisible(false);
287       sixthOptionalLine.setVisible(false);
288     } else if (isAvlSuite(suiteNames.get(listIndex))) {
289       thirdOptionalLine.setVisible(false);
290       fourthOptionalLine.setVisible(true);
291       fifthOptionalLine.setVisible(true);
292       sixthOptionalLine.setVisible(false);
293     } else if(listIndex == suiteNames.indexOf("power_measurement_wrapper") ||
294         listIndex == suiteNames.indexOf("wifi_matfunc") ||
295         listIndex == suiteNames.indexOf("wifi_perf")) {
296       thirdOptionalLine.setVisible(false);
297       fourthOptionalLine.setVisible(false);
298       fifthOptionalLine.setVisible(false);
299       sixthOptionalLine.setVisible(true);
300     } else {
301       suiteArgsTextArea.setText("");
302       thirdOptionalLine.setVisible(false);
303       fourthOptionalLine.setVisible(false);
304       fifthOptionalLine.setVisible(false);
305       sixthOptionalLine.setVisible(false);
306     }
307   }
308 
buildSelected()309   private void buildSelected() {
310     int selectedIndex = buildSelector.getSelectedIndex();
311     if (selectedIndex != 0) {
312       suiteSelector.setEnabled(true);
313     }
314   }
315 
boardSelected()316   private void boardSelected() {
317     suiteSelector.setEnabled(false);
318     actionButton.setEnabled(false);
319     String selectedBoard = getSelectedBoard();
320     if (selectedBoard != null) {
321       loadBuilds(selectedBoard);
322     }
323   }
324 
getSelectedBoard()325   private String getSelectedBoard() {
326     int selectedIndex = boardSelector.getSelectedIndex();
327     if (selectedIndex != 0) {
328       String model = boardSelector.getItemText(selectedIndex);
329       return modelBoardMap.get(model);
330     }
331     else {
332       return null;
333     }
334   }
335 
336   /**
337    * Call an RPC to get the boards that are connected to the moblab and populate them in the
338    * dropdown.
339    */
loadBoards()340   private void loadBoards() {
341     boardSelector.setEnabled(false);
342     boardSelector.clear();
343     boardSelector.addItem("Select the board");
344     MoblabRpcHelper.fetchConnectedBoards(new MoblabRpcCallbacks.FetchConnectedBoardsCallback() {
345       @Override
346       public void onFetchConnectedBoardsSubmitted(
347           List<ConnectedBoard> connectedBoards) {
348         modelBoardMap = new HashMap<String, String>();
349         for (ConnectedBoard connectedBoard : connectedBoards) {
350           // remember the board that goes with this model
351           modelBoardMap.put(
352               connectedBoard.getModel(), connectedBoard.getBoard());
353           boardSelector.addItem(connectedBoard.getModel());
354         }
355         boardSelector.setEnabled(true);
356       }
357     });
358   }
359 
360   /**
361    * Call an RPC to get the pools that are configured on the devices connected to the moblab.
362    * and fill in the .
363    */
loadPools()364   private void loadPools() {
365     poolSelector.setEnabled(false);
366     poolSelector.clear();
367     poolSelector.addItem("Select a pool");
368     MoblabRpcHelper.fetchConnectedPools(new MoblabRpcCallbacks.FetchConnectedPoolsCallback() {
369       @Override
370       public void onFetchConnectedPoolsSubmitted(List<String> connectedPools) {
371         for (String connectedPool : connectedPools) {
372           poolSelector.addItem(connectedPool);
373         }
374         poolSelector.setEnabled(true);
375       }
376     });
377   }
378 
379 
380   /**
381    * Make a RPC to get the most recent builds available for the specified board and populate them
382    * in the dropdown.
383    * @param selectedBoard
384    */
loadBuilds(String selectedBoard)385   private void loadBuilds(String selectedBoard) {
386     buildSelector.setEnabled(false);
387     buildSelector.clear();
388     buildSelector.addItem("Select the build");
389     MoblabRpcHelper.fetchBuildsForBoard(selectedBoard,
390         new MoblabRpcCallbacks.FetchBuildsForBoardCallback() {
391       @Override
392       public void onFetchBuildsForBoardCallbackSubmitted(List<String> boards) {
393         for (String board : boards) {
394           buildSelector.addItem(board);
395         }
396         buildSelector.setEnabled(true);
397       }
398     });
399   }
400 
401 
402   /**
403    * Make a RPC to get the most recent firmware available for the specified board and populate them
404    * in the dropdowns.
405    * @param selectedBoard
406    */
loadFirmwareBuilds(String selectedBoard)407   private void loadFirmwareBuilds(String selectedBoard) {
408     rwFirmwareSelector.setEnabled(false);
409     roFirmwareSelector.setEnabled(false);
410     rwFirmwareSelector.clear();
411     roFirmwareSelector.clear();
412     rwFirmwareSelector.addItem("Select the RW Firmware (Faft only) (Optional)");
413     roFirmwareSelector.addItem("Select the RO Firmware (Faft only) (Optional)");
414     MoblabRpcHelper.fetchFirmwareForBoard(selectedBoard,
415         new MoblabRpcCallbacks.FetchFirmwareForBoardCallback() {
416       @Override
417       public void onFetchFirmwareForBoardCallbackSubmitted(List<String> firmwareBuilds) {
418         for (String firmware : firmwareBuilds) {
419           rwFirmwareSelector.addItem(firmware);
420           roFirmwareSelector.addItem(firmware);
421         }
422         rwFirmwareSelector.setEnabled(true);
423         roFirmwareSelector.setEnabled(true);
424       }
425     });
426   }
427 
isAvlSuite(String suite)428   private boolean isAvlSuite(String suite) {
429     return Arrays.asList("hardware_storagequal", "hardware_storagequal_quick",
430       "hardware_memoryqual").contains(suite);
431   }
432 
433 
434   /**
435    * For the selection option of board, build, suite and pool make a RPC call that will instruct
436    * AFE to run the suite selected.
437    * @param board, a string that specified a device connected to the moblab.
438    * @param model, a string that specifies a device model connected to moblab.
439    * @param build, a string that is a valid build for the specified board available in GCS.
440    * @param suite, a string that specifies the name of a suite selected to run.
441    * @param pool, an optional name of a pool to run the suite in.
442    * @param rwFirmware, an optional firmware to use for some qual tests.
443    * @param roFirmware, an optional firmware to use for some qual tests.
444    * @param suiteArgs, optional params to pass to the suite.
445    * @param testArgs, optional params to pass to tests in the suite.
446    * @param bugId, an optional param indicates the bugnizer ticket for
447    * memory/hardware avl process. Required for AVL suites.
448    * @param partId, an optional param identifies the component involved for
449    * memory/hardware avl process. Required for AVL suites.
450    */
runSuite(String board, String model, String build, String suite, String pool, String rwFirmware, String roFirmware, String suiteArgs, String testArgs, String bugId, String partId)451   private void runSuite(String board, String model, String build, String suite,
452       String pool, String rwFirmware, String roFirmware, String suiteArgs,
453       String testArgs, String bugId, String partId) {
454     String realPoolLabel = pool;
455     if (pool != null && !pool.isEmpty()) {
456       realPoolLabel = pool.trim();
457     }
458 
459     // partId, bugId required for avl suites
460     if (isAvlSuite(suite)) {
461       if ((bugId == null || bugId.isEmpty()) ||
462         (partId == null || partId.isEmpty())) {
463           Window.alert("Part ID and Bug ID are required for suite " + suite);
464           return;
465       }
466 
467       // bug id is an integer id
468       if (!bugId.matches("\\d+")) {
469           Window.alert("Bug ID must be numeric");
470           return;
471       }
472     }
473 
474     MoblabRpcHelper.runSuite(board, model, build, suite, realPoolLabel,
475         rwFirmware, roFirmware, suiteArgs, testArgs, bugId, partId,
476         new RunSuiteCallback() {
477       @Override
478       public void onRunSuiteComplete() {
479         Window.Location.assign("/afe");
480       }
481     });
482   };
483 
484 }
485