kc-20-item-find-stress.c [plain text]
#import <Security/Security.h>
#import <Security/SecCertificatePriv.h>
#include "keychain_regressions.h"
#include "kc-helpers.h"
#include "kc-item-helpers.h"
#include <Security/Security.h>
#include <stdlib.h>
#define BLOCKS 7000
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();
for(int i = 0; i < BLOCKS; i++) {
dispatch_group_async(g, release_queue, ^() {
SecKeychainItemRef blockItem = NULL;
CFMutableDictionaryRef query = createQueryCustomItemDictionaryWithService(kc, kSecClassInternetPassword, CFSTR("test_service"), CFSTR("test_service"));
CFDictionarySetValue(query, kSecMatchLimit, kSecMatchLimitOne);
ok_status(SecItemCopyMatching(query, (CFTypeRef*) &blockItem), "%s: SecItemCopyMatching(%d)", testName, i);
CFReleaseNull(blockItem);
});
}
dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
ok_status(SecKeychainDelete(kc), "%s: SecKeychainDelete", testName);
CFReleaseNull(kc);
}
int kc_20_item_find_stress(int argc, char *const *argv)
{
plan_tests((1)*BLOCKS + getPopulatedTestKeychainTests + 1);
initializeKeychainTests(__FUNCTION__);
tests();
deleteTestFiles();
return 0;
}