Skip to content
This repository was archived by the owner on Feb 6, 2022. It is now read-only.

Commit 6adc608

Browse files
committed
fix: Use limits from cacos.toml
1 parent d2039fa commit 6adc608

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

include/cacos/task/opts.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "cacos/util/util.h"
44

5+
#include "cacos/process/limits.h"
6+
57
#include <string_view>
68
#include <vector>
79

@@ -47,6 +49,7 @@ struct ExeOpts {
4749

4850
struct TaskOpts {
4951
ExeOpts exe;
52+
process::Limits limits;
5053
};
5154

5255
} // namespace cacos::opts

src/config/config.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,16 @@ void Config::parseConfig() {
366366
if (auto node = taskConfig_->get_qualified_as<std::string>("exe.build")) {
367367
task_.exe.compiler.buildType = opts::parseBuildType(*node);
368368
}
369+
370+
/* limits */
371+
if (auto node = taskConfig_->get_qualified_as<double>("limits.time")) {
372+
task_.limits.cpu = seconds{*node};
373+
task_.limits.real = seconds{*node};
374+
}
375+
if (auto node = taskConfig_->get_qualified_as<double>("limits.memory")) {
376+
static constexpr bytes MIBYTE = 1024 * 1024;
377+
task_.limits.ml = *node * MIBYTE;
378+
}
369379
}
370380
}
371381

src/test/run/run.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ int run(int argc, const char* argv[]) {
7676
.description("Test name to run (name prefix) [default = \"\"]")
7777
.store(prefix);
7878

79-
RunOpts runOpts;
79+
RunOpts runOpts{
80+
cfg.task().limits
81+
};
82+
8083
parser.add("stats").optional().no_argument().description("Print run stats").handle([&](auto) {
8184
runOpts.printInfo = true;
8285
});
@@ -91,17 +94,15 @@ int run(int argc, const char* argv[]) {
9194
.optional()
9295
.value_type("SECONDS")
9396
.description("Time limit")
94-
.default_value(1.0)
9597
.handle<double>([&](double s) {
9698
runOpts.limits.cpu = seconds(s);
97-
runOpts.limits.real = seconds(s) * 2;
99+
runOpts.limits.real = seconds(s);
98100
});
99101

100102
parser.add("ml")
101103
.optional()
102104
.value_type("MiB")
103105
.description("Memory limit")
104-
.default_value(64.0)
105106
.handle<double>(
106107
[&](double ram) { runOpts.limits.ml = static_cast<bytes>(ram * 1024. * 1024.); });
107108

0 commit comments

Comments
 (0)