Bug 1209911 - Add oomThreadTypes() test function to report the number of thread types we can simulate OOM on r=terrence

--HG--
extra : rebase_source : facfa7ff892375e7c5999cd9310948866542e2f9
This commit is contained in:
Jon Coppeard 2015-10-06 14:50:49 +01:00
Родитель 810fbfb206
Коммит 298b347ff4
2 изменённых файлов: 37 добавлений и 19 удалений

Просмотреть файл

@ -984,6 +984,14 @@ DisableTrackAllocations(JSContext* cx, unsigned argc, Value* vp)
}
#if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
static bool
OOMThreadTypes(JSContext* cx, unsigned argc, Value* vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
args.rval().setInt32(js::oom::THREAD_TYPE_MAX);
return true;
}
static bool
OOMAfterAllocations(JSContext* cx, unsigned argc, Value* vp)
{
@ -2928,6 +2936,11 @@ static const JSFunctionSpecWithHelp TestingFunctions[] = {
" Stop capturing the JS stack at every allocation."),
#if defined(DEBUG) || defined(JS_OOM_BREAKPOINT)
JS_FN_HELP("oomThreadTypes", OOMThreadTypes, 0, 0,
"oomThreadTypes()",
" Get the number of thread types that can be used as an argument for\n"
"oomAfterAllocations() and oomAtAllocation()."),
JS_FN_HELP("oomAfterAllocations", OOMAfterAllocations, 2, 0,
"oomAfterAllocations(count [,threadType])",
" After 'count' js_malloc memory allocations, fail every following allocation\n"

Просмотреть файл

@ -1,34 +1,39 @@
// Function to test OOM handling by repeatedly calling a function and failing
// successive allocations.
const verbose = false;
if (!("oomAtAllocation" in this && "resetOOMFailure" in this))
if (!("oomAtAllocation" in this && "resetOOMFailure" in this && "oomThreadTypes" in this))
quit();
if ("gczeal" in this)
gczeal(0);
const verbose = ("os" in this) && os.getenv("OOM_VERBOSE");
// Test out of memory handing by calling a function f() while causing successive
// memory allocations to fail. Repeat until f() finishes without reaching the
// failing allocation.
function oomTest(f) {
var i = 1;
var more;
do {
for (let thread = 1; thread < oomThreadTypes(); thread++) {
if (verbose)
print("fail at " + i);
try {
oomAtAllocation(i);
f();
more = resetOOMFailure();
} catch (e) {
// Ignore exceptions.
more = resetOOMFailure();
}
i++;
} while(more);
print("testing thread " + thread);
if (verbose)
print("finished after " + i);
var i = 1;
var more;
do {
if (verbose)
print("fail at " + i);
try {
oomAtAllocation(i, thread);
f();
more = resetOOMFailure();
} catch (e) {
// Ignore exceptions.
more = resetOOMFailure();
}
i++;
} while(more);
if (verbose)
print("finished after " + (i - 2) + " failures");
}
}