2 * Copyright (c) 2015 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
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"
31 static int kTestTestCount = 53;
33 // Add 1000 items on each device. Then delete 1000 items on each device.
34 static void test_engine_views(void) {
35 __block int iteration=0;
36 __block int objectix=0;
37 __block CFMutableArrayRef objectNames = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
38 const size_t itemDataSize = 1024;
39 const int peerCount = 4;
40 const int edgeCount = peerCount * (peerCount - 1);
41 const int itemsPerPeer = 1000;
42 const int itemsPerIteration = 100;
43 const int itemChunkCount = (itemsPerPeer / itemsPerIteration);
44 const int deleteIteration = edgeCount * (itemChunkCount + 30);
45 const int idleIteration = 616; //deleteIteration + edgeCount * (itemChunkCount + 10);
47 CFMutableDataRef itemData = CFDataCreateMutable(kCFAllocatorDefault, itemDataSize);
48 CFDataSetLength(itemData, itemDataSize);
50 const char *name = "engine_views";
51 //const char *test_directive
52 //const char *test_reason
54 bool(^pre)(SOSTestDeviceRef source, SOSTestDeviceRef dest) = ^bool(SOSTestDeviceRef source, SOSTestDeviceRef dest) {
56 if (iteration <= edgeCount * itemChunkCount) {
57 if (iteration % (peerCount - 1) == 0) {
58 for (int j = 0; j < itemsPerIteration; ++j) {
59 CFStringRef name = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@-pre-%d"), SOSTestDeviceGetID(source), objectix++);
60 CFArrayAppendValue(objectNames, name);
61 SOSTestDeviceAddGenericItemWithData(source, name, name, itemData);
66 } else if (iteration == deleteIteration) {
67 //diag("deletion starting");
68 } else if (deleteIteration < iteration && iteration <= deleteIteration + edgeCount * itemChunkCount) {
69 if (iteration % (peerCount - 1) == 0) {
70 for (int j = 0; j < itemsPerIteration; ++j) {
71 CFStringRef name = CFArrayGetValueAtIndex(objectNames, --objectix);
72 SOSTestDeviceAddGenericItemTombstone(source, name, name);
76 } else if (idleIteration == iteration) {
77 //diag("idle starting");
78 } else if (617 == iteration) {
79 //diag("interesting");
82 return result || iteration < deleteIteration;
84 bool(^post)(SOSTestDeviceRef source, SOSTestDeviceRef dest, SOSMessageRef message) = ^bool(SOSTestDeviceRef source, SOSTestDeviceRef dest, SOSMessageRef message) {
88 // Optionally prefix each peer with name to make them more unique.
89 CFArrayRef deviceIDs = CFArrayCreateForCFTypes(kCFAllocatorDefault, CFSTR("becks"), CFSTR("corona"), CFSTR("heineken"), CFSTR("spaten"), NULL);
90 CFSetRef views = SOSViewsCopyTestV2Default();
91 CFMutableArrayRef peerMetas = CFArrayCreateMutableForCFTypes(kCFAllocatorDefault);
93 CFArrayForEachC(deviceIDs, deviceID) {
94 SOSPeerMetaRef peerMeta = SOSPeerMetaCreateWithComponents(deviceID, views, NULL);
95 CFArrayAppendValue(peerMetas, peerMeta);
96 CFReleaseNull(peerMeta);
99 CFMutableDictionaryRef testDevices = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
100 CFArrayForEachC(deviceIDs, deviceID) {
101 SOSTestDeviceRef device = SOSTestDeviceCreateWithDbNamed(kCFAllocatorDefault, deviceID, deviceID);
102 SOSTestDeviceSetPeerIDs(device, peerMetas, version, NULL);
103 CFDictionarySetValue(testDevices, deviceID, device);
104 CFReleaseNull(device);
106 CFDictionarySetValue(testDevices, CFSTR("@devicesIDs"), deviceIDs);
107 CFReleaseNull(deviceIDs);
109 SOSTestDeviceListSync(name, test_directive, test_reason, testDevices, pre, post);
110 SOSTestDeviceListInSync(name, test_directive, test_reason, testDevices);
111 SOSTestDeviceDestroyEngine(testDevices);
112 CFReleaseNull(testDevices);
114 CFReleaseNull(views);
115 CFReleaseNull(objectNames);
116 CFReleaseNull(itemData);
119 int secd_75_engine_views(int argc, char *const *argv)
121 plan_tests(kTestTestCount);
123 /* custom keychain dir */
124 secd_test_setup_temp_keychain(__FUNCTION__, NULL);