Skip to content

Commit 78c6780

Browse files
committed
Merge remote-tracking branch 'origin/master' into int64-for-used-memory
2 parents 5e4eeb1 + bce62d1 commit 78c6780

30 files changed

Lines changed: 1219 additions & 30 deletions

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ if(ENABLE_LTO)
308308
endif()
309309
endif()
310310

311+
# ==================================================================================
312+
# Tests
313+
# ==================================================================================
314+
315+
enable_testing()
316+
add_subdirectory(tests)
317+
311318
# ==================================================================================
312319
# Platform-dependent installation process and deployment
313320
# ==================================================================================

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A tiny judging environment for OI contest based on Lemon + LemonPlus
88

9-
需要 Qt 6.8 或更高版本(可通过 `-DLEMON_QT_MAJOR_VERSION=<6|7>` 选择对应 Qt 主版本)
9+
需要 Qt 6.8 或更高版本。
1010

1111
现已支持 Linux,Windows 以及 macOS
1212

src/core/contest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ int Contest::readFromJson(const QJsonObject &in) {
277277
QJsonArray tasks;
278278
READ_JSON(in, tasks);
279279

280+
// NOTE: taskList and contestantList are empty here because readFromJson is
281+
// only ever called once on a freshly constructed Contest (immediately after
282+
// construction, before any tasks or contestants are added). If this invariant
283+
// ever changes, qDeleteAll() must be called before clear() to avoid leaks.
280284
taskList.clear();
281285
for (const auto &task : tasks) {
282286
Task *newTask = new Task();
@@ -288,6 +292,7 @@ int Contest::readFromJson(const QJsonObject &in) {
288292
QJsonArray contestants;
289293
READ_JSON(in, contestants);
290294

295+
// See note above: contestantList is also empty at this point.
291296
contestantList.clear();
292297
for (const auto &contestant : contestants) {
293298
auto *newContestant = new Contestant();

src/core/judgesharedvariables.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/core/judgingthread.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
//
1212

1313
#include "base/LemonType.hpp"
14+
#include "processrunner.h"
1415
#include <QProcessEnvironment>
1516
#include <QThread>
17+
#include <atomic>
1618

1719
class Task;
1820

@@ -75,15 +77,15 @@ class JudgingThread : public QThread {
7577
int judgedTimes;
7678
ResultState result;
7779
QString message;
78-
bool stopJudging;
80+
std::atomic<bool> stopJudging{false};
7981
bool interpreterAsWatcher{};
8082
void compareLineByLine(const QString &);
8183
void compareIgnoreSpaces(const QString &);
8284
void compareWithDiff(const QString &);
8385
void compareRealNumbers(const QString &);
8486
void lemonSpecialJudge(const QString &);
8587
void testlibSpecialJudge(const QString &);
86-
void runProgram();
88+
8789
void judgeOutput();
8890
void judgeTraditionalTask();
8991
void judgeAnswersOnlyTask();

src/core/processrunner.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2019-2022 Project LemonLime
3+
*
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*
6+
*/
7+
8+
#include "processrunner.h"
9+
10+
#ifdef Q_OS_WIN32
11+
#include "processrunner_win.h"
12+
#else
13+
#include "processrunner_unix.h"
14+
#endif
15+
16+
ProcessRunner::ProcessRunner(ProcessRunnerConfig cfg, const std::atomic<bool> &stop)
17+
: config(std::move(cfg)), stopFlag(stop) {}
18+
19+
auto ProcessRunner::create(ProcessRunnerConfig config,
20+
const std::atomic<bool> &stopFlag) -> std::unique_ptr<ProcessRunner> {
21+
#ifdef Q_OS_WIN32
22+
return std::make_unique<WinProcessRunner>(std::move(config), stopFlag);
23+
#else
24+
return std::make_unique<UnixProcessRunner>(std::move(config), stopFlag);
25+
#endif
26+
}

src/core/processrunner.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2019-2022 Project LemonLime
3+
*
4+
* SPDX-License-Identifier: GPL-3.0-or-later
5+
*
6+
*/
7+
8+
#pragma once
9+
10+
#include "base/LemonType.hpp"
11+
#include <QProcessEnvironment>
12+
#include <QString>
13+
#include <QtGlobal>
14+
#include <atomic>
15+
#include <memory>
16+
17+
struct ProcessRunnerConfig {
18+
QString executableFile;
19+
QString arguments;
20+
QString workingDirectory;
21+
QString inputFile;
22+
QProcessEnvironment environment;
23+
int timeLimit{};
24+
int rawTimeLimit{};
25+
int memoryLimit{};
26+
int rawMemoryLimit{};
27+
double extraTimeRatio{};
28+
bool standardInputCheck{};
29+
bool standardOutputCheck{};
30+
QString inputFileName;
31+
QString outputFileName;
32+
bool interpreterAsWatcher{};
33+
};
34+
35+
struct ProcessRunnerResult {
36+
ResultState result = CorrectAnswer;
37+
int score = 0;
38+
int timeUsed = -1;
39+
int memoryUsed = -1;
40+
QString message;
41+
};
42+
43+
class ProcessRunner {
44+
public:
45+
ProcessRunner(ProcessRunnerConfig config, const std::atomic<bool> &stopFlag);
46+
virtual ~ProcessRunner() = default;
47+
48+
virtual ProcessRunnerResult run() = 0;
49+
50+
static std::unique_ptr<ProcessRunner> create(ProcessRunnerConfig config,
51+
const std::atomic<bool> &stopFlag);
52+
53+
protected:
54+
ProcessRunnerConfig config;
55+
const std::atomic<bool> &stopFlag;
56+
};

0 commit comments

Comments
 (0)