Skip to content

Commit 652efb4

Browse files
author
jantje
committed
Added unit test for #555
This meant I had to extend the API with a set to BoardDescription. I also created a junit class to share code between the full create and compile and the regression tests
1 parent 2d96def commit 652efb4

File tree

4 files changed

+166
-86
lines changed

4 files changed

+166
-86
lines changed

io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java

+28-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
import org.eclipse.core.runtime.CoreException;
3434
import org.eclipse.core.runtime.IPath;
3535
import org.eclipse.core.runtime.IProgressMonitor;
36+
import org.eclipse.core.runtime.IStatus;
3637
import org.eclipse.core.runtime.NullProgressMonitor;
3738
import org.eclipse.core.runtime.OperationCanceledException;
3839
import org.eclipse.core.runtime.Path;
40+
import org.eclipse.core.runtime.Status;
3941
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
4042
import org.eclipse.core.runtime.preferences.InstanceScope;
4143

@@ -51,7 +53,7 @@ public class BoardDescriptor {
5153
// preference nodes
5254
public static final String NODE_ARDUINO = Const.PLUGIN_START + "arduino"; //$NON-NLS-1$
5355
/**
54-
*
56+
*
5557
*/
5658

5759
private String myUploadPort;
@@ -77,7 +79,7 @@ public class BoardDescriptor {
7779
* does contain a create to create the project When confdesc is null the
7880
* data will be taken from the "last used " otherwise the data is taken from
7981
* the project the confdesc belongs to
80-
*
82+
*
8183
*/
8284
public static BoardDescriptor makeBoardDescriptor(ICConfigurationDescription confdesc) {
8385
return new InternalBoardDescriptor(confdesc);
@@ -132,6 +134,30 @@ protected BoardDescriptor(File boardsFile, String boardID, Map<String, String> o
132134
this.myTxtFile = new TxtFile(this.myBoardsFile);
133135
}
134136

137+
/**
138+
* tries to set the project to the boarddescriptor
139+
*
140+
* @param project
141+
* @param monitor
142+
* @return true if success false if failed
143+
*/
144+
public boolean configureProject(IProject project, IProgressMonitor monitor) {
145+
ICProjectDescription prjCDesc = CoreModel.getDefault().getProjectDescription(project);
146+
ICConfigurationDescription configurationDescription = prjCDesc.getActiveConfiguration();
147+
try {
148+
save(configurationDescription);
149+
prjCDesc.setActiveConfiguration(configurationDescription);
150+
CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(project, prjCDesc, true, null);
151+
} catch (Exception e) {
152+
// TODO Auto-generated catch block
153+
e.printStackTrace();
154+
Common.log(new Status(IStatus.ERROR, io.sloeber.core.Activator.getId(), "failed to save the board settings", //$NON-NLS-1$
155+
e));
156+
return false;
157+
}
158+
return true;
159+
}
160+
135161
/*
136162
* Method to create a project based on the board
137163
*/

io.sloeber.core/src/jUnit/CreateAndCompile.java

+36-61
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@
88
import java.util.HashSet;
99
import java.util.Map;
1010

11-
import org.eclipse.cdt.core.model.ICModelMarker;
12-
import org.eclipse.core.resources.IMarker;
1311
import org.eclipse.core.resources.IProject;
14-
import org.eclipse.core.resources.IResource;
1512
import org.eclipse.core.resources.IncrementalProjectBuilder;
1613
import org.eclipse.core.runtime.CoreException;
1714
import org.eclipse.core.runtime.NullProgressMonitor;
18-
import org.eclipse.core.runtime.jobs.IJobManager;
19-
import org.eclipse.core.runtime.jobs.Job;
2015
import org.junit.BeforeClass;
2116
import org.junit.Test;
2217
import org.junit.runner.RunWith;
@@ -36,8 +31,6 @@ public class CreateAndCompile {
3631
private String mPlatform;
3732
private String mJsonFileName;
3833
private static int mCounter = 0;
39-
private static String teensyInstall = "D:/arduino/arduino-1.6.9 - Teensy 1.29/hardware";
40-
private static String teensyBoards_txt = teensyInstall + "/teensy/avr/boards.txt";
4134

4235
public CreateAndCompile(String jsonFileName, String packageName, String platform, String boardID, String options) {
4336
this.mBoardID = boardID;
@@ -149,10 +142,16 @@ public static Collection boards() {
149142

150143
// arrow SAMD
151144
{ "package_index.json", "Arrow", "Arrow Boards", "SmartEverything_Fox_atmel_ice", "" }, //
152-
{ "package_index.json", "Arrow", "Arrow Boards", "SmartEverything_Fox_sam_ice", "" }, //
153145
{ "package_index.json", "Arrow", "Arrow Boards", "SmartEverything_Fox_native", "" }, //
146+
{ "package_index.json", "Arrow", "Arrow Boards", "SmartEverything_Fox3_atmel_ice", "" }, //
147+
{ "package_index.json", "Arrow", "Arrow Boards", "SmartEverything_Fox3_native", "" }, //
148+
{ "package_index.json", "Arrow", "Arrow Boards", "SmartEverything_Lion_atmel_ice", "" }, //
149+
{ "package_index.json", "Arrow", "Arrow Boards", "SmartEverything_Lion_native", "" }, //
150+
{ "package_index.json", "Arrow", "Arrow Boards", "SmartEverything_Dragonfly_atmel_ice", "" }, //
151+
{ "package_index.json", "Arrow", "Arrow Boards", "SmartEverything_Dragonfly_native", "" }, //
152+
{ "package_index.json", "Arrow", "Arrow Boards", "adi_atmel_ice", "" }, //
153+
{ "package_index.json", "Arrow", "Arrow Boards", "adi_native", "" }, //
154154
{ "package_index.json", "Arrow", "Arrow Boards", "NetTrotter_atmel_ice", "" }, //
155-
{ "package_index.json", "Arrow", "Arrow Boards", "NetTrotter_sam_ice", "" }, //
156155
{ "package_index.json", "Arrow", "Arrow Boards", "NetTrotter_native", "" }, //
157156

158157
// atmel-avr-xminis
@@ -164,32 +163,31 @@ public static Collection boards() {
164163

165164
// ATTinyCore
166165
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attinyx41",
167-
"chip=841\nclock=8internal\n=bod=disable)" }, //
166+
"chip=841\nclock=8internal\nbod=disable\nLTO=enable" }, //
168167
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attiny841opti",
169-
"clock=8internal\n=bod=1v8" }, //
168+
"clock=8internal\n=bod=1v8\nLTO=enable" }, //
170169
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attiny1634",
171-
"clock=8internal\n=bod=1v8" }, //
170+
"clock=8internal\n=bod=1v8\nLTO=enable" }, //
172171
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attiny1634opti",
173-
"clock=8internal\nbod=2v7" }, //
172+
"clock=8internal\nbod=2v7\nLTO=enable" }, //
174173
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attiny828",
175-
"clock=8internal\n=bod=2v7" }, //
176-
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attiny828opti", "bod=2v7\nvcc=3v3" }, //
174+
"clock=8internal\n=bod=2v7\nLTO=enable" }, //
175+
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attiny828opti",
176+
"bod=2v7\nvcc=3v3\nLTO=enable" }, //
177177
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attinyx5",
178-
"chip=85\nclock=20external\nbod=2v7\nTimerClockSource=default" }, //
178+
"chip=85\nclock=20external\nbod=2v7\nTimerClockSource=default\nLTO=enable" }, //
179179
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attinyx4",
180-
"chip=44\nclock=6external\nbod=2v7\npinmapping=new" }, //
180+
"chip=44\nclock=6external\nbod=2v7\npinmapping=new\nLTO=disable" }, //
181181
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attinyx61",
182-
"chip=261\nclock=1internal\nbod=2v7\nTimerClockSource=pll" }, //
183-
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attiny167opti",
184-
"clock=16external\nbod=2v7\npinmapping=new" }, //
185-
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attiny87opti",
186-
"clock=16external\nbod=2v7\npinmapping=new" }, //
182+
"chip=261\nclock=1internal\nbod=2v7\nTimerClockSource=pll\nLTO=enable" }, //
183+
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attinyx7opti",
184+
"clock=16external\nbod=2v7\npinmapping=new\nLTO=enable" }, //
187185
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attinyx7",
188-
"chip=87\nclock=12external\nbod=2v7\npinmapping=new" }, //
186+
"chip=87\nclock=12external\nbod=2v7\npinmapping=new\nLTO=enable" }, //
189187
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attinyx8",
190-
"chip=88\nclock=1internal\nbod=2v7" }, //
188+
"chip=88\nclock=1internal\nbod=2v7\nLTO=enable" }, //
191189
{ "package_drazzy.com_index.json", "ATTinyCore", "ATTinyCore", "attinyx313",
192-
"chip=4313\nclock=5internal\nbod=2v7\nINITIALIZE_SECONDARY_TIMERS=1" }, //
190+
"chip=4313\nclock=5internal\nbod=2v7\nINITIALIZE_SECONDARY_TIMERS=1\nLTO=enable" }, //
193191

