Added optional execution of a testing function.
Through a command line parameter, the virtual firmware executable can be instructed to execute a testing function instead of processing stdin/stdout I/O. This can be used to attach an external testing interface. Signed-off-by: Florian Fleissner <florian.fleissner@inpartik.de>
This commit is contained in:
parent
cc38d157ae
commit
61ac4a1586
@ -29,6 +29,12 @@ void initVariant() { }
|
|||||||
void setupUSB() __attribute__((weak));
|
void setupUSB() __attribute__((weak));
|
||||||
void setupUSB() { }
|
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) {
|
void init(void) {
|
||||||
// Arduino core does some device-related setup here.
|
// Arduino core does some device-related setup here.
|
||||||
// We don't need to do anything.
|
// We don't need to do anything.
|
||||||
@ -37,6 +43,13 @@ void init(void) {
|
|||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if (!initVirtualInput(argc, argv)) return 1;
|
if (!initVirtualInput(argc, argv)) return 1;
|
||||||
|
|
||||||
|
if(testFunctionExecutionRequested()) {
|
||||||
|
if(executeTestFunction) {
|
||||||
|
executeTestFunction();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
initVariant();
|
initVariant();
|
||||||
|
|
||||||
@ -51,4 +64,3 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
#include <sys/stat.h> // mkdir()
|
#include <sys/stat.h> // mkdir()
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static bool interactive;
|
static bool interactive = false;
|
||||||
|
static bool test_function = false;
|
||||||
static std::istream* input = NULL;
|
static std::istream* input = NULL;
|
||||||
static std::ostream* usbstream = NULL;
|
static std::ostream* usbstream = NULL;
|
||||||
static std::ostream* ledstream = NULL;
|
static std::ostream* ledstream = NULL;
|
||||||
@ -18,6 +19,10 @@ bool isInteractive(void) {
|
|||||||
return interactive;
|
return interactive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool testFunctionExecutionRequested() {
|
||||||
|
return test_function;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned currentCycle(void) {
|
unsigned currentCycle(void) {
|
||||||
return cycle;
|
return cycle;
|
||||||
}
|
}
|
||||||
@ -58,6 +63,8 @@ bool initVirtualInput(int argc, char* argv[]) {
|
|||||||
if (strcmp(argv[1], "-i") == 0) {
|
if (strcmp(argv[1], "-i") == 0) {
|
||||||
interactive = true;
|
interactive = true;
|
||||||
input = &std::cin;
|
input = &std::cin;
|
||||||
|
} else if(strcmp(argv[1], "-t") == 0) {
|
||||||
|
test_function = true;
|
||||||
} else {
|
} else {
|
||||||
interactive = false;
|
interactive = false;
|
||||||
input = new std::ifstream(argv[1]);
|
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 << "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 << " 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 << " 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 << "\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 << " 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;
|
std::cout << " prompt (in interactive mode), represents one scan cycle; a blank line or empty prompt means" << std::endl;
|
||||||
|
@ -10,6 +10,7 @@ bool initVirtualInput(int argc, char* argv[]);
|
|||||||
|
|
||||||
std::string getLineOfInput(bool anythingHeld);
|
std::string getLineOfInput(bool anythingHeld);
|
||||||
bool isInteractive(void);
|
bool isInteractive(void);
|
||||||
|
bool testFunctionExecutionRequested();
|
||||||
void printHelp(void);
|
void printHelp(void);
|
||||||
|
|
||||||
unsigned currentCycle(void); // current cycle number, first cycle is 0
|
unsigned currentCycle(void); // current cycle number, first cycle is 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user