Skip to content

Commit 7596d43

Browse files
author
jantje
committed
Modded library testing to use library properties to find the board
1 parent e2578e2 commit 7596d43

11 files changed

+351
-292
lines changed

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

+35-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.sloeber.core;
22

3+
import java.util.HashSet;
4+
import java.util.Set;
5+
36
public class BoardAttributes {
47
public boolean serial = false;
58
public boolean serial1 = false;
@@ -27,18 +30,12 @@ public class BoardAttributes {
2730
* Only a very rare selection of boards supports input_pulldown as pin mode
2831
*/
2932
public boolean inputPullDown = false;
30-
public boolean teensy = false;// Teensy specific hardware or software
3133
/*
3234
* No board is out of the box compatible with code that needs a change
3335
*/
3436
public boolean worksOutOfTheBox = true;
35-
/*
36-
* Composite video output from M0 microcontrollers: Circuit Playground Express
37-
* (not 'classic'), Feather M0, Arduino Zero
38-
*/
39-
public boolean mo_mcu = false;
40-
public boolean esp8266_mcu = false;
41-
public String boardName = null;
37+
public String boardID = null;
38+
public final Set<String> myArchitectures = new HashSet<>(); //Bit wierd to have multiple architectures I know
4239

4340
public boolean compatibleWithExampleRequirements(BoardAttributes example) {
4441
boolean ret = worksOutOfTheBox;
@@ -52,24 +49,38 @@ public boolean compatibleWithExampleRequirements(BoardAttributes example) {
5249
ret = ret && matches(example.midi, midi);
5350
ret = ret && matches(example.mouse, mouse);
5451
ret = ret && matches(example.wire1, wire1);
55-
ret = ret && matches(example.teensy, teensy);
52+
// ret = ret && matches(example.teensy, teensy);
5653
ret = ret && matches(example.inputPullDown, inputPullDown);
57-
ret = ret && matches(example.mo_mcu, mo_mcu);
58-
ret = ret && matches(example.esp8266_mcu, esp8266_mcu);
54+
// ret = ret && matches(example.mo_mcu, mo_mcu);
55+
// ret = ret && matches(example.esp8266_mcu, esp8266_mcu);
5956
ret = ret && matches(example.buildInLed, buildInLed);
6057
ret = ret && matches(example.tone, tone);
6158
ret = ret && matches(example.directMode, directMode);
6259

60+
ret = ret && matches(example.myArchitectures, myArchitectures);
61+
6362
ret = ret && example.myNumAD <= myNumAD;
6463

65-
if (example.boardName != null) {
66-
ret = ret && example.boardName.equals(boardName);
64+
if (example.boardID != null) {
65+
ret = ret && example.boardID.equals(boardID);
6766
}
6867

6968
return ret;
7069

7170
}
7271

72+
private static boolean matches(Set<String> example_Archs, Set<String> board_archs) {
73+
if (example_Archs.size() == 0) {
74+
//no requirements for example
75+
return true;
76+
}
77+
Set<String> result = new HashSet<>(example_Archs);
78+
79+
result.retainAll(board_archs);
80+
81+
return result.size() > 0;
82+
}
83+
7384
private static boolean matches(boolean needs, boolean has) {
7485
if (!needs)
7586
return true;
@@ -82,6 +93,8 @@ private static boolean matches(boolean needs, boolean has) {
8293
*/
8394
public BoardAttributes or(BoardAttributes or) {
8495
BoardAttributes ret = new BoardAttributes();
96+
ret.myArchitectures.addAll(myArchitectures);
97+
ret.myArchitectures.addAll(or.myArchitectures);
8598
// fields that need a binary and
8699
ret.worksOutOfTheBox = worksOutOfTheBox && or.worksOutOfTheBox;
87100
ret.buildInLed = buildInLed && or.buildInLed;
@@ -99,19 +112,19 @@ public BoardAttributes or(BoardAttributes or) {
99112
ret.mouse = mouse || or.mouse;
100113
ret.wire1 = wire1 || or.wire1;
101114
ret.inputPullDown = inputPullDown || or.inputPullDown;
102-
ret.teensy = teensy || or.teensy;
103-
ret.mo_mcu = mo_mcu || or.mo_mcu;
104-
ret.esp8266_mcu = esp8266_mcu || or.esp8266_mcu;
115+
// ret.teensy = teensy || or.teensy;
116+
// ret.mo_mcu = mo_mcu || or.mo_mcu;
117+
// ret.esp8266_mcu = esp8266_mcu || or.esp8266_mcu;
105118

106119
// other special fields
107-
if (boardName == null) {
108-
ret.boardName = or.boardName;
120+
if (boardID == null) {
121+
ret.boardID = or.boardID;
109122
} else {
110-
if (or.boardName == null) {
111-
ret.boardName = boardName;
123+
if (or.boardID == null) {
124+
ret.boardID = boardID;
112125
} else {
113-
if (or.boardName.equals(boardName)) {
114-
ret.boardName = boardName;
126+
if (or.boardID.equals(boardID)) {
127+
ret.boardID = boardID;
115128
} else {
116129
ret.worksOutOfTheBox = false;
117130
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static Collection examples() {
5555
Shared.waitForAllJobsToFinish();
5656
installMyStuff();
5757

58-
MCUBoard myBoards[] = { Arduino.leonardo(), Arduino.uno(), Arduino.esplora(), Adafruit.feather(),
58+
MCUBoard myBoards[] = { Arduino.uno(), Arduino.leonardo(), Arduino.esplora(), Adafruit.feather(),
5959
Adafruit.featherMO(), Arduino.adafruitnCirquitPlayground(), ESP8266.nodeMCU(), ESP8266.wemosD1(),
6060
ESP8266.ESPressoLite(), Teensy.Teensy3_6(), Arduino.zeroProgrammingPort(),
6161
Arduino.cirquitPlaygroundExpress(), Arduino.gemma(), Adafruit.trinket8MH(), Arduino.yun(),

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

+83-76
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,20 @@ public Example(String fqn, IPath path) {
3939
myRequiredBoardAttributes.tone = examplesUsingTone().contains(myFQN);
4040
myRequiredBoardAttributes.wire1 = examplesUsingWire1().contains(myFQN);
4141
myRequiredBoardAttributes.midi = examplesUsingMidi().contains(myFQN) || myFQN.contains("USB_MIDI");
42-
myRequiredBoardAttributes.teensy = myFQN.startsWith("Example/Teensy");
42+
// myRequiredBoardAttributes.teensy = myFQN.startsWith("Example/Teensy");
4343
myRequiredBoardAttributes.worksOutOfTheBox = !failingExamples().contains(myFQN);
44-
myRequiredBoardAttributes.boardName = getRequiredBoardID(myFQN);
45-
myRequiredBoardAttributes.mo_mcu = examplesUsingMCUmo().contains(fqn);
44+
myRequiredBoardAttributes.boardID = getRequiredBoardID(myFQN);
45+
// myRequiredBoardAttributes.mo_mcu = examplesUsingMCUmo().contains(fqn);
4646
myRequiredBoardAttributes.rawHID = myFQN.contains("USB_RawHID");
4747
myRequiredBoardAttributes.buildInLed = myFQN.contains("Blink");
4848
myRequiredBoardAttributes.myNumAD = getNumADCUsedInExample(myFQN);
4949
myRequiredBoardAttributes.directMode = examplesUsingDirectMode().contains(myFQN);
5050

51-
myRequiredBoardAttributes = myRequiredBoardAttributes.or(Libraries.getRequiredBoardAttributes(getLibName()));
51+
myRequiredBoardAttributes = myRequiredBoardAttributes.or(Libraries.getRequiredBoardAttributes(getLibFolder()));
52+
}
53+
54+
private IPath getLibFolder() {//Need to remove the examples folder and the example folder
55+
return myPath.removeLastSegments(2);
5256
}
5357

5458
private static int getNumADCUsedInExample(String myFQN2) {
@@ -237,12 +241,6 @@ private static LinkedList<String> examplesUsingWire1() {
237241
return ret;
238242
}
239243

240-
private static LinkedList<String> examplesUsingMCUmo() {
241-
LinkedList<String> ret = new LinkedList<>();
242-
ret.add("Library/Adafruit_Circuit_Playground/CircuitPlaygroundFirmata_Express_CodeOrg");
243-
return ret;
244-
}
245-
246244
/*
247245
* These examples that are known to fail
248246
*/
@@ -258,8 +256,8 @@ private static LinkedList<String> failingExamples() {
258256
// These examples are the processing part and are not a deal of sloeber
259257
ret.add("Library/Adafruit_BNO055/bunny/processing/cuberotate");
260258
// manual action is needed for following examples
259+
ret.add("Library/AbsoluteMouse/DevKit");
261260
ret.add("Library/Accessories/CANCommander");
262-
ret.add("Library/Accessories_CANCommander");
263261
ret.add("Library/Accessories/Demo");
264262
ret.add("Library/Accessories/Full");
265263
ret.add("Library/Accessories/Group");
@@ -428,6 +426,8 @@ private static LinkedList<String> failingExamples() {
428426
ret.add("Library/Blinker/Blinker_AUTO/AUTO_MQTT");
429427
// 3: error: 'StaticJsonBuffer' was not declared in this scope
430428
ret.add("Library/Boodskap_Message_library/SimpleMessageUsage");
429+
//uses #include <ArduinoDebug.hpp>
430+
ret.add("Library/107-Arduino-BoostUnits/Basic");
431431
return ret;
432432
}
433433

@@ -442,83 +442,90 @@ public static MCUBoard pickBestBoard(Example example, MCUBoard myBoards[]) {
442442
String libName = example.getLibName();
443443
String fqn = example.getFQN();
444444
if (myBoards.length == 0) {
445+
//No boards =>no match
446+
System.out.println("No boards to select from found for ");
447+
return null;
448+
}
449+
//examples using DHT_sensor_library libraries are not found as the include is
450+
// DHT.h
451+
if (!libName.equals("DHT_sensor_library") && fqn.contains("DHT")) {
452+
System.out.println("Ignore Lib as it is known to fail " + libName);
453+
return null;
454+
}
455+
if (!example.getRequiredBoardAttributes().worksOutOfTheBox) {
456+
System.out.println("Example is known to fail " + example.getFQN());
445457
return null;
446458
}
447459

448-
if (example.getRequiredBoardAttributes().worksOutOfTheBox) {
460+
// if example states which board it wants use that board
461+
if (example.getRequiredBoardAttributes().boardID != null) {
462+
String wantedBoardName = example.getRequiredBoardAttributes().boardID;
463+
for (MCUBoard curBoard : myBoards) {
464+
if (curBoard.getID().equals(wantedBoardName)) {
465+
return curBoard;
466+
}
467+
}
468+
System.out.println(
469+
"Example " + example.getFQN() + " requires board " + wantedBoardName + " that is not listed");
470+
return null;
471+
}
449472

450-
// if example states which board it wants use that board
451-
if (example.getRequiredBoardAttributes().boardName != null) {
452-
String wantedBoardName = example.getRequiredBoardAttributes().boardName;
453-
for (MCUBoard curBoard : myBoards) {
454-
if (curBoard.getID().equals(wantedBoardName)) {
473+
// if the boardname is in the libname or ino name pick this one
474+
for (MCUBoard curBoard : myBoards) {
475+
String curBoardName = curBoard.getName();
476+
List<String> curBoardExampleNames = getSlangNames(curBoardName);
477+
for (String curBoardExampleName : curBoardExampleNames) {
478+
if (libName.toLowerCase().contains(curBoardName) || fqn.toLowerCase().contains(curBoardExampleName)) {
479+
if (curBoard.isExampleSupported(example)) {
455480
return curBoard;
456481
}
457482
}
458-
} else {
459-
// examples using DHT_sensor_library libraries are not found as the include is
460-
// DHT.h
461-
if (!libName.equals("DHT_sensor_library") && fqn.contains("DHT")) {
462-
return null;
463-
}
464-
// if the boardname is in the libname or ino name pick this one
465-
for (MCUBoard curBoard : myBoards) {
466-
String curBoardName = curBoard.getName();
467-
List<String> curBoardExampleNames = getSlangNames(curBoardName);
468-
for (String curBoardExampleName : curBoardExampleNames) {
469-
if (libName.toLowerCase().contains(curBoardName)
470-
|| fqn.toLowerCase().contains(curBoardExampleName)) {
471-
if (curBoard.isExampleSupported(example)) {
472-
return curBoard;
473-
}
474-
}
475-
}
476-
}
477-
// If the architecture is in the libname or boardname pick this one
478-
for (MCUBoard curBoard : myBoards) {
479-
String curArchitectureName = curBoard.getBoardDescriptor().getArchitecture().toLowerCase();
480-
if (libName.toLowerCase().contains(curArchitectureName)
481-
|| fqn.toLowerCase().contains(curArchitectureName)) {
482-
if (curBoard.isExampleSupported(example)) {
483-
return curBoard;
484-
}
485-
}
486-
}
487-
// if the example name contains teensy try teensy board
488-
if (example.getFQN().toLowerCase().contains("teensy")) {
489-
for (MCUBoard curBoard : myBoards) {
490-
if (Teensy.class.isInstance(curBoard)) {
491-
return curBoard;
492-
}
493-
}
483+
}
484+
}
485+
// If the architecture is in the libname or boardname pick this one
486+
for (MCUBoard curBoard : myBoards) {
487+
String curArchitectureName = curBoard.getBoardDescriptor().getArchitecture().toLowerCase();
488+
if (libName.toLowerCase().contains(curArchitectureName)
489+
|| fqn.toLowerCase().contains(curArchitectureName)) {
490+
if (curBoard.isExampleSupported(example)) {
491+
return curBoard;
494492
}
495-
// if the example name contains ESP32 try ESP32 board
496-
if (example.getFQN().toLowerCase().contains("esp32")) {
497-
for (MCUBoard curBoard : myBoards) {
498-
if (ESP32.class.isInstance(curBoard)) {
499-
return curBoard;
500-
}
501-
}
493+
}
494+
}
495+
// if the example name contains teensy try teensy board
496+
if (example.getFQN().toLowerCase().contains("teensy")) {
497+
for (MCUBoard curBoard : myBoards) {
498+
if (Teensy.class.isInstance(curBoard)) {
499+
return curBoard;
502500
}
503-
// if the example name contains ESP try ESP8266 board
504-
// if (example.getFQN().toLowerCase().contains("esp")) {
505-
// for (MCUBoard curBoard : myBoards) {
506-
// if (ESP8266.class.isInstance(curBoard)) {
507-
// return curBoard;
508-
// }
509-
// }
510-
// }
511-
//causes issues with response
512-
513-
// Out of guesses based on the name. Take the first ok one
514-
for (MCUBoard curBoard : myBoards) {
515-
if (curBoard.isExampleSupported(example)) {
516-
return curBoard;
517-
}
501+
}
502+
}
503+
// if the example name contains ESP32 try ESP32 board
504+
if (example.getFQN().toLowerCase().contains("esp32")) {
505+
for (MCUBoard curBoard : myBoards) {
506+
if (ESP32.class.isInstance(curBoard)) {
507+
return curBoard;
518508
}
519509
}
520510
}
521-
System.out.println("No board found for " + Integer.toString(++noBoardFoundCount) + " " + example.getFQN());
511+
// if the example name contains ESP try ESP8266 board
512+
// if (example.getFQN().toLowerCase().contains("esp")) {
513+
// for (MCUBoard curBoard : myBoards) {
514+
// if (ESP8266.class.isInstance(curBoard)) {
515+
// return curBoard;
516+
// }
517+
// }
518+
// }
519+
//causes issues with response
520+
521+
// Out of guesses based on the name. Take the first ok one
522+
for (MCUBoard curBoard : myBoards) {
523+
if (curBoard.isExampleSupported(example)) {
524+
return curBoard;
525+
}
526+
}
527+
System.out.println(
528+
"No board found for " + Integer.toString(++noBoardFoundCount) + " " + example.getPath().toOSString());
522529
return null;
523530
}
524531

0 commit comments

Comments
 (0)