Skip to content

Commit 73dbfc4

Browse files
author
jantje
committed
Add unit test for upload
1 parent 25aa1cf commit 73dbfc4

File tree

5 files changed

+193
-4
lines changed

5 files changed

+193
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package jUnit;
2+
3+
import static org.junit.Assert.fail;
4+
5+
import java.util.Arrays;
6+
import java.util.Collection;
7+
import java.util.HashSet;
8+
import java.util.LinkedList;
9+
10+
import org.eclipse.core.resources.IProject;
11+
import org.eclipse.core.resources.IncrementalProjectBuilder;
12+
import org.eclipse.core.runtime.CoreException;
13+
import org.eclipse.core.runtime.IPath;
14+
import org.eclipse.core.runtime.NullProgressMonitor;
15+
import org.junit.Test;
16+
import org.junit.runner.RunWith;
17+
import org.junit.runners.Parameterized;
18+
import org.junit.runners.Parameterized.Parameters;
19+
20+
import io.sloeber.core.api.BoardsManager;
21+
import io.sloeber.core.api.CodeDescriptor;
22+
import io.sloeber.core.api.CompileOptions;
23+
import io.sloeber.core.api.ConfigurationDescriptor;
24+
import io.sloeber.core.api.Sketch;
25+
import jUnit.boards.Due;
26+
import jUnit.boards.IBoard;
27+
import jUnit.boards.NodeMCUBoard;
28+
import jUnit.boards.UnoBoard;
29+
import jUnit.boards.Zero;
30+
import jUnit.boards.megaBoard;
31+
32+
@SuppressWarnings("nls")
33+
@RunWith(Parameterized.class)
34+
public class CompileAndUpload {
35+
private static final boolean reinstall_boards_and_libraries = false;
36+
private static int mCounter = 0;
37+
private IBoard myBoard;
38+
private String myName;
39+
40+
public CompileAndUpload(String name, IBoard board) {
41+
this.myBoard = board;
42+
this.myName = name;
43+
44+
}
45+
46+
@SuppressWarnings("rawtypes")
47+
@Parameters(name = "{index}: {0}")
48+
public static Collection examples() {
49+
WaitForInstallerToFinish();
50+
51+
IBoard unoBoard = new UnoBoard();
52+
IBoard nodeMCUBoard = new NodeMCUBoard();
53+
IBoard megaBoard = new megaBoard();
54+
IBoard zeroBoard = new Zero();
55+
IBoard dueBoard = new Due();
56+
LinkedList<Object[]> examples = new LinkedList<>();
57+
58+
examples.add(new Object[] { "uno", unoBoard });
59+
examples.add(new Object[] { "mega", megaBoard });
60+
examples.add(new Object[] { "zero", zeroBoard });
61+
examples.add(new Object[] { "due", dueBoard });
62+
63+
return examples;
64+
// new leonardoBoard(), new EsploraBoard(), new AdafruitnRF52idBoard(),
65+
// new AdafruitnCirquitPlaygroundBoard(), new Primo(),
66+
}
67+
68+
/*
69+
* In new new installations (of the Sloeber development environment) the
70+
* installer job will trigger downloads These mmust have finished before we
71+
* can start testing
72+
*/
73+
74+
public static void WaitForInstallerToFinish() {
75+
76+
installAdditionalBoards();
77+
78+
Shared.waitForAllJobsToFinish();
79+
}
80+
81+
public static void installAdditionalBoards() {
82+
String[] packageUrlsToAdd = { "http://arduino.esp8266.com/stable/package_esp8266com_index.json",
83+
"https://raw.githubusercontent.com/stm32duino/BoardManagerFiles/master/STM32/package_stm_index.json" };
84+
BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true);
85+
if (reinstall_boards_and_libraries) {
86+
BoardsManager.installAllLatestPlatforms();
87+
}
88+
89+
}
90+
91+
@Test
92+
public void testExamples() {
93+
IPath templateFolder = Shared.getTemplateFolder("fastBlink");
94+
Build_Verify_upload(CodeDescriptor.createCustomTemplate(templateFolder));
95+
96+
}
97+
98+
public void Build_Verify_upload(CodeDescriptor codeDescriptor) {
99+
100+
IProject theTestProject = null;
101+
102+
NullProgressMonitor monitor = new NullProgressMonitor();
103+
String projectName = String.format("%05d_%s", new Integer(mCounter++), this.myName);
104+
try {
105+
106+
theTestProject = this.myBoard.getBoardDescriptor().createProject(projectName, null,
107+
ConfigurationDescriptor.getDefaultDescriptors(), codeDescriptor, new CompileOptions(null), monitor);
108+
Shared.waitForAllJobsToFinish(); // for the indexer
109+
} catch (Exception e) {
110+
e.printStackTrace();
111+
fail("Failed to create the project:" + projectName);
112+
return;
113+
}
114+
try {
115+
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
116+
if (Shared.hasBuildErrors(theTestProject)) {
117+
// try again because the libraries may not yet been added
118+
Shared.waitForAllJobsToFinish(); // for the indexer
119+
try {
120+
Thread.sleep(3000);// seen sometimes the libs were still not
121+
// added
122+
} catch (InterruptedException e) {
123+
// ignore
124+
}
125+
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
126+
if (Shared.hasBuildErrors(theTestProject)) {
127+
// give up
128+
fail("Failed to compile the project:" + projectName + " build errors");
129+
}
130+
}
131+
132+
} catch (CoreException e) {
133+
e.printStackTrace();
134+
fail("Failed to compile the project:" + projectName + " exception");
135+
}
136+
Sketch.upload(theTestProject);
137+
}
138+
}

