Skip to content

Commit

Permalink
Merge pull request #104 from hpc/feature-hdf5-backend
Browse files Browse the repository at this point in the history
Changed the parser to fix #98.  Does _not_ yet have the HDF5 backend args updated.  They were reverted to allow this to make the 3.2 release and should be re-applied as a separate commit.
  • Loading branch information
glennklockwood authored Dec 4, 2018
2 parents 5c847f5 + 7db8ffd commit 5e2e1cc
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 183 deletions.
6 changes: 3 additions & 3 deletions src/aiori-DUMMY.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ static struct dummy_options o = {
};

static option_help options [] = {
{'c', "delay-create", "Delay per create in usec", OPTION_OPTIONAL_ARGUMENT, 'l', & o.delay_creates},
{'x', "delay-xfer", "Delay per xfer in usec", OPTION_OPTIONAL_ARGUMENT, 'l', & o.delay_xfer},
{'z', "delay-only-rank0", "Delay only Rank0", OPTION_FLAG, 'd', & o.delay_rank_0_only},
{0, "dummy.delay-create", "Delay per create in usec", OPTION_OPTIONAL_ARGUMENT, 'l', & o.delay_creates},
{0, "dummy.delay-xfer", "Delay per xfer in usec", OPTION_OPTIONAL_ARGUMENT, 'l', & o.delay_xfer},
{0, "dummy.delay-only-rank0", "Delay only Rank0", OPTION_FLAG, 'd', & o.delay_rank_0_only},
LAST_OPTION
};

Expand Down
6 changes: 3 additions & 3 deletions src/aiori-RADOS.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ static struct rados_options o = {
};

static option_help options [] = {
{'u', "user", "Username for the RADOS cluster", OPTION_REQUIRED_ARGUMENT, 's', & o.user},
{'c', "conf", "Config file for the RADOS cluster", OPTION_REQUIRED_ARGUMENT, 's', & o.conf},
{'p', "pool", "RADOS pool to use for I/O", OPTION_REQUIRED_ARGUMENT, 's', & o.pool},
{0, "rados.user", "Username for the RADOS cluster", OPTION_REQUIRED_ARGUMENT, 's', & o.user},
{0, "rados.conf", "Config file for the RADOS cluster", OPTION_REQUIRED_ARGUMENT, 's', & o.conf},
{0, "rados.pool", "RADOS pool to use for I/O", OPTION_REQUIRED_ARGUMENT, 's', & o.pool},
LAST_OPTION
};

Expand Down
20 changes: 20 additions & 0 deletions src/aiori.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ ior_aiori_t *available_aiori[] = {
NULL
};

void airoi_parse_options(int argc, char ** argv, option_help * global_options){
int airoi_c = aiori_count();
options_all opt;
opt.module_count = airoi_c + 1;
opt.modules = malloc(sizeof(option_module) * (airoi_c + 1));
opt.modules[0].prefix = NULL;
opt.modules[0].options = global_options;
ior_aiori_t **tmp = available_aiori;
for (int i=1; *tmp != NULL; ++tmp, i++) {
opt.modules[i].prefix = (*tmp)->name;
if((*tmp)->get_options != NULL){
opt.modules[i].options = (*tmp)->get_options();
}else{
opt.modules[i].options = NULL;
}
}
option_parse(argc, argv, &opt);
free(opt.modules);
}

