Skip to content

Commit b0d0e9e

Browse files
author
jantje
committed
Adding test for local debug build
1 parent 68c1e30 commit b0d0e9e

File tree

3 files changed

+303
-3
lines changed

3 files changed

+303
-3
lines changed
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
package io.sloeber.core;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import java.util.ArrayList;
6+
import java.util.Collection;
7+
import java.util.LinkedList;
8+
import java.util.Map;
9+
import java.util.TreeMap;
10+
11+
import org.eclipse.core.resources.IProject;
12+
import org.eclipse.core.resources.IncrementalProjectBuilder;
13+
import org.eclipse.core.runtime.CoreException;
14+
import org.eclipse.core.runtime.IPath;
15+
import org.eclipse.core.runtime.NullProgressMonitor;
16+
import org.eclipse.core.runtime.Path;
17+
import org.junit.Test;
18+
import org.junit.runner.RunWith;
19+
import org.junit.runners.Parameterized;
20+
import org.junit.runners.Parameterized.Parameters;
21+
22+
import io.sloeber.core.api.BoardDescriptor;
23+
import io.sloeber.core.api.BoardsManager;
24+
import io.sloeber.core.api.CodeDescriptor;
25+
import io.sloeber.core.api.CompileOptions;
26+
import io.sloeber.core.api.ConfigurationDescriptor;
27+
import io.sloeber.core.boards.GenericJantjeBoard;
28+
import io.sloeber.core.boards.IBoard;
29+
30+
@SuppressWarnings("nls")
31+
@RunWith(Parameterized.class)
32+
public class CreateAndCompileJantjesBoardsTest {
33+
private static int mCounter = 0;
34+
private CodeDescriptor myCodeDescriptor;
35+
private String myName;
36+
private boolean myUsesSerial1;
37+
private boolean myUsesKeyboard;
38+
private boolean myUsesSerial;
39+
private static int totalFails = 0;
40+
41+
public CreateAndCompileJantjesBoardsTest(String name, CodeDescriptor codeDescriptor,
42+
boolean usesSerial, boolean usesSerial1, boolean usesKeyboard) {
43+
44+
this.myCodeDescriptor = codeDescriptor;
45+
this.myName = name;
46+
this.myUsesSerial = usesSerial;
47+
this.myUsesSerial1 = usesSerial1;
48+
this.myUsesKeyboard = usesKeyboard;
49+
50+
}
51+
52+
@SuppressWarnings("rawtypes")
53+
@Parameters(name = "{index}: {0}")
54+
public static Collection examples() {
55+
LinkedList<Object[]> examples = new LinkedList<>();
56+
Shared.waitForAllJobsToFinish();
57+
BoardsManager.installLatestPlatform(GenericJantjeBoard.getJsonFileName(), GenericJantjeBoard.getPackageName(), GenericJantjeBoard.getPlatformName());
58+
59+
60+
TreeMap<String, IPath> exampleFolders = BoardsManager.getAllArduinoIDEExamples();
61+
for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
62+
if(!skipExample(curexample.getKey())) {
63+
ArrayList<Path> paths = new ArrayList<>();
64+
65+
paths.add(new Path(curexample.getValue().toString()));
66+
CodeDescriptor codeDescriptor = CodeDescriptor.createExample(false, paths);
67+
String inoName = curexample.getKey().trim();
68+
Boolean usesSerial = new Boolean(Examples.getUsesSerialExamples().contains(inoName));
69+
Boolean usesSerial1 = new Boolean(Examples.getUsesSerial1Examples().contains(inoName));
70+
Boolean usesKeyboard = new Boolean(Examples.getUsesKeyboardExamples().contains(inoName));
71+
72+
Object[] theData = new Object[] { "Example:" + inoName, codeDescriptor, usesSerial, usesSerial1,
73+
usesKeyboard };
74+
examples.add(theData);
75+
}
76+
}
77+
78+
return examples;
79+
80+
}
81+
82+
private static boolean skipExample(String curexample) {
83+
String searchName=curexample.trim().replace('?', '_');
84+
searchName=searchName.replace(' ', '_');
85+
searchName=searchName.replace('.', '_');
86+
switch (searchName) {
87+
case "examples__10_StarterKit_BasicKit_p13_TouchSensorLamp":
88+
return true;
89+
case "examples__09_USB_KeyboardAndMouseControl":
90+
return true;
91+
case "examples__09_USB__Mouse_JoystickMouseControl":
92+
return true;
93+
case "examples__09_USB__Mouse_ButtonMouseControl":
94+
return true;
95+
case "examples__09_USB__Keyboard_KeyboardSerial":
96+
return true;
97+
case "examples__09_USB__Keyboard_KeyboardReprogram":
98+
return true;
99+
case "examples__09_USB__Keyboard_KeyboardMessage":
100+
return true;
101+
case "examples__09_USB__Keyboard_KeyboardLogout":
102+
return true;
103+
}
104+
return false;
105+
}
106+
107+
public void testExample(IBoard board) {
108+
// Stop after X fails because
109+
// the fails stays open in eclipse and it becomes really slow
110+
// There are only a number of issues you can handle
111+
// best is to focus on the first ones and then rerun starting with the
112+
// failures
113+
if (this.myUsesSerial && !board.supportsSerial()) {
114+
System.out.println("!TEST SKIPPED due to Serial " + this.myName + " " + board.getName());
115+
return;
116+
}
117+
if (this.myUsesSerial1 && !board.supportsSerial1()) {
118+
System.out.println("!TEST SKIPPED due to Serial1 " + this.myName + " " + board.getName());
119+
return;
120+
}
121+
if (this.myUsesKeyboard && !board.supportsKeyboard()) {
122+
System.out.println("!TEST SKIPPED due to keyboard " + this.myName + " " + board.getName());
123+
return;
124+
}
125+
if (totalFails < 40) {
126+
BuildAndVerify(board.getBoardDescriptor());
127+
} else {
128+
fail("To many fails. Stopping test");
129+
}
130+
131+
}
132+
133+
@Test
134+
public void testJantjeYun() {
135+
testExample(new GenericJantjeBoard("yun"));
136+
}
137+
138+
@Test
139+
public void testJantjeUno() {
140+
testExample(new GenericJantjeBoard("uno"));
141+
}
142+
143+
@Test
144+
public void testJantjeDiecimila() {
145+
testExample(new GenericJantjeBoard("diecimila"));
146+
}
147+
148+
@Test
149+
public void testJantjeNano() {
150+
testExample(new GenericJantjeBoard("nano"));
151+
}
152+
153+
@Test
154+
public void testJantjeMega() {
155+
testExample(new GenericJantjeBoard("mega"));
156+
}
157+
@Test
158+
public void testJantjeMegaADK() {
159+
testExample(new GenericJantjeBoard("megaADK"));
160+
}
161+
@Test
162+
public void testJantjeLeonardo() {
163+
testExample(new GenericJantjeBoard("leonardo"));
164+
}
165+
@Test
166+
public void testJantjeMicro() {
167+
testExample(new GenericJantjeBoard("micro"));
168+
}
169+
@Test
170+
public void testJantjeEsplora() {
171+
testExample(new GenericJantjeBoard("esplora"));
172+
}
173+
@Test
174+
public void testJantjeMini() {
175+
testExample(new GenericJantjeBoard("mini"));
176+
}
177+
@Test
178+
public void testJantjeEthernet() {
179+
testExample(new GenericJantjeBoard("ethernet"));
180+
}
181+
@Test
182+
public void testJantje_fio() {
183+
testExample(new GenericJantjeBoard("fio"));
184+
}
185+
@Test
186+
public void testJantje_bt() {
187+
testExample(new GenericJantjeBoard("bt"));
188+
}
189+
@Test
190+
public void testJantje_LilyPadUSB() {
191+
testExample(new GenericJantjeBoard("LilyPadUSB"));
192+
}
193+
@Test
194+
public void testJantje_lilypad() {
195+
testExample(new GenericJantjeBoard("lilypad"));
196+
}
197+
@Test
198+
public void testJantje_pro() {
199+
testExample(new GenericJantjeBoard("pro"));
200+
}
201+
@Test
202+
public void testJantje_atmegang() {
203+
testExample(new GenericJantjeBoard("atmegang"));
204+
}
205+
@Test
206+
public void testJantje_robotControl() {
207+
testExample(new GenericJantjeBoard("robotControl"));
208+
}
209+
210+
211+
212+
public void BuildAndVerify(BoardDescriptor boardDescriptor) {
213+
214+
IProject theTestProject = null;
215+
216+
NullProgressMonitor monitor = new NullProgressMonitor();
217+
String projectName = String.format("%05d_:%s_%s", new Integer(mCounter++), this.myName,
218+
boardDescriptor.getBoardID());
219+
try {
220+
221+
theTestProject = boardDescriptor.createProject(projectName, null,
222+
ConfigurationDescriptor.getDefaultDescriptors(), this.myCodeDescriptor, new CompileOptions(null),
223+
monitor);
224+
Shared.waitForAllJobsToFinish(); // for the indexer
225+
} catch (Exception e) {
226+
e.printStackTrace();
227+
totalFails++;
228+
fail("Failed to create the project:" + projectName);
229+
return;
230+
}
231+
try {
232+
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
233+
if (Shared.hasBuildErrors(theTestProject)) {
234+
// try again because the libraries may not yet been added
235+
Shared.waitForAllJobsToFinish(); // for the indexer
236+
try {
237+
Thread.sleep(3000);// seen sometimes the libs were still not
238+
// added
239+
} catch (InterruptedException e) {
240+
// ignore
241+
}
242+
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
243+
if (Shared.hasBuildErrors(theTestProject)) {
244+
// give up
245+
totalFails++;
246+
fail("Failed to compile the project:" + projectName + " build errors");
247+
} else {
248+
theTestProject.delete(true, null);
249+
}
250+
} else {
251+
theTestProject.delete(true, null);
252+
}
253+
} catch (CoreException e) {
254+
e.printStackTrace();
255+
totalFails++;
256+
fail("Failed to compile the project:" + projectName + " exception");
257+
}
258+
}
259+
260+
}

