Changeset 181670 in webkit
- Timestamp:
- Mar 17, 2015 4:06:37 PM (9 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/tests/testapi.c
r181315 r181670 36 36 #include <wtf/Assertions.h> 37 37 38 #if OS(DARWIN)39 #include <mach/mach.h>40 #include <mach/mach_time.h>41 #include <sys/time.h>42 #endif43 44 38 #if OS(WINDOWS) 45 39 #include <windows.h> … … 48 42 #include "CompareAndSwapTest.h" 49 43 #include "CustomGlobalObjectClassTest.h" 44 45 #if OS(DARWIN) 46 #include "ExecutionTimeLimitTest.h" 47 #endif 50 48 51 49 #if JSC_OBJC_API_ENABLED … … 1113 1111 val.name = "something"; 1114 1112 } 1115 1116 #if OS(DARWIN)1117 static double currentCPUTime()1118 {1119 mach_msg_type_number_t infoCount = THREAD_BASIC_INFO_COUNT;1120 thread_basic_info_data_t info;1121 1122 /* Get thread information */1123 mach_port_t threadPort = mach_thread_self();1124 thread_info(threadPort, THREAD_BASIC_INFO, (thread_info_t)(&info), &infoCount);1125 mach_port_deallocate(mach_task_self(), threadPort);1126 1127 double time = info.user_time.seconds + info.user_time.microseconds / 1000000.;1128 time += info.system_time.seconds + info.system_time.microseconds / 1000000.;1129 1130 return time;1131 }1132 1133 static JSValueRef currentCPUTime_callAsFunction(JSContextRef ctx, JSObjectRef functionObject, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)1134 {1135 UNUSED_PARAM(functionObject);1136 UNUSED_PARAM(thisObject);1137 UNUSED_PARAM(argumentCount);1138 UNUSED_PARAM(arguments);1139 UNUSED_PARAM(exception);1140 1141 ASSERT(JSContextGetGlobalContext(ctx) == context);1142 return JSValueMakeNumber(ctx, currentCPUTime());1143 }1144 1145 bool shouldTerminateCallbackWasCalled = false;1146 static bool shouldTerminateCallback(JSContextRef ctx, void* context)1147 {1148 UNUSED_PARAM(ctx);1149 UNUSED_PARAM(context);1150 shouldTerminateCallbackWasCalled = true;1151 return true;1152 }1153 1154 bool cancelTerminateCallbackWasCalled = false;1155 static bool cancelTerminateCallback(JSContextRef ctx, void* context)1156 {1157 UNUSED_PARAM(ctx);1158 UNUSED_PARAM(context);1159 cancelTerminateCallbackWasCalled = true;1160 return false;1161 }1162 1163 int extendTerminateCallbackCalled = 0;1164 static bool extendTerminateCallback(JSContextRef ctx, void* context)1165 {1166 UNUSED_PARAM(context);1167 extendTerminateCallbackCalled++;1168 if (extendTerminateCallbackCalled == 1) {1169 JSContextGroupRef contextGroup = JSContextGetGroup(ctx);1170 JSContextGroupSetExecutionTimeLimit(contextGroup, .200f, extendTerminateCallback, 0);1171 return false;1172 }1173 return true;1174 }1175 #endif /* OS(DARWIN) */1176 1113 1177 1114 … … 1918 1855 1919 1856 #if OS(DARWIN) 1920 JSStringRef currentCPUTimeStr = JSStringCreateWithUTF8CString("currentCPUTime"); 1921 JSObjectRef currentCPUTimeFunction = JSObjectMakeFunctionWithCallback(context, currentCPUTimeStr, currentCPUTime_callAsFunction); 1922 JSObjectSetProperty(context, globalObject, currentCPUTimeStr, currentCPUTimeFunction, kJSPropertyAttributeNone, NULL); 1923 JSStringRelease(currentCPUTimeStr); 1924 1925 /* Test script timeout: */ 1926 JSContextGroupSetExecutionTimeLimit(contextGroup, .10f, shouldTerminateCallback, 0); 1927 { 1928 const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .150) break; } "; 1929 JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript); 1930 double startTime; 1931 double endTime; 1932 exception = NULL; 1933 shouldTerminateCallbackWasCalled = false; 1934 startTime = currentCPUTime(); 1935 v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); 1936 endTime = currentCPUTime(); 1937 1938 if (((endTime - startTime) < .150f) && shouldTerminateCallbackWasCalled) 1939 printf("PASS: script timed out as expected.\n"); 1940 else { 1941 if (!((endTime - startTime) < .150f)) 1942 printf("FAIL: script did not time out as expected.\n"); 1943 if (!shouldTerminateCallbackWasCalled) 1944 printf("FAIL: script timeout callback was not called.\n"); 1945 failed = true; 1946 } 1947 1948 if (!exception) { 1949 printf("FAIL: TerminatedExecutionException was not thrown.\n"); 1950 failed = true; 1951 } 1952 } 1953 1954 /* Test the script timeout's TerminatedExecutionException should NOT be catchable: */ 1955 JSContextGroupSetExecutionTimeLimit(contextGroup, 0.10f, shouldTerminateCallback, 0); 1956 { 1957 const char* loopForeverScript = "var startTime = currentCPUTime(); try { while (true) { if (currentCPUTime() - startTime > .150) break; } } catch(e) { }"; 1958 JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript); 1959 double startTime; 1960 double endTime; 1961 exception = NULL; 1962 shouldTerminateCallbackWasCalled = false; 1963 startTime = currentCPUTime(); 1964 v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); 1965 endTime = currentCPUTime(); 1966 1967 if (((endTime - startTime) >= .150f) || !shouldTerminateCallbackWasCalled) { 1968 if (!((endTime - startTime) < .150f)) 1969 printf("FAIL: script did not time out as expected.\n"); 1970 if (!shouldTerminateCallbackWasCalled) 1971 printf("FAIL: script timeout callback was not called.\n"); 1972 failed = true; 1973 } 1974 1975 if (exception) 1976 printf("PASS: TerminatedExecutionException was not catchable as expected.\n"); 1977 else { 1978 printf("FAIL: TerminatedExecutionException was caught.\n"); 1979 failed = true; 1980 } 1981 } 1982 1983 /* Test script timeout with no callback: */ 1984 JSContextGroupSetExecutionTimeLimit(contextGroup, .10f, 0, 0); 1985 { 1986 const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .150) break; } "; 1987 JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript); 1988 double startTime; 1989 double endTime; 1990 exception = NULL; 1991 startTime = currentCPUTime(); 1992 v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); 1993 endTime = currentCPUTime(); 1994 1995 if (((endTime - startTime) < .150f) && shouldTerminateCallbackWasCalled) 1996 printf("PASS: script timed out as expected when no callback is specified.\n"); 1997 else { 1998 if (!((endTime - startTime) < .150f)) 1999 printf("FAIL: script did not time out as expected when no callback is specified.\n"); 2000 failed = true; 2001 } 2002 2003 if (!exception) { 2004 printf("FAIL: TerminatedExecutionException was not thrown.\n"); 2005 failed = true; 2006 } 2007 } 2008 2009 /* Test script timeout cancellation: */ 2010 JSContextGroupSetExecutionTimeLimit(contextGroup, 0.10f, cancelTerminateCallback, 0); 2011 { 2012 const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .150) break; } "; 2013 JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript); 2014 double startTime; 2015 double endTime; 2016 exception = NULL; 2017 startTime = currentCPUTime(); 2018 v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); 2019 endTime = currentCPUTime(); 2020 2021 if (((endTime - startTime) >= .150f) && cancelTerminateCallbackWasCalled && !exception) 2022 printf("PASS: script timeout was cancelled as expected.\n"); 2023 else { 2024 if (((endTime - startTime) < .150) || exception) 2025 printf("FAIL: script timeout was not cancelled.\n"); 2026 if (!cancelTerminateCallbackWasCalled) 2027 printf("FAIL: script timeout callback was not called.\n"); 2028 failed = true; 2029 } 2030 2031 if (exception) { 2032 printf("FAIL: Unexpected TerminatedExecutionException thrown.\n"); 2033 failed = true; 2034 } 2035 } 2036 2037 /* Test script timeout extension: */ 2038 JSContextGroupSetExecutionTimeLimit(contextGroup, 0.100f, extendTerminateCallback, 0); 2039 { 2040 const char* loopForeverScript = "var startTime = currentCPUTime(); while (true) { if (currentCPUTime() - startTime > .500) break; } "; 2041 JSStringRef script = JSStringCreateWithUTF8CString(loopForeverScript); 2042 double startTime; 2043 double endTime; 2044 double deltaTime; 2045 exception = NULL; 2046 startTime = currentCPUTime(); 2047 v = JSEvaluateScript(context, script, NULL, NULL, 1, &exception); 2048 endTime = currentCPUTime(); 2049 deltaTime = endTime - startTime; 2050 2051 if ((deltaTime >= .300f) && (deltaTime < .500f) && (extendTerminateCallbackCalled == 2) && exception) 2052 printf("PASS: script timeout was extended as expected.\n"); 2053 else { 2054 if (deltaTime < .200f) 2055 printf("FAIL: script timeout was not extended as expected.\n"); 2056 else if (deltaTime >= .500f) 2057 printf("FAIL: script did not timeout.\n"); 2058 2059 if (extendTerminateCallbackCalled < 1) 2060 printf("FAIL: script timeout callback was not called.\n"); 2061 if (extendTerminateCallbackCalled < 2) 2062 printf("FAIL: script timeout callback was not called after timeout extension.\n"); 2063 2064 if (!exception) 2065 printf("FAIL: TerminatedExecutionException was not thrown during timeout extension test.\n"); 2066 2067 failed = true; 2068 } 2069 } 1857 failed = testExecutionTimeLimit(&context) || failed; 2070 1858 #endif /* OS(DARWIN) */ 2071 1859 -
trunk/Source/JavaScriptCore/ChangeLog
r181664 r181670 1 2015-03-17 Mark Lam <mark.lam@apple.com> 2 3 Refactor execution time limit tests out of testapi.c. 4 <https://webkit.org/b/142798> 5 6 Rubber stamped by Michael Saboff. 7 8 These tests were sometimes failing to time out on C loop builds. Let's 9 refactor them out of the big monolith that is testapi.c so that we can 10 reason more easily about them and make adjustments if needed. 11 12 * API/tests/ExecutionTimeLimitTest.cpp: Added. 13 (currentCPUTime): 14 (currentCPUTimeAsJSFunctionCallback): 15 (shouldTerminateCallback): 16 (cancelTerminateCallback): 17 (extendTerminateCallback): 18 (testExecutionTimeLimit): 19 * API/tests/ExecutionTimeLimitTest.h: Added. 20 * API/tests/testapi.c: 21 (main): 22 (currentCPUTime): Deleted. 23 (currentCPUTime_callAsFunction): Deleted. 24 (shouldTerminateCallback): Deleted. 25 (cancelTerminateCallback): Deleted. 26 (extendTerminateCallback): Deleted. 27 * JavaScriptCore.xcodeproj/project.pbxproj: 28 1 29 2015-03-17 Geoffrey Garen <ggaren@apple.com> 2 30 -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r181458 r181670 75 75 76 76 /* Begin PBXBuildFile section */ 77 0A6441519420A6C61AD1882E /* MapDataInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 593D43CCA0BBE06D89C59707 /* MapDataInlines.h */; settings = {ATTRIBUTES = (Private, ); }; }; 77 78 0F0123321944EA1B00843A0C /* DFGValueStrength.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F0123301944EA1B00843A0C /* DFGValueStrength.cpp */; }; 78 79 0F0123331944EA1B00843A0C /* DFGValueStrength.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F0123311944EA1B00843A0C /* DFGValueStrength.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 1332 1333 A784A26411D16622005776AC /* SyntaxChecker.h in Headers */ = {isa = PBXBuildFile; fileRef = A7A7EE7711B98B8D0065A14F /* SyntaxChecker.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1333 1334 A78507D717CBC6FD0011F6E7 /* MapData.h in Headers */ = {isa = PBXBuildFile; fileRef = A78507D517CBC6FD0011F6E7 /* MapData.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1334 0A6441519420A6C61AD1882E /* MapDataInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 593D43CCA0BBE06D89C59707 /* MapDataInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };1335 1335 A785F6BC18C553FE00F10626 /* SpillRegistersMode.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FF647A18C52E8500B55307 /* SpillRegistersMode.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1336 1336 A78853F917972629001440E4 /* IntendedStructureChain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A78853F717972629001440E4 /* IntendedStructureChain.cpp */; }; … … 1612 1612 E49DC16C12EF294E00184A1F /* SourceProviderCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC15112EF272200184A1F /* SourceProviderCache.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1613 1613 E49DC16D12EF295300184A1F /* SourceProviderCacheItem.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC14912EF261A00184A1F /* SourceProviderCacheItem.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1614 FE0D4A061AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE0D4A041AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp */; }; 1614 1615 FE20CE9D15F04A9500DF3430 /* LLIntCLoop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE20CE9B15F04A9500DF3430 /* LLIntCLoop.cpp */; }; 1615 1616 FE20CE9E15F04A9500DF3430 /* LLIntCLoop.h in Headers */ = {isa = PBXBuildFile; fileRef = FE20CE9C15F04A9500DF3430 /* LLIntCLoop.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 2576 2577 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = "<group>"; }; 2577 2578 5540758418F4A37500602A5D /* CompileRuntimeToLLVMIR.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CompileRuntimeToLLVMIR.xcconfig; sourceTree = "<group>"; }; 2579 593D43CCA0BBE06D89C59707 /* MapDataInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapDataInlines.h; sourceTree = "<group>"; }; 2578 2580 5D53726D0E1C546B0021E549 /* Tracing.d */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Tracing.d; sourceTree = "<group>"; }; 2579 2581 5D53726E0E1C54880021E549 /* Tracing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tracing.h; sourceTree = "<group>"; }; … … 3040 3042 A77F18241641925400640A47 /* ParserModes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ParserModes.h; sourceTree = "<group>"; }; 3041 3043 A78507D517CBC6FD0011F6E7 /* MapData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapData.h; sourceTree = "<group>"; }; 3042 593D43CCA0BBE06D89C59707 /* MapDataInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MapDataInlines.h; sourceTree = "<group>"; };3043 3044 A78853F717972629001440E4 /* IntendedStructureChain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntendedStructureChain.cpp; sourceTree = "<group>"; }; 3044 3045 A78853F817972629001440E4 /* IntendedStructureChain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntendedStructureChain.h; sourceTree = "<group>"; }; … … 3358 3359 F692A87E0255597D01FF60F7 /* RegExp.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = RegExp.h; sourceTree = "<group>"; tabWidth = 8; }; 3359 3360 F692A8870255597D01FF60F7 /* JSCJSValue.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCJSValue.cpp; sourceTree = "<group>"; tabWidth = 8; }; 3361 FE0D4A041AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExecutionTimeLimitTest.cpp; path = API/tests/ExecutionTimeLimitTest.cpp; sourceTree = "<group>"; }; 3362 FE0D4A051AB8DD0A002F54BF /* ExecutionTimeLimitTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExecutionTimeLimitTest.h; path = API/tests/ExecutionTimeLimitTest.h; sourceTree = "<group>"; }; 3360 3363 FE20CE9B15F04A9500DF3430 /* LLIntCLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LLIntCLoop.cpp; path = llint/LLIntCLoop.cpp; sourceTree = "<group>"; }; 3361 3364 FE20CE9C15F04A9500DF3430 /* LLIntCLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LLIntCLoop.h; path = llint/LLIntCLoop.h; sourceTree = "<group>"; }; … … 3743 3746 C288B2DC18A54D3E007BE40B /* DateTests.h */, 3744 3747 C288B2DD18A54D3E007BE40B /* DateTests.mm */, 3748 FE0D4A041AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp */, 3749 FE0D4A051AB8DD0A002F54BF /* ExecutionTimeLimitTest.h */, 3745 3750 C2181FC018A948FB0025A235 /* JSExportTests.h */, 3746 3751 C2181FC118A948FB0025A235 /* JSExportTests.mm */, … … 6792 6797 1440F6100A4F85670005F061 /* testapi.c in Sources */, 6793 6798 86D2221A167EF9440024C804 /* testapi.mm in Sources */, 6799 FE0D4A061AB8DD0A002F54BF /* ExecutionTimeLimitTest.cpp in Sources */, 6794 6800 ); 6795 6801 runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset
for help on using the changeset viewer.