]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/kc/kc-50-thread.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / regressions / kc / kc-50-thread.c
1 #include <stdlib.h>
2 #include <Security/Security.h>
3 #include <CoreFoundation/CoreFoundation.h>
4 #include <dispatch/dispatch.h>
5 #include <sys/time.h>
6 #include "testmore.h"
7 #include "testenv.h"
8 #include "testleaks.h"
9 #include <pthread.h>
10
11 const double kTestLength = 10.0; // length of a test
12
13 #define MAXIMUM_NUMBER_OF_THREADS 100
14
15 double GetTimeOfDay()
16 {
17 struct timeval tv;
18 gettimeofday(&tv, NULL);
19
20 return (double) tv.tv_sec + (double) tv.tv_usec / 1000000.0;
21 }
22
23
24
25 void* CopyDefaultAndReleaseInSingleThread(void* arg)
26 {
27 OSStatus result;
28
29 double endTime = GetTimeOfDay() + kTestLength;
30 do
31 {
32 SecKeychainRef kc;
33 result = SecKeychainCopyDefault(&kc);
34 CFRelease(kc);
35
36 if (result != noErr)
37 {
38 return NULL;
39 }
40
41 } while (GetTimeOfDay() < endTime);
42
43 return NULL;
44 }
45
46
47
48 int CopyDefaultAndDeleteInMultipleThreadsTest()
49 {
50 const int gMax = MAXIMUM_NUMBER_OF_THREADS;
51 pthread_t threads[gMax];
52
53 // make the threads
54 int i;
55 for (i = 0; i < gMax; ++i)
56 {
57 pthread_create(&threads[i], NULL, CopyDefaultAndReleaseInSingleThread, NULL);
58 }
59
60 // wait for them to complete
61 for (i = 0; i < gMax; ++i)
62 {
63 pthread_join(threads[i], NULL);
64 }
65
66 return 1;
67 }
68
69
70
71 int main(int argc, char* const argv[])
72 {
73 plan_tests(2);
74 ok(CopyDefaultAndDeleteInMultipleThreadsTest(), "CopyDefaultAndDeleteInMultipleThreadsTest");
75 ok_leaks("kc-50-thread");
76 return 0;
77 }
78