void aiori_supported_apis(char * APIs, char * APIs_legacy){
ior_aiori_t **tmp = available_aiori;
if(*tmp != NULL){
Expand Down
1 change: 1 addition & 0 deletions src/aiori.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void aiori_finalize(IOR_test_t * tests);
const ior_aiori_t *aiori_select (const char *api);
int aiori_count (void);
void aiori_supported_apis(char * APIs, char * APIs_legacy);
void airoi_parse_options(int argc, char ** argv, option_help * global_options);
const char *aiori_default (void);

/* some generic POSIX-based backend calls */
Expand Down
1 change: 0 additions & 1 deletion src/ior.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ typedef struct
char* URI; /* "path" to target object */
size_t part_number; /* multi-part upload increment (PER-RANK!) */
char* UploadId; /* key for multi-part-uploads */
int collective_md; /* use collective metatata optimization */

/* RADOS variables */
rados_t rados_cluster; /* RADOS cluster handle */
Expand Down
24 changes: 1 addition & 23 deletions src/mdtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -2161,35 +2161,13 @@ mdtest_results_t * mdtest_run(int argc, char **argv, MPI_Comm world_com, FILE *
{'Z', NULL, "print time instead of rate", OPTION_FLAG, 'd', & print_time},
LAST_OPTION
};
int printhelp = 0;
int parsed_options = option_parse(argc, argv, options, & printhelp);
airoi_parse_options(argc, argv, options);

backend = aiori_select(backend_name);
if (NULL == backend) {
FAIL("Could not find suitable backend to use");
}

if(backend->get_options != NULL){
option_parse(argc - parsed_options, argv + parsed_options, backend->get_options(), & printhelp);
}

if(printhelp != 0){
printf("Usage: %s ", argv[0]);

option_print_help(options, 0);

if(backend->get_options != NULL){
printf("\nPlugin options for backend %s\n", backend_name);
option_print_help(backend->get_options(), 1);
}
if(printhelp == 1){
exit(0);
}else{
exit(1);
}
}


MPI_Comm_rank(testComm, &rank);
MPI_Comm_size(testComm, &size);

Expand Down
236 changes: 111 additions & 125 deletions src/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,40 +135,7 @@ static void print_help_section(option_help * args, option_value_type type, char
}
}

void option_print_help(option_help * args, int is_plugin){
option_help * o;
int optionalArgs = 0;
for(o = args; o->shortVar != 0 || o->longVar != 0 ; o++){
if(o->arg != OPTION_REQUIRED_ARGUMENT){
optionalArgs = 1;
}

switch(o->arg){
case (OPTION_OPTIONAL_ARGUMENT):
case (OPTION_FLAG):{
if(o->shortVar != 0){
printf("[-%c] ", o->shortVar);
}else if(o->longVar != 0){
printf("[--%s] ", o->longVar);
}
break;
}case (OPTION_REQUIRED_ARGUMENT):{
if(o->shortVar != 0){
printf("-%c ", o->shortVar);
}else if(o->longVar != 0){
printf("--%s ", o->longVar);
}
break;
}
}
}
if (optionalArgs){
//printf(" [Optional Args]");
}
if (! is_plugin){
printf(" -- <Plugin options, see below>\n");
}

void option_print_help(option_help * args){
print_help_section(args, OPTION_REQUIRED_ARGUMENT, "Required arguments");
print_help_section(args, OPTION_FLAG, "Flags");
print_help_section(args, OPTION_OPTIONAL_ARGUMENT, "Optional arguments");
Expand Down Expand Up @@ -253,17 +220,23 @@ void option_print_current(option_help * args){
print_current_option_section(args, OPTION_FLAG);
}

int option_parse(int argc, char ** argv, option_help * args, int * printhelp){
int option_parse(int argc, char ** argv, options_all * opt_all){
int error = 0;
int requiredArgsSeen = 0;
int requiredArgsNeeded = 0;
int i;

for(option_help * o = args; o->shortVar != 0 || o->longVar != 0 ; o++ ){
if(o->arg == OPTION_REQUIRED_ARGUMENT){
requiredArgsNeeded++;
int printhelp = 0;

for(int m = 0; m < opt_all->module_count; m++ ){
option_help * args = opt_all->modules[m].options;
if(args == NULL) continue;
for(option_help * o = args; o->shortVar != 0 || o->longVar != 0 ; o++ ){
if(o->arg == OPTION_REQUIRED_ARGUMENT){
requiredArgsNeeded++;
}
}
}

for(i=1; i < argc; i++){
char * txt = argv[i];
int foundOption = 0;
Expand All @@ -274,105 +247,104 @@ int option_parse(int argc, char ** argv, option_help * args, int * printhelp){
arg++;
replaced_equal = 1;
}
if(strcmp(txt, "--") == 0){
// we found plugin options
break;
}

// try to find matching option help
for(option_help * o = args; o->shortVar != 0 || o->longVar != 0 || o->help != NULL ; o++ ){
if( o->shortVar == 0 && o->longVar == 0 ){
// section
continue;
}

if ( (txt[0] == '-' && o->shortVar == txt[1]) || (strlen(txt) > 2 && txt[0] == '-' && txt[1] == '-' && o->longVar != NULL && strcmp(txt + 2, o->longVar) == 0)){
foundOption = 1;

// now process the option.
switch(o->arg){
case (OPTION_FLAG):{
assert(o->type == 'd');
(*(int*) o->variable)++;
break;
}
case (OPTION_OPTIONAL_ARGUMENT):
case (OPTION_REQUIRED_ARGUMENT):{
// check if next is an argument
if(arg == NULL){
if(o->shortVar == txt[1] && txt[2] != 0){
arg = & txt[2];
}else{
// simply take the next value as argument
i++;
arg = argv[i];
}
}

if(arg == NULL){
const char str[] = {o->shortVar, 0};
printf("Error, argument missing for option %s\n", (o->longVar != NULL) ? o->longVar : str);
exit(1);
for(int m = 0; m < opt_all->module_count; m++ ){
option_help * args = opt_all->modules[m].options;
if(args == NULL) continue;
// try to find matching option help
for(option_help * o = args; o->shortVar != 0 || o->longVar != 0 || o->help != NULL ; o++ ){
if( o->shortVar == 0 && o->longVar == 0 ){
// section
continue;
}
if ( (txt[0] == '-' && o->shortVar == txt[1]) || (strlen(txt) > 2 && txt[0] == '-' && txt[1] == '-' && o->longVar != NULL && strcmp(txt + 2, o->longVar) == 0)){
foundOption = 1;

// now process the option.
switch(o->arg){
case (OPTION_FLAG):{
assert(o->type == 'd');
(*(int*) o->variable)++;
break;
}

switch(o->type){
case('p'):{
// call the function in the variable
void(*fp)() = o->variable;
fp(arg);
break;
}
case('F'):{
*(double*) o->variable = atof(arg);
break;
}
case('f'):{
*(float*) o->variable = atof(arg);
break;
}
case('d'):{
int64_t val = string_to_bytes(arg);
if (val > INT_MAX || val < INT_MIN){
printf("WARNING: parsing the number %s to integer, this produced an overflow!\n", arg);
case (OPTION_OPTIONAL_ARGUMENT):
case (OPTION_REQUIRED_ARGUMENT):{
// check if next is an argument
if(arg == NULL){
if(o->shortVar == txt[1] && txt[2] != 0){
arg = & txt[2];
}else{
// simply take the next value as argument
i++;
arg = argv[i];
}
*(int*) o->variable = val;
break;
}
case('H'):
case('s'):{
(*(char **) o->variable) = strdup(arg);
break;

if(arg == NULL){
const char str[] = {o->shortVar, 0};
printf("Error, argument missing for option %s\n", (o->longVar != NULL) ? o->longVar : str);
exit(1);
}
case('c'):{
(*(char *)o->variable) = arg[0];
if(strlen(arg) > 1){
printf("Error, ignoring remainder of string for option %c (%s).\n", o->shortVar, o->longVar);

switch(o->type){
case('p'):{
// call the function in the variable
void(*fp)() = o->variable;
fp(arg);
break;
}
break;
}
case('l'):{
*(long long*) o->variable = string_to_bytes(arg);
break;
case('F'):{
*(double*) o->variable = atof(arg);
break;
}
case('f'):{
*(float*) o->variable = atof(arg);
break;
}
case('d'):{
int64_t val = string_to_bytes(arg);
if (val > INT_MAX || val < INT_MIN){
printf("WARNING: parsing the number %s to integer, this produced an overflow!\n", arg);
}
*(int*) o->variable = val;
break;
}
case('H'):
case('s'):{
(*(char **) o->variable) = strdup(arg);
break;
}
case('c'):{
(*(char *)o->variable) = arg[0];
if(strlen(arg) > 1){
printf("Error, ignoring remainder of string for option %c (%s).\n", o->shortVar, o->longVar);
}
break;
}
case('l'):{
*(long long*) o->variable = string_to_bytes(arg);
break;
}
default:
printf("ERROR: Unknown option type %c\n", o->type);
}
default:
printf("ERROR: Unknown option type %c\n", o->type);
}
}
}
if(replaced_equal){
arg[-1] = '=';
}
if(replaced_equal){
arg[-1] = '=';
}

if(o->arg == OPTION_REQUIRED_ARGUMENT){
requiredArgsSeen++;
}
if(o->arg == OPTION_REQUIRED_ARGUMENT){
requiredArgsSeen++;
}

break;
break;
}
}
}
if (! foundOption){
if(strcmp(txt, "-h") == 0 || strcmp(txt, "--help") == 0){
*printhelp=1;
printhelp = 1;
}else{
printf("Error invalid argument: %s\n", txt);
error = 1;
Expand All @@ -382,12 +354,26 @@ int option_parse(int argc, char ** argv, option_help * args, int * printhelp){

if( requiredArgsSeen != requiredArgsNeeded ){
printf("Error: Missing some required arguments\n\n");
*printhelp = -1;
printhelp = -1;
}

if(error != 0){
printf("Invalid options\n");
*printhelp = -1;
printhelp = -1;
}

if(printhelp == 1){
printf("Synopsis %s\n", argv[0]);
for(int m = 0; m < opt_all->module_count; m++ ){
option_help * args = opt_all->modules[m].options;
if(args == NULL) continue;
char * prefix = opt_all->modules[m].prefix;
if(prefix != NULL){
printf("\n\nModule %s\n", prefix);
}
option_print_help(args);
}
exit(0);
}

return i;
Expand Down
Loading

0 comments on commit 5e2e1cc

Please sign in to comment.