有人能帮我理解一下这种罕见且随机的崩溃吗?有没有办法修复此问题而不会重现?线程 0 名称:线程 0 崩溃:0 libdispatch.dylib
有人能帮我理解一下这种罕见且随机的崩溃吗?有没有办法修复这个问题而不让它重现?
Thread 0 name:
Thread 0 Crashed:
0 libdispatch.dylib 0x00000001b2d7e538 _dispatch_sync_f + 4 (queue.c:1898)
1 Security 0x00000001b372d0d8 SecTrustGetCertificateAtIndex + 244 (SecTrust.c:0)
2 PK9 0x0000000102d63124 __61+[CertificateUtils certificatesFromTrust:options:completion:]_block_invoke + 88 (CertificateUtils.m:201)
3 CoreFoundation 0x00000001aadb51b8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28 (CFRunLoop.c:1805)
4 CoreFoundation 0x00000001aadb39ac __CFRunLoopDoBlocks + 356 (CFRunLoop.c:1847)
5 CoreFoundation 0x00000001aadb1888 __CFRunLoopRun + 812 (CFRunLoop.c:2953)
6 CoreFoundation 0x00000001aadb1478 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
7 GraphicsServices 0x00000001ee30a4f8 GSEventRunModal + 164 (GSEvent.c:2196)
8 UIKitCore 0x00000001ad1db360 -[UIApplication _run] + 888 (UIApplication.m:3685)
9 UIKitCore 0x00000001ad1da99c UIApplicationMain + 340 (UIApplication.m:5270)
10 PK9 0x0000000102e5dfe8 main + 68 (main.m:15)
11 dyld 0x00000001cdae9dcc start + 2240 (dyldMain.cpp:1269)
发生崩溃的函数:
+ (void)certificatesFromTrust:(SecTrustRef)trust options:(CertificateOptions)options completion:(void (^)(NSArray *))completion
{
if (trust == NULL) {
completion(nil);
}
else {
// trust needs to be evaluated prior to attempting to retrieve the certs
CFIndex count = SecTrustGetCertificateCount(trust);
[self evaluateTrust:trust completion:^(OSStatus status, SecTrustResultType result) {
NSMutableArray *certs = [NSMutableArray arrayWithCapacity:(NSInteger)count];
for (CFIndex i = 0; i < count; i++) {
SecCertificateRef cert = SecTrustGetCertificateAtIndex(trust, i);
if (cert != NULL) {
// Extract certificate data
NSData *certData = CFBridgingRelease(SecCertificateCopyData(cert));
if (certData != nil && (options & CertificateOptionsRemoveRootCertificates) && count > 1) {
// We were told to strip all anchor certificates, so only keep this one if it's issued by someone else (and not the only cert, i.e. self-signed)
const unsigned char *certDataBytes = (const unsigned char *)[certData bytes];
X509 *x509Cert = d2i_X509(NULL, &certDataBytes, [certData length]);
NSString *subjectCN = X509CertificateGetCommonName(X509_get_subject_name(x509Cert));
NSString *issuerCN = X509CertificateGetCommonName(X509_get_issuer_name(x509Cert));
X509_free(x509Cert);
if ([subjectCN isEqualToString:issuerCN]) {
certData = nil; // do not add root certificates
}
}
if (certData != nil) {
// create a copy of the certificate and add it to the array transferring ownership to ARC
cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)(certData));
[certs addObject:CFBridgingRelease(cert)];
}
}
}
completion(certs);
}];
}
}
我有一个应用需要在其 XCTestCase 子类中动态生成测试方法。我使用 +(NSArray
我有一个应用程序需要在其 XCTestCase
子类中动态生成测试方法。我使用 +(NSArray<NSInvocation*>*)testInvocations
以下(虚拟)名称在运行时动态生成测试方法: example_test
, permissions_location_test
和 permissions_many_test
。下面是简化的、可直接粘贴到 Xcode 中的代码。
@import XCTest;
@import ObjectiveC.runtime;
@interface ParametrizedTests : XCTestCase
@end
@implementation ParametrizedTests
+ (NSArray<NSInvocation *> *)testInvocations {
NSLog(@"testInvocations() called");
/* Prepare dummy input */
__block NSMutableArray<NSString *> *dartTestFiles = [[NSMutableArray alloc] init];
[dartTestFiles addObject:@"example_test"];
[dartTestFiles addObject:@"permissions_location_test"];
[dartTestFiles addObject:@"permissions_many_test"];
NSMutableArray<NSInvocation *> *invocations = [[NSMutableArray alloc] init];
NSLog(@"Before the loop, %lu elements in the array", (unsigned long)dartTestFiles.count);
for (int i = 0; i < dartTestFiles.count; i++) {
/* Step 1 */
NSString *name = dartTestFiles[i];
void (^anonymousFunc)(ParametrizedTests *) = ^(ParametrizedTests *instance) {
NSLog(@"anonymousFunc called!");
};
IMP implementation = imp_implementationWithBlock(anonymousFunc);
NSString *selectorStr = [NSString stringWithFormat:@"%@", name];
SEL selector = NSSelectorFromString(selectorStr);
class_addMethod(self, selector, implementation, "v@:");
/* Step 2 */
NSMethodSignature *signature = [self instanceMethodSignatureForSelector:selector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
invocation.selector = selector;
NSLog(@"RunnerUITests.testInvocations(): selectorStr = %@", selectorStr);
[invocations addObject:invocation];
}
NSLog(@"After the loop");
return invocations;
}
@end
我可以使用以下方法同时运行所有这些测试:
xcodebuild test \
-scheme Landmarks \
-destination 'platform=iOS Simulator,name=iPhone 15'
摘自上述命令的标准输出:
Test Suite 'Selected tests' passed at 2023-11-16 13:44:59.148.
Executed 3 tests, with 0 failures (0 unexpected) in 0.246 (0.248) seconds
我现在面临的问题是,我无法使用 标志选择仅运行一个测试 xcodebuild
。 -only-testing
例如:
xcodebuild test \
-scheme Landmarks \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-only-testing 'LandmarksUITests/ParametrizedTests/example_test'
不起作用-没有执行任何测试:
Test Suite 'ParametrizedTests' passed at 2023-11-16 13:45:58.472.
Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.000) seconds
我也尝试过这样做:
xcodebuild test \
-scheme Landmarks \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-only-testing 'LandmarksUITests/ParametrizedTests/testInvocations'
但结果是一样的。
所以问题是: 如何使用 -only-testing 选项选择测试子集(在运行时使用 testInvocations 动态生成)? 有可能吗?