MIDAS
Loading...
Searching...
No Matches
torture_odb.cxx File Reference
#include <stdio.h>
#include <sys/time.h>
#include <iostream>
#include <assert.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include "tmfe.h"
#include "midasio.h"
#include "mvodb.h"
#include "midas.h"
Include dependency graph for torture_odb.cxx:

Go to the source code of this file.

Functions

std::string toString (int i)
 
void print_ia (const std::vector< int > &ia)
 
void print_da (const std::vector< double > &da)
 
void report_fail (const char *text)
 
static void test_depth_bomb (MVOdb *odb, bool cleanup)
 
static void test_width_bomb_key (MVOdb *odb, bool cleanup)
 
static void test_width_bomb_data (MVOdb *odb, bool cleanup)
 
void all (MVOdb *odb)
 
void help ()
 
int main (int argc, char *argv[])
 

Variables

static int gCountFail = 0
 

Function Documentation

◆ all()

void all ( MVOdb *  odb)

Definition at line 164 of file torture_odb.cxx.

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}
static void test_width_bomb_data(MVOdb *odb, bool cleanup)
static void test_depth_bomb(MVOdb *odb, bool cleanup)
static void test_width_bomb_key(MVOdb *odb, bool cleanup)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ help()

void help ( )

Definition at line 175 of file torture_odb.cxx.

176{
177
178
179
180}
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 184 of file torture_odb.cxx.

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}
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 i
Definition mdump.cxx:32
void help()
void all(MVOdb *odb)
Here is the call graph for this function:

◆ print_da()

void print_da ( const std::vector< double > &  da)

Definition at line 39 of file torture_odb.cxx.

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}

◆ print_ia()

void print_ia ( const std::vector< int > &  ia)

Definition at line 27 of file torture_odb.cxx.

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}

◆ report_fail()

void report_fail ( const char *  text)

Definition at line 53 of file torture_odb.cxx.

54{
55 printf("FAIL: %s\n", text);
56 gCountFail++;
57}
static int gCountFail

◆ test_depth_bomb()

static void test_depth_bomb ( MVOdb *  odb,
bool  cleanup 
)
static

Definition at line 59 of file torture_odb.cxx.

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}
Here is the caller graph for this function:

◆ test_width_bomb_data()

static void test_width_bomb_data ( MVOdb *  odb,
bool  cleanup 
)
static

Definition at line 121 of file torture_odb.cxx.

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}
void * data
Definition mana.cxx:268
double count
Definition mdump.cxx:33
std::string msprintf(const char *format,...)
Definition midas.cxx:419
#define name(x)
Definition midas_macro.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_width_bomb_key()

static void test_width_bomb_key ( MVOdb *  odb,
bool  cleanup 
)
static

Definition at line 88 of file torture_odb.cxx.

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}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

std::string toString ( int  i)

Definition at line 20 of file torture_odb.cxx.

21{
22 char buf[256];
23 sprintf(buf, "%d", i);
24 return buf;
25}

Variable Documentation

◆ gCountFail

int gCountFail = 0
static

Definition at line 51 of file torture_odb.cxx.