Release SPHLite 0.8.2
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
#include "sph_worker_cli.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static int fail(const char *message)
|
||||
{
|
||||
fprintf(stderr, "%s\n", message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int contains(const char *text, const char *needle)
|
||||
{
|
||||
return strstr(text, needle) != 0;
|
||||
}
|
||||
|
||||
static int parse_args(int argc, char **argv, sphlite_worker_options_t *options,
|
||||
char *message, int message_capacity)
|
||||
{
|
||||
message[0] = '\0';
|
||||
return sphlite_worker_parse_args(argc, argv, options, message,
|
||||
message_capacity);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
sphlite_worker_options_t options;
|
||||
char message[256];
|
||||
char *plain[] = {"sphlite", "model.inp", "--run"};
|
||||
char *valid_min[] = {
|
||||
"sphlite", "--cclite-worker", "--case", "case.inp",
|
||||
"--ipc-name", "local-ipc"
|
||||
};
|
||||
char *valid_full[] = {
|
||||
"sphlite", "--cclite-worker", "--solver-id", "SPH-1",
|
||||
"--case", "case.inp", "--ipc-name", "ipc",
|
||||
"--command-block", "cmd", "--data-prefix", "data",
|
||||
"--log", "worker.log", "--timeout-ms", "1500",
|
||||
"--worker-id", "worker-a"
|
||||
};
|
||||
char *missing_case[] = {"sphlite", "--cclite-worker",
|
||||
"--ipc-name", "ipc"};
|
||||
char *missing_ipc[] = {"sphlite", "--cclite-worker",
|
||||
"--case", "case.inp"};
|
||||
char *conflict[] = {"sphlite", "--cclite-worker", "--case",
|
||||
"case.inp", "--ipc-name", "ipc", "--run"};
|
||||
char *bad_timeout[] = {"sphlite", "--cclite-worker", "--case",
|
||||
"case.inp", "--ipc-name", "ipc",
|
||||
"--timeout-ms", "0"};
|
||||
char *positional[] = {"sphlite", "--cclite-worker", "case.inp",
|
||||
"--ipc-name", "ipc"};
|
||||
char *missing_value[] = {"sphlite", "--cclite-worker", "--case"};
|
||||
|
||||
if (sphlite_worker_args_requested(3, plain)) {
|
||||
return fail("ordinary CLI was detected as worker mode");
|
||||
}
|
||||
if (!sphlite_worker_args_requested(6, valid_min)) {
|
||||
return fail("worker CLI was not detected");
|
||||
}
|
||||
|
||||
if (parse_args(6, valid_min, &options, message,
|
||||
(int)sizeof(message)) != 0) {
|
||||
return fail("minimal worker args did not parse");
|
||||
}
|
||||
if (!options.enabled || strcmp(options.solver_id, "SPH") != 0 ||
|
||||
strcmp(options.case_file, "case.inp") != 0 ||
|
||||
strcmp(options.ipc_name, "local-ipc") != 0 ||
|
||||
strcmp(options.log_path, "sphlite_cclite_worker.log") != 0 ||
|
||||
options.timeout_ms != 30000 ||
|
||||
strcmp(options.worker_id, "sphlite") != 0) {
|
||||
return fail("minimal worker defaults mismatch");
|
||||
}
|
||||
|
||||
if (parse_args(18, valid_full, &options, message,
|
||||
(int)sizeof(message)) != 0) {
|
||||
return fail("full worker args did not parse");
|
||||
}
|
||||
if (strcmp(options.solver_id, "SPH-1") != 0 ||
|
||||
strcmp(options.command_block, "cmd") != 0 ||
|
||||
strcmp(options.data_prefix, "data") != 0 ||
|
||||
strcmp(options.log_path, "worker.log") != 0 ||
|
||||
options.timeout_ms != 1500 ||
|
||||
strcmp(options.worker_id, "worker-a") != 0) {
|
||||
return fail("full worker option values mismatch");
|
||||
}
|
||||
|
||||
if (parse_args(4, missing_case, &options, message,
|
||||
(int)sizeof(message)) == 0 ||
|
||||
!contains(message, "--case is required")) {
|
||||
return fail("missing case error mismatch");
|
||||
}
|
||||
if (parse_args(4, missing_ipc, &options, message,
|
||||
(int)sizeof(message)) == 0 ||
|
||||
!contains(message, "--ipc-name is required")) {
|
||||
return fail("missing ipc error mismatch");
|
||||
}
|
||||
if (parse_args(7, conflict, &options, message,
|
||||
(int)sizeof(message)) == 0 ||
|
||||
!contains(message, "conflicts")) {
|
||||
return fail("worker conflict error mismatch");
|
||||
}
|
||||
if (parse_args(8, bad_timeout, &options, message,
|
||||
(int)sizeof(message)) == 0 ||
|
||||
!contains(message, "positive integer")) {
|
||||
return fail("bad timeout error mismatch");
|
||||
}
|
||||
if (parse_args(5, positional, &options, message,
|
||||
(int)sizeof(message)) == 0 ||
|
||||
!contains(message, "unknown option")) {
|
||||
return fail("positional input error mismatch");
|
||||
}
|
||||
if (parse_args(3, missing_value, &options, message,
|
||||
(int)sizeof(message)) == 0 ||
|
||||
!contains(message, "missing a value")) {
|
||||
return fail("missing value error mismatch");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user