X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/SecurityTests/clxutils/threadTest/dbOpenClose.cpp?ds=sidebyside diff --git a/SecurityTests/clxutils/threadTest/dbOpenClose.cpp b/SecurityTests/clxutils/threadTest/dbOpenClose.cpp new file mode 100644 index 00000000..e6825d90 --- /dev/null +++ b/SecurityTests/clxutils/threadTest/dbOpenClose.cpp @@ -0,0 +1,76 @@ +/* + * dbOpenClose.cpp - multi-threaded DB open/close test + */ +#include "testParams.h" +#include +#include +#include +#include +#include +#include +#include + +/* One create at init time, multi threads opening and closing this DB */ +#define DB_NAME "/tmp/dbOpenCLose.db" + +static CSSM_DL_HANDLE dlHand = 0; + +int dbOpenCloseInit(TestParams *testParams) +{ + dlHand = cuDlStartup(); + if(dlHand == 0) { + printf("***dbOpenCloseInit: Error connecting to DL\n"); + return -1; + } + + int ourRtn = 0; + + /* Create the DB, deleting existing */ + CSSM_RETURN crtn; + CSSM_DB_HANDLE dbHand = 0; + crtn = dbCreateOpen(dlHand, DB_NAME, + CSSM_TRUE, // doCreate + CSSM_TRUE, // delete exist + "foobar", + &dbHand); + if(crtn) { + printf("***Error creating %s. Aborting.\n", DB_NAME); + ourRtn = -1; + } + return ourRtn; +} + +int dbOpenCloseEval(TestParams *testParams) +{ + int ourRtn = 0; + for(unsigned loop=0; loopnumLoops; loop++) { + if(testParams->verbose) { + printf("dbOpenClose thread %d: loop %d\n", + testParams->threadNum, loop); + } + else if(!testParams->quiet) { + printChar(testParams->progressChar); + } + + /* attach to existing DB - don't create */ + CSSM_DB_HANDLE dbHand = cuDbStartupByName(dlHand, (char *)DB_NAME, + CSSM_FALSE, // don't create + testParams->quiet); + if(dbHand == 0) { + printf("***dbOpenClose: error attaching to db %s\n", DB_NAME); + ourRtn = -1; + break; + } + + CSSM_DL_DB_HANDLE dlDbHand = {dlHand, dbHand}; + CSSM_RETURN crtn = CSSM_DL_DbClose(dlDbHand); + if(crtn) { + cssmPerror("CSSM_DL_DbClose", crtn); + printf("***Error closing %s\n", DB_NAME); + ourRtn = -1; + break; + } + } + return ourRtn; +} +