]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/threadTest/dbOpenClose.cpp
Security-57336.1.9.tar.gz
[apple/security.git] / SecurityTests / clxutils / threadTest / dbOpenClose.cpp
1 /*
2 * dbOpenClose.cpp - multi-threaded DB open/close test
3 */
4 #include "testParams.h"
5 #include <Security/cssm.h>
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <time.h>
9 #include <security_cdsa_utils/cuCdsaUtils.h>
10 #include <strings.h>
11 #include <utilLib/common.h>
12
13 /* One create at init time, multi threads opening and closing this DB */
14 #define DB_NAME "/tmp/dbOpenCLose.db"
15
16 static CSSM_DL_HANDLE dlHand = 0;
17
18 int dbOpenCloseInit(TestParams *testParams)
19 {
20 dlHand = cuDlStartup();
21 if(dlHand == 0) {
22 printf("***dbOpenCloseInit: Error connecting to DL\n");
23 return -1;
24 }
25
26 int ourRtn = 0;
27
28 /* Create the DB, deleting existing */
29 CSSM_RETURN crtn;
30 CSSM_DB_HANDLE dbHand = 0;
31 crtn = dbCreateOpen(dlHand, DB_NAME,
32 CSSM_TRUE, // doCreate
33 CSSM_TRUE, // delete exist
34 "foobar",
35 &dbHand);
36 if(crtn) {
37 printf("***Error creating %s. Aborting.\n", DB_NAME);
38 ourRtn = -1;
39 }
40 return ourRtn;
41 }
42
43 int dbOpenCloseEval(TestParams *testParams)
44 {
45 int ourRtn = 0;
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);
50 }
51 else if(!testParams->quiet) {
52 printChar(testParams->progressChar);
53 }
54
55 /* attach to existing DB - don't create */
56 CSSM_DB_HANDLE dbHand = cuDbStartupByName(dlHand, (char *)DB_NAME,
57 CSSM_FALSE, // don't create
58 testParams->quiet);
59 if(dbHand == 0) {
60 printf("***dbOpenClose: error attaching to db %s\n", DB_NAME);
61 ourRtn = -1;
62 break;
63 }
64
65 CSSM_DL_DB_HANDLE dlDbHand = {dlHand, dbHand};
66 CSSM_RETURN crtn = CSSM_DL_DbClose(dlDbHand);
67 if(crtn) {
68 cssmPerror("CSSM_DL_DbClose", crtn);
69 printf("***Error closing %s\n", DB_NAME);
70 ourRtn = -1;
71 break;
72 }
73 }
74 return ourRtn;
75 }
76