Skip to content

Commit 9febb54

Browse files
author
jantje
committed
better more consistend handling of examples in tests
basically there were many places examples were filtered/assigned to boards. This is a effort to try to use a more consistent approach using a example class and Iboard to tell wether they are "compatible" Is there a free reverse engineering uml java tool?
1 parent 259e46d commit 9febb54

7 files changed

+300
-191
lines changed

io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest.java

+46-54
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.eclipse.core.runtime.CoreException;
1414
import org.eclipse.core.runtime.IPath;
1515
import org.eclipse.core.runtime.NullProgressMonitor;
16-
import org.eclipse.core.runtime.Path;
1716
import org.junit.Test;
1817
import org.junit.runner.RunWith;
1918
import org.junit.runners.Parameterized;
@@ -33,69 +32,62 @@ public class CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest {
3332
private static int mCounter = 0;
3433
private CodeDescriptor myCodeDescriptor;
3534
private String myName;
36-
private boolean myUsesSerial1;
37-
private boolean myUsesKeyboard;
38-
private boolean myUsesSerial;
35+
private Example myExample;
3936
private static int totalFails = 0;
37+
private static int maxFails = 500;
4038

4139
public CreateAndCompileArduinoIDEExamplesOnAVRHardwareTest(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;
40+
Example example) {
4941

42+
myCodeDescriptor = codeDescriptor;
43+
myName = name;
44+
myExample = example;
5045
}
5146

5247
@SuppressWarnings("rawtypes")
5348
@Parameters(name = "{index}: {0}")
5449
public static Collection examples() {
55-
56-
5750
Shared.waitForAllJobsToFinish();
58-
5951
LinkedList<Object[]> examples = new LinkedList<>();
52+
6053
TreeMap<String, IPath> exampleFolders = LibraryManager.getAllArduinoIDEExamples();
6154
for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
62-
ArrayList<Path> paths = new ArrayList<>();
63-
64-
paths.add(new Path(curexample.getValue().toString()));
65-
CodeDescriptor codeDescriptor = CodeDescriptor.createExample(false, paths);
6655
String inoName = curexample.getKey().trim();
67-
Boolean usesSerial = new Boolean(Examples.getUsesSerialExamples().contains(inoName));
68-
Boolean usesSerial1 = new Boolean(Examples.getUsesSerial1Examples().contains(inoName));
69-
Boolean usesKeyboard = new Boolean(Examples.getUsesKeyboardExamples().contains(inoName));
56+
IPath examplePath = curexample.getValue();
57+
Example example = new Example(inoName, null, examplePath);
58+
if (!skipExample(example)){
59+
ArrayList<IPath> paths = new ArrayList<>();
7060

71-
Object[] theData = new Object[] { "Example:" + inoName, codeDescriptor, usesSerial, usesSerial1,
72-
usesKeyboard };
73-
examples.add(theData);
61+
paths.add(examplePath);
62+
CodeDescriptor codeDescriptor = CodeDescriptor.createExample(false, paths);
63+
64+
Object[] theData = new Object[] { "Example:" + inoName, codeDescriptor, example };
65+
examples.add(theData);
66+
}
7467
}
7568

7669
return examples;
7770

7871
}
79-
72+
73+
private static boolean skipExample(Example example) {
74+
// skip Teensy stuff on Arduino hardware
75+
// Teensy is so mutch more advanced that most arduino avr hardware can not
76+
// handle
77+
// it
78+
return example.getPath().toString().contains("Teensy");
79+
}
8080
public void testExample(IBoard board) {
8181
// Stop after X fails because
8282
// the fails stays open in eclipse and it becomes really slow
8383
// There are only a number of issues you can handle
8484
// best is to focus on the first ones and then rerun starting with the
8585
// failures
86-
if (this.myUsesSerial && !board.supportsSerial()) {
87-
System.out.println("!TEST SKIPPED due to Serial " + this.myName + " " + board.getName());
88-
return;
89-
}
90-
if (this.myUsesSerial1 && !board.supportsSerial1()) {
91-
System.out.println("!TEST SKIPPED due to Serial1 " + this.myName + " " + board.getName());
86+
if (!board.isExampleSupported(myExample)) {
9287
return;
9388
}
94-
if (this.myUsesKeyboard && !board.supportsKeyboard()) {
95-
System.out.println("!TEST SKIPPED due to keyboard " + this.myName + " " + board.getName());
96-
return;
97-
}
98-
if (totalFails < 40) {
89+
90+
if (totalFails < maxFails) {
9991
BuildAndVerify(board.getBoardDescriptor());
10092
} else {
10193
fail("To many fails. Stopping test");
@@ -125,7 +117,7 @@ public void testArduinoIDEExamplesOnYun() {
125117

126118
@Test
127119
public void testArduinoIDEExamplesOnDiecimila() {
128-
testExample( ArduinoBoards.getAvrBoard("diecimila"));
120+
testExample(ArduinoBoards.getAvrBoard("diecimila"));
129121
}
130122

131123
@Test
@@ -142,71 +134,71 @@ public void testArduinoIDEExamplesOneMegaADK() {
142134
@Test
143135
public void testArduinoIDEExamplesOnLeonardoEth() {
144136

145-
testExample( ArduinoBoards.getAvrBoard("leonardoeth"));
137+
testExample(ArduinoBoards.getAvrBoard("leonardoeth"));
146138

147139
}
148140

149141
@Test
150142
public void testArduinoIDEExamplesOneMicro() {
151143

152-
testExample( ArduinoBoards.getAvrBoard("micro"));
144+
testExample(ArduinoBoards.getAvrBoard("micro"));
153145

154146
}
155147

156148
@Test
157149
public void testArduinoIDEExamplesOneMini() {
158-
testExample( ArduinoBoards.getAvrBoard("mini"));
150+
testExample(ArduinoBoards.getAvrBoard("mini"));
159151

160152
}
161153

162154
@Test
163155
public void testArduinoIDEExamplesOnEthernet() {
164-
testExample( ArduinoBoards.getAvrBoard("ethernet"));
156+
testExample(ArduinoBoards.getAvrBoard("ethernet"));
165157
}
166158

167159
@Test
168160
public void testArduinoIDEExamplesOnFio() {
169-
testExample( ArduinoBoards.getAvrBoard("fio"));
161+
testExample(ArduinoBoards.getAvrBoard("fio"));
170162
}
171163

172164
@Test
173165
public void testArduinoIDEExamplesOnBt() {
174-
testExample( ArduinoBoards.getAvrBoard("bt"));
166+
testExample(ArduinoBoards.getAvrBoard("bt"));
175167
}
176168

177169
@Test
178170
public void testArduinoIDEExamplesOnLilyPadUSB() {
179-
testExample( ArduinoBoards.getAvrBoard("LilyPadUSB"));
171+
testExample(ArduinoBoards.getAvrBoard("LilyPadUSB"));
180172
}
181173

182174
@Test
183175
public void testArduinoIDEExamplesOnlilypad() {
184-
testExample( ArduinoBoards.getAvrBoard("lilypad"));
176+
testExample(ArduinoBoards.getAvrBoard("lilypad"));
185177
}
186178

187179
@Test
188180
public void testArduinoIDEExamplesOnPro() {
189-
testExample( ArduinoBoards.getAvrBoard("pro"));
181+
testExample(ArduinoBoards.getAvrBoard("pro"));
190182
}
191183

192184
@Test
193185
public void testArduinoIDEExamplesOnatmegang() {
194-
testExample( ArduinoBoards.getAvrBoard("atmegang"));
186+
testExample(ArduinoBoards.getAvrBoard("atmegang"));
195187
}
196188

197189
@Test
198190
public void testArduinoIDEExamplesOnrobotControl() {
199-
testExample( ArduinoBoards.getAvrBoard("robotControl"));
191+
testExample(ArduinoBoards.getAvrBoard("robotControl"));
200192
}
201193

202194
@Test
203195
public void testArduinoIDEExamplesOnrobotMotor() {
204-
testExample( ArduinoBoards.getAvrBoard("robotMotor"));
196+
testExample(ArduinoBoards.getAvrBoard("robotMotor"));
205197
}
206198

207199
@Test
208200
public void testArduinoIDEExamplesOngemma() {
209-
testExample( ArduinoBoards.getAvrBoard("gemma"));
201+
testExample(ArduinoBoards.getAvrBoard("gemma"));
210202
}
211203

212204
@Test
@@ -216,23 +208,23 @@ public void testArduinoIDEExamplesOncircuitplay32u4cat() {
216208

217209
@Test
218210
public void testArduinoIDEExamplesOnyunmini() {
219-
testExample( ArduinoBoards.getAvrBoard("yunmini"));
211+
testExample(ArduinoBoards.getAvrBoard("yunmini"));
220212

221213
}
222214

223215
@Test
224216
public void testArduinoIDEExamplesOnchiwawa() {
225-
testExample( ArduinoBoards.getAvrBoard("chiwawa"));
217+
testExample(ArduinoBoards.getAvrBoard("chiwawa"));
226218
}
227219

228220
@Test
229221
public void testArduinoIDEExamplesOnone() {
230-
testExample( ArduinoBoards.getAvrBoard("one"));
222+
testExample(ArduinoBoards.getAvrBoard("one"));
231223
}
232224

233225
@Test
234226
public void testArduinoIDEExamplesOnunowifi() {
235-
testExample( ArduinoBoards.getAvrBoard("unowifi"));
227+
testExample(ArduinoBoards.getAvrBoard("unowifi"));
236228
}
237229

238230
public void BuildAndVerify(BoardDescriptor boardDescriptor) {

io.sloeber.tests/src/io/sloeber/core/CreateAndCompileArduinoIDEExamplesOnTeensyTest.java

+34-48
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.eclipse.core.runtime.CoreException;
1414
import org.eclipse.core.runtime.IPath;
1515
import org.eclipse.core.runtime.NullProgressMonitor;
16-
import org.eclipse.core.runtime.Path;
1716
import org.junit.Test;
1817
import org.junit.runner.RunWith;
1918
import org.junit.runners.Parameterized;
@@ -34,76 +33,64 @@ public class CreateAndCompileArduinoIDEExamplesOnTeensyTest {
3433
private static int mCounter = 0;
3534
private CodeDescriptor myCodeDescriptor;
3635
private String myName;
37-
private boolean myUsesSerial1;
38-
private boolean myUsesKeyboard;
39-
private boolean myUsesSerial;
36+
private Example myExample;
4037
private static int totalFails = 0;
38+
private static int maxFails = 500;
4139

42-
public CreateAndCompileArduinoIDEExamplesOnTeensyTest(String name, CodeDescriptor codeDescriptor,
43-
boolean usesSerial, boolean usesSerial1, boolean usesKeyboard) {
44-
45-
this.myCodeDescriptor = codeDescriptor;
46-
this.myName = name;
47-
this.myUsesSerial = usesSerial;
48-
this.myUsesSerial1 = usesSerial1;
49-
this.myUsesKeyboard = usesKeyboard;
40+
public CreateAndCompileArduinoIDEExamplesOnTeensyTest(String name, CodeDescriptor codeDescriptor, Example example) {
5041

42+
myCodeDescriptor = codeDescriptor;
43+
myName = name;
44+
myExample = example;
5145
}
5246

5347
@SuppressWarnings("rawtypes")
5448
@Parameters(name = "{index}: {0}")
5549
public static Collection examples() {
56-
LinkedList<Object[]> examples = new LinkedList<>();
57-
if(MySystem.getTeensyPlatform().isEmpty()) {
50+
if (MySystem.getTeensyPlatform().isEmpty()) {
5851
System.err.println("ERROR: Teensy not installed/configured skipping tests!!!");
59-
}
60-
else {
52+
} else {
6153
PackageManager.addPrivateHardwarePath(MySystem.getTeensyPlatform());
6254
}
6355

64-
6556
Shared.waitForAllJobsToFinish();
66-
57+
LinkedList<Object[]> examples = new LinkedList<>();
6758

6859
TreeMap<String, IPath> exampleFolders = LibraryManager.getAllArduinoIDEExamples();
6960
for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) {
70-
ArrayList<Path> paths = new ArrayList<>();
71-
72-
paths.add(new Path(curexample.getValue().toString()));
73-
CodeDescriptor codeDescriptor = CodeDescriptor.createExample(false, paths);
7461
String inoName = curexample.getKey().trim();
75-
Boolean usesSerial = new Boolean(Examples.getUsesSerialExamples().contains(inoName));
76-
Boolean usesSerial1 = new Boolean(Examples.getUsesSerial1Examples().contains(inoName));
77-
Boolean usesKeyboard = new Boolean(Examples.getUsesKeyboardExamples().contains(inoName));
78-
79-
Object[] theData = new Object[] { "Example:" + inoName, codeDescriptor, usesSerial, usesSerial1,
80-
usesKeyboard };
81-
examples.add(theData);
62+
IPath examplePath = curexample.getValue();
63+
Example example = new Example(inoName, null, examplePath);
64+
if (!skipExample(example)) {
65+
ArrayList<IPath> paths = new ArrayList<>();
66+
paths.add(examplePath);
67+
CodeDescriptor codeDescriptor = CodeDescriptor.createExample(false, paths);
68+
69+
Object[] theData = new Object[] { "Example:" + inoName, codeDescriptor, example };
70+
examples.add(theData);
71+
}
8272
}
8373

8474
return examples;
8575

8676
}
8777

78+
private static boolean skipExample(Example example) {
79+
// no need to skip examples in this test
80+
return false;
81+
}
82+
8883
public void testExample(IBoard board) {
8984
// Stop after X fails because
9085
// the fails stays open in eclipse and it becomes really slow
9186
// There are only a number of issues you can handle
9287
// best is to focus on the first ones and then rerun starting with the
9388
// failures
94-
if (this.myUsesSerial && !board.supportsSerial()) {
95-
System.out.println("!TEST SKIPPED due to Serial " + this.myName + " " + board.getName());
96-
return;
97-
}
98-
if (this.myUsesSerial1 && !board.supportsSerial1()) {
99-
System.out.println("!TEST SKIPPED due to Serial1 " + this.myName + " " + board.getName());
89+
if (!board.isExampleSupported(myExample)) {
10090
return;
10191
}
102-
if (this.myUsesKeyboard && !board.supportsKeyboard()) {
103-
System.out.println("!TEST SKIPPED due to keyboard " + this.myName + " " + board.getName());
104-
return;
105-
}
106-
if (totalFails < 40) {
92+
93+
if (totalFails < maxFails) {
10794
BuildAndVerify(board.getBoardDescriptor());
10895
} else {
10996
fail("To many fails. Stopping test");
@@ -114,47 +101,46 @@ public void testExample(IBoard board) {
114101
@Test
115102
public void testArduinoIDEExamplesOnTeensy3_6() {
116103
if (!MySystem.getTeensyPlatform().isEmpty())
117-
testExample( TeensyBoards.Teensy3_6());
104+
testExample(TeensyBoards.Teensy3_6());
118105
}
119106

120107
@Test
121108
public void testArduinoIDEExamplesOnTeensy3_5() {
122109
if (!MySystem.getTeensyPlatform().isEmpty())
123-
testExample( TeensyBoards.Teensy3_5());
110+
testExample(TeensyBoards.Teensy3_5());
124111
}
125112

126113
@Test
127114
public void testArduinoIDEExamplesOnTeensy3_1() {
128115
if (!MySystem.getTeensyPlatform().isEmpty())
129-
testExample( TeensyBoards.Teensy3_1());
116+
testExample(TeensyBoards.Teensy3_1());
130117
}
131118

132119
@Test
133120
public void testArduinoIDEExamplesOnTeensy3_0() {
134121
if (!MySystem.getTeensyPlatform().isEmpty())
135-
testExample( TeensyBoards.Teensy3_0());
122+
testExample(TeensyBoards.Teensy3_0());
136123
}
137124

138125
@Test
139126
public void testArduinoIDEExamplesOnTeensyLC() {
140127
if (!MySystem.getTeensyPlatform().isEmpty())
141-
testExample(TeensyBoards.Teensy_LC());
128+
testExample(TeensyBoards.Teensy_LC());
142129
}
143130

144131
@Test
145132
public void testArduinoIDEExamplesOnTeensyPP2() {
146133
if (!MySystem.getTeensyPlatform().isEmpty())
147-
testExample( TeensyBoards.teensypp2());
134+
testExample(TeensyBoards.teensypp2());
148135
}
149136

150137
@Test
151138
public void testArduinoIDEExamplesOnTeensy2() {
152139
if (!MySystem.getTeensyPlatform().isEmpty())
153-
testExample( TeensyBoards.teensy2());
140+
testExample(TeensyBoards.teensy2());
154141

155142
}
156143

157-
158144
public void BuildAndVerify(BoardDescriptor boardDescriptor) {
159145

160146
IProject theTestProject = null;

0 commit comments

Comments
 (0)