]> git.saurik.com Git - apple/security.git/blob - tests/secdmockaks/mockaksWatchDog.m
Security-59306.11.20.tar.gz
[apple/security.git] / tests / secdmockaks / mockaksWatchDog.m
1 //
2 // mockaksWatchDog.m
3 // Security
4 //
5
6 #import <XCTest/XCTest.h>
7 #import <OCMock/OCMock.h>
8
9 #import "mockaksxcbase.h"
10 #import "SecdWatchdog.h"
11
12 @interface mockaksWatchDog : mockaksxcbase
13 @property (assign) uint64_t diskusage;
14 @end
15
16 @implementation mockaksWatchDog
17
18 - (bool)mockedWatchdogrusage:(rusage_info_current *)rusage
19 {
20 memset(rusage, 0, sizeof(*rusage));
21 rusage->ri_diskio_byteswritten = self.diskusage;
22 rusage->ri_logical_writes = self.diskusage;
23 return true;
24 }
25
26
27 - (void)testWatchDogDiskWrite {
28
29 id mock = OCMClassMock([SecdWatchdog class]);
30 OCMStub([mock watchdogrusage:[OCMArg anyPointer]]).andCall(self, @selector(mockedWatchdogrusage:));
31 OCMStub([mock triggerOSFaults]).andReturn(FALSE);
32
33 SecdWatchdog *wd = [SecdWatchdog watchdog];
34
35 self.diskusage = 0;
36 XCTAssertFalse(wd.diskUsageHigh, "diskusage high should not be true");
37
38 self.diskusage = 2 * 1000 * 1024 * 1024; // 2GiBi
39 [wd runWatchdog];
40
41 XCTAssertTrue(wd.diskUsageHigh, "diskusage high should be true");
42 }
43
44 @end