~ubuntu-branches/ubuntu/trusty/silo-llnl/trusty

« back to all changes in this revision

Viewing changes to tests/std.c

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2011-01-02 00:03:01 UTC
  • Revision ID: james.westby@ubuntu.com-20110102000301-9s2hfsjrkguz6h4r
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
 
3
LLNL-CODE-425250.
 
4
All rights reserved.
 
5
 
 
6
This file is part of Silo. For details, see silo.llnl.gov.
 
7
 
 
8
Redistribution and use in source and binary forms, with or without
 
9
modification, are permitted provided that the following conditions
 
10
are met:
 
11
 
 
12
   * Redistributions of source code must retain the above copyright
 
13
     notice, this list of conditions and the disclaimer below.
 
14
   * Redistributions in binary form must reproduce the above copyright
 
15
     notice, this list of conditions and the disclaimer (as noted
 
16
     below) in the documentation and/or other materials provided with
 
17
     the distribution.
 
18
   * Neither the name of the LLNS/LLNL nor the names of its
 
19
     contributors may be used to endorse or promote products derived
 
20
     from this software without specific prior written permission.
 
21
 
 
22
THIS SOFTWARE  IS PROVIDED BY  THE COPYRIGHT HOLDERS  AND CONTRIBUTORS
 
23
"AS  IS" AND  ANY EXPRESS  OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT
 
24
LIMITED TO, THE IMPLIED  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
25
A  PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN  NO  EVENT SHALL  LAWRENCE
 
26
LIVERMORE  NATIONAL SECURITY, LLC,  THE U.S.  DEPARTMENT OF  ENERGY OR
 
