-
Notifications
You must be signed in to change notification settings - Fork 2
/
kovantestwindow.cpp
324 lines (260 loc) · 7.48 KB
/
kovantestwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include <QDebug>
#include <QScrollBar>
#include <QCleanlooksStyle>
#include <QStyle>
#include <QFile>
#include <QDir>
#include "kovantestwindow.h"
#include "ui_kovantestwindow.h"
class BiggerScrollbar : public QCleanlooksStyle {
public:
int pixelMetric(PixelMetric metric, const QStyleOption *, const QWidget *pWidget = 0) const
{
if ( metric == PM_ScrollBarExtent )
{
return 50;
}
return QWindowsStyle::pixelMetric( metric, 0, pWidget );
}
};
KovanTestWindow::KovanTestWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::KovanTestWindow)
{
QApplication::setStyle(new BiggerScrollbar);
ui->setupUi(this);
// Start on the "Start Screen"
ui->startScreen->setVisible(true);
ui->mainScreen->setVisible(false);
ui->debugScreen->setVisible(false);
ui->debugActiveLabel->setVisible(false);
ui->selectTestButton->setVisible(false);
ui->startTestsButton->setVisible(false);
ui->lookingForUSBLabel->setVisible(true);
#ifdef linux
showFullScreen();
#endif
engine = new KovanTestEngine(this);
engine->loadAllTests();
// Wire up all start-screen UI buttons
connect(ui->startTestsButton, SIGNAL(clicked(bool)),
this, SLOT(startTests()));
connect(ui->debugMode1, SIGNAL(clicked(bool)),
this, SLOT(debugMode1Clicked()));
connect(ui->debugMode2, SIGNAL(clicked(bool)),
this, SLOT(debugMode2Clicked()));
connect(ui->debugMode3, SIGNAL(clicked(bool)),
this, SLOT(debugMode3Clicked()));
connect(ui->runSelectedTestsButton, SIGNAL(clicked()),
this, SLOT(debugRunSelectedItems()));
connect(ui->testSelectionButton, SIGNAL(clicked()),
this, SLOT(moveToDebugScreen()));
// Print out the serial number to the screen
serialLabelString.sprintf("Serial number: %s",
(const char *)(engine->serialNumber().toAscii()));
ui->serialLabel->setText(serialLabelString);
// Start the secret debug code at stage 0
sequencePosition = 0;
openLogFile();
ui->startTestsButton->setVisible(true);
ui->lookingForUSBLabel->setVisible(false);
}
void KovanTestWindow::openLogFile()
{
#ifdef linux
QString mountPoint;
while (1) {
qApp->processEvents();
QFile mounts("/proc/mounts");
QString line;
mounts.open(QIODevice::ReadOnly | QIODevice::Text);
for (line = mounts.readLine();
!line.isNull();
line = mounts.readLine()) {
if (!line.contains("/media/sd"))
continue;
QString testDirectory;
QString testFile;
QString serial = engine->serialNumber();
QFile currentFile;
mountPoint = line.split(' ')[1];
QDir currentDir(mountPoint);
qDebug() << "Current dir (mountPoint):" << currentDir.path();
testDirectory = "kovan-logs/";
testDirectory.append(serial.split('-')[0]);
if (!currentDir.mkpath(testDirectory)) {
qDebug() << "Unable to make directory";
continue;
}
testFile = testDirectory;
testFile.append("/");
testFile.append(serial);
testFile.append(".html");
logFile.setFileName(currentDir.absoluteFilePath(testFile));
if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
qDebug() << "Unable to create logfile" << logFile.fileName();
continue;
}
logFile.write("<p>Started a new test\n");
logFile.flush();
return;
}
}
#endif
return;
}
void KovanTestWindow::debugItemPressed(QListWidgetItem *)
{
if (ui->testListWidget->selectedItems().count())
ui->runSelectedTestsButton->setEnabled(true);
else
ui->runSelectedTestsButton->setEnabled(false);
}
void KovanTestWindow::debugRunSelectedItems()
{
QList<QListWidgetItem *>selected = ui->testListWidget->selectedItems();
QList<KovanTest *>testsToRun;
int i;
for (i=0; i<selected.count(); i++) {
QVariant v = selected.at(i)->data(Qt::UserRole);
KovanTest *t = reinterpret_cast<KovanTest*>(v.value<void*>());
testsToRun.append(t);
}
moveToMainScreen();
engine->runSelectedTests(testsToRun);
}
void KovanTestWindow::debugMode1Clicked()
{
advanceDebugSequence('1');
}
void KovanTestWindow::debugMode2Clicked()
{
advanceDebugSequence('2');
}
void KovanTestWindow::debugMode3Clicked()
{
advanceDebugSequence('3');
}
void KovanTestWindow::advanceDebugSequence(const char c)
{
if (SEQUENCE[sequencePosition] == c)
sequencePosition++;
else if (SEQUENCE[0] == c)
sequencePosition = 1;
else
sequencePosition = 0;
if (sequencePosition >= sizeof(SEQUENCE)-1)
moveToDebugScreen();
}
void KovanTestWindow::moveToDebugScreen()
{
ui->debugActiveLabel->setVisible(true);
ui->selectTestButton->setVisible(true);
ui->debugMode1->setVisible(false);
ui->debugMode2->setVisible(false);
ui->debugMode3->setVisible(false);
ui->testSelectionButton->setVisible(false);
ui->errorFailLabel->setVisible(false);
ui->errorLabel->setVisible(false);
ui->passLabel->setVisible(false);
ui->runSelectedTestsButton->setEnabled(false);
sequencePosition = 0;
engine->setDebug(true);
ui->startScreen->setVisible(false);
ui->debugScreen->setVisible(true);
QList<KovanTest *>tests = engine->allTests();
int i;
ui->testListWidget->clear();
for (i=0; i<tests.count(); i++) {
QListWidgetItem *item = new QListWidgetItem(*(tests.at(i)->testName()));
QVariant v = QVariant::fromValue<void*>(tests.at(i));
item->setData(Qt::UserRole, v);
item->setSizeHint(QSize(320,30));
ui->testListWidget->addItem(item);
connect(ui->testListWidget, SIGNAL(itemPressed(QListWidgetItem *)),
this, SLOT(debugItemPressed(QListWidgetItem *)));
}
ui->testListWidget->setDragDropMode(QAbstractItemView::NoDragDrop);
}
void KovanTestWindow::moveToMainScreen()
{
ui->errorLabel->setVisible(false);
ui->errorFailLabel->setVisible(false);
ui->passLabel->setVisible(false);
ui->testSelectionButton->setVisible(false);
ui->progressBar->setVisible(true);
ui->progressLabel->setVisible(true);
ui->mainScreen->setVisible(true);
ui->debugScreen->setVisible(false);
ui->startScreen->setVisible(false);
QString str("");
addTestLog(str);
QScrollBar *vert = ui->testLog->verticalScrollBar();
vert->setValue(vert->maximum());
}
void KovanTestWindow::startTests()
{
if (!logFile.isOpen()) {
logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
logFile.write("<p>Restarted test\n");
logFile.flush();
}
moveToMainScreen();
engine->runAllTests();
}
void KovanTestWindow::setStatusText(QString *message)
{
ui->statusLabel->setText(*message);
return;
}
void KovanTestWindow::setProgressBar(double progress)
{
ui->progressBar->setValue(progress*100);
return;
}
void KovanTestWindow::setProgressText(QString &message)
{
ui->progressLabel->setText(message);
}
void KovanTestWindow::setErrorString(QString &message)
{
errorString = message;
ui->errorLabel->setText(errorString);
}
void KovanTestWindow::finishTests(bool successful)
{
ui->progressLabel->setVisible(false);
ui->progressBar->setVisible(false);
if (successful) {
ui->passLabel->setVisible(true);
logFile.write("<p><font color=\"green\">PASS</font>\n");
}
else {
ui->errorLabel->setVisible(true);
ui->errorFailLabel->setVisible(true);
logFile.write("<p><font color=\"red\">FAIL</font>\n");
}
if (engine->debugModeOn()) {
ui->testSelectionButton->setVisible(true);
}
logFile.close();
}
void KovanTestWindow::addTestLog(QString &message)
{
QScrollBar *vert = ui->testLog->verticalScrollBar();
bool shouldScroll = false;
if (vert->value() == vert->maximum())
shouldScroll = true;
ui->testLog->appendHtml(message);
if (shouldScroll)
vert->setValue(vert->maximum());
if (logFile.isOpen()) {
logFile.write(message.toUtf8());
logFile.write("\n");
logFile.flush();
}
}
KovanTestWindow::~KovanTestWindow()
{
delete ui;
}