Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: test/fuzz-natives/base.js

Issue 252143002: Refactor mjsunit/fuzz-natives-* into a separate test suite. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/fuzz-natives/fuzz-natives.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/fuzz-natives/base.js
diff --git a/test/fuzz-natives/base.js b/test/fuzz-natives/base.js
new file mode 100644
index 0000000000000000000000000000000000000000..b9f70043fb5d7b6c4429e250a9a38d343180ba38
--- /dev/null
+++ b/test/fuzz-natives/base.js
@@ -0,0 +1,99 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// TODO(jkummerow): There are many ways to improve these tests, e.g.:
+// - more variance in randomized inputs
+// - better time complexity management
+// - better code readability and documentation of intentions.
+
+var RUN_WITH_ALL_ARGUMENT_ENTRIES = false;
+var kOnManyArgumentsRemove = 5;
+
+function makeArguments() {
+ var result = [ ];
+ result.push(17);
+ result.push(-31);
+ result.push(new Array(100));
+ result.push(new Array(100003));
+ result.push(Number.MIN_VALUE);
+ result.push("whoops");
+ result.push("x");
+ result.push({"x": 1, "y": 2});
+ var slowCaseObj = {"a": 3, "b": 4, "c": 5};
+ delete slowCaseObj.c;
+ result.push(slowCaseObj);
+ result.push(function () { return 8; });
+ return result;
+}
+
+var kArgObjects = makeArguments().length;
+
+function makeFunction(name, argc) {
+ var args = [];
+ for (var i = 0; i < argc; i++)
+ args.push("x" + i);
+ var argsStr = args.join(", ");
+ return new Function(argsStr,
+ "return %" + name + "(" + argsStr + ");");
+}
+
+function testArgumentCount(name, argc) {
+ for (var i = 0; i < 10; i++) {
+ var func = null;
+ try {
+ func = makeFunction(name, i);
+ } catch (e) {
+ if (e != "SyntaxError: Illegal access") throw e;
+ }
+ if (func === null && i == argc) {
+ throw "unexpected exception";
+ }
+ var args = [ ];
+ for (var j = 0; j < i; j++)
+ args.push(0);
+ try {
+ func.apply(void 0, args);
+ } catch (e) {
+ // we don't care what happens as long as we don't crash
+ }
+ }
+}
+
+function testArgumentTypes(name, argc) {
+ var type = 0;
+ var hasMore = true;
+ var func = makeFunction(name, argc);
+ while (hasMore) {
+ var argPool = makeArguments();
+ // When we have 5 or more arguments we lower the amount of tests cases
+ // by randomly removing kOnManyArgumentsRemove entries
+ var numArguments = RUN_WITH_ALL_ARGUMENT_ENTRIES ?
+ kArgObjects : kArgObjects - kOnManyArgumentsRemove;
+ if (kArgObjects >= 5 && !RUN_WITH_ALL_ARGUMENT_ENTRIES) {
+ for (var i = 0; i < kOnManyArgumentsRemove; i++) {
+ var rand = Math.floor(Math.random() * (kArgObjects - i));
+ argPool.splice(rand, 1);
+ }
+ }
+ var current = type;
+ hasMore = false;
+ var argList = [ ];
+ for (var i = 0; i < argc; i++) {
+ var index = current % numArguments;
+ current = (current / numArguments) << 0;
+ if (index != (numArguments - 1))
+ hasMore = true;
+ argList.push(argPool[index]);
+ }
+ try {
+ func.apply(void 0, argList);
+ } catch (e) {
+ // we don't care what happens as long as we don't crash
+ }
+ type++;
+ }
+}
+
+testArgumentCount(NAME, ARGC);
+testArgumentTypes(NAME, ARGC);
« no previous file with comments | « no previous file | test/fuzz-natives/fuzz-natives.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698