Skip to content

Commit 46edc9f

Browse files
committed
Started to integrate the Autotester in the Qt GUI
Loading and launching a JSON config works :)
1 parent b358957 commit 46edc9f

File tree

6 files changed

+590
-23
lines changed

6 files changed

+590
-23
lines changed

gui/qt/CEmu.pro

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,19 @@ SOURCES += utils.cpp \
7474
qtkeypadbridge.cpp \
7575
qmlbridge.cpp \
7676
keymap.cpp \
77+
datawidget.cpp \
78+
lcdpopout.cpp \
79+
searchwidget.cpp \
80+
basiccodeviewerwindow.cpp \
7781
qhexedit/chunks.cpp \
7882
qhexedit/commands.cpp \
7983
qhexedit/qhexedit.cpp \
84+
capture/gif.cpp \
8085
tivarslib/utils_tivarslib.cpp \
8186
tivarslib/TypeHandlers/TH_0x00.cpp \
8287
tivarslib/TypeHandlers/TH_0x05.cpp \
88+
autotesterthread.cpp \
89+
../../tests/autotester/autotester.cpp \
8390
../../core/asic.c \
8491
../../core/cpu.c \
8592
../../core/keypad.c \
@@ -100,14 +107,9 @@ SOURCES += utils.cpp \
100107
../../core/mem.c \
101108
../../core/link.c \
102109
../../core/vat.c \
110+
../../core/emu.c \
103111
../../core/debug/disasm.cpp \
104112
../../core/debug/debug.c \
105-
../../core/emu.c \
106-
capture/gif.cpp \
107-
datawidget.cpp \
108-
lcdpopout.cpp \
109-
searchwidget.cpp \
110-
basiccodeviewerwindow.cpp \
111113
../../core/debug/stepping.cpp
112114

113115
linux|macx|ios: SOURCES += ../../core/os/os-linux.c
@@ -122,9 +124,15 @@ HEADERS += utils.h \
122124
qtkeypadbridge.h \
123125
qmlbridge.h \
124126
keymap.h \
127+
datawidget.h \
128+
lcdpopout.h \
129+
searchwidget.h \
130+
basiccodeviewerwindow.h \
125131
qhexedit/chunks.h \
126132
qhexedit/commands.h \
127133
qhexedit/qhexedit.h \
134+
capture/gif.h \
135+
capture/giflib.h \
128136
tivarslib/autoloader.h \
129137
tivarslib/utils_tivarslib.h \
130138
tivarslib/TypeHandlers/TypeHandlerFuncGetter.h \
@@ -134,6 +142,8 @@ HEADERS += utils.h \
134142
tivarslib/TypeHandlers/TH_0x04.h \
135143
tivarslib/TypeHandlers/TH_0x05.h \
136144
tivarslib/TypeHandlers/TH_0x06.h \
145+
autotesterthread.h \
146+
../../tests/autotester/autotester.h \
137147
../../core/asic.h \
138148
../../core/cpu.h \
139149
../../core/defines.h \
@@ -157,15 +167,9 @@ HEADERS += utils.h \
157167
../../core/mem.h \
158168
../../core/link.h \
159169
../../core/vat.h \
170+
../../core/os/os.h \
160171
../../core/debug/debug.h \
161172
../../core/debug/disasm.h \
162-
../../core/os/os.h \
163-
capture/gif.h \
164-
capture/giflib.h \
165-
datawidget.h \
166-
lcdpopout.h \
167-
searchwidget.h \
168-
basiccodeviewerwindow.h \
169173
../../core/debug/stepping.h
170174

171175
FORMS += mainwindow.ui \

gui/qt/autotesterthread.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "autotesterthread.h"
2+
3+
#include "../../tests/autotester/autotester.h"
4+
5+
AutotesterThread *autotester_thread;
6+
7+
AutotesterThread::AutotesterThread(QObject *parent) : QThread(parent)
8+
{
9+
autotester_thread = this;
10+
}
11+
12+
void AutotesterThread::launchActualTest()
13+
{
14+
if (!autotester::configLoaded) {
15+
emit testError(-1);
16+
return;
17+
}
18+
19+
// Files are sent from the Qt part before that
20+
21+
// Follow the sequence
22+
if (!autotester::doTestSequence()) {
23+
emit testError(1);
24+
return;
25+
}
26+
}

