]> git.saurik.com Git - apple/security.git/blame - SecurityTests/clxutils/threadTest/attach.cpp
Security-57740.31.2.tar.gz
[apple/security.git] / SecurityTests / clxutils / threadTest / attach.cpp
CommitLineData
d8f41ccd
A
1/*
2 * attach/creatContext/deleteContext/detach 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 <string.h>
10#include <utilLib/common.h>
11#include <utilLib/cspwrap.h>
12
13/* for memory leak debug only, with only one thread running */
14#define DO_PAUSE 0
15
16#define ATTACHES_PER_LOOP 100
17#define ATTACH_EACH_LOOP 1 /* 1 ==> ATTACHES_PER_LOOP moduleAttaches */
18 /* 0 ==> all thru testParams->cspHand */
19#define CONTEXT_EACH_LOOP 1 /* 1 ==> CSSM_CSP_Create*Context for each attach */
20 /* 0 ==> just do attach/detach */
21#define CSPDL_ENABLE 1 /* attach to CSP and DL sides of CSPDL */
22#define DO_UNLOAD 0 /* enable CSSM_ModuleUnload() */
23
24#if (!ATTACH_EACH_LOOP && !CONTEXT_EACH_LOOP)
25#error Hey! Must configure for attach and/or createContext!
26#endif
27
28static CSSM_API_MEMORY_FUNCS memFuncs = {
29 appMalloc,
30 appFree,
31 appRealloc,
32 appCalloc,
33 NULL
34 };
35
36int attachTestInit(TestParams *testParams)
37{
38 /* nothing for now */
39 return 0;
40}
41
42static uint8 bogusKeyBits[] = {0, 1, 2, 3};
43static CSSM_VERSION vers = {2, 0};
44
45static CSSM_RETURN attachMod(
46 const CSSM_GUID *guid,
47 CSSM_SERVICE_TYPE svc,
48 CSSM_MODULE_HANDLE_PTR hand)
49{
50 CSSM_RETURN crtn = CSSM_ModuleLoad(guid,
51 CSSM_KEY_HIERARCHY_NONE,
52 NULL, // eventHandler
53 NULL); // AppNotifyCallbackCtx
54 if(crtn) {
55 return crtn;
56 }
57 return CSSM_ModuleAttach(guid,
58 &vers,
59 &memFuncs, // memFuncs
60 0, // SubserviceID
61 svc, // SubserviceFlags
62 0, // AttachFlags
63 CSSM_KEY_HIERARCHY_NONE,
64 NULL, // FunctionTable
65 0, // NumFuncTable
66 NULL, // reserved
67 hand);
68}
69
70static int detachUnload(
71 CSSM_HANDLE hand,
72 const CSSM_GUID *guid)
73{
74 CSSM_RETURN crtn = CSSM_ModuleDetach(hand);
75 if(crtn) {
76 cssmPerror("CSSM_ModuleDetach", crtn);
77 return crtn;
78 }
79 #if DO_UNLOAD
80 crtn = CSSM_ModuleUnload(guid, NULL, NULL);
81 if(crtn) {
82 cssmPerror("CSSM_ModuleUnload", crtn);
83 }
84 #endif
85 return crtn;
86}
87
88int attachTest(TestParams *testParams)
89{
90 unsigned loop;
91 CSSM_RETURN crtn;
92 CSSM_CSP_HANDLE cspHand[ATTACHES_PER_LOOP];
93 CSSM_CL_HANDLE clHand[ATTACHES_PER_LOOP];
94 CSSM_TP_HANDLE tpHand[ATTACHES_PER_LOOP];
95 #if CSPDL_ENABLE
96 CSSM_DL_HANDLE dlHand[ATTACHES_PER_LOOP];
97 CSSM_CSP_HANDLE cspDlHand[ATTACHES_PER_LOOP];
98 #endif
99 CSSM_CC_HANDLE ccHand[ATTACHES_PER_LOOP];
100 unsigned dex;
101 CSSM_KEY bogusKey;
102
103 memset(cspHand, 0, ATTACHES_PER_LOOP * sizeof(CSSM_CSP_HANDLE));
104 memset(ccHand, 0, ATTACHES_PER_LOOP * sizeof(CSSM_CC_HANDLE));
105
106