io.sloeber.core/src/jUnit/boards/IBoard.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ private void createDoNotTestTheseSketches() {
6868
"BLEPeripheral examples?temp_sensor", "Brasilino examples? Basicos?controleGradual",
6969
"ClosedCube_HDC1010 examples?hdc1010demo", "Chrono examples?Resolutions", "Chrono examples?StopResume",
7070
"ConfigurableFirmata examples?ConfigurableFirmataWiFi", "ControleForno examples?configuravel",
71-
"CopyThreads examples?c" });
71+
"CopyThreads examples?c", "ArduinoCloud examples?SimpleCloudButtonYun", "Brzo_I2Cexamples",
72+
"CopyThreads examples?ExamplesFromReadme", "DallasTemperature examples?Multibus_simple",
73+
"DecodeIR examples?InfraredDecode" });
7274
runSketchOnBoard.put("fix case Sensitive include first",
7375
new String[] { "AutoAnalogAudio examples? SDAudio?SdAudioRecording",
7476
"AutoAnalogAudio examples? SDAudio?SdAudioWavPlayer",
@@ -123,10 +125,12 @@ private void createDoNotTestTheseLibs() {
123125
"Adafruit_SSD1325", "ArdBitmap", "ArdOSC", "Arduino-Websocket-Fast", "ArduinoFacil",
124126
"ArduinoMenu_library", "ArduinoSensors", "ArduinoSerialToTCPBridgeClient", "ArduinoUnit", "arduinoVNC",
125127
"ArduZ80", "AS3935", "AzureIoTHubMQTTClient", "BigCrystal", "Babelduino", "Blynk", "Brief", "Brzo_I2C",
126-
"BTLE", "Cayenne", "CayenneMQTT", "Chronos", "CoAP_simple_library", "Comp6DOF_n0m1", "Constellation" });
128+
"BTLE", "Cayenne", "CayenneMQTT", "Chronos", "CoAP_simple_library", "Comp6DOF_n0m1", "Constellation",
129+
"CRC_Simula_Library", "Cytron_3A_Motor_Driver_Shield", "dcf77_xtal examples?DCF77_Scope" });
127130
runLibOnBoard.put("uno",
128131
new String[] { "A4963", "Adafruit_Motor_Shield_library", "Adafruit_Motor_Shield_library_V2",
129-
"AccelStepper", "Arduino_Uno_WiFi_Dev_Ed_Library", "ardyno", "AVR_Standard_C_Time_Library" });
132+
"AccelStepper", "Arduino_Uno_WiFi_Dev_Ed_Library", "ardyno", "AVR_Standard_C_Time_Library",
133+
"DCF77 examples?DCFBinaryStream", "DDS examples?SimpleSin" });
130134
runLibOnBoard.put("esplora", new String[] { "Esplora" });
131135
runLibOnBoard.put("circuitplay32u4cat",
132136
new String[] { "Adafruit_Circuit_Playground", "Adafruit_BluefruitLE_nRF51", "Adafruit_GPS_Library" });

io.sloeber.core/src/jUnit/boards/Zero.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ public String getName() {
99

1010
public Zero() {
1111
super("arduino_zero_edbg");
12-
this.myBoardDescriptor.setUploadPort("COM9");
12+
this.myBoardDescriptor.setUploadPort("COM14");
1313
}
1414
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package jUnit.boards;
22

3+
import java.util.Map;
4+
import java.util.TreeMap;
5+
36
@SuppressWarnings("nls")
47
public class megaBoard extends GenericArduinoAvrBoard {
58
public megaBoard() {
69
super("mega");
710
this.myBoardDescriptor.setUploadPort("COM11");
11+
12+
Map<String, String> options = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
13+
options.put("cpu", "atmega2560");
14+
this.myBoardDescriptor.setOptions(options);
815
}
916

1017
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "Arduino.h"
2+
#ifndef LED_BUILTIN
3+
#define LED_BUILTIN 13
4+
#endif
5+
#ifndef INTERVAL
6+
#define INTERVAL 100
7+
#endif
8+
const int ledPin = LED_BUILTIN; // the number of the LED pin
9+
10+
// Variables will change :
11+
int ledState = LOW; // ledState used to set the LED
12+
13+
// Generally, you should use "unsigned long" for variables that hold time
14+
// The value will quickly become too large for an int to store
15+
unsigned long previousMillis = 0; // will store last time LED was updated
16+
17+
// constants won't change :
18+
const long interval = INTERVAL; // interval at which to blink (milliseconds)
19+
20+
void setup() {
21+
// set the digital pin as output:
22+
pinMode(ledPin, OUTPUT);
23+
}
24+
25+
void loop() {
26+
27+
unsigned long currentMillis = millis();
28+
29+
if (currentMillis - previousMillis >= interval) {
30+
// save the last time you blinked the LED
31+
previousMillis = currentMillis;
32+
33+
// if the LED is off turn it on and vice-versa:
34+
ledState = !ledState;
35+
36+
// set the LED with the ledState of the variable:
37+
digitalWrite(ledPin, ledState);
38+
}
39+
}
40+

0 commit comments

Comments
 (0)