diff options
author | Alon Zakai <azakai@mozilla.com> | 2011-02-19 22:44:16 -0800 |
---|---|---|
committer | Alon Zakai <azakai@mozilla.com> | 2011-02-19 22:44:16 -0800 |
commit | 8855d03cc54dda19e6cd4a885c0e1171f7a7d126 (patch) | |
tree | 79977e6ab50627fa098f6e7beea04666580ccc7b | |
parent | f81feaff967ffdd8212ffe2da8579c4734fc7cbb (diff) |
use line-specific corrections in zlib test
-rw-r--r-- | src/jsifier.js | 4 | ||||
-rw-r--r-- | src/parseTools.js | 10 | ||||
-rw-r--r-- | src/preamble.js | 30 | ||||
-rw-r--r-- | tests/runner.py | 37 |
4 files changed, 53 insertions, 28 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index f3e55a39..73774373 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -769,7 +769,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria // TODO: figure out something here along the lines of return '(' + Math.pow(2, 32) + '+((' + value + ')|0))'; } } - return op + 'Sign(' + value + ', ' + bits + ')'; + return op + 'Sign(' + value + ', ' + bits + ', ' + correctSpecificSign() + ')'; // If we are correcting a specific sign here, do not check for it } else { return value; } @@ -778,7 +778,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria function handleOverflow(text, bits) { if (!bits) return text; if (bits <= 32 && correctOverflows()) text = '(' + text + ')&' + (Math.pow(2, bits) - 1); - if (!CHECK_OVERFLOWS) return text; + if (!CHECK_OVERFLOWS || correctSpecificOverflow()) return text; // If we are correcting a specific overflow here, do not check for it return 'CHECK_OVERFLOW(' + text + ', ' + bits + ')'; } diff --git a/src/parseTools.js b/src/parseTools.js index 81831d75..0990eb2f 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -539,11 +539,17 @@ function indentify(text, indent) { // Correction tools +function correctSpecificSign() { + return CORRECT_SIGNS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_SIGNS_LINES; +} function correctSigns() { - return CORRECT_SIGNS === 1 || (CORRECT_SIGNS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_SIGNS_LINES); + return CORRECT_SIGNS === 1 || correctSpecificSign(); } +function correctSpecificOverflow() { + return CORRECT_OVERFLOWS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_OVERFLOWS_LINES; +} function correctOverflows() { - return CORRECT_OVERFLOWS === 1 || (CORRECT_OVERFLOWS === 2 && Debugging.getIdentifier(Framework.currItem.lineNum) in CORRECT_OVERFLOWS_LINES); + return CORRECT_OVERFLOWS === 1 || correctSpecificOverflow(); } diff --git a/src/preamble.js b/src/preamble.js index a65ffdce..0124e6c3 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -101,13 +101,31 @@ function __Z18UNPROTECT_HEAPADDRPv(dest) { //========================================== #endif +var CorrectionsMonitor = { + MAX_ALLOWED: 0, // Infinity, + corrections: 0, + sigs: {}, + + note: function(type) { + var sig = type + '|' + new Error().stack; + if (!this.sigs[sig]) { + print('Correction: ' + sig); + this.sigs[sig] = 0; + } + this.sigs[sig]++; + this.corrections++; + if (this.corrections >= this.MAX_ALLOWED) abort('\n\nToo many corrections!'); + } +}; + #if CHECK_OVERFLOWS //======================================== // Debugging tools - Mathop overflows //======================================== function CHECK_OVERFLOW(value, bits) { - assert(value !== Infinity && value !== -Infinity, 'Infinity!'); - assert(Math.abs(value) < Math.pow(2, bits), 'Overflow!'); + if (value === Infinity || value === -Infinity || Math.abs(value) >= Math.pow(2, bits)) { + CorrectionsMonitor.note('Overflow'); + } return value; } #endif @@ -374,10 +392,10 @@ function intArrayToString(array) { // Converts a value we have as signed, into an unsigned value. For // example, -1 in int32 would be a very large number as unsigned. -function unSign(value, bits) { +function unSign(value, bits, ignore) { if (value >= 0) return value; #if CHECK_SIGNS - abort('unSign needed, data: ' + [value, bits]); + if (!ignore) CorrectionsMonitor.note('UnSign'); #endif return bits <= 32 ? 2*Math.abs(1 << (bits-1)) + value // Need some trickery, since if bits == 32, we are right at the limit of the bits JS uses in bitshifts : Math.pow(2, bits) + value; @@ -386,13 +404,13 @@ function unSign(value, bits) { // Converts a value we have as unsigned, into a signed value. For // example, 200 in a uint8 would be a negative number. -function reSign(value, bits) { +function reSign(value, bits, ignore) { if (value <= 0) return value; var half = bits <= 32 ? Math.abs(1 << (bits-1)) // abs is needed if bits == 32 : Math.pow(2, bits-1); if (value >= half) { #if CHECK_SIGNS - abort('reSign needed, data: ' + [value, bits]); + if (!ignore) CorrectionsMonitor.note('ReSign'); #endif value = -2*half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts } diff --git a/tests/runner.py b/tests/runner.py index 882a7403..6f23ae34 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -165,9 +165,6 @@ class RunnerCore(unittest.TestCase): exported_settings = {} for setting in ['QUANTUM_SIZE', 'RELOOP', 'OPTIMIZE', 'GUARD_MEMORY', 'USE_TYPED_ARRAYS', 'SAFE_HEAP', 'CHECK_OVERFLOWS', 'CORRECT_OVERFLOWS', 'CORRECT_SIGNS', 'CHECK_SIGNS', 'CORRECT_OVERFLOWS_LINES', 'CORRECT_SIGNS_LINES']: value = eval(setting) - if type(value) == str: - if value == '': continue - value = eval(value) exported_settings[setting] = value out = open(filename + '.o.js', 'w') if not OUTPUT_TO_SCREEN else None timeout_run(Popen([EMSCRIPTEN, filename + '.o.ll', COMPILER_ENGINE[0], str(exported_settings).replace("'", '"')], stdout=out, stderr=STDOUT), TIMEOUT, 'Compiling') @@ -1589,14 +1586,17 @@ if 'benchmark' not in sys.argv: post_build=post) def test_zlib(self): - global CORRECT_OVERFLOWS; CORRECT_OVERFLOWS = 1 # Overflows in inflate_table() getelementptr (in phi) - #global CHECK_OVERFLOWS; CHECK_OVERFLOWS = 0 - - global CORRECT_SIGNS; CORRECT_SIGNS = 1 - #global CHECK_SIGNS; CHECK_SIGNS = 0 - - #global COMPILER_TEST_OPTS - #COMPILER_TEST_OPTS += ['-DEMSCRIPTEN_OPTS'] + global CORRECT_OVERFLOWS, CORRECT_OVERFLOWS_LINES, CORRECT_SIGNS, CORRECT_SIGNS_LINES + + if COMPILER == LLVM_GCC: + # Test for line-specific corrections in gcc, and in clang do the opposite + CORRECT_SIGNS = 2 + CORRECT_SIGNS_LINES = [ + "trees.c:728", "inflate.c:1169", "deflate.c:1566", "trees.c:773", "trees.c:1089", "adler32.c:69", "trees.c:1233", + "deflate.c:1685", "inflate.c:850", "inflate.c:851", "trees.c:1148", "inflate.c:1333" + ] + else: + CORRECT_SIGNS = 1 self.do_test(open(path_from_root('tests', 'zlib', 'example.c'), 'r').read(), open(path_from_root('tests', 'zlib', 'ref.txt'), 'r').read(), @@ -1722,7 +1722,8 @@ if 'benchmark' not in sys.argv: self.do_test(src, '*nothingatall*') except Exception, e: # This test *should* fail, by throwing this exception - assert 'Overflow!' in str(e), str(e) + assert 'Too many corrections' in str(e), str(e) + assert 'CHECK_OVERFLOW' in str(e), str(e) def test_debug(self): global COMPILER_TEST_OPTS @@ -1780,12 +1781,12 @@ if 'benchmark' not in sys.argv: # And now let's fix just that one line CORRECT_SIGNS = 2 - CORRECT_SIGNS_LINES = '["src.cpp:9"]' + CORRECT_SIGNS_LINES = ["src.cpp:9"] self.do_test(src, '*0*') # Fixing the wrong line should not work CORRECT_SIGNS = 2 - CORRECT_SIGNS_LINES = '["src.cpp:3"]' + CORRECT_SIGNS_LINES = ["src.cpp:3"] self.do_test(src, '*1*') src = ''' @@ -1814,12 +1815,12 @@ if 'benchmark' not in sys.argv: # And now let's fix just that one line CORRECT_OVERFLOWS = 2 - CORRECT_OVERFLOWS_LINES = '["src.cpp:6"]' + CORRECT_OVERFLOWS_LINES = ["src.cpp:6"] self.do_test(src, correct) # Fixing the wrong line should not work CORRECT_OVERFLOWS = 2 - CORRECT_OVERFLOWS_LINES = '["src.cpp:3"]' + CORRECT_OVERFLOWS_LINES = ["src.cpp:3"] try: self.do_test(src, correct) raise Exception('UNEXPECTED-PASS') @@ -1845,7 +1846,7 @@ class %s(T): CHECK_OVERFLOWS = 1-(embetter or llvm_opts) CORRECT_OVERFLOWS = 1-(embetter and llvm_opts) CORRECT_SIGNS = 0 - CORRECT_OVERFLOWS_LINES = CORRECT_SIGNS_LINES = '' + CORRECT_OVERFLOWS_LINES = CORRECT_SIGNS_LINES = [] CHECK_SIGNS = 0 #1-(embetter or llvm_opts) if LLVM_OPTS: self.pick_llvm_opts(3, True) @@ -1881,7 +1882,7 @@ else: USE_TYPED_ARRAYS = 0 GUARD_MEMORY = SAFE_HEAP = CHECK_OVERFLOWS = CORRECT_OVERFLOWS = 0 CORRECT_SIGNS = 0 - CORRECT_OVERFLOWS_LINES = CORRECT_SIGNS_LINES = '' + CORRECT_OVERFLOWS_LINES = CORRECT_SIGNS_LINES = [] LLVM_OPTS = 1 USE_CLOSURE_COMPILER = 1 |