MIDAS
Loading...
Searching...
No Matches
torture_odb.cxx
Go to the documentation of this file.
1//
2// test_odb.cxx --- test ODB corner cases
3//
4// K.Olchanski
5//
6
7#include <stdio.h>
8#include <sys/time.h>
9#include <iostream>
10#include <assert.h>
11#include <signal.h>
12#include <string.h>
13#include <stdlib.h> // exit()
14
15#include "tmfe.h"
16#include "midasio.h"
17#include "mvodb.h"
18#include "midas.h"
19
20std::string toString(int i)
21{
22 char buf[256];
23 sprintf(buf, "%d", i);
24 return buf;
25}
26
27void print_ia(const std::vector<int> &ia)
28{
29 int size = ia.size();
30 printf("int[%d] has [", size);
31 for (int i=0; i<size; i++) {
32 if (i>0)
33 printf(", ");
34 printf("%d", ia[i]);
35 }
36 printf("]");
37}
38
39void print_da(const std::vector<double> &da)
40{
41 int size = da.size();
42 printf("int[%d] has [", size);
43 for (int i=0; i<size; i++) {
44 if (i>0)
45 printf(", ");
46 printf("%f", da[i]);
47 }
48 printf("]");
49}
50
51static int gCountFail = 0;
52
53void report_fail(const char* text)
54{
55 printf("FAIL: %s\n", text);
56 gCountFail++;
57}
58
59static void test_depth_bomb(MVOdb* odb, bool cleanup)
60{
61 printf("Depth bomb: creating test_odb/depth_bomb/down/down/...\n");
62
63 MVOdb *s = odb->Chdir("test_odb", true);
64 s = s->Chdir("depth_bomb", true);
65
66 assert(s);
67
68 int level = 1;
69
70 MVOdb *p = s;
71
72 while (1) {
73 p = p->Chdir("down", true);
74 if (!p)
75 break;
76 if (p->IsReadOnly()) // detect NullOdb created when Chdir() failed to mkdir()
77 break;
78 level ++;
79 //printf("%d.", level);
80 }
81
82 printf("Created tree %d deep\n", level);
83
84 if (cleanup)
85 odb->Delete("test_odb");
86}
87
88static void test_width_bomb_key(MVOdb* odb, bool cleanup)
89{
90 printf("Width bomb: creating test_odb/width_bomb_key/dir1,dir2,dir3,...\n");
91
92 MVOdb *s = odb->Chdir("test_odb", true);
93 s = s->Chdir("width_bomb_key", true);
94
95 assert(s);
96
97 int count = 1;
98
99 MVOdb *p = s;
100
101 while (1) {
102 std::string name = msprintf("width_bomb_%06d", count);
103
104 p = s->Chdir(name.c_str(), true);
105 if (!p)
106 break;
107 if (p->IsReadOnly()) // detect NullOdb created when Chdir() failed to mkdir()
108 break;
109 count ++;
110 //printf("%d.", count);
111 //if (count > 10)
112 // break;
113 }
114
115 printf("Created %d subdirectories\n", count);
116
117 if (cleanup)
118 odb->Delete("test_odb");
119}
120
121static void test_width_bomb_data(MVOdb* odb, bool cleanup)
122{
123 printf("Width bomb: creating test_odb/width_bomb_data/dir1,dir2,dir3,...\n");
124
125 MVOdb *s = odb->Chdir("test_odb", true);
126 s = s->Chdir("width_bomb_data", true);
127
128 assert(s);
129
130 int count = 1;
131
132 std::string data;
133
134 for (int i=0; i<20; i++) {
135 data += (char)('a' + i);
136 }
137
138 data += data;
139 data += data;
140
141 while (1) {
142 std::string name = msprintf("width_data_%06d", count);
143
144 s->WS(name.c_str(), data.c_str());
145 count ++;
146
147 std::string r;
148 s->RS(name.c_str(), &r);
149
150 if (r.empty())
151 break;
152
153 //printf("%d.", count);
154 //if (count > 10)
155 // break;
156 }
157
158 printf("Created %d subdirectories\n", count);
159
160 if (cleanup)
161 odb->Delete("test_odb");
162}
163
164void all(MVOdb* odb)
165{
166 printf("\n");
167 printf("Starting all tests:\n");
168 printf("\n");
169
170 test_depth_bomb(odb, true);
171 test_width_bomb_key(odb, true);
172 test_width_bomb_data(odb, true);
173}
174
175void help()
176{
177
178
179
180}
181
182// Main function call
183
184int main(int argc, char *argv[])
185{
186 setbuf(stdout,NULL);
187 setbuf(stderr,NULL);
188
189 signal(SIGILL, SIG_DFL);
190 signal(SIGBUS, SIG_DFL);
191 signal(SIGSEGV, SIG_DFL);
192 signal(SIGPIPE, SIG_DFL);
193
194 const char* hostname = NULL;
195 const char* exptname = NULL;
196
197 TMFE* mfe = NULL;
198
199 MVOdb* odb = NULL;
200 MVOdbError odberror;
201
202 printf("Using TMFE ODB\n");
203 mfe = TMFE::Instance();
204
205 TMFeResult r;
206
207 r = mfe->Connect("test_odb", hostname, exptname);
208 if (r.error_flag) {
209 fprintf(stderr,"Cannot connect to MIDAS, error %s\n", r.error_message.c_str());
210 exit(1);
211 }
212
213 odb = MakeMidasOdb(mfe->fDB, &odberror);
214
215 if (odberror.fError) {
216 fprintf(stderr, "Cannot make MVOdb object, error: %s\n", odberror.fErrorString.c_str());
217 exit(1);
218 }
219
220 for (int i=0; i<argc; i++) {
221 std::string arg = argv[i];
222
223 if (arg == "--all")
224 all(odb);
225 else if (arg == "--depth-bomb")
226 test_depth_bomb(odb, false);
227 else if (arg == "--width-bomb-key")
228 test_width_bomb_key(odb, false);
229 else if (arg == "--width-bomb-data")
230 test_width_bomb_data(odb, false);
231 else
232 help();
233 }
234
235 if (mfe)
236 mfe->Disconnect();
237
238 return 0;
239}
240
241//end
242/* emacs
243 * Local Variables:
244 * tab-width: 8
245 * c-basic-offset: 3
246 * indent-tabs-mode: nil
247 * End:
248 */
Definition tmfe.h:381
int fDB
ODB database handle.
Definition tmfe.h:394
TMFeResult Connect(const char *progname=NULL, const char *hostname=NULL, const char *exptname=NULL)
Definition tmfe.cxx:65
static TMFE * Instance()
Definition tmfe.cxx:57
TMFeResult Disconnect()
Definition tmfe.cxx:154
bool error_flag
Definition tmfe.h:89
std::string error_message
Definition tmfe.h:91
int main()
Definition hwtest.cxx:23
void * data
Definition mana.cxx:268
double count
Definition mdump.cxx:33
INT i
Definition mdump.cxx:32
std::string msprintf(const char *format,...)
Definition midas.cxx:419
#define name(x)
Definition midas_macro.h:24
static void test_width_bomb_data(MVOdb *odb, bool cleanup)
void print_da(const std::vector< double > &da)
static int gCountFail
void report_fail(const char *text)
void print_ia(const std::vector< int > &ia)
void help()
static void test_depth_bomb(MVOdb *odb, bool cleanup)
std::string toString(int i)
static void test_width_bomb_key(MVOdb *odb, bool cleanup)
void all(MVOdb *odb)