kc-20-key-find-stress.c [plain text]
#import <Security/Security.h>
#import <Security/SecCertificatePriv.h>
#include "keychain_regressions.h"
#include "kc-helpers.h"
#include "kc-key-helpers.h"
#include <Security/Security.h>
#include <stdlib.h>
#define BLOCKS 7000
static long concurrentBlocks = 64;
static void tests() {
SecKeychainRef kc = getPopulatedTestKeychain();
static dispatch_once_t onceToken = 0;
static dispatch_queue_t release_queue = NULL;
dispatch_once(&onceToken, ^{
release_queue = dispatch_queue_create("com.apple.security.identity-search-queue", DISPATCH_QUEUE_CONCURRENT);
});
dispatch_group_t g = dispatch_group_create();
__block int iteration = 0;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(concurrentBlocks);
dispatch_block_t identityBlock = ^() {
SecKeychainItemRef blockItem = NULL;
CFMutableDictionaryRef query = createQueryKeyDictionary(kc, kSecAttrKeyClassSymmetric);
CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitOne);
ok_status(SecItemCopyMatching(query, (CFTypeRef*) &blockItem), "%s: SecItemCopyMatching", testName);
CFReleaseNull(blockItem);
CFReleaseNull(query);
dispatch_semaphore_signal(semaphore);
};
dispatch_group_async(g, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
for (iteration = 0; iteration < BLOCKS; iteration++) {
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_group_async(g, release_queue, identityBlock);
}
});
dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
ok_status(SecKeychainDelete(kc), "%s: SecKeychainDelete", testName);
CFReleaseNull(kc);
}
int kc_20_key_find_stress(int argc, char *const *argv)
{
plan_tests((1)*BLOCKS + 3);
initializeKeychainTests(__FUNCTION__);
tests();
deleteTestFiles();
return 0;
}