Skip to content

Commit b358957

Browse files
committed
[Autotester] Multiple improvements, see commit message
- Reset the config struct each time we load a JSON config - Correctly handle numbers in sendLetterKeyPress(...) - DO_STEP_CALLBACK() to call a custom function after each action (useful for GUI) - configLoaded boolean for checks
1 parent bdbfe2d commit b358957

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

tests/autotester/autotester.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ namespace autotester
2727
/* The global config variable */
2828
config_t config;
2929

30+
bool configLoaded = false;
31+
void (*stepCallback)(void) = nullptr;
32+
33+
#define DO_STEP_CALLBACK() if (stepCallback) { stepCallback(); }
34+
3035
/* Will be incremented in case of matching CRC */
3136
unsigned int hashesPassed = 0;
3237
/* Will be incremented in case of non-matching CRC, and used as the return value */
@@ -63,13 +68,15 @@ void sendKey(uint16_t key)
6368
cemucore::mem_poke_byte(0xD0009F, (uint8_t)(cemucore::mem_peek_byte(0xD0009F) | 0x20)); // TODO: name 0xD0009F (= flags+graphFlags2 = 0xD00080+0x1F)
6469

6570
std::this_thread::sleep_for(std::chrono::milliseconds(100));
71+
DO_STEP_CALLBACK();
6672
}
6773

6874
void sendLetterKeyPress(char letter)
6975
{
7076
uint16_t val;
7177
if (letter != '@') { // @ is actually theta (replaced earlier)
72-
val = (uint16_t)(0x9A + letter - 'A');
78+
// Handles A-Z and 0-9
79+
val = (uint16_t)((letter >= 'A' && letter <= 'Z') ? (0x9A + letter - 'A') : (0x8E + letter - '0'));
7380
} else {
7481
val = 0xCC; // theta
7582
}
@@ -205,6 +212,8 @@ bool loadJSONConfig(const std::string& jsonContents)
205212
return -1;
206213
}
207214

215+
config = config_t();
216+
208217
json11::Json tmp, tmp2;
209218

210219
tmp = configJson["rom"];
@@ -397,6 +406,7 @@ bool loadJSONConfig(const std::string& jsonContents)
397406
return false;
398407
}
399408

409+
configLoaded = true;
400410
return true;
401411
}
402412

@@ -410,6 +420,7 @@ bool sendFilesForTest()
410420
std::cerr << "[Error] File couldn't be sent" << std::endl;
411421
return false;
412422
}
423+
DO_STEP_CALLBACK();
413424
std::this_thread::sleep_for(std::chrono::milliseconds(150));
414425
}
415426
return true;
@@ -423,6 +434,7 @@ bool doTestSequence()
423434
if (!launchCommand(command)) {
424435
return false;
425436
}
437+
DO_STEP_CALLBACK();
426438
std::this_thread::sleep_for(std::chrono::milliseconds(100));
427439
}
428440
return true;

tests/autotester/autotester.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ namespace autotester
7070

7171
bool doTestSequence();
7272

73+
/* Optional callback function called after each step (useful for GUIs) */
74+
extern void (*stepCallback)(void);
75+
7376
/* The global config variable */
7477
extern config_t config;
7578

79+
extern bool configLoaded;
80+
7681
/* Will be incremented in case of matching CRC */
7782
extern unsigned int hashesPassed;
7883
/* Will be incremented in case of non-matching CRC, and used as the return value */

tests/autotester/test_graphc_example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"demo1.8xp"
77
],
88
"target": {
9-
"name": "DEMO1",
9+
"name": "PROG01",
1010
"isASM": false
1111
},
1212
"sequence": [

0 commit comments

Comments
 (0)