• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 HashMap<String, String> modelBoardMap;
51 
52   private static List<String> suiteNames = Arrays.asList("bvt-cq",
53       "bvt-inline", "cts_N", "gts",
54       "hardware_storagequal", "hardware_memoryqual", "usb-camera");
55 
56   private static String TEST_LIST_PLACEHOLDER = "arm.CtsAnimationTestCases, x86.CtsDeqpTestCases";
57 
58   @Override
getElementId()59   public String getElementId() {
60     return "suite_run";
61   }
62 
63   @Override
refresh()64   public void refresh() {
65     super.refresh();
66     boardSelector.clear();
67     buildSelector.clear();
68     suiteSelector.clear();
69     rwFirmwareSelector.clear();
70     roFirmwareSelector.clear();
71     poolSelector.clear();
72     suiteArgsTextArea.setText("");
73     bugIdTextBox.setText("");
74     partIdTextBox.setText("");
75 
76     buildSelector.addItem("Select the build");
77     suiteSelector.addItem("Select the suite");
78     poolSelector.addItem("Select the pool");
79 
80     rwFirmwareSelector.addItem("Select the RW Firmware (Faft only) (Optional)");
81     roFirmwareSelector.addItem("Select the RO Firmware (Faft only) (Optional)");
82 
83     for (String suite : suiteNames) {
84       suiteSelector.addItem(suite);
85     }
86 
87     loadBoards();
88     loadPools();
89     addWidget(suiteRunnerMainPanel, "view_suite_run");
90   };
91 
92   @Override
initialize()93   public void initialize() {
94     super.initialize();
95 
96     boardSelector = new ListBox();
97     buildSelector = new ListBox();
98     suiteSelector = new ListBox();
99     rwFirmwareSelector = new ListBox();
100     roFirmwareSelector = new ListBox();
101     poolSelector = new ListBox();
102     suiteArgsTextArea = new TextArea();
103     suiteArgsTextArea.getElement().setPropertyString("placeholder", TEST_LIST_PLACEHOLDER);
104 
105     bugIdTextBox = new TextBox();
106     partIdTextBox = new TextBox();
107 
108     boardSelector.addChangeHandler(new ChangeHandler() {
109       @Override
110       public void onChange(ChangeEvent event) {
111         boardSelected();
112       }
113     });
114     boardSelector.setStyleName("run_suite_selector");
115 
116     buildSelector.setEnabled(false);
117     buildSelector.addChangeHandler(new ChangeHandler() {
118       @Override
119       public void onChange(ChangeEvent event) {
120          buildSelected();
121       }
122     });
123     buildSelector.setStyleName("run_suite_selector");
124 
125     suiteSelector.setEnabled(false);
126     suiteSelector.addChangeHandler(new ChangeHandler() {
127       @Override
128       public void onChange(ChangeEvent event) {
129         suiteSelected();
130       }
131     });
132     suiteSelector.setStyleName("run_suite_selector");
133 
134     rwFirmwareSelector.setEnabled(false);
135     rwFirmwareSelector.setStyleName("run_suite_selector");
136     roFirmwareSelector.setEnabled(false);
137     roFirmwareSelector.setStyleName("run_suite_selector");
138     poolSelector.setEnabled(false);
139     poolSelector.setStyleName("run_suite_selector");
140 
141     suiteArgsTextArea.setStyleName("run_suite_test_args");
142     bugIdTextBox.setStyleName("run_suite_avl_args");
143     partIdTextBox.setStyleName("run_suite_avl_args");
144 
145     HorizontalPanel firstLine = createHorizontalLineItem("Select board:", boardSelector);
146     HorizontalPanel secondLine = createHorizontalLineItem("Select build:", buildSelector);
147     HorizontalPanel thirdLine = createHorizontalLineItem("Select suite:", suiteSelector);
148     thirdOptionalLine = createHorizontalLineItem("Only run specified tests (Optional):",
149                                                  suiteArgsTextArea);
150     thirdOptionalLine.setVisible(false);
151     fourthOptionalLine = createHorizontalLineItem("AVL process bug ID (Optional):",
152                                                  bugIdTextBox);
153     fourthOptionalLine.setVisible(false);
154     fifthOptionalLine = createHorizontalLineItem("AVL part number (Optional):",
155                                                  partIdTextBox);
156     fifthOptionalLine.setVisible(false);
157     HorizontalPanel fourthLine = createHorizontalLineItem("RW Firmware (Optional):", rwFirmwareSelector);
158     HorizontalPanel fifthLine = createHorizontalLineItem("RO Firmware (Optional):", roFirmwareSelector);
159     HorizontalPanel sixthLine = createHorizontalLineItem("Pool (Optional):", poolSelector);
160 
161     actionButton = new Button("Run Suite", new ClickHandler() {
162       public void onClick(ClickEvent event) {
163         int boardSelection = boardSelector.getSelectedIndex();
164         int buildSelection = buildSelector.getSelectedIndex();
165         int suiteSelection = suiteSelector.getSelectedIndex();
166         int poolSelection = poolSelector.getSelectedIndex();
167         int rwFirmwareSelection = rwFirmwareSelector.getSelectedIndex();
168         int roFirmwareSelection = roFirmwareSelector.getSelectedIndex();
169         if (boardSelection != 0 && buildSelection != 0 && suiteSelection != 0) {
170           String poolLabel = new String();
171           if (poolSelection != 0) {
172             poolLabel = poolSelector.getItemText(poolSelection);
173           }
174           String rwFirmware = new String();
175           if (rwFirmwareSelection != 0) {
176             rwFirmware = rwFirmwareSelector.getItemText(rwFirmwareSelection);
177           }
178           String roFirmware = new String();
179           if (roFirmwareSelection != 0) {
180             roFirmware = roFirmwareSelector.getItemText(roFirmwareSelection);
181           }
182           runSuite(getSelectedBoard(),
183               boardSelector.getItemText(boardSelection),
184               buildSelector.getItemText(buildSelection),
185               suiteSelector.getItemText(suiteSelection),
186               poolLabel,
187               rwFirmware,
188               roFirmware,
189               suiteArgsTextArea.getText(),
190               bugIdTextBox.getText(),
191               partIdTextBox.getText());
192         } else {
193           Window.alert("You have to select a valid board, build and suite.");
194         }
195       }});
196 
197     actionButton.setEnabled(false);
198     actionButton.setStyleName("run_suite_button");
199     HorizontalPanel seventhLine = createHorizontalLineItem("", actionButton);
200 
201     suiteRunnerMainPanel = new VerticalPanel();
202 
203     suiteRunnerMainPanel.add(firstLine);
204     suiteRunnerMainPanel.add(secondLine);
205     suiteRunnerMainPanel.add(thirdLine);
206     suiteRunnerMainPanel.add(thirdOptionalLine);
207     suiteRunnerMainPanel.add(fourthOptionalLine);
208     suiteRunnerMainPanel.add(fifthOptionalLine);
209     suiteRunnerMainPanel.add(fourthLine);
210     suiteRunnerMainPanel.add(fifthLine);
211     suiteRunnerMainPanel.add(sixthLine);
212     suiteRunnerMainPanel.add(seventhLine);
213   }
214 
createHorizontalLineItem(String label, Widget item)215   private HorizontalPanel createHorizontalLineItem(String label, Widget item) {
216     HorizontalPanel panel = new HorizontalPanel();
217     panel.add(contstructLabel(label));
218     panel.add(item);
219     return panel;
220   }
221 
contstructLabel(String labelName)222   private Label contstructLabel(String labelName) {
223     Label label = new Label(labelName);
224     label.setStyleName("run_suite_label");
225     return label;
226   }
227 
suiteSelected()228   private void suiteSelected() {
229     int selectedIndex = suiteSelector.getSelectedIndex();
230     if (selectedIndex != 0) {
231       actionButton.setEnabled(true);
232     }
233     // Account for their being an extra item in the drop down
234     int listIndex = selectedIndex - 1;
235     if (listIndex  == suiteNames.indexOf("faft_setup") ||
236       listIndex == suiteNames.indexOf("faft_bios") ||
237       listIndex == suiteNames.indexOf("faft_ec")) {
238       loadFirmwareBuilds(getSelectedBoard());
239     } else {
240       rwFirmwareSelector.setEnabled(false);
241       roFirmwareSelector.setEnabled(false);
242       rwFirmwareSelector.setSelectedIndex(0);
243       roFirmwareSelector.setSelectedIndex(0);
244     }
245 
246     if (listIndex  == suiteNames.indexOf("gts") ||
247       listIndex == suiteNames.indexOf("cts_N")) {
248       thirdOptionalLine.setVisible(true);
249       fourthOptionalLine.setVisible(false);
250       fifthOptionalLine.setVisible(false);
251     } else if(listIndex == suiteNames.indexOf("hardware_storagequal") ||
252         listIndex == suiteNames.indexOf("hardware_memoryqual")) {
253       thirdOptionalLine.setVisible(false);
254       fourthOptionalLine.setVisible(true);
255       fifthOptionalLine.setVisible(true);
256     } else {
257       suiteArgsTextArea.setText("");
258       thirdOptionalLine.setVisible(false);
259       fourthOptionalLine.setVisible(false);
260       fifthOptionalLine.setVisible(false);
261     }
262   }
263 
buildSelected()264   private void buildSelected() {
265     int selectedIndex = buildSelector.getSelectedIndex();
266     if (selectedIndex != 0) {
267       suiteSelector.setEnabled(true);
268     }
269   }
270 
boardSelected()271   private void boardSelected() {
272     suiteSelector.setEnabled(false);
273     actionButton.setEnabled(false);
274     String selectedBoard = getSelectedBoard();
275     if (selectedBoard != null) {
276       loadBuilds(selectedBoard);
277     }
278   }
279 
getSelectedBoard()280   private String getSelectedBoard() {
281     int selectedIndex = boardSelector.getSelectedIndex();
282     if (selectedIndex != 0) {
283       String model = boardSelector.getItemText(selectedIndex);
284       return modelBoardMap.get(model);
285     }
286     else {
287       return null;
288     }
289   }
290 
291   /**
292    * Call an RPC to get the boards that are connected to the moblab and populate them in the
293    * dropdown.
294    */
loadBoards()295   private void loadBoards() {
296     boardSelector.setEnabled(false);
297     boardSelector.clear();
298     boardSelector.addItem("Select the board");
299     MoblabRpcHelper.fetchConnectedBoards(new MoblabRpcCallbacks.FetchConnectedBoardsCallback() {
300       @Override
301       public void onFetchConnectedBoardsSubmitted(
302           List<ConnectedBoard> connectedBoards) {
303         modelBoardMap = new HashMap<String, String>();
304         for (ConnectedBoard connectedBoard : connectedBoards) {
305           // remember the board that goes with this model
306           modelBoardMap.put(
307               connectedBoard.getModel(), connectedBoard.getBoard());
308           boardSelector.addItem(connectedBoard.getModel());
309         }
310         boardSelector.setEnabled(true);
311       }
312     });
313   }
314 
315   /**
316    * Call an RPC to get the pools that are configured on the devices connected to the moblab.
317    * and fill in the .
318    */
loadPools()319   private void loadPools() {
320     poolSelector.setEnabled(false);
321     poolSelector.clear();
322     poolSelector.addItem("Select a pool");
323     MoblabRpcHelper.fetchConnectedPools(new MoblabRpcCallbacks.FetchConnectedPoolsCallback() {
324       @Override
325       public void onFetchConnectedPoolsSubmitted(List<String> connectedPools) {
326         for (String connectedPool : connectedPools) {
327           poolSelector.addItem(connectedPool);
328         }
329         poolSelector.setEnabled(true);
330       }
331     });
332   }
333 
334 
335   /**
336    * Make a RPC to get the most recent builds available for the specified board and populate them
337    * in the dropdown.
338    * @param selectedBoard
339    */
loadBuilds(String selectedBoard)340   private void loadBuilds(String selectedBoard) {
341     buildSelector.setEnabled(false);
342     buildSelector.clear();
343     buildSelector.addItem("Select the build");
344     MoblabRpcHelper.fetchBuildsForBoard(selectedBoard,
345         new MoblabRpcCallbacks.FetchBuildsForBoardCallback() {
346       @Override
347       public void onFetchBuildsForBoardCallbackSubmitted(List<String> boards) {
348         for (String board : boards) {
349           buildSelector.addItem(board);
350         }
351         buildSelector.setEnabled(true);
352       }
353     });
354   }
355 
356 
357   /**
358    * Make a RPC to get the most recent firmware available for the specified board and populate them
359    * in the dropdowns.
360    * @param selectedBoard
361    */
loadFirmwareBuilds(String selectedBoard)362   private void loadFirmwareBuilds(String selectedBoard) {
363     rwFirmwareSelector.setEnabled(false);
364     roFirmwareSelector.setEnabled(false);
365     rwFirmwareSelector.clear();
366     roFirmwareSelector.clear();
367     rwFirmwareSelector.addItem("Select the RW Firmware (Faft only) (Optional)");
368     roFirmwareSelector.addItem("Select the RO Firmware (Faft only) (Optional)");
369     MoblabRpcHelper.fetchFirmwareForBoard(selectedBoard,
370         new MoblabRpcCallbacks.FetchFirmwareForBoardCallback() {
371       @Override
372       public void onFetchFirmwareForBoardCallbackSubmitted(List<String> firmwareBuilds) {
373         for (String firmware : firmwareBuilds) {
374           rwFirmwareSelector.addItem(firmware);
375           roFirmwareSelector.addItem(firmware);
376         }
377         rwFirmwareSelector.setEnabled(true);
378         roFirmwareSelector.setEnabled(true);
379       }
380     });
381   }
382 
383 
384   /**
385    * For the selection option of board, build, suite and pool make a RPC call that will instruct
386    * AFE to run the suite selected.
387    * @param board, a string that specified a device connected to the moblab.
388    * @param model, a string that specifies a device model connected to moblab.
389    * @param build, a string that is a valid build for the specified board available in GCS.
390    * @param suite, a string that specifies the name of a suite selected to run.
391    * @param pool, an optional name of a pool to run the suite in.
392    * @param rwFirmware, an optional firmware to use for some qual tests.
393    * @param roFirmware, an optional firmware to use for some qual tests.
394    * @param suiteArgs, optional params to pass to the suite.
395    * @param bugId, an optional param indicates the bugnizer ticket for
396    * memory/hardware avl process.
397    * @param partId, an optional param identifies the component involved for
398    * memory/hardare avl process.
399    */
runSuite(String board, String model, String build, String suite, String pool, String rwFirmware, String roFirmware, String suiteArgs, String bugId, String partId)400   private void runSuite(String board, String model, String build, String suite,
401       String pool, String rwFirmware, String roFirmware, String suiteArgs,
402       String bugId, String partId) {
403     String realPoolLabel = pool;
404     if (pool != null && !pool.isEmpty()) {
405       realPoolLabel = pool.trim();
406     }
407     MoblabRpcHelper.runSuite(board, model, build, suite, realPoolLabel,
408         rwFirmware, roFirmware, suiteArgs, bugId, partId,
409         new RunSuiteCallback() {
410       @Override
411       public void onRunSuiteComplete() {
412         Window.Location.assign("/afe");
413       }
414     });
415   };
416 
417 }
418