test/test_config.c
/* helper function to compare given configuration values with a kvtree */
helper function to compare given configuration values with a kvtree
helper function to compare given configuration values with a kvtree
void check_options(const kvtree* configured_values, int is_global,
                   size_t exp_file_buf_size, int exp_debug,
                   int exp_make_directories, int exp_copy_metadata,
                   int exp_rank)
{
    static const char* known_global_options[] = {
        AXL_KEY_CONFIG_FILE_BUF_SIZE,
        AXL_KEY_CONFIG_DEBUG,
        AXL_KEY_CONFIG_MKDIR,
        AXL_KEY_CONFIG_COPY_METADATA,
        AXL_KEY_CONFIG_RANK,
        NULL
    };
    static const char* known_transfer_options[] = {
        AXL_KEY_CONFIG_FILE_BUF_SIZE,
        AXL_KEY_CONFIG_MKDIR,
        AXL_KEY_CONFIG_COPY_METADATA,
        NULL
    };
    const char** known_options = is_global ? known_global_options :
                                             known_transfer_options;
    unsigned long ul;
    if (kvtree_util_get_bytecount(configured_values,
      AXL_KEY_CONFIG_FILE_BUF_SIZE, &ul) != KVTREE_SUCCESS)
    {
        printf("Could not get %s from AXL_Config\n",
               AXL_KEY_CONFIG_FILE_BUF_SIZE);
        exit(EXIT_FAILURE);
    }
    size_t cfg_file_buf_size = (size_t) ul;
    if (cfg_file_buf_size != ul) {
        char* value;
        kvtree_util_get_str(configured_values, AXL_KEY_CONFIG_FILE_BUF_SIZE,
                            &value);
        printf("Value '%s' passed for %s exceeds int range\n",
          value, AXL_KEY_CONFIG_FILE_BUF_SIZE
        );
        exit(EXIT_FAILURE);
    }
    if (cfg_file_buf_size != exp_file_buf_size) {
        printf("AXL_Config returned unexpected value %llu for %s. Expected %llu.\n",
               (unsigned long long)cfg_file_buf_size,
               AXL_KEY_CONFIG_FILE_BUF_SIZE,
               (unsigned long long)exp_file_buf_size);
        exit(EXIT_FAILURE);
    }
    if (is_global) {
        int cfg_debug;
        if (kvtree_util_get_int(configured_values, AXL_KEY_CONFIG_DEBUG,
                                &cfg_debug) != KVTREE_SUCCESS)
        {
            printf("Could not get %s from AXL_Config\n",
                   AXL_KEY_CONFIG_DEBUG);
            exit(EXIT_FAILURE);
        }
        if (cfg_debug != exp_debug) {
            printf("AXL_Config returned unexpected value %d for %s. Expected %d.\n",
                   cfg_debug, AXL_KEY_CONFIG_DEBUG, exp_debug);
            exit(EXIT_FAILURE);
        }
        int cfg_rank;
        if (kvtree_util_get_int(configured_values, AXL_KEY_CONFIG_RANK,
                                &cfg_rank) != KVTREE_SUCCESS)
        {
            printf("Could not get %s from AXL_Config\n",
                   AXL_KEY_CONFIG_RANK);
            exit(EXIT_FAILURE);
        }
        if (cfg_rank != exp_rank) {
            printf("AXL_Config returned unexpected value %d for %s. Expected %d.\n",
                   cfg_rank, AXL_KEY_CONFIG_RANK,
                   exp_rank);
            exit(EXIT_FAILURE);
        }
    }
    int cfg_make_directories;
    if (kvtree_util_get_int(configured_values, AXL_KEY_CONFIG_MKDIR,
                            &cfg_make_directories) != KVTREE_SUCCESS)
    {
        printf("Could not get %s from AXL_Config\n",
               AXL_KEY_CONFIG_MKDIR);
        exit(EXIT_FAILURE);
    }
    if (cfg_make_directories != exp_make_directories) {
        printf("AXL_Config returned unexpected value %d for %s. Expected %d.\n",
               cfg_make_directories, AXL_KEY_CONFIG_MKDIR,
               exp_make_directories);
        exit(EXIT_FAILURE);
    }
    int cfg_copy_metadata;
    if (kvtree_util_get_int(configured_values, AXL_KEY_CONFIG_COPY_METADATA,
                            &cfg_copy_metadata) != KVTREE_SUCCESS)
    {
        printf("Could not get %s from AXL_Config\n",
               AXL_KEY_CONFIG_COPY_METADATA);
        exit(EXIT_FAILURE);
    }
    if (cfg_copy_metadata != exp_copy_metadata) {
        printf("AXL_Config returned unexpected value %d for %s. Expected %d.\n",
               cfg_copy_metadata, AXL_KEY_CONFIG_COPY_METADATA,
               exp_copy_metadata);
        exit(EXIT_FAILURE);
    }
    check_known_options(configured_values, is_global, known_options);
}
void check_options ( const kvtree * configured_values , int is_global , size_t exp_file_buf_size , int exp_debug , int exp_make_directories , int exp_copy_metadata , int exp_rank ) { static const char * known_global_options [ ] = { AXL_KEY_CONFIG_FILE_BUF_SIZE , AXL_KEY_CONFIG_DEBUG , AXL_KEY_CONFIG_MKDIR , AXL_KEY_CONFIG_COPY_METADATA , AXL_KEY_CONFIG_RANK , NULL } ; static const char * known_transfer_options [ ] = { AXL_KEY_CONFIG_FILE_BUF_SIZE , AXL_KEY_CONFIG_MKDIR , AXL_KEY_CONFIG_COPY_METADATA , NULL } ; const char * * known_options = is_global ? known_global_options : known_transfer_options ; unsigned long ul ; if ( kvtree_util_get_bytecount ( configured_values , AXL_KEY_CONFIG_FILE_BUF_SIZE , & ul ) != KVTREE_SUCCESS ) { printf ( " \n " , AXL_KEY_CONFIG_FILE_BUF_SIZE ) ; exit ( EXIT_FAILURE ) ; } size_t cfg_file_buf_size = ( size_t ) ul ; if ( cfg_file_buf_size != ul ) { char * value ; kvtree_util_get_str ( configured_values , AXL_KEY_CONFIG_FILE_BUF_SIZE , & value ) ; printf ( " \n " , value , AXL_KEY_CONFIG_FILE_BUF_SIZE ) ; exit ( EXIT_FAILURE ) ; } if ( cfg_file_buf_size != exp_file_buf_size ) { printf ( " \n " , ( unsigned long long ) cfg_file_buf_size , AXL_KEY_CONFIG_FILE_BUF_SIZE , ( unsigned long long ) exp_file_buf_size ) ; exit ( EXIT_FAILURE ) ; } if ( is_global ) { int cfg_debug ; if ( kvtree_util_get_int ( configured_values , AXL_KEY_CONFIG_DEBUG , & cfg_debug ) != KVTREE_SUCCESS ) { printf ( " \n " , AXL_KEY_CONFIG_DEBUG ) ; exit ( EXIT_FAILURE ) ; } if ( cfg_debug != exp_debug ) { printf ( " \n " , cfg_debug , AXL_KEY_CONFIG_DEBUG , exp_debug ) ; exit ( EXIT_FAILURE ) ; } int cfg_rank ; if ( kvtree_util_get_int ( configured_values , AXL_KEY_CONFIG_RANK , & cfg_rank ) != KVTREE_SUCCESS ) { printf ( " \n " , AXL_KEY_CONFIG_RANK ) ; exit ( EXIT_FAILURE ) ; } if ( cfg_rank != exp_rank ) { printf ( " \n " , cfg_rank , AXL_KEY_CONFIG_RANK , exp_rank ) ; exit ( EXIT_FAILURE ) ; } } int cfg_make_directories ; if ( kvtree_util_get_int ( configured_values , AXL_KEY_CONFIG_MKDIR , & cfg_make_directories ) != KVTREE_SUCCESS ) { printf ( " \n " , AXL_KEY_CONFIG_MKDIR ) ; exit ( EXIT_FAILURE ) ; } if ( cfg_make_directories != exp_make_directories ) { printf ( " \n " , cfg_make_directories , AXL_KEY_CONFIG_MKDIR , exp_make_directories ) ; exit ( EXIT_FAILURE ) ; } int cfg_copy_metadata ; if ( kvtree_util_get_int ( configured_values , AXL_KEY_CONFIG_COPY_METADATA , & cfg_copy_metadata ) != KVTREE_SUCCESS ) { printf ( " \n " , AXL_KEY_CONFIG_COPY_METADATA ) ; exit ( EXIT_FAILURE ) ; } if ( cfg_copy_metadata != exp_copy_metadata ) { printf ( " \n " , cfg_copy_metadata , AXL_KEY_CONFIG_COPY_METADATA , exp_copy_metadata ) ; exit ( EXIT_FAILURE ) ; } check_known_options ( configured_values , is_global , known_options ) ; }
helper function to compare given configuration values with a kvtree
helper function to compare given configuration values with a kvtree