/* * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ #include #include #include #include #include #include #include #include /* * IOPMAssertions test case. * Assert each known assertion once, then release it. * Then assert all assertions together, and release them. * */ #define kSystemMaxAssertionsAllowed 64 #define kInvalidNamesCount 2 const char *invalidNames[] = { "••000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000•••••••••••••••00000", "00005555555566666666666666667777777777777777700000000000AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA000000000000000XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", }; #define kFunnyNamesCount 8 const char *funnyAssertionNames[] = { "AssertionZero", "AssertionThatIsVeryLong.WhatTheHellAreYouLookingAt.WaitItGetsEvenLonger.", "???????????????????????????????????????????????????????????????????????????????????????????", "blah", "test one, test two. uh huh uh huh.", "hi.", "aura real", "test test" }; static CFStringRef createFunnyAssertionName(void) { static int i = 0; return CFStringCreateWithCString(0, funnyAssertionNames[i++ % kFunnyNamesCount], kCFStringEncodingMacRoman); } static CFStringRef createInvalidAssertionName(void) { static int i = 0; return CFStringCreateWithCString(0, invalidNames[i++ % kInvalidNamesCount], kCFStringEncodingMacRoman); }; int main() { char *XIconfig = NULL; int XIecho = true; int XIxml = false; char *XILogPath = NULL; //"~/Desktop/AssertEach.log"; // // XILog Initialization // XILogRef logRef = XILogOpenLog(XILogPath, "PMAssertions", "com.apple.iokit.ethan", XIconfig, XIxml, XIecho); if(logRef == NULL) { fprintf(stderr,"Couldn't create log: %s", XILogPath ? XILogPath : "(NULL)"); exit(-1); } Test_runthroughonce(logRef); Test_loderunner(); return 0; } void Test_runthrughonce(XILogRef logRef) { CFDictionaryRef currentAssertionsStatus = NULL; IOReturn ret; CFStringRef *listAssertions = NULL; int assertionsCount = 0; IOPMAssertionID *assertionIDArray = NULL; int i; // // Test setup // ret = IOPMCopyAssertionsStatus(¤tAssertionsStatus); if ((ret != kIOReturnSuccess) && (NULL == currentAssertionsStatus)) { fprintf(stderr, "Error return ret = 0x%08x currentAssertionsStatus dictionary = %p", ret, currentAssertionsStatus); } assertionsCount = CFDictionaryGetCount(currentAssertionsStatus); listAssertions = (CFStringRef *)calloc(assertionsCount, sizeof(void *)); assertionIDArray = (IOPMAssertionID *)calloc(assertionsCount, sizeof(IOPMAssertionID)); CFDictionaryGetKeysAndValues( currentAssertionsStatus, (const void **)listAssertions, (const void **)NULL); /**************************************************************************/ /**************************************************************************/ /* Test: Assert one at a time *****/ XILogBeginTestCase(logRef, "AssertAndReleaseTest", "Can we assert and release assertions individually."); XILogMsg("Assert and Release test will run %d assertions.", assertionsCount); for (i=0; iMax assertions **********/ #define kDoManyManyAssertionsCount 70 XILogBeginTestCase(logRef, "AssertMoreThanAllowed", "Assert greater than MAX_ASSERTIONS = 64."); XILogMsg("Creating %d assertions to exceed the system's per-process PM assertion limit.", kDoManyManyAssertionsCount); IOPMAssertionID manyAssertions[kDoManyManyAssertionsCount]; bzero(manyAssertions, sizeof(manyAssertions)); for (i=0; i MAC_OS_X_VERSION_10_5