gui/qt/autotesterthread.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef AUTOTESTERTHREAD_H
2+
#define AUTOTESTERTHREAD_H
3+
4+
#include <QtCore/QThread>
5+
6+
class AutotesterThread : public QThread
7+
{
8+
Q_OBJECT
9+
public:
10+
explicit AutotesterThread(QObject *parent = 0);
11+
void launchActualTest();
12+
13+
signals:
14+
void testError(int errCode);
15+
16+
};
17+
18+
// For friends
19+
extern AutotesterThread *autotester_thread;
20+
21+
#endif

gui/qt/mainwindow.cpp

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2015
1+
/* Copyright (C) 2015-2016
22
* Parts derived from Firebird by Fabian Vogt
33
*
44
* This program is free software: you can redistribute it and/or modify
@@ -26,6 +26,7 @@
2626
#include <QtGui/QPixmap>
2727

2828
#include <fstream>
29+
#include <unistd.h>
2930

3031
#include "mainwindow.h"
3132
#include "ui_mainwindow.h"
@@ -46,6 +47,10 @@
4647
#include "../../core/link.h"
4748
#include "../../core/os/os.h"
4849

50+
#include "../../tests/autotester/autotester.h"
51+
#include "autotesterthread.h"
52+
53+
4954
static const constexpr int WindowStateVersion = 0;
5055

5156
MainWindow::MainWindow(QWidget *p) : QMainWindow(p), ui(new Ui::MainWindow) {
@@ -124,6 +129,12 @@ MainWindow::MainWindow(QWidget *p) : QMainWindow(p), ui(new Ui::MainWindow) {
124129
connect(this, &MainWindow::setReceiveState, &emu, &EmuThread::setReceiveState);
125130
connect(ui->buttonReceiveFiles, &QPushButton::clicked, this, &MainWindow::saveSelected);
126131

132+
// Autotester
133+
connect(&tester, &AutotesterThread::testError, this, &MainWindow::dispAutotesterError, Qt::QueuedConnection);
134+
connect(ui->buttonOpenJSONconfig, &QPushButton::clicked, this, &MainWindow::prepareAndOpenJSONConfig);
135+
connect(ui->buttonReloadJSONconfig, &QPushButton::clicked, this, &MainWindow::reloadJSONConfig);
136+
connect(ui->buttonLaunchTest, &QPushButton::clicked, this, &MainWindow::launchTest);
137+
127138
// Toolbar Actions
128139
connect(ui->actionSetup, &QAction::triggered, this, &MainWindow::runSetup);
129140
connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close);
@@ -224,6 +235,8 @@ MainWindow::MainWindow(QWidget *p) : QMainWindow(p), ui(new Ui::MainWindow) {
224235
setAcceptDrops(true);
225236
debuggerOn = false;
226237

238+
autotester::stepCallback = []() { QApplication::processEvents(); };
239+
227240
settings = new QSettings(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/CEmu/cemu_config.ini"), QSettings::IniFormat);
228241

229242
#ifdef _WIN32
@@ -1064,6 +1077,105 @@ void MainWindow::saveSelected() {
10641077
}
10651078
}
10661079

1080+
/* ================================================ */
1081+
/* Autotester Things */
1082+
/* ================================================ */
1083+
1084+
void MainWindow::dispAutotesterError(int errCode) {
1085+
QString errMsg;
1086+
switch (errCode) {
1087+
case -1:
1088+
errMsg = tr("Error. No config loaded");
1089+
break;
1090+
case 1:
1091+
errMsg = tr("Error. Couldn't follow the test sequence defined in the configuration");
1092+
break;
1093+
default:
1094+
errMsg = tr("Error. Unknown one - wat?");
1095+
break;
1096+
}
1097+
QMessageBox::warning(this, tr("Autotester error"), errMsg);
1098+
}
1099+
1100+
1101+
void MainWindow::openJSONConfig(const QString& jsonPath) {
1102+
std::string jsonContents;
1103+
std::ifstream ifs(jsonPath.toStdString());
1104+
if (ifs.good())
1105+
{
1106+
ui->buttonReloadJSONconfig->setEnabled(true);
1107+
chdir(QDir::toNativeSeparators(QFileInfo(jsonPath).absoluteDir().path()).toStdString().c_str());
1108+
std::getline(ifs, jsonContents, '\0');
1109+
if (!ifs.eof()) {
1110+
QMessageBox::warning(this, tr("File error"), tr("Couldn't read JSON file."));
1111+
return;
1112+
}
1113+
} else {
1114+
ui->buttonReloadJSONconfig->setEnabled(false);
1115+
QMessageBox::warning(this, tr("Opening error"), tr("Unable to open the file."));
1116+
return;
1117+
}
1118+
1119+
if (autotester::loadJSONConfig(jsonContents))
1120+
{
1121+
ui->JSONconfigPath->setText(jsonPath);
1122+
ui->buttonLaunchTest->setEnabled(true);
1123+
std::cout << "[OK] Test config loaded and verified. " << autotester::config.hashes.size() << " unique tests found." << std::endl;
1124+
} else {
1125+
QMessageBox::warning(this, tr("JSON format error"), tr("Error. See the test config file format and make sure values are correct and referenced files are there."));
1126+
return;
1127+
}
1128+
}
1129+
1130+
void MainWindow::prepareAndOpenJSONConfig() {
1131+
QFileDialog dialog(this);
1132+
1133+
ui->buttonLaunchTest->setEnabled(false);
1134+
1135+
dialog.setDirectory(QDir::homePath());
1136+
dialog.setFileMode(QFileDialog::ExistingFile);
1137+
dialog.setNameFilter(QStringLiteral("JSON config (*.json)"));
1138+
if (!dialog.exec()) {
1139+
return;
1140+
}
1141+
1142+
openJSONConfig(dialog.selectedFiles().at(0));
1143+
}
1144+
1145+
void MainWindow::reloadJSONConfig() {
1146+
openJSONConfig(ui->JSONconfigPath->text());
1147+
}
1148+
1149+
void MainWindow::launchTest() {
1150+
if (!autotester::configLoaded) {
1151+
dispAutotesterError(-1);
1152+
return;
1153+
}
1154+
1155+
if (ui->checkBoxTestReset->isChecked()) {
1156+
resetCalculator();
1157+
QThread::msleep(1000);
1158+
}
1159+
1160+
if (ui->checkBoxTestClear->isChecked()) {
1161+
// Clear home screen
1162+
autotester::sendKey(0x09);
1163+
}
1164+
1165+
QStringList filesList;
1166+
for (const auto& file : autotester::config.transfer_files) {
1167+
filesList << QString::fromStdString(file);
1168+
}
1169+
sendFiles(filesList);
1170+
QThread::msleep(200);
1171+
1172+
autotester_thread->launchActualTest();
1173+
}
1174+
1175+
/* ================================================ */
1176+
/* Debugger Things */
1177+
/* ================================================ */
1178+
10671179
void MainWindow::setFont(int fontSize) {
10681180
ui->textSizeSlider->setValue(fontSize);
10691181
settings->setValue(QStringLiteral("textSize"), ui->textSizeSlider->value());
@@ -1100,10 +1212,6 @@ void MainWindow::setFont(int fontSize) {
11001212
ui->lcdcurrView->setFont(monospace);
11011213
}
11021214

1103-
/* ================================================ */
1104-
/* Debugger Things */
1105-
/* ================================================ */
1106-
11071215
static int hex2int(QString str) {
11081216
return std::stoi(str.toStdString(), nullptr, 16);
11091217
}

gui/qt/mainwindow.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "lcdwidget.h"
1313
#include "romselection.h"
1414
#include "emuthread.h"
15+
#include "autotesterthread.h"
1516
#include "../../core/vat.h"
1617
#include "../../core/debug/debug.h"
1718
#include "../../core/debug/disasm.h"
@@ -168,6 +169,13 @@ public slots:
168169
void variableClicked(QTableWidgetItem*);
169170
void saveSelected();
170171

172+
// Autotester
173+
void dispAutotesterError(int errCode);
174+
void openJSONConfig(const QString& jsonPath);
175+
void prepareAndOpenJSONConfig();
176+
void reloadJSONConfig();
177+
void launchTest();
178+
171179
// Hex Editor
172180
void flashUpdate();
173181
void flashGotoPressed();
@@ -219,6 +227,7 @@ public slots:
219227
QDir currentDir;
220228
QString currentEquateFile;
221229
EmuThread emu;
230+
AutotesterThread tester;
222231

223232
bool debuggerOn = false;
224233
bool inReceivingMode = false;

0 commit comments

Comments
 (0)