194192
// chipKIT
195193
{ "package_chipkit_index.json", "chipKIT", "chipKIT", "cerebot32mx4", "" }, //
@@ -269,7 +267,7 @@ public static Collection boards() {
269267
{ "package_digistump_index.json", "digistump", "Digistump AVR Boards", "digispark-tiny1", "" }, //
270268

271269
// digistump oak (needs MSVCR100.dll to be added to
272-
// tools/digistump/esptool2/[version]
270+
// digistump/tools/esptool2/[version]
273271
// folder
274272
{ "package_digistump_index.json", "digistump", "Oak by Digistump", "oak1",
275273
"CpuFrequency=80\nUploadTool=oak\nFlashSize=OAK\nRomConfig=Full" }, //
@@ -364,6 +362,9 @@ public static Collection boards() {
364362
"" }, //
365363

366364
// redbear
365+
// needs a workaround in platform.txt
366+
// see
367+
// https://github.com/jantje/arduino-eclipse-plugin/issues/546
367368
{ "package_redbear_index.json", "RedBear", "RedBear Duo (32-bits ARM Cortex-M3)", "RedBear_Duo_native",
368369
"" }, //
369370
{ "package_redbear_index.json", "RedBear", "RedBear Duo (32-bits ARM Cortex-M3)", "RedBear_Duo", "" }, //
@@ -398,11 +399,11 @@ public static Collection boards() {
398399
{ "package_sparkfun_index.json", "SparkFun", "SparkFun AVR Boards", "atmega128rfa1", "" }, //
399400

400401
// Teensy
401-
{ "local", teensyBoards_txt, "", "teensy31", "usb=serial\nspeed=96\nkeys=en-us" }, //
402-
{ "local", teensyBoards_txt, "", "teensy30", "usb=serial\nspeed=96\nkeys=en-us" }, //
403-
{ "local", teensyBoards_txt, "", "teensyLC", "usb=serial\nl\nspeed=48\nkeys=en-us" }, //
404-
{ "local", teensyBoards_txt, "", "teensypp2", "usb=serial\nspeed=16\nkeys=en-us" }, //
405-
{ "local", teensyBoards_txt, "", "teensy2", "usb=serial\nspeed=16\nkeys=en-us" }, //
402+
{ "local", Shared.teensyBoards_txt, "", "teensy31", "usb=serial\nspeed=96\nkeys=en-us" }, //
403+
{ "local", Shared.teensyBoards_txt, "", "teensy30", "usb=serial\nspeed=96\nkeys=en-us" }, //
404+
{ "local", Shared.teensyBoards_txt, "", "teensyLC", "usb=serial\nl\nspeed=48\nkeys=en-us" }, //
405+
{ "local", Shared.teensyBoards_txt, "", "teensypp2", "usb=serial\nspeed=16\nkeys=en-us" }, //
406+
{ "local", Shared.teensyBoards_txt, "", "teensy2", "usb=serial\nspeed=16\nkeys=en-us" }, //
406407

407408
// TeeOnArdu avr
408409
{ "package_adafruit_index.json", "TeeOnArdu", "Adafruit TeeOnArdu", "TeeOnArdu",
@@ -425,24 +426,7 @@ public static Collection boards() {
425426
@BeforeClass
426427
public static void WaitForInstallerToFinish() {
427428
installAdditionalBoards();
428-
waitForAllJobsToFinish();
429-
}
430-
431-
public static void waitForAllJobsToFinish() {
432-
try {
433-
Thread.sleep(10000);
434-
435-
IJobManager jobMan = Job.getJobManager();
436-
437-
while (!jobMan.isIdle()) {
438-
Thread.sleep(5000);
439-
}
440-
// As nothing is running now we can start installing
441-
442-
} catch (InterruptedException e) {
443-
e.printStackTrace();
444-
fail("can not find installerjob");
445-
}
429+
Shared.waitForAllJobsToFinish();
446430
}
447431

448432
public static void installAdditionalBoards() {
@@ -514,7 +498,7 @@ public static void installAdditionalBoards() {
514498
"https://zevero.github.io/avr_boot/package_zevero_avr_boot_index.json", };
515499
BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true);
516500
BoardsManager.installAllLatestPlatforms();
517-
BoardsManager.referenceLocallInstallation(teensyInstall);
501+
BoardsManager.referenceLocallInstallation(Shared.teensyInstall);
518502
}
519503

520504
@Test
@@ -540,15 +524,15 @@ public static void BuildAndVerify(BoardDescriptor boardid) {
540524

541525
theTestProject = boardid.createProject(projectName, null, ConfigurationDescriptor.getDefaultDescriptors(),
542526
codeDescriptor, monitor);
543-
waitForAllJobsToFinish(); // for the indexer
527+
Shared.waitForAllJobsToFinish(); // for the indexer
544528
} catch (Exception e) {
545529
e.printStackTrace();
546530
fail("Failed to create the project:" + projectName);
547531
return;
548532
}
549533
try {
550534
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
551-
if (hasBuildErrors(theTestProject)) {
535+
if (Shared.hasBuildErrors(theTestProject)) {
552536
fail("Failed to compile the project:" + projectName + " build errors");
553537
}
554538
} catch (CoreException e) {
@@ -557,13 +541,4 @@ public static void BuildAndVerify(BoardDescriptor boardid) {
557541
}
558542
}
559543

560-
private static boolean hasBuildErrors(IProject project) throws CoreException {
561-
IMarker[] markers = project.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
562-
for (IMarker marker : markers) {
563-
if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR) {
564-
return true;
565-
}
566-
}
567-
return false;
568-
}
569544
}

io.sloeber.core/src/jUnit/Regression.java

+55-23
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77
import java.util.HashSet;
88
import java.util.Map;
99

10-
import org.eclipse.core.runtime.jobs.IJobManager;
11-
import org.eclipse.core.runtime.jobs.Job;
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.NullProgressMonitor;
1214
import org.junit.BeforeClass;
1315
import org.junit.Test;
1416

1517
import io.sloeber.core.api.BoardDescriptor;
1618
import io.sloeber.core.api.BoardsManager;
19+
import io.sloeber.core.api.CodeDescriptor;
20+
import io.sloeber.core.api.ConfigurationDescriptor;
1721

1822
@SuppressWarnings("nls")
1923
public class Regression {
@@ -25,30 +29,11 @@ public class Regression {
2529
*/
2630
@BeforeClass
2731
public static void WaitForInstallerToFinish() {
28-
waitForAllJobsToFinish();
32+
Shared.waitForAllJobsToFinish();
2933
installAdditionalBoards();
3034
BoardsManager.installAllLatestPlatforms();
3135
}
3236

33-
public static void waitForAllJobsToFinish() {
34-
try {
35-
Thread.sleep(10000);
36-
37-
IJobManager jobMan = Job.getJobManager();
38-
39-
while (!jobMan.isIdle()) {
40-
Thread.sleep(5000);
41-
// If you do not get out of this loop it probably means you are
42-
// runnning the test in the gui thread
43-
}
44-
// As nothing is running now we can start installing
45-
46-
} catch (InterruptedException e) {
47-
e.printStackTrace();
48-
fail("can not find installerjob");
49-
}
50-
}
51-
5237
public static void installAdditionalBoards() {
5338
String[] packageUrlsToAdd = { "http://talk2arduino.wisen.com.au/master/package_talk2.wisen.com_index.json" };
5439
BoardsManager.addPackageURLs(new HashSet<>(Arrays.asList(packageUrlsToAdd)), true);
@@ -63,7 +48,7 @@ public static void installAdditionalBoards() {
6348
public void redirectedJson() {
6449

6550
Map<String, String> options = new HashMap<>();
66-
options.put("CPU Speed", "16MHz External Crystal (default)");
51+
options.put("mhz", "16MHz");
6752
BoardDescriptor boardid = BoardsManager.getBoardID("package_talk2.wisen.com_index.json", "Talk2",
6853
"Talk2 AVR Boards", "whispernode", options);
6954
if (boardid == null) {
@@ -73,4 +58,51 @@ public void redirectedJson() {
7358
CreateAndCompile.BuildAndVerify(boardid);
7459
}
7560

61+
@SuppressWarnings("static-method")
62+
@Test
63+
public void issue555() {
64+
Map<String, String> unoOptions = new HashMap<>();
65+
BoardDescriptor unoBoardid = BoardsManager.getBoardID("package_index.json", "arduino", "Arduino AVR Boards",
66+
"uno", unoOptions);
67+
Map<String, String> teensyOptions = new HashMap<>();
68+
teensyOptions.put("usb", "serial");
69+
teensyOptions.put("speed", "96");
70+
teensyOptions.put("keys", "en-us");
71+
BoardDescriptor teensyBoardid = BoardsManager.getBoardID("local", Shared.teensyBoards_txt, "", "teensy31",
72+
teensyOptions);
73+
IProject theTestProject = null;
74+
CodeDescriptor codeDescriptor = CodeDescriptor.createDefaultIno();
75+
String projectName = "issue555";
76+
NullProgressMonitor monitor = new NullProgressMonitor();
77+
try {
78+
79+
theTestProject = unoBoardid.createProject(projectName, null,
80+
ConfigurationDescriptor.getDefaultDescriptors(), codeDescriptor, monitor);
81+
Shared.waitForAllJobsToFinish(); // for the indexer
82+
} catch (Exception e) {
83+
e.printStackTrace();
84+
fail("Failed to create the project:" + projectName);
85+
return;
86+
}
87+
try {
88+
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
89+
if (Shared.hasBuildErrors(theTestProject)) {
90+
fail("Failed to compile the project:" + projectName + " as teensy build errors");
91+
}
92+
} catch (CoreException e) {
93+
e.printStackTrace();
94+
fail("Failed to compile the project:" + unoBoardid.getBoardName() + " as uno exception");
95+
}
96+
teensyBoardid.configureProject(theTestProject, monitor);
97+
Shared.waitForAllJobsToFinish();
98+
try {
99+
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
100+
if (Shared.hasBuildErrors(theTestProject)) {
101+
fail("Failed to compile the project:" + projectName + " as teensy");
102+
}
103+
} catch (CoreException e) {
104+
e.printStackTrace();
105+
fail("Failed to compile the project:" + unoBoardid.getBoardName() + " as teensy exception");
106+
}
107+
}
76108
}

0 commit comments

Comments
 (0)