Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/autotester/autotester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,37 @@ static char* myrealpath(const char* file_name)
#endif
}

static void dumpScreenshot(const std::string& description)
{
std::string safe_name = description;
for (char& c : safe_name) {
if (c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' || c == '|') {
c = '_';
}
}

std::string path = safe_name + ".rgba";

uint32_t *frame = static_cast<uint32_t*>(malloc(LCD_SIZE * sizeof(uint32_t)));
if (!frame) {
std::cerr << "\t[Screenshot] Failed to allocate frame buffer" << std::endl;
return;
}

cemucore::emu_lcd_drawframe(frame);

FILE *f = fopen(path.c_str(), "wb");
if (f) {
fwrite(frame, sizeof(uint32_t), LCD_SIZE, f);
fclose(f);
std::cout << "\t[Screenshot] Saved " << path << std::endl;
} else {
std::cerr << "\t[Screenshot] Failed to write " << path << std::endl;
}

free(frame);
}

namespace autotester
{

Expand All @@ -54,6 +85,7 @@ config_t config;
std::string oldCWD;

bool debugMode = true;
bool screenshotsMode = false;
bool ignoreROMfield = false;
bool configLoaded = false;

Expand Down Expand Up @@ -217,6 +249,9 @@ static const std::unordered_map<std::string, seq_cmd_func_t> valid_seq_commands
::free(temp_buffer_dup);
}
hashesTested++;
if (screenshotsMode) {
dumpScreenshot(param.description);
}
} else {
std::cerr << "\t[Error] hash #" << which_hash << " was not declared in the JSON file. Ignoring." << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/autotester/autotester.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
{ "cursorImage", 0xE30800 }, { "cursorImage_size", 1024 }
};

static const char* varExtensions[] = {

Check warning on line 76 in tests/autotester/autotester.h

View workflow job for this annotation

GitHub Actions / Build: ubuntu-22.04 - x64

‘autotester::varExtensions’ defined but not used [-Wunused-variable]

Check warning on line 76 in tests/autotester/autotester.h

View workflow job for this annotation

GitHub Actions / Build: ubuntu-22.04 - x64-Dynamic

‘autotester::varExtensions’ defined but not used [-Wunused-variable]

Check warning on line 76 in tests/autotester/autotester.h

View workflow job for this annotation

GitHub Actions / Build: ubuntu-22.04 - x64-Dynamic

‘autotester::varExtensions’ defined but not used [-Wunused-variable]

Check warning on line 76 in tests/autotester/autotester.h

View workflow job for this annotation

GitHub Actions / Build: ubuntu-22.04 - x64

‘autotester::varExtensions’ defined but not used [-Wunused-variable]
"8xn", // 00
"8xl",
"8xm",
Expand Down Expand Up @@ -135,6 +135,7 @@
extern config_t config;

extern bool debugMode;
extern bool screenshotsMode;
extern bool ignoreROMfield;
extern bool configLoaded;

Expand All @@ -147,4 +148,3 @@
}

#endif

30 changes: 19 additions & 11 deletions tests/autotester/autotester_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,29 @@ int main(int argc, char* argv[])
// Used if the coreThread has been started (need to exit properly ; uses gotos)
int retVal = 0;

if (argc < 2)
{
std::cerr << "[Error] Needs a path argument, the test config JSON file" << std::endl;
return -1;
autotester::debugMode = false;
autotester::screenshotsMode = false;
int argi = 1;
while (argi < argc && argv[argi][0] == '-') {
if (strcmp(argv[argi], "-d") == 0) {
autotester::debugMode = true;
} else if (strcmp(argv[argi], "-s") == 0 || strcmp(argv[argi], "--screenshots") == 0) {
autotester::screenshotsMode = true;
} else {
std::cerr << "[Error] Unknown option: " << argv[argi] << std::endl;
std::cerr << "Usage: autotester [-d] [-s|--screenshots] <config.json>" << std::endl;
return -1;
}
argi++;
}

if (strcmp(argv[1], "-d") == 0)
{
autotester::debugMode = true;
argv++;
} else {
autotester::debugMode = false;
if (argi >= argc) {
std::cerr << "[Error] Needs a path argument, the test config JSON file" << std::endl;
std::cerr << "Usage: autotester [-d] [-s|--screenshots] <config.json>" << std::endl;
return -1;
}

const std::string jsonPath(argv[1]);
const std::string jsonPath(argv[argi]);
std::string jsonContents;
std::ifstream ifs(jsonPath);
if (ifs.good())
Expand Down
Loading