27
CONTRIBUTORS BE LIABLE FOR  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
28
EXEMPLARY, OR  CONSEQUENTIAL DAMAGES  (INCLUDING, BUT NOT  LIMITED TO,
 
29
PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS  OF USE,  DATA, OR
 
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
31
LIABILITY, WHETHER  IN CONTRACT, STRICT LIABILITY,  OR TORT (INCLUDING
 
32
NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT  OF THE USE  OF THIS
 
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
34
 
 
35
This work was produced at Lawrence Livermore National Laboratory under
 
36
Contract  No.   DE-AC52-07NA27344 with  the  DOE.  Neither the  United
 
37
States Government  nor Lawrence  Livermore National Security,  LLC nor
 
38
any of  their employees,  makes any warranty,  express or  implied, or
 
39
assumes   any   liability   or   responsibility  for   the   accuracy,
 
40
completeness, or usefulness of any information, apparatus, product, or
 
41
process  disclosed, or  represents  that its  use  would not  infringe
 
42
privately-owned   rights.  Any  reference   herein  to   any  specific
 
43
commercial products,  process, or  services by trade  name, trademark,
 
44
manufacturer or otherwise does not necessarily constitute or imply its
 
45
endorsement,  recommendation,   or  favoring  by   the  United  States
 
46
Government or Lawrence Livermore National Security, LLC. The views and
 
47
opinions  of authors  expressed  herein do  not  necessarily state  or
 
48
reflect those  of the United  States Government or  Lawrence Livermore
 
49
National  Security, LLC,  and shall  not  be used  for advertising  or
 
50
product endorsement purposes.
 
51
*/
 
52
#include <stdio.h>
 
53
#include <string.h>
 
54
#include <errno.h>
 
55
#include <stdlib.h>
 
56
#ifdef _WIN32
 
57
  #ifndef WINDOWS_LEAN_AND_MEAN
 
58
    #define WINDOWS_LEAN_AND_MEAN
 
59
  #endif
 
60
  #include <windows.h>
 
61
#endif
 
62
 
 
63
#define CHECK_SYMBOL(A)  if (!strncmp(str, #A, strlen(str))) return A
 
64
 
 
65
#define CHECK_SYMBOLN_INT(A)                            \
 
66
if (!strncmp(tok, #A, strlen(#A)))                      \
 
67
{                                                       \
 
68
    int n = sscanf(tok, #A"=%d", &driver_ints[driver_nints]);\
 
69
    if (n == 1)                                         \
 
70
    {                                                   \
 
71
        DBAddOption(opts, A, &driver_ints[driver_nints]);\
 
72
        driver_nints++;                                 \
 
73
        got_it = 1;                                     \
 
74
    }                                                   \
 
75
}
 
76
 
 
77
#define CHECK_SYMBOLN_STR(A)                            \
 
78
if (!strncmp(tok, #A, strlen(#A)))                      \
 
79
{                                                       \
 
80
    driver_strs[driver_nstrs] = strdup(&tok[strlen(#A)]+1);\
 
81
    DBAddOption(opts, A, driver_strs[driver_nstrs]);    \
 
82
    driver_nstrs++;                                     \
 
83
    got_it = 1;                                         \
 
84
}
 
85
 
 
86
#define CHECK_SYMBOLN_SYM(A)                            \
 
87
if (!strncmp(tok, #A, strlen(#A)))                      \
 
88
{                                                       \
 
89
    driver_ints[driver_nints] = StringToDriver(&tok[strlen(#A)]+1);\
 
90
    DBAddOption(opts, A, &driver_ints[driver_nints]);   \
 
91
    driver_nints++;                                     \
 
92
    got_it = 1;                                         \
 
93
}
 
94
 
 
95
 
 
96
static DBoptlist *driver_opts[] = {0,0,0,0,0,0,0,0,0,0};
 
97
static int driver_opts_ids[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
 
98
static int driver_ints[100];
 
99
static int driver_nints = 0;
 
100
static char *driver_strs[] = {0,0,0,0,0,0,0,0,0,0};
 
101
static int driver_nstrs = 0;
 
102
static const int driver_nopts = sizeof(driver_opts)/sizeof(driver_opts[0]);
 
103
 
 
104
static void CleanupDriverStuff()
 
105
{
 
106
    int i;
 
107
    for (i = 0; i < driver_nopts; i++)
 
108
    {
 
109
        if (driver_opts_ids[i] != -1) DBUnregisterFileOptionsSet(driver_opts_ids[i]);
 
110
        if (driver_opts[i]) DBFreeOptlist(driver_opts[i]);
 
111
    }
 
112
    for (i = 0; i < sizeof(driver_strs)/sizeof(driver_strs[0]); i++)
 
113
        if (driver_strs[i]) free(driver_strs[i]);
 
114
}
 
115
 
 
116
static void MakeDriverOpts(DBoptlist **_opts, int *opts_id)
 
117
{
 
118
    DBoptlist *opts = DBMakeOptlist(30);
 
119
    int i;
 
120
 
 
121
    for (i = 0; i < driver_nopts; i++)
 
122
    {
 
123
        if (driver_opts[i] == 0)
 
124
        {
 
125
            driver_opts[i] = opts;
 
126
            break;
 
127
        }
 
128
    }
 
129
 
 
130
    *_opts = opts;
 
131
    *opts_id = DBRegisterFileOptionsSet(opts);
 
132
     driver_opts_ids[i] = *opts_id;
 
133
}
 
134
 
 
135
static int StringToDriver(const char *str)
 
136
{
 
137
    DBoptlist *opts = 0;
 
138
    int opts_id = -1;
 
139
 
 
140
    CHECK_SYMBOL(DB_PDB);
 
141
    CHECK_SYMBOL(DB_PDBP);
 
142
    CHECK_SYMBOL(DB_HDF5);
 
143
    CHECK_SYMBOL(DB_HDF5_SEC2);
 
144
    CHECK_SYMBOL(DB_HDF5_STDIO);
 
145
    CHECK_SYMBOL(DB_HDF5_CORE);
 
146
    CHECK_SYMBOL(DB_HDF5_SPLIT);
 
147
    CHECK_SYMBOL(DB_HDF5_MPIO);
 
148
    CHECK_SYMBOL(DB_HDF5_MPIP);
 
149
    CHECK_SYMBOL(DB_HDF5_LOG);
 
150
    CHECK_SYMBOL(DB_HDF5_DIRECT);
 
151
    CHECK_SYMBOL(DB_HDF5_FAMILY);
 
152
    CHECK_SYMBOL(DB_HDF5_SILO);
 
153
    
 
154
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_DEFAULT);
 
155
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_SEC2);
 
156
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_STDIO);
 
157
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_CORE);
 
158
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_LOG);
 
159
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_SPLIT);
 
160
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_DIRECT);
 
161
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_FAMILY);
 
162
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_MPIP);
 
163
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_MPIO);
 
164
    CHECK_SYMBOL(DB_FILE_OPTS_H5_DEFAULT_SILO);
 
165
 
 
166
    CHECK_SYMBOL(DB_H5VFD_DEFAULT);
 
167
    CHECK_SYMBOL(DB_H5VFD_SEC2);
 
168
    CHECK_SYMBOL(DB_H5VFD_STDIO);
 
169
    CHECK_SYMBOL(DB_H5VFD_CORE);
 
170
    CHECK_SYMBOL(DB_H5VFD_LOG);
 
171
    CHECK_SYMBOL(DB_H5VFD_SPLIT);
 
172
    CHECK_SYMBOL(DB_H5VFD_DIRECT);
 
173
    CHECK_SYMBOL(DB_H5VFD_FAMILY);
 
174
    CHECK_SYMBOL(DB_H5VFD_MPIO);
 
175
    CHECK_SYMBOL(DB_H5VFD_MPIP);
 
176
    CHECK_SYMBOL(DB_H5VFD_SILO);
 
177
 
 
178
    if (!strncmp(str, "DB_HDF5_OPTS(", 13))
 
179
    {
 
180
        char *tok, *tmpstr;;
 
181
 
 
182
        MakeDriverOpts(&opts, &opts_id);
 
183
 
 
184
        tmpstr = strdup(&str[13]);
 
185
        errno = 0;
 
186
        tok = strtok(tmpstr, ",)");
 
187
 
 
188
        while (tok)
 
189
        {
 
190
            int got_it = 0;
 
191
 
 
192
            CHECK_SYMBOLN_SYM(DBOPT_H5_VFD)
 
193
            CHECK_SYMBOLN_SYM(DBOPT_H5_RAW_FILE_OPTS)
 
194
            CHECK_SYMBOLN_STR(DBOPT_H5_RAW_EXTENSION)
 
195
            CHECK_SYMBOLN_SYM(DBOPT_H5_META_FILE_OPTS)
 
196
            CHECK_SYMBOLN_STR(DBOPT_H5_META_EXTENSION)
 
197
            CHECK_SYMBOLN_INT(DBOPT_H5_CORE_ALLOC_INC)
 
198
            CHECK_SYMBOLN_INT(DBOPT_H5_CORE_NO_BACK_STORE)
 
199
            CHECK_SYMBOLN_INT(DBOPT_H5_META_BLOCK_SIZE)
 
200
            CHECK_SYMBOLN_INT(DBOPT_H5_SMALL_RAW_SIZE)
 
201
            CHECK_SYMBOLN_INT(DBOPT_H5_ALIGN_MIN)
 
202
            CHECK_SYMBOLN_INT(DBOPT_H5_ALIGN_VAL)
 
203
            CHECK_SYMBOLN_INT(DBOPT_H5_DIRECT_MEM_ALIGN)
 
204
            CHECK_SYMBOLN_INT(DBOPT_H5_DIRECT_BLOCK_SIZE)
 
205
            CHECK_SYMBOLN_INT(DBOPT_H5_DIRECT_BUF_SIZE)
 
206
            CHECK_SYMBOLN_STR(DBOPT_H5_LOG_NAME)
 
207
            CHECK_SYMBOLN_INT(DBOPT_H5_LOG_BUF_SIZE)
 
208
            CHECK_SYMBOLN_INT(DBOPT_H5_SIEVE_BUF_SIZE)
 
209
            CHECK_SYMBOLN_INT(DBOPT_H5_CACHE_NELMTS)
 
210
            CHECK_SYMBOLN_INT(DBOPT_H5_CACHE_NBYTES)
 
211
            CHECK_SYMBOLN_INT(DBOPT_H5_FAM_SIZE)
 
212
            CHECK_SYMBOLN_SYM(DBOPT_H5_FAM_FILE_OPTS)
 
213
            CHECK_SYMBOLN_INT(DBOPT_H5_SILO_BLOCK_SIZE)
 
214
            CHECK_SYMBOLN_INT(DBOPT_H5_SILO_BLOCK_COUNT)
 
215
            CHECK_SYMBOLN_INT(DBOPT_H5_SILO_LOG_STATS)
 
216
            CHECK_SYMBOLN_INT(DBOPT_H5_SILO_USE_DIRECT)
 
217
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_DEFAULT)
 
218
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_SEC2)
 
219
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_STDIO)
 
220
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_CORE)
 
221
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_LOG)
 
222
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_SPLIT)
 
223
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_DIRECT)
 
224
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_FAMILY)
 
225
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_MPIP)
 
226
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_MPIO)
 
227
            CHECK_SYMBOLN_STR(DB_FILE_OPTS_H5_DEFAULT_SILO)
 
228
 
 
229
            if (!got_it)
 
230
            {
 
231
                fprintf(stderr, "Unable to determine driver from string \"%s\"\n", tok);
 
232
                exit(-1);
 
233
            }
 
234
 
 
235
            tok = strtok(0, ",)");
 
236
            if (errno != 0)
 
237
            {
 
238
                fprintf(stderr, "Unable to determine driver from string \"%s\"\n", tok);
 
239
                exit(-1);
 
240
            }
 
241
        }
 
242
 
 
243
        free(tmpstr);
 
244
 
 
245
        return DB_HDF5_OPTS(opts_id);
 
246
    }
 
247
 
 
248
    fprintf(stderr, "Unable to determine driver from string \"%s\"\n", str);
 
249
    exit(-1);
 
250
}