3 // libsecurity_transform
5 // Created by J Osborne on 8/17/10.
6 // Copyright 2010 Apple. All rights reserved.
10 #include "SecTransform.h"
11 #include "SecExternalSourceTransform.h"
12 #include "SecNullTransform.h"
15 @implementation speed_test
21 typedef void (^push_block_t)(CFDataRef d);
23 void timed_test(NSString *name, float seconds, SecTransformRef tr, push_block_t push) {
24 __block int num_out = 0;
25 __block int num_in = 0;
26 __block int timeout_out = -1;
27 __block int timeout_in = -1;
28 volatile __block bool done;
29 static CFDataRef z = CFDataCreateWithBytesNoCopy(NULL, zeros, sizeof(zeros), NULL);
31 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, static_cast<int64_t>(seconds * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
33 timeout_out = num_out;
37 dispatch_group_t dg = dispatch_group_create();
38 dispatch_group_enter(dg);
40 dispatch_queue_t q = dispatch_queue_create("counter", NULL);
42 SecTransformExecuteAsync(tr, q, ^(CFTypeRef message, CFErrorRef error, Boolean isFinal) {
47 NSLog(@"Error %@ while running %@", error, name);
50 dispatch_group_leave(dg);
59 dispatch_group_wait(dg, DISPATCH_TIME_FOREVER);
60 NSString *m = [NSString stringWithFormat:@"%@ %d in, %d out times in %f seconds, %d stragglers\n", name, timeout_in, timeout_out, seconds, num_out - timeout_out];
61 [m writeToFile:@"/dev/stdout" atomically:NO encoding:NSUTF8StringEncoding error:NULL];
64 int main(int argc, char *argv[]) {
65 NSAutoreleasePool *ap = [[NSAutoreleasePool alloc] init];
69 SecTransformRef x = SecExternalSourceTransformCreate(NULL);
70 //SecTransformRef t = SecEncodeTransformCreate(kSecBase64Encoding, NULL);
71 SecTransformRef t = SecNullTransformCreate();
72 SecTransformRef g = SecTransformCreateGroupTransform();
74 SecTransformConnectTransforms(x, kSecTransformOutputAttributeName, t, kSecTransformInputAttributeName, g, NULL);
76 timed_test(@"external source", seconds, t, ^(CFDataRef d){
77 SecExternalSourceSetValue(x, d, NULL);
82 // This second test has issues with the stock transform framwork -- it don't think the graph is valid (missing input)
84 //SecTransformRef t = SecEncodeTransformCreate(kSecBase64Encoding, NULL);
85 SecTransformRef t = SecNullTransformCreate();
88 timed_test(@"set INPUT", seconds, t, ^(CFDataRef d){
89 SecTransformSetAttribute(t, kSecTransformInputAttributeName, d, NULL);