diff --git a/virtual/cores/virtual/main.cpp b/virtual/cores/virtual/main.cpp index 2c23272..c7c1fd1 100644 --- a/virtual/cores/virtual/main.cpp +++ b/virtual/cores/virtual/main.cpp @@ -29,6 +29,12 @@ void initVariant() { } void setupUSB() __attribute__((weak)); void setupUSB() { } +// This function can be overridden in other libraries +// e.g. to run a testing framework. +// +__attribute__((weak)) +extern void executeTestFunction(); + void init(void) { // Arduino core does some device-related setup here. // We don't need to do anything. @@ -36,6 +42,13 @@ void init(void) { int main(int argc, char* argv[]) { if (!initVirtualInput(argc, argv)) return 1; + + if(testFunctionExecutionRequested()) { + if(executeTestFunction) { + executeTestFunction(); + } + return 0; + } init(); initVariant(); @@ -51,4 +64,3 @@ int main(int argc, char* argv[]) { return 0; } - diff --git a/virtual/cores/virtual/virtual_io.cpp b/virtual/cores/virtual/virtual_io.cpp index d40fd6f..9cd2f1d 100644 --- a/virtual/cores/virtual/virtual_io.cpp +++ b/virtual/cores/virtual/virtual_io.cpp @@ -8,7 +8,8 @@ #include // mkdir() #include -static bool interactive; +static bool interactive = false; +static bool test_function = false; static std::istream* input = NULL; static std::ostream* usbstream = NULL; static std::ostream* ledstream = NULL; @@ -18,6 +19,10 @@ bool isInteractive(void) { return interactive; } +bool testFunctionExecutionRequested() { + return test_function; +} + unsigned currentCycle(void) { return cycle; } @@ -58,6 +63,8 @@ bool initVirtualInput(int argc, char* argv[]) { if (strcmp(argv[1], "-i") == 0) { interactive = true; input = &std::cin; + } else if(strcmp(argv[1], "-t") == 0) { + test_function = true; } else { interactive = false; input = new std::ifstream(argv[1]); @@ -95,6 +102,7 @@ void printHelp(void) { std::cout << "This program expects a single argument, which is either:" << std::endl; std::cout << " 1. An input file/script, with format given below, or" << std::endl; std::cout << " 2. \"-i\", to run interactively, where you can interactively enter commands and see results." << std::endl; + std::cout << " 3. \"-t\", to run a test function that is specified in the sketch file." << std::endl; std::cout << "\nIn either case, for each scan cycle you will specify zero or more input 'commands', that is," << std::endl; std::cout << " actions to take on the keys of the virtual keyboard. Each line of the input file, or each" << std::endl; std::cout << " prompt (in interactive mode), represents one scan cycle; a blank line or empty prompt means" << std::endl; diff --git a/virtual/cores/virtual/virtual_io.h b/virtual/cores/virtual/virtual_io.h index 848cbb1..605aa74 100644 --- a/virtual/cores/virtual/virtual_io.h +++ b/virtual/cores/virtual/virtual_io.h @@ -10,6 +10,7 @@ bool initVirtualInput(int argc, char* argv[]); std::string getLineOfInput(bool anythingHeld); bool isInteractive(void); +bool testFunctionExecutionRequested(); void printHelp(void); unsigned currentCycle(void); // current cycle number, first cycle is 0