assert_settimeout.c [plain text]
#include <IOKit/IOReturn.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/pwr_mgt/IOPMLibPrivate.h>
#include <stdlib.h>
#include <stdio.h>
#include "PMTestLib.h"
#define DO_ITERATIONS 10
int main()
{
IOReturn ret = kIOReturnSuccess;
IOPMAssertionID assertion_id = 0;
int didIterations = 0;
int didFork = 0;
int i=0;
int failureLine = 0;
PMTestInitialize("assertion_settimeout: stressing assertion create, release, and timeouts", "com.apple.iokit.powermanagement");
PMTestLog("Performing %d assert, settimeout, release cycles.", DO_ITERATIONS);
for (i=0; i<DO_ITERATIONS; i++)
{
if (0 != fork()) {
continue;
}
ret = IOPMAssertionCreate( kIOPMAssertionTypeNoDisplaySleep,
kIOPMAssertionLevelOn,
&assertion_id);
if(kIOReturnSuccess != ret) {
PMTestFail("Error 0x%08x from IOPMAssertionCreate()\n", ret);
failureLine = __LINE__;
break;
}
ret = IOPMAssertionSetTimeout(assertion_id, 1.0);
if(kIOReturnSuccess != ret) {
PMTestFail("Error 0x%08x from IOPMAssertionSetTimeout()\n", ret);
failureLine = __LINE__;
break;
}
printf("Forked child exiting without releasing assertion. (%d)\n", didFork);
exit(0);
}
didIterations = i;
PMTestLog("IOPMAssertionSetTimeout stress test: Did %d iterations, %d of which were forked children.", didIterations, didFork);
if (kIOReturnSuccess != ret) {
PMTestFail("Failure - IOReturn value 0x%08x returned at %s:%d", ret, __FILE__, failureLine);
} else {
PMTestPass("settimeout stress test succeeded.");
}
return 0;
}