From 4b4df68c5d0a8bb15cfe4d2a338afb50aef808e7 Mon Sep 17 00:00:00 2001 From: Andrii Filippov Date: Thu, 11 Sep 2025 13:54:43 +0200 Subject: [PATCH 1/4] ci: add Debug test --- .../project/IDFProjectDebugProcessTest.java | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java new file mode 100644 index 000000000..b6240e20b --- /dev/null +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright 2025 Espressif Systems (Shanghai) PTE LTD. + * All rights reserved. Use is subject to license terms. + *******************************************************************************/ + +package com.espressif.idf.ui.test.executable.cases.project; + +import java.io.IOException; + +import org.apache.commons.lang3.SystemUtils; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; + +import com.espressif.idf.ui.test.common.WorkBenchSWTBot; +import static org.eclipse.swtbot.swt.finder.waits.Conditions.*; +import static org.junit.Assert.assertTrue; + +import com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility; +import com.espressif.idf.ui.test.operations.EnvSetupOperations; +import com.espressif.idf.ui.test.operations.ProjectTestOperations; +import com.espressif.idf.ui.test.operations.selectors.LaunchBarConfigSelector; +import com.espressif.idf.ui.test.operations.selectors.LaunchBarTargetSelector; + +/** + * Test class to test Debug Process + * + * @author Andrii Filippov + * + */ + +@SuppressWarnings("restriction") +@RunWith(SWTBotJunit4ClassRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class IDFProjectDebugProcessTest +{ + @BeforeClass + public static void beforeTestClass() throws Exception + { + Fixture.loadEnv(); + } + + @After + public void afterEachTest() + { + try + { + Fixture.cleanTestEnv(); + } + catch (Exception e) + { + System.err.println("Error during cleanup: " + e.getMessage()); + } + } + + @Test + public void givenNewProjectCreatedWhenSelectDebugWhenBuiltThenCheckDebugSuccessfully() throws Exception + { + if (SystemUtils.IS_OS_LINUX) //temporary solution until new ESP boards arrive for Windows + { + Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); + Fixture.givenProjectNameIs("NewProjecDebugTest"); + Fixture.whenNewProjectIsSelected(); + Fixture.whenSelectDebugConfig(); + Fixture.whenSelectLaunchTargetBoard(); + Fixture.whenProjectIsBuiltUsingContextMenu(); + Fixture.whenDebugProject(); + Fixture.thenVerifyJTAGflashDone(); + } + else + { + assertTrue(true); + } + } + + private static class Fixture + { + private static SWTWorkbenchBot bot; + private static String category; + private static String subCategory; + private static String projectName; + + private static void loadEnv() throws Exception + { + bot = WorkBenchSWTBot.getBot(); + EnvSetupOperations.setupEspressifEnv(bot); + bot.sleep(1000); + ProjectTestOperations.deleteAllProjects(bot); + } + + private static void givenNewEspressifIDFProjectIsSelected(String category, String subCategory) + { + Fixture.category = category; + Fixture.subCategory = subCategory; + } + + private static void givenProjectNameIs(String projectName) + { + Fixture.projectName = projectName; + } + + private static void whenNewProjectIsSelected() throws Exception + { + ProjectTestOperations.setupProject(projectName, category, subCategory, bot); + } + + private static void whenProjectIsBuiltUsingContextMenu() throws IOException + { + ProjectTestOperations.buildProjectUsingContextMenu(projectName, bot); + ProjectTestOperations.waitForProjectBuild(bot); + TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); + } + + private static void whenDebugProject() throws IOException + { + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Debug Configurations..."); + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Debug Configurations", 10000); + bot.tree().getTreeItem("ESP-IDF GDB OpenOCD Debugging").select(); + bot.tree().getTreeItem("ESP-IDF GDB OpenOCD Debugging").expand(); + bot.tree().getTreeItem("ESP-IDF GDB OpenOCD Debugging").getNode(projectName + " Debug").select(); + bot.waitUntil(widgetIsEnabled(bot.button("Debug")), 5000); + bot.button("Debug").click(); + } + + private static void whenSelectDebugConfig() throws Exception + { + LaunchBarConfigSelector configSelector = new LaunchBarConfigSelector(bot); + configSelector.select(projectName + " Debug"); + } + + private static void whenSelectLaunchTargetBoard() throws Exception + { + LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot); + targetSelector.clickEdit(); + TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000); + SWTBotShell shell = bot.shell("New ESP Target"); + bot.comboBoxWithLabel("Board:").setSelection("ESP32-ETHERNET-KIT [usb://1-10]"); + TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot); + shell.setFocus(); + bot.button("Finish").click(); + } + + private static void thenVerifyJTAGflashDone() throws Exception + { + ProjectTestOperations.verifyTheConsoleOutput(bot, "** Flashing done for partition_table/partition-table.bin"); + } + + private static void cleanTestEnv() + { + TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); + ProjectTestOperations.closeAllProjects(bot); + ProjectTestOperations.deleteAllProjects(bot); + } + } +} From 70b72067edbf994656829fc4925c89bad41967ce Mon Sep 17 00:00:00 2001 From: Andrii Filippov Date: Thu, 11 Sep 2025 17:57:15 +0200 Subject: [PATCH 2/4] ci: improve first test --- .../project/IDFProjectDebugProcessTest.java | 60 +++++++++++++++++-- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java index b6240e20b..a18356a08 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java @@ -10,6 +10,7 @@ import org.apache.commons.lang3.SystemUtils; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; import org.junit.After; import org.junit.BeforeClass; @@ -60,18 +61,22 @@ public void afterEachTest() } @Test - public void givenNewProjectCreatedWhenSelectDebugWhenBuiltThenCheckDebugSuccessfully() throws Exception + public void givenNewProjectCreatedWhenFlashedAndDebuggedThenDebuggingWorks() throws Exception { if (SystemUtils.IS_OS_LINUX) //temporary solution until new ESP boards arrive for Windows { Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); Fixture.givenProjectNameIs("NewProjecDebugTest"); Fixture.whenNewProjectIsSelected(); + Fixture.whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig(); + Fixture.whenProjectIsBuiltUsingContextMenu(); + Fixture.whenSelectLaunchTargetSerialPort(); + Fixture.whenFlashProject(); + Fixture.thenVerifyFlashDoneSuccessfully(); Fixture.whenSelectDebugConfig(); Fixture.whenSelectLaunchTargetBoard(); - Fixture.whenProjectIsBuiltUsingContextMenu(); - Fixture.whenDebugProject(); - Fixture.thenVerifyJTAGflashDone(); +// Fixture.whenDebugProject(); +// Fixture.whenSwitchPerspective(); } else { @@ -146,9 +151,52 @@ private static void whenSelectLaunchTargetBoard() throws Exception bot.button("Finish").click(); } - private static void thenVerifyJTAGflashDone() throws Exception + private static void whenSwitchPerspective() throws Exception + { + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Confirm Perspective Switch", 20000); + bot.button("Switch").click(); + } + + private static void whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig() throws Exception + { + LaunchBarConfigSelector configSelector = new LaunchBarConfigSelector(bot); + configSelector.clickEdit(); + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit Configuration", 20000); + bot.cTabItem("Main").show(); + bot.cTabItem("Main").setFocus(); + SWTBotCheckBox checkBox = bot.checkBox("Open Serial Monitor After Flashing"); + if (checkBox.isChecked()) { + checkBox.click(); + } + bot.button("OK").click(); + } + + private static void whenSelectLaunchTargetSerialPort() throws Exception + { + LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot); + targetSelector.clickEdit(); + TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000); + SWTBotShell shell = bot.shell("New ESP Target"); + bot.comboBoxWithLabel("Serial Port:").setSelection("/dev/ttyUSB1 Dual RS232-HS"); + TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot); + shell.setFocus(); + bot.button("Finish").click(); + } + + private static void whenFlashProject() throws IOException + { + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Run Configurations..."); + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Run Configurations", 10000); + bot.tree().getTreeItem("ESP-IDF Application").select(); + bot.tree().getTreeItem("ESP-IDF Application").expand(); + bot.tree().getTreeItem("ESP-IDF Application").getNode(projectName).select(); + bot.waitUntil(widgetIsEnabled(bot.button("Run")), 5000); + bot.button("Run").click(); + } + + private static void thenVerifyFlashDoneSuccessfully() throws Exception { - ProjectTestOperations.verifyTheConsoleOutput(bot, "** Flashing done for partition_table/partition-table.bin"); + ProjectTestOperations.waitForProjectFlash(bot); } private static void cleanTestEnv() From f5a42cca303f6f74ca1c0f3f76f009af01416a9b Mon Sep 17 00:00:00 2001 From: Andrii Filippov Date: Wed, 1 Oct 2025 18:12:43 +0200 Subject: [PATCH 3/4] ci: first test addition --- .../project/IDFProjectDebugProcessTest.java | 72 ++++++++++++++++--- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java index a18356a08..f22aef5ec 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java @@ -5,13 +5,20 @@ package com.espressif.idf.ui.test.executable.cases.project; +import static org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled; +import static org.junit.Assert.assertTrue; + import java.io.IOException; +import java.util.Arrays; +import java.util.Optional; import org.apache.commons.lang3.SystemUtils; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; import org.junit.After; import org.junit.BeforeClass; import org.junit.FixMethodOrder; @@ -20,9 +27,6 @@ import org.junit.runners.MethodSorters; import com.espressif.idf.ui.test.common.WorkBenchSWTBot; -import static org.eclipse.swtbot.swt.finder.waits.Conditions.*; -import static org.junit.Assert.assertTrue; - import com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility; import com.espressif.idf.ui.test.operations.EnvSetupOperations; import com.espressif.idf.ui.test.operations.ProjectTestOperations; @@ -63,20 +67,22 @@ public void afterEachTest() @Test public void givenNewProjectCreatedWhenFlashedAndDebuggedThenDebuggingWorks() throws Exception { - if (SystemUtils.IS_OS_LINUX) //temporary solution until new ESP boards arrive for Windows + if (SystemUtils.IS_OS_LINUX) // temporary solution until new ESP boards arrive for Windows { Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); Fixture.givenProjectNameIs("NewProjecDebugTest"); Fixture.whenNewProjectIsSelected(); Fixture.whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig(); - Fixture.whenProjectIsBuiltUsingContextMenu(); Fixture.whenSelectLaunchTargetSerialPort(); + Fixture.whenProjectIsBuiltUsingContextMenu(); Fixture.whenFlashProject(); Fixture.thenVerifyFlashDoneSuccessfully(); Fixture.whenSelectDebugConfig(); Fixture.whenSelectLaunchTargetBoard(); // Fixture.whenDebugProject(); // Fixture.whenSwitchPerspective(); +// Fixture.checkIfOpenOCDandGDBprocessesArePresent(); +// Fixture.whenDebugStoppedUsingContextMenu(); } else { @@ -155,6 +161,7 @@ private static void whenSwitchPerspective() throws Exception { TestWidgetWaitUtility.waitForDialogToAppear(bot, "Confirm Perspective Switch", 20000); bot.button("Switch").click(); + bot.sleep(10000); } private static void whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig() throws Exception @@ -165,8 +172,9 @@ private static void whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig() th bot.cTabItem("Main").show(); bot.cTabItem("Main").setFocus(); SWTBotCheckBox checkBox = bot.checkBox("Open Serial Monitor After Flashing"); - if (checkBox.isChecked()) { - checkBox.click(); + if (checkBox.isChecked()) + { + checkBox.click(); } bot.button("OK").click(); } @@ -193,12 +201,60 @@ private static void whenFlashProject() throws IOException bot.waitUntil(widgetIsEnabled(bot.button("Run")), 5000); bot.button("Run").click(); } - + private static void thenVerifyFlashDoneSuccessfully() throws Exception { ProjectTestOperations.waitForProjectFlash(bot); } + private static SWTBotTreeItem fetchProjectFromDebugView() + { + SWTBotView debugView = bot.viewByTitle("Debug"); + debugView.show(); + debugView.setFocus(); + SWTBotTreeItem[] items = debugView.bot().tree().getAllItems(); + Optional project = Arrays.asList(items).stream() + .filter(i -> i.getText().equals(projectName + "Debug [ESP-IDF GDB OpenOCD Debugging]")).findFirst(); + if (project.isPresent()) + { + return project.get(); + } + + return null; + } + + private static boolean checkifOpenOCDandGDBprocessesArePresent() + { + SWTBotTreeItem projectItem = fetchProjectFromDebugView(); + if (projectItem != null) + { + projectItem.select(); + + boolean openOCDexe = ProjectTestOperations.isFileAbsent(projectItem, "openocd.exe"); + boolean GDBexe = ProjectTestOperations.isFileAbsent(projectItem, "riscv32-esp-elf-gdb.exe"); + if (openOCDexe || GDBexe) + { + return false; + } + return true; + } + return false; + } + + private static void checkIfOpenOCDandGDBprocessesArePresent() throws IOException + { + assertTrue("Debug process was not successfully started", checkifOpenOCDandGDBprocessesArePresent()); + } + + private static void whenDebugStoppedUsingContextMenu() throws IOException + { + ProjectTestOperations.launchCommandUsingContextMenu(projectName + "Debug [ESP-IDF GDB OpenOCD Debugging]", + bot, "Terminate/Disconnect All"); + bot.sleep(10000); + ProjectTestOperations.findInConsole(bot, "IDF Process Console", "dropped 'gdb'"); + TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot); + } + private static void cleanTestEnv() { TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); From 3a897f32524c9e1e0dbcf9d728b893bcd204a211 Mon Sep 17 00:00:00 2001 From: Andrii Filippov Date: Thu, 2 Oct 2025 12:40:26 +0200 Subject: [PATCH 4/4] ci: first test Linux --- .../project/IDFProjectDebugProcessTest.java | 215 ++++++++++-------- 1 file changed, 119 insertions(+), 96 deletions(-) diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java index f22aef5ec..fe5810511 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectDebugProcessTest.java @@ -1,7 +1,7 @@ /******************************************************************************* - * Copyright 2025 Espressif Systems (Shanghai) PTE LTD. - * All rights reserved. Use is subject to license terms. - *******************************************************************************/ +* Copyright 2025 Espressif Systems (Shanghai) PTE LTD. +* All rights reserved. Use is subject to license terms. +*******************************************************************************/ package com.espressif.idf.ui.test.executable.cases.project; @@ -35,7 +35,7 @@ /** * Test class to test Debug Process - * + * * @author Andrii Filippov * */ @@ -67,22 +67,11 @@ public void afterEachTest() @Test public void givenNewProjectCreatedWhenFlashedAndDebuggedThenDebuggingWorks() throws Exception { - if (SystemUtils.IS_OS_LINUX) // temporary solution until new ESP boards arrive for Windows + if (SystemUtils.IS_OS_LINUX) // Temporary solution until new ESP boards arrive for Windows { - Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); - Fixture.givenProjectNameIs("NewProjecDebugTest"); - Fixture.whenNewProjectIsSelected(); - Fixture.whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig(); - Fixture.whenSelectLaunchTargetSerialPort(); - Fixture.whenProjectIsBuiltUsingContextMenu(); - Fixture.whenFlashProject(); - Fixture.thenVerifyFlashDoneSuccessfully(); - Fixture.whenSelectDebugConfig(); - Fixture.whenSelectLaunchTargetBoard(); -// Fixture.whenDebugProject(); -// Fixture.whenSwitchPerspective(); -// Fixture.checkIfOpenOCDandGDBprocessesArePresent(); -// Fixture.whenDebugStoppedUsingContextMenu(); + Fixture.createNewEspressifProject("EspressIf", "Espressif IDF Project", "NewProjecDebugTest"); + Fixture.buildAndFlashProject(); + Fixture.debugProject(); } else { @@ -93,8 +82,6 @@ public void givenNewProjectCreatedWhenFlashedAndDebuggedThenDebuggingWorks() thr private static class Fixture { private static SWTWorkbenchBot bot; - private static String category; - private static String subCategory; private static String projectName; private static void loadEnv() throws Exception @@ -105,20 +92,49 @@ private static void loadEnv() throws Exception ProjectTestOperations.deleteAllProjects(bot); } - private static void givenNewEspressifIDFProjectIsSelected(String category, String subCategory) + private static void createNewEspressifProject(String category, String subCategory, String projectName) { - Fixture.category = category; - Fixture.subCategory = subCategory; + Fixture.projectName = projectName; + ProjectTestOperations.setupProject(projectName, category, subCategory, bot); } - private static void givenProjectNameIs(String projectName) + private static void buildAndFlashProject() throws Exception { - Fixture.projectName = projectName; + whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig(); + whenSelectLaunchTargetSerialPort(); + whenProjectIsBuiltUsingContextMenu(); + whenFlashProject(); + thenVerifyFlashDoneSuccessfully(); } - private static void whenNewProjectIsSelected() throws Exception + private static void debugProject() throws Exception { - ProjectTestOperations.setupProject(projectName, category, subCategory, bot); + whenSelectDebugConfig(); + whenSelectLaunchTargetBoard(); + whenDebugProject(); + whenSwitchPerspective(); + thenOpenOCDexeIsPresent(); + thenGDBexeIsPresent(); + thenDebugStoppedUsingContextMenu(); + } + + private static void whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig() throws Exception + { + modifyLaunchConfig("Open Serial Monitor After Flashing", false); + } + + private static void modifyLaunchConfig(String checkboxLabel, boolean check) throws Exception + { + LaunchBarConfigSelector configSelector = new LaunchBarConfigSelector(bot); + configSelector.clickEdit(); + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit Configuration", 20000); + bot.cTabItem("Main").show(); + SWTBotCheckBox checkBox = bot.checkBox(checkboxLabel); + if (checkBox.isChecked() != check) + { + checkBox.click(); + } + bot.button("OK").click(); } private static void whenProjectIsBuiltUsingContextMenu() throws IOException @@ -128,15 +144,20 @@ private static void whenProjectIsBuiltUsingContextMenu() throws IOException TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); } - private static void whenDebugProject() throws IOException + private static void whenFlashProject() throws IOException { - ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Debug Configurations..."); - TestWidgetWaitUtility.waitForDialogToAppear(bot, "Debug Configurations", 10000); - bot.tree().getTreeItem("ESP-IDF GDB OpenOCD Debugging").select(); - bot.tree().getTreeItem("ESP-IDF GDB OpenOCD Debugging").expand(); - bot.tree().getTreeItem("ESP-IDF GDB OpenOCD Debugging").getNode(projectName + " Debug").select(); - bot.waitUntil(widgetIsEnabled(bot.button("Debug")), 5000); - bot.button("Debug").click(); + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Run Configurations..."); + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Run Configurations", 10000); + bot.tree().getTreeItem("ESP-IDF Application").select(); + bot.tree().getTreeItem("ESP-IDF Application").expand(); + bot.tree().getTreeItem("ESP-IDF Application").getNode(projectName).select(); + bot.waitUntil(widgetIsEnabled(bot.button("Run")), 5000); + bot.button("Run").click(); + } + + private static void thenVerifyFlashDoneSuccessfully() throws Exception + { + ProjectTestOperations.waitForProjectFlash(bot); } private static void whenSelectDebugConfig() throws Exception @@ -146,12 +167,22 @@ private static void whenSelectDebugConfig() throws Exception } private static void whenSelectLaunchTargetBoard() throws Exception + { + selectLaunchTarget("Board:", "ESP32-ETHERNET-KIT [usb://1-10]"); + } + + private static void whenSelectLaunchTargetSerialPort() throws Exception + { + selectLaunchTarget("Serial Port:", "/dev/ttyUSB1 Dual RS232-HS"); + } + + private static void selectLaunchTarget(String label, String target) throws Exception { LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot); targetSelector.clickEdit(); TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000); SWTBotShell shell = bot.shell("New ESP Target"); - bot.comboBoxWithLabel("Board:").setSelection("ESP32-ETHERNET-KIT [usb://1-10]"); + bot.comboBoxWithLabel(label).setSelection(target); TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot); shell.setFocus(); bot.button("Finish").click(); @@ -161,98 +192,90 @@ private static void whenSwitchPerspective() throws Exception { TestWidgetWaitUtility.waitForDialogToAppear(bot, "Confirm Perspective Switch", 20000); bot.button("Switch").click(); - bot.sleep(10000); } - private static void whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig() throws Exception + private static void whenDebugProject() throws IOException { - LaunchBarConfigSelector configSelector = new LaunchBarConfigSelector(bot); - configSelector.clickEdit(); - TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit Configuration", 20000); - bot.cTabItem("Main").show(); - bot.cTabItem("Main").setFocus(); - SWTBotCheckBox checkBox = bot.checkBox("Open Serial Monitor After Flashing"); - if (checkBox.isChecked()) - { - checkBox.click(); - } - bot.button("OK").click(); + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Debug Configurations..."); + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Debug Configurations", 10000); + bot.tree().getTreeItem("ESP-IDF GDB OpenOCD Debugging").select(); + bot.tree().getTreeItem("ESP-IDF GDB OpenOCD Debugging").expand(); + bot.tree().getTreeItem("ESP-IDF GDB OpenOCD Debugging").getNode(projectName + " Debug").select(); + bot.waitUntil(widgetIsEnabled(bot.button("Debug")), 5000); + bot.button("Debug").click(); } - private static void whenSelectLaunchTargetSerialPort() throws Exception + private static void thenOpenOCDexeIsPresent() throws IOException { - LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot); - targetSelector.clickEdit(); - TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000); - SWTBotShell shell = bot.shell("New ESP Target"); - bot.comboBoxWithLabel("Serial Port:").setSelection("/dev/ttyUSB1 Dual RS232-HS"); - TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot); - shell.setFocus(); - bot.button("Finish").click(); + fetchProjectFromDebugView(); + assertTrue("OpenOCD.exe process was not found", + bot.tree().getTreeItem(projectName + " Debug [ESP-IDF GDB OpenOCD Debugging]").getNodes() + .contains("openocd")); } - private static void whenFlashProject() throws IOException + private static void thenGDBexeIsPresent() throws IOException { - ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Run Configurations..."); - TestWidgetWaitUtility.waitForDialogToAppear(bot, "Run Configurations", 10000); - bot.tree().getTreeItem("ESP-IDF Application").select(); - bot.tree().getTreeItem("ESP-IDF Application").expand(); - bot.tree().getTreeItem("ESP-IDF Application").getNode(projectName).select(); - bot.waitUntil(widgetIsEnabled(bot.button("Run")), 5000); - bot.button("Run").click(); + fetchProjectFromDebugView(); + assertTrue("riscv32-esp-elf-gdb.exe process was not found", + bot.tree().getTreeItem(projectName + " Debug [ESP-IDF GDB OpenOCD Debugging]").getNodes() + .contains("riscv32-esp-elf-gdb")); } - private static void thenVerifyFlashDoneSuccessfully() throws Exception + private static void waitForDebugView() { - ProjectTestOperations.waitForProjectFlash(bot); + long timeout = System.currentTimeMillis() + 10000; + while (System.currentTimeMillis() < timeout) + { + try + { + bot.viewByTitle("Debug"); + bot.sleep(2000); + return; + } + catch (Exception e) + { + } + try + { + Thread.sleep(500); + } + catch (InterruptedException ex) + { + Thread.currentThread().interrupt(); + } + } + throw new RuntimeException("Debug view did not appear within the given time"); } private static SWTBotTreeItem fetchProjectFromDebugView() { + waitForDebugView(); SWTBotView debugView = bot.viewByTitle("Debug"); debugView.show(); debugView.setFocus(); SWTBotTreeItem[] items = debugView.bot().tree().getAllItems(); Optional project = Arrays.asList(items).stream() - .filter(i -> i.getText().equals(projectName + "Debug [ESP-IDF GDB OpenOCD Debugging]")).findFirst(); - if (project.isPresent()) - { - return project.get(); - } - - return null; + .filter(i -> i.getText().equals(projectName + " Debug [ESP-IDF GDB OpenOCD Debugging]")) + .findFirst(); + return project.orElse(null); } - private static boolean checkifOpenOCDandGDBprocessesArePresent() + private static void launchCommandUsingDebugContextMenu(String projectName, SWTWorkbenchBot bot, + String contextMenuLabel) { SWTBotTreeItem projectItem = fetchProjectFromDebugView(); if (projectItem != null) { projectItem.select(); - - boolean openOCDexe = ProjectTestOperations.isFileAbsent(projectItem, "openocd.exe"); - boolean GDBexe = ProjectTestOperations.isFileAbsent(projectItem, "riscv32-esp-elf-gdb.exe"); - if (openOCDexe || GDBexe) - { - return false; - } - return true; + projectItem.contextMenu(contextMenuLabel).click(); } - return false; - } - - private static void checkIfOpenOCDandGDBprocessesArePresent() throws IOException - { - assertTrue("Debug process was not successfully started", checkifOpenOCDandGDBprocessesArePresent()); } - private static void whenDebugStoppedUsingContextMenu() throws IOException + private static void thenDebugStoppedUsingContextMenu() throws IOException { - ProjectTestOperations.launchCommandUsingContextMenu(projectName + "Debug [ESP-IDF GDB OpenOCD Debugging]", - bot, "Terminate/Disconnect All"); - bot.sleep(10000); + launchCommandUsingDebugContextMenu(projectName + " Debug [ESP-IDF GDB OpenOCD Debugging]", bot, + "Terminate/Disconnect All"); ProjectTestOperations.findInConsole(bot, "IDF Process Console", "dropped 'gdb'"); - TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot); } private static void cleanTestEnv()