|
12 | 12 | * only the private static method skipExample allows to skip examples
|
13 | 13 | */
|
14 | 14 |
|
15 |
| -import static org.junit.Assert.fail; |
| 15 | +import static org.junit.Assert.*; |
16 | 16 |
|
17 | 17 | import java.util.ArrayList;
|
18 | 18 | import java.util.Collection;
|
19 | 19 | import java.util.LinkedList;
|
| 20 | +import java.util.List; |
20 | 21 | import java.util.Map;
|
21 | 22 | import java.util.TreeMap;
|
22 | 23 |
|
|
28 | 29 | import org.junit.runners.Parameterized.Parameters;
|
29 | 30 |
|
30 | 31 | import io.sloeber.core.api.BoardDescription;
|
| 32 | +import io.sloeber.core.api.BoardsManager; |
31 | 33 | import io.sloeber.core.api.CodeDescription;
|
32 | 34 | import io.sloeber.core.api.CompileDescription;
|
33 | 35 | import io.sloeber.core.api.LibraryManager;
|
34 |
| -import io.sloeber.core.api.BoardsManager; |
35 | 36 | import io.sloeber.core.api.Preferences;
|
36 | 37 | import io.sloeber.providers.MCUBoard;
|
37 | 38 | import io.sloeber.providers.Teensy;
|
38 | 39 |
|
39 | 40 | @SuppressWarnings({ "nls" })
|
40 | 41 | @RunWith(Parameterized.class)
|
41 | 42 | public class CreateAndCompileArduinoIDEExamplesOnTeensyTest {
|
42 |
| - private CodeDescription myCodeDescriptor; |
43 |
| - |
44 |
| - private String myTestName; |
45 |
| - private BoardDescription myBoardDescriptor; |
46 |
| - private static int myBuildCounter = 0; |
47 |
| - private static int myTotalFails = 0; |
48 |
| - private static int maxFails = 50; |
49 |
| - private static int mySkipAtStart = 0; |
50 |
| - |
51 |
| - public CreateAndCompileArduinoIDEExamplesOnTeensyTest(String testName, CodeDescription codeDescriptor, |
52 |
| - BoardDescription board) { |
53 |
| - |
54 |
| - myCodeDescriptor = codeDescriptor; |
55 |
| - myTestName = testName; |
56 |
| - myBoardDescriptor = board; |
57 |
| - } |
58 |
| - |
59 |
| - @SuppressWarnings("rawtypes") |
60 |
| - @Parameters(name = "{0}") |
61 |
| - public static Collection examples() { |
62 |
| - installAdditionalBoards(); |
63 |
| - |
64 |
| - Shared.waitForAllJobsToFinish(); |
65 |
| - Preferences.setUseBonjour(false); |
66 |
| - LinkedList<Object[]> examples = new LinkedList<>(); |
67 |
| - MCUBoard[] allBoards = Teensy.getAllBoards(); |
68 |
| - |
69 |
| - TreeMap<String, IPath> exampleFolders = LibraryManager.getAllArduinoIDEExamples(); |
70 |
| - for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) { |
71 |
| - String fqn = curexample.getKey().trim(); |
72 |
| - IPath examplePath = curexample.getValue(); |
73 |
| - Example example = new Example(fqn, examplePath); |
74 |
| - if (!skipExample(example)) { |
75 |
| - ArrayList<IPath> paths = new ArrayList<>(); |
76 |
| - paths.add(examplePath); |
77 |
| - CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); |
78 |
| - |
79 |
| - for (MCUBoard curBoard : allBoards) { |
80 |
| - if (curBoard.isExampleSupported(example)) { |
81 |
| - String projectName = Shared.getProjectName(codeDescriptor, example, curBoard); |
82 |
| - Map<String, String> boardOptions = curBoard.getBoardOptions(example); |
83 |
| - BoardDescription boardDescriptor = curBoard.getBoardDescriptor(); |
84 |
| - boardDescriptor.setOptions(boardOptions); |
85 |
| - Object[] theData = new Object[] { projectName, codeDescriptor, boardDescriptor }; |
86 |
| - examples.add(theData); |
87 |
| - } |
88 |
| - } |
89 |
| - } |
90 |
| - } |
91 |
| - |
92 |
| - return examples; |
93 |
| - |
94 |
| - } |
95 |
| - |
96 |
| - @SuppressWarnings("unused") |
97 |
| - private static boolean skipExample(Example example) { |
98 |
| - // no need to skip examples in this test |
99 |
| - return false; |
100 |
| - } |
101 |
| - |
102 |
| - public static void installAdditionalBoards() { |
103 |
| - if (MySystem.getTeensyPlatform().isEmpty()) { |
104 |
| - System.err.println("ERROR: Teensy not installed/configured skipping tests!!!"); |
105 |
| - } else { |
106 |
| - BoardsManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); |
107 |
| - } |
108 |
| - |
109 |
| - } |
110 |
| - |
111 |
| - @Test |
112 |
| - public void testArduinoIDEExamplesOnTeensy() { |
113 |
| - Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); |
114 |
| - Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); |
| 43 | + private CodeDescription myCodeDescriptor; |
| 44 | + |
| 45 | + private String myTestName; |
| 46 | + private BoardDescription myBoardDescriptor; |
| 47 | + private static int myBuildCounter = 0; |
| 48 | + private static int myTotalFails = 0; |
| 49 | + private static int maxFails = 50; |
| 50 | + private static int mySkipAtStart = 0; |
| 51 | + |
| 52 | + public CreateAndCompileArduinoIDEExamplesOnTeensyTest(String testName, CodeDescription codeDescriptor, |
| 53 | + BoardDescription board) { |
| 54 | + |
| 55 | + myCodeDescriptor = codeDescriptor; |
| 56 | + myTestName = testName; |
| 57 | + myBoardDescriptor = board; |
| 58 | + } |
| 59 | + |
| 60 | + @SuppressWarnings("rawtypes") |
| 61 | + @Parameters(name = "{0}") |
| 62 | + public static Collection examples() { |
| 63 | + installAdditionalBoards(); |
| 64 | + |
| 65 | + Shared.waitForAllJobsToFinish(); |
| 66 | + Preferences.setUseBonjour(false); |
| 67 | + LinkedList<Object[]> examples = new LinkedList<>(); |
| 68 | + List<MCUBoard> allBoards = Teensy.getAllBoards(); |
| 69 | + |
| 70 | + TreeMap<String, IPath> exampleFolders = LibraryManager.getAllArduinoIDEExamples(); |
| 71 | + for (Map.Entry<String, IPath> curexample : exampleFolders.entrySet()) { |
| 72 | + String fqn = curexample.getKey().trim(); |
| 73 | + IPath examplePath = curexample.getValue(); |
| 74 | + Example example = new Example(fqn, examplePath); |
| 75 | + if (!skipExample(example)) { |
| 76 | + ArrayList<IPath> paths = new ArrayList<>(); |
| 77 | + paths.add(examplePath); |
| 78 | + CodeDescription codeDescriptor = CodeDescription.createExample(false, paths); |
| 79 | + |
| 80 | + for (MCUBoard curBoard : allBoards) { |
| 81 | + if (curBoard.isExampleSupported(example)) { |
| 82 | + String projectName = Shared.getProjectName(codeDescriptor, example, curBoard); |
| 83 | + Map<String, String> boardOptions = curBoard.getBoardOptions(example); |
| 84 | + BoardDescription boardDescriptor = curBoard.getBoardDescriptor(); |
| 85 | + boardDescriptor.setOptions(boardOptions); |
| 86 | + Object[] theData = new Object[] { projectName, codeDescriptor, boardDescriptor }; |
| 87 | + examples.add(theData); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + return examples; |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | + @SuppressWarnings("unused") |
| 98 | + private static boolean skipExample(Example example) { |
| 99 | + // no need to skip examples in this test |
| 100 | + return false; |
| 101 | + } |
| 102 | + |
| 103 | + public static void installAdditionalBoards() { |
| 104 | + if (MySystem.getTeensyPlatform().isEmpty()) { |
| 105 | + System.err.println("ERROR: Teensy not installed/configured skipping tests!!!"); |
| 106 | + } else { |
| 107 | + BoardsManager.addPrivateHardwarePath(MySystem.getTeensyPlatform()); |
| 108 | + } |
| 109 | + |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + public void testArduinoIDEExamplesOnTeensy() { |
| 114 | + Assume.assumeTrue("Skipping first " + mySkipAtStart + " tests", myBuildCounter++ >= mySkipAtStart); |
| 115 | + Assume.assumeTrue("To many fails. Stopping test", myTotalFails < maxFails); |
115 | 116 | if (!Shared.BuildAndVerify(myTestName, myBoardDescriptor, myCodeDescriptor, new CompileDescription())) {
|
116 |
| - myTotalFails++; |
117 |
| - fail(Shared.getLastFailMessage()); |
118 |
| - } |
119 |
| - } |
| 117 | + myTotalFails++; |
| 118 | + fail(Shared.getLastFailMessage()); |
| 119 | + } |
| 120 | + } |
120 | 121 |
|
121 | 122 | }
|
0 commit comments