io.sloeber.tests/src/io/sloeber/core/boards/GenericArduinoAvrBoard.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public GenericArduinoAvrBoard(String boardName) {
2727
setSupportKeyboard(supportKeyboardList().contains(boardName));
2828
}
2929

30-
private static List<String> supportSerial1List() {
30+
static List<String> supportSerial1List() {
3131
if (mySupportSerial1List == null) {
3232
mySupportSerial1List = new LinkedList<>();
3333
mySupportSerial1List.add("circuitplay32u4cat");
@@ -48,15 +48,15 @@ private static List<String> supportSerial1List() {
4848
return mySupportSerial1List;
4949
}
5050

51-
private static List<String> doesNotSupportSerialList() {
51+
static List<String> doesNotSupportSerialList() {
5252
if (myDoesNotSupportSerialList == null) {
5353
myDoesNotSupportSerialList = new LinkedList<>();
5454
myDoesNotSupportSerialList.add("gemma");
5555
}
5656
return myDoesNotSupportSerialList;
5757
}
5858

59-
private static List<String> supportKeyboardList() {
59+
static List<String> supportKeyboardList() {
6060
if (mySupportKeyboardList == null) {
6161
mySupportKeyboardList = new LinkedList<>();
6262
mySupportKeyboardList.add("circuitplay32u4cat");
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.sloeber.core.boards;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import java.util.Map;
6+
import java.util.TreeMap;
7+
8+
import io.sloeber.core.api.BoardsManager;
9+
10+
@SuppressWarnings("nls")
11+
public class GenericJantjeBoard extends IBoard {
12+
13+
14+
15+
public static String getJsonFileName() {
16+
return "package_jantje_index.json";
17+
}
18+
public static String getPackageName() {
19+
return "Jantje";
20+
}
21+
public static String getPlatformName() {
22+
return "Arduino avr Boards (local debug)";
23+
}
24+
public GenericJantjeBoard(String boardName) {
25+
Map<String, String> options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
26+
this.myBoardDescriptor = BoardsManager.getBoardDescriptor(getJsonFileName(),getPackageName(),getPlatformName() ,
27+
boardName, options);
28+
if (this.myBoardDescriptor == null) {
29+
fail(boardName + " Board not found");
30+
}
31+
this.myBoardDescriptor.setUploadPort("none");
32+
33+
setSupportSerial(!GenericArduinoAvrBoard.doesNotSupportSerialList().contains(boardName));
34+
setSupportSerial1(GenericArduinoAvrBoard.supportSerial1List().contains(boardName));
35+
setSupportKeyboard(GenericArduinoAvrBoard.supportKeyboardList().contains(boardName));
36+
}
37+
38+
39+
40+
}

0 commit comments

Comments
 (0)