2 * dbOpenClose.cpp - multi-threaded DB open/close test
4 #include "testParams.h"
5 #include <Security/cssm.h>
9 #include <security_cdsa_utils/cuCdsaUtils.h>
11 #include <utilLib/common.h>
13 /* One create at init time, multi threads opening and closing this DB */
14 #define DB_NAME "/tmp/dbOpenCLose.db"
16 static CSSM_DL_HANDLE dlHand
= 0;
18 int dbOpenCloseInit(TestParams
*testParams
)
20 dlHand
= cuDlStartup();
22 printf("***dbOpenCloseInit: Error connecting to DL\n");
28 /* Create the DB, deleting existing */
30 CSSM_DB_HANDLE dbHand
= 0;
31 crtn
= dbCreateOpen(dlHand
, DB_NAME
,
32 CSSM_TRUE
, // doCreate
33 CSSM_TRUE
, // delete exist
37 printf("***Error creating %s. Aborting.\n", DB_NAME
);
43 int dbOpenCloseEval(TestParams
*testParams
)
46 for(unsigned loop
=0; loop
<testParams
->numLoops
; loop
++) {
47 if(testParams
->verbose
) {
48 printf("dbOpenClose thread %d: loop %d\n",
49 testParams
->threadNum
, loop
);
51 else if(!testParams
->quiet
) {
52 printChar(testParams
->progressChar
);
55 /* attach to existing DB - don't create */
56 CSSM_DB_HANDLE dbHand
= cuDbStartupByName(dlHand
, (char *)DB_NAME
,
57 CSSM_FALSE
, // don't create
60 printf("***dbOpenClose: error attaching to db %s\n", DB_NAME
);
65 CSSM_DL_DB_HANDLE dlDbHand
= {dlHand
, dbHand
};
66 CSSM_RETURN crtn
= CSSM_DL_DbClose(dlDbHand
);
68 cssmPerror("CSSM_DL_DbClose", crtn
);
69 printf("***Error closing %s\n", DB_NAME
);