Skip to content

Commit

Permalink
Move the diagnostic logs delegate code from all clusters app common code
Browse files Browse the repository at this point in the history
- Fix the MTRDeviceTests to generate log files of different sizes using a sample text string
  • Loading branch information
nivi-apple committed Nov 14, 2023
1 parent 56b73e2 commit c259633
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/binding-handler.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/bridged-actions-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/concentration-measurement-instances.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/diagnostic-logs-provider-delegate-impl.cpp",
"${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/dishwasher-alarm-stub.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/dishwasher-mode.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/fan-stub.cpp",
Expand Down
31 changes: 22 additions & 9 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#import <XCTest/XCTest.h>

static const uint16_t kPairingTimeoutInSeconds = 10;
static const uint16_t kDownloadLogTimeoutInSeconds = 50;
static const uint16_t kDownloadLogTimeoutInSeconds = 30;
static const uint16_t kTimeoutInSeconds = 3;
static const uint64_t kDeviceId = 0x12344321;
static NSString * kOnboardingPayload = @"MT:-24J0AFN00KA0648G00";
Expand Down Expand Up @@ -2631,20 +2631,33 @@ - (NSTask *)createTaskForPath:(NSString *)path
}

- (NSError *)generateLogFile:(NSString *)outFile
size:(unsigned long long)size
{
NSTask * appTask = [self createTaskForPath:@"out/debug/chip-all-clusters-app"];

// Remove the file if one exists
[[NSFileManager defaultManager] removeItemAtPath:outFile error:nil];

// Create the file
[[NSFileManager defaultManager] createFileAtPath:outFile contents:nil attributes:nil];

NSFileHandle * handle = [NSFileHandle fileHandleForUpdatingAtPath:outFile];
appTask.standardOutput = handle;
NSString * content = @"The quick brown fox jumps over the lazy dog";
NSFileHandle * handle = [NSFileHandle fileHandleForWritingAtPath:outFile];
if (handle == nil)
{
NSLog(@"Failed to generate the log file %@", outFile);
}

NSError * error = nil;
unsigned long long offset = 0;

while (offset < size - content.length && error == nil)
{
if ([handle getOffset:&offset error:nil])
{
[handle writeData:[content dataUsingEncoding:NSUTF8StringEncoding] error:&error];
}
}

[appTask launchAndReturnError:&error];
[handle closeFile];
return error;
}

Expand All @@ -2661,7 +2674,7 @@ - (void)test029_DownloadEndUserSupportLog_NoTimeout
XCTAssertNotNil(device);

NSString * outFile = [NSString stringWithFormat:@"/tmp/endusersupportlog.txt"];
NSError * error = [self generateLogFile:outFile];
NSError * error = [self generateLogFile:outFile size:(10 * 1024)];

if (error != nil) {
NSLog(@"Failed to generate log file");
Expand Down Expand Up @@ -2696,7 +2709,7 @@ - (void)test030_DownloadNetworkDiagnosticsLog_NoTimeout
XCTAssertNotNil(device);

NSString * outFile = [NSString stringWithFormat:@"/tmp/networkdiagnosticslog.txt"];
NSError * error = [self generateLogFile:outFile];
NSError * error = [self generateLogFile:outFile size:(4 * 1024)];

if (error != nil) {
NSLog(@"Failed to generate log file");
Expand Down Expand Up @@ -2731,7 +2744,7 @@ - (void)test031_DownloadCrashLog_NoTimeout
XCTAssertNotNil(device);

NSString * outFile = [NSString stringWithFormat:@"/tmp/crashlog.txt"];
NSError * error = [self generateLogFile:outFile];
NSError * error = [self generateLogFile:outFile size:(3 * 1024)];

if (error != nil) {
NSLog(@"Failed to generate log file");
Expand Down

0 comments on commit c259633

Please sign in to comment.