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
24 changes: 24 additions & 0 deletions planning/src/RS/rsOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,45 +203,69 @@ static char* make_file_name(CStr arg) noexcept {
void rsOpts::setFunction(CStr fun) noexcept {
function_ = nullptr;
if (!fun) return;

uint16_t tr = ltrace();

static CStr s_funList[] = {"cmd", // 0
"pinc", // 1
"stars", // 2
"partition", // 3
"pack", // 4
"route", // 5
"shell", // 6
nullptr};
string f = str::s2lower(fun);
if (f.empty()) return;
if (f == "cmd") {
function_ = s_funList[0];
if (tr >= 5)
lprintf("Opts::setFunction: %s\n", function_);
assert(is_fun_cmd());
return;
}
if (f == "pin" or f == "pinc" or f == "pin_c") {
function_ = s_funList[1];
if (tr >= 5)
lprintf("Opts::setFunction: %s\n", function_);
assert(is_fun_pinc());
return;
}
if (f == "sta" or f == "star" or f == "stars") {
function_ = s_funList[2];
if (tr >= 5)
lprintf("Opts::setFunction: %s\n", function_);
assert(is_fun_stars());
return;
}
if (f == "par" or f == "part" or f == "partition") {
function_ = s_funList[3];
if (tr >= 5)
lprintf("Opts::setFunction: %s\n", function_);
assert(is_fun_partition());
return;
}
if (f == "pac" or f == "pack" or f == "packing") {
function_ = s_funList[4];
if (tr >= 5)
lprintf("Opts::setFunction: %s\n", function_);
assert(is_fun_pack());
return;
}
if (f == "rt" or f == "route" or f == "routing") {
function_ = s_funList[5];
if (tr >= 5)
lprintf("Opts::setFunction: %s\n", function_);
assert(is_fun_route());
return;
}
if (f == "sh" or f == "SH" or f == "shell" or
f == "shel" or f == "Shell") {
function_ = s_funList[6];
if (tr >= 5)
lprintf("Opts::setFunction: %s\n", function_);
assert(is_fun_shell());
return;
}
}

bool rsOpts::is_arg0_pinc() const noexcept {
Expand Down
44 changes: 25 additions & 19 deletions planning/src/RS/rsOpts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#define __pln_Opts_H__e91c943c16c2d_

#include "util/pln_log.h"
#include <bitset>

#undef MAX_UNITS

namespace pln {

Expand All @@ -12,30 +15,39 @@ using CStr = const char*;

struct rsOpts {

static constexpr uint MAX_UNITS = 64;

CStr shortVer_ = nullptr;

int argc_ = 0;
const char** argv_ = nullptr;

CStr function_ = nullptr; // {cmd, pinc, stars, partition, pack, route}
CStr function_ = nullptr; // {cmd, pinc, stars, partition, pack, route, shell}
bool have_function() const noexcept { return function_; }
bool function_is(CStr x) const noexcept {
if (!x) return !function_;
return function_ and ::strcmp(function_, x) == 0;
}
bool is_fun_cmd() const noexcept {
return function_ && !strcmp(function_, "cmd");
return function_is("cmd");
}
bool is_fun_pinc() const noexcept {
return function_ && !strcmp(function_, "pinc");
return function_is("pinc");
}
bool is_fun_stars() const noexcept {
return function_ && !strcmp(function_, "stars");
return function_is("stars");
}
bool is_fun_partition() const noexcept {
return function_ && !strcmp(function_, "partition");
return function_is("partition");
}
bool is_fun_pack() const noexcept {
return function_ && !strcmp(function_, "pack");
return function_is("pack");
}
bool is_fun_route() const noexcept {
return function_ && !strcmp(function_, "route");
return function_is("route");
}
bool is_fun_shell() const noexcept {
return function_is("shell");
}
bool is_arg0_pinc() const noexcept;
bool is_implicit_pinc() const noexcept;
Expand Down Expand Up @@ -74,13 +86,7 @@ struct rsOpts {
bool check_ = false;
bool cleanup_ = false;

bool unit1_ = false;
bool unit2_ = false;
bool unit3_ = false;
bool unit4_ = false;
bool unit5_ = false;
bool unit6_ = false;
bool unit7_ = false;
std::bitset<MAX_UNITS> units_;

rsOpts() noexcept = default;
rsOpts(int argc, const char** argv) noexcept { parse(argc, argv); }
Expand All @@ -92,13 +98,13 @@ struct rsOpts {
void print(CStr label = nullptr) const noexcept;
void printHelp() const noexcept;

bool unit_specified() const noexcept {
return unit1_ or unit2_ or unit3_ or unit4_ or unit5_ or unit6_
or unit7_;
}
bool unit_specified() const noexcept { return units_.any(); }

bool ver_or_help() const noexcept { return version_ or det_ver_ or help_; }

bool trace_specified() const noexcept { return traceIndex_ > 0 and trace_ > 0; }
bool trace_specified() const noexcept {
return traceIndex_ > 0 and trace_ > 0;
}
bool test_id_specified() const noexcept { return test_id_ > 0; }

bool set_STA_testCase(int TC_id) noexcept;
Expand Down
69 changes: 46 additions & 23 deletions planning/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const char* _pln_VERSION_STR = "pln0363";
static const char* _pln_VERSION_STR = "pln0364";

#include "RS/rsEnv.h"
#include "util/pln_log.h"
Expand Down Expand Up @@ -470,16 +470,20 @@ static void deal_help(const rsOpts& opts) {
static void deal_units(const rsOpts& opts) {
#ifdef PLN_UNIT_TEST_ON
using namespace tes;
if (opts.unit1_) tes::run_U1();
if (opts.unit2_) tes::run_U2();
if (opts.unit3_) tes::run_U3();
if (opts.unit4_) tes::run_U4();
if (opts.unit5_) tes::run_U5();
if (opts.unit6_) tes::run_U6();
if (opts.unit7_) tes::run_U7();
if (opts.units_[1]) tes::run_U1();
if (opts.units_[2]) tes::run_U2();
if (opts.units_[3]) tes::run_U3();
if (opts.units_[4]) tes::run_U4();
if (opts.units_[5]) tes::run_U5();
if (opts.units_[6]) tes::run_U6();
if (opts.units_[7]) tes::run_U7();
#endif
}

static bool deal_shell(const rsOpts& opts) {
return true;
}

} // NS pln

int main(int argc, char** argv) {
Expand All @@ -503,13 +507,14 @@ int main(int argc, char** argv) {
if (opts.trace_specified())
set_ltrace(opts.trace_);

if (opts.trace_ >= 8 or ltrace() >= 9 or ::getenv("pln_trace_env")) {
uint16_t tr = ltrace();
if (opts.trace_ >= 8 or tr >= 9 or ::getenv("pln_trace_env")) {
s_env.dump("\n----env----\n");
lout() << "-----------" << endl;
}

if (opts.ver_or_help()) {
if (ltrace() >= 2) {
if (tr >= 2) {
printf("\t %s\n", _pln_VERSION_STR);
printf("\t compiled: %s\n", s_env.compTimeCS());
}
Expand All @@ -518,12 +523,12 @@ int main(int argc, char** argv) {
std::quick_exit(0);
}

if (ltrace() >= 2) {
if (tr >= 2) {
lprintf("\t %s\n", _pln_VERSION_STR);
lprintf("\t compiled: %s\n", s_env.compTimeCS());
}
if (ltrace() >= 4) {
lprintf("ltrace()= %u cmd.argc= %i\n", ltrace(), argc);
if (tr >= 4) {
lprintf("ltrace= %u cmd.argc= %i\n", tr, argc);
}

if (opts.unit_specified()) {
Expand Down Expand Up @@ -552,21 +557,21 @@ int main(int argc, char** argv) {
if (opts.is_fun_cmd()) {
ok = deal_cmd(opts);
if (ok) {
if (ltrace() >= 2) lputs("deal_cmd() succeeded.");
if (tr >= 2) lputs("deal_cmd() succeeded.");
status = 0;
} else {
if (ltrace() >= 2) lputs("deal_cmd() failed.");
if (tr >= 2) lputs("deal_cmd() failed.");
}
goto ret;
}

if (opts.is_fun_pinc() or opts.is_arg0_pinc() or opts.is_implicit_pinc()) {
ok = deal_pinc(opts, true);
if (ok) {
if (ltrace() >= 2) lputs("deal_pinc() succeeded.");
if (tr >= 2) lputs("deal_pinc() succeeded.");
status = 0;
} else {
if (ltrace() >= 2) lputs("deal_pinc() failed.");
if (tr >= 2) lputs("deal_pinc() failed.");
}
goto ret;
}
Expand All @@ -575,7 +580,7 @@ int main(int argc, char** argv) {
lputs("======== PARTITION MODE specified ========");
ok = validate_partition_opts(opts);
if (!ok) {
if (ltrace() >= 4) lputs("validate_partition_opts() failed.");
if (tr >= 4) lputs("validate_partition_opts() failed.");
status = 2;
goto ret;
}
Expand All @@ -584,25 +589,43 @@ int main(int argc, char** argv) {
if (opts.is_fun_partition() or opts.is_fun_pack()) {
ok = deal_vpr(opts, true);
if (ok) {
if (ltrace() >= 2) lputs("deal_vpr() succeeded.");
if (tr >= 2) lputs("deal_vpr() succeeded.");
status = 0;
} else {
if (ltrace() >= 2) lputs("deal_vpr() failed.");
if (tr >= 2) lputs("deal_vpr() failed.");
}
goto ret;
}

if (opts.is_fun_shell()) {
lputs("======== SHELL MODE specified ========");
ok = true; // validate_shell_opts(opts);
if (!ok) {
if (tr >= 4) lputs("validate_shell_opts() failed.");
status = 2;
goto ret;
}
ok = deal_shell(opts);
if (ok) {
if (tr >= 2) lputs("deal_shell() succeeded.");
status = 0;
} else {
if (tr >= 2) lputs("deal_shell() failed.");
}
goto ret;
}

// default function is stars
ok = deal_stars(opts, true);
if (ok) {
if (ltrace() >= 2) lputs("deal_stars() succeeded.");
if (tr >= 2) lputs("deal_stars() succeeded.");
status = 0;
} else {
if (ltrace() >= 2) lputs("deal_stars() failed.");
if (tr >= 2) lputs("deal_stars() failed.");
}

ret:
if (ltrace() >= 4)
if (tr >= 4)
lprintf("(planner main status) %i\n", status);
pln::flush_out(true);
return status;
Expand Down
Loading