]> git.saurik.com Git - apple/security.git/blob - keychain/securityd/Regressions/secd-75-engine-views.m
Security-59754.80.3.tar.gz
[apple/security.git] / keychain / securityd / Regressions / secd-75-engine-views.m
1 /*
2 * Copyright (c) 2015 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 #include "keychain/SecureObjectSync/Regressions/SOSTestDevice.h"
26 #include "secd_regressions.h"
27 #include "SecdTestKeychainUtilities.h"
28 #include <utilities/SecCFWrappers.h>
29 #include "keychain/SecureObjectSync/SOSPeer.h"
30 #include "SOSAccountTesting.h"
31
32 #if SOS_ENABLED
33
34 static int kTestTestCount = 53;
35
36 // Add 1000 items on each device. Then delete 1000 items on each device.
37 static void test_engine_views(void) {
38 __block int iteration=0;
39 __block int objectix=0;
40 __block CFMutableArrayRef objectNames = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
41 const size_t itemDataSize = 1024;
42 const int peerCount = 4;
43 const int edgeCount = peerCount * (peerCount - 1);
44 const int itemsPerPeer = 1000;
45 const int itemsPerIteration = 100;
46 const int itemChunkCount = (itemsPerPeer / itemsPerIteration);
47 const int deleteIteration = edgeCount * (itemChunkCount + 30);
48 const int idleIteration = 616; //deleteIteration + edgeCount * (itemChunkCount + 10);
49
50 CFMutableDataRef itemData = CFDataCreateMutable(kCFAllocatorDefault, itemDataSize);
51 CFDataSetLength(itemData, itemDataSize);
52
53 const char *name = "engine_views";
54 //const char *test_directive
55 //const char *test_reason
56 CFIndex version = 0;
57 bool(^pre)(SOSTestDeviceRef source, SOSTestDeviceRef dest) = ^bool(SOSTestDeviceRef source, SOSTestDeviceRef dest) {
58 bool result = false;
59 if (iteration <= edgeCount * itemChunkCount) {
60 if (iteration % (peerCount - 1) == 0) {
61 for (int j = 0; j < itemsPerIteration; ++j) {
62 CFStringRef name = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@-pre-%d"), SOSTestDeviceGetID(source), objectix++);
63 CFArrayAppendValue(objectNames, name);
64 SOSTestDeviceAddGenericItemWithData(source, name, name, itemData);
65 CFReleaseNull(name);
66 }
67 }
68 result = true;
69 } else if (iteration == deleteIteration) {
70 //diag("deletion starting");
71 } else if (deleteIteration < iteration && iteration <= deleteIteration + edgeCount * itemChunkCount) {
72 if (iteration % (peerCount - 1) == 0) {
73 for (int j = 0; j < itemsPerIteration; ++j) {
74 CFStringRef name = CFArrayGetValueAtIndex(objectNames, --objectix);
75 SOSTestDeviceAddGenericItemTombstone(source, name, name);
76 }
77 result = true;
78 }
79 } else if (idleIteration == iteration) {
80 //diag("idle starting");
81 } else if (617 == iteration) {
82 //diag("interesting");
83 }
84 iteration++;
85 return result || iteration < deleteIteration;
86 };
87 bool(^post)(SOSTestDeviceRef source, SOSTestDeviceRef dest, SOSMessageRef message) = ^bool(SOSTestDeviceRef source, SOSTestDeviceRef dest, SOSMessageRef message) {
88 return false;
89 };
90
91 // Optionally prefix each peer with name to make them more unique.
92 CFArrayRef deviceIDs = CFArrayCreateForCFTypes(kCFAllocatorDefault, CFSTR("becks"), CFSTR("corona"), CFSTR("heineken"), CFSTR("spaten"), NULL);
93 CFSetRef views = SOSViewsCopyTestV2Default();
94 CFMutableArrayRef peerMetas = CFArrayCreateMutableForCFTypes(kCFAllocatorDefault);
95 CFStringRef deviceID;
96 CFArrayForEachC(deviceIDs, deviceID) {
97 SOSPeerMetaRef peerMeta = SOSPeerMetaCreateWithComponents(deviceID, views, NULL);
98 CFArrayAppendValue(peerMetas, peerMeta);
99 CFReleaseNull(peerMeta);
100 }
101
102 CFMutableDictionaryRef testDevices = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
103 CFArrayForEachC(deviceIDs, deviceID) {
104 SOSTestDeviceRef device = SOSTestDeviceCreateWithDbNamed(kCFAllocatorDefault, deviceID, deviceID);
105 SOSTestDeviceSetPeerIDs(device, peerMetas, version, NULL);
106 CFDictionarySetValue(testDevices, deviceID, device);
107 CFReleaseNull(device);
108 }
109 CFDictionarySetValue(testDevices, CFSTR("@devicesIDs"), deviceIDs);
110 CFReleaseNull(deviceIDs);
111
112 SOSTestDeviceListSync(name, test_directive, test_reason, testDevices, pre, post);
113 SOSTestDeviceListInSync(name, test_directive, test_reason, testDevices);
114 SOSTestDeviceDestroyEngine(testDevices);
115 CFReleaseNull(testDevices);
116
117 CFReleaseNull(views);
118 CFReleaseNull(objectNames);
119 CFReleaseNull(itemData);
120 }
121 #endif
122
123 int secd_75_engine_views(int argc, char *const *argv)
124 {
125 #if SOS_ENABLED
126 plan_tests(kTestTestCount);
127 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
128 test_engine_views();
129 #else
130 plan_tests(0);
131 #endif
132 return 0;
133 }