Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 1 | // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Flags: --ignition --trace-ignition-dispatches |
| 6 | |
| 7 | assertEquals(typeof getIgnitionDispatchCounters, "function"); |
| 8 | |
| 9 | var old_dispatch_counters = getIgnitionDispatchCounters(); |
| 10 | |
| 11 | // Check that old_dispatch_counters is a non-empty object of objects, such that |
| 12 | // the value of each property in the inner objects is a number. |
| 13 | |
| 14 | assertEquals(typeof old_dispatch_counters, "object"); |
| 15 | assertTrue(Object.getOwnPropertyNames(old_dispatch_counters).length > 0); |
| 16 | for (var source_bytecode in old_dispatch_counters) { |
| 17 | var counters_row = old_dispatch_counters[source_bytecode]; |
| 18 | assertEquals(typeof counters_row, "object"); |
| 19 | for (var counter in counters_row) { |
| 20 | assertEquals(typeof counters_row[counter], "number"); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | // Do something |
| 25 | function f(x) { return x*x; } |
| 26 | f(42); |
| 27 | |
| 28 | var new_dispatch_counters = getIgnitionDispatchCounters(); |
| 29 | |
| 30 | var old_source_bytecodes = Object.getOwnPropertyNames(old_dispatch_counters); |
| 31 | var new_source_bytecodes = Object.getOwnPropertyNames(new_dispatch_counters); |
| 32 | var common_source_bytecodes = new_source_bytecodes.filter(function (name) { |
| 33 | return old_source_bytecodes.indexOf(name) > -1; |
| 34 | }); |
| 35 | |
| 36 | // Check that the keys on the outer objects are the same |
| 37 | assertEquals(common_source_bytecodes, old_source_bytecodes); |
| 38 | assertEquals(common_source_bytecodes, new_source_bytecodes); |
| 39 | |
| 40 | common_source_bytecodes.forEach(function (source_bytecode) { |
| 41 | var new_counters_row = new_dispatch_counters[source_bytecode]; |
| 42 | var old_counters_row = old_dispatch_counters[source_bytecode]; |
| 43 | |
| 44 | var old_destination_bytecodes = Object.getOwnPropertyNames(old_counters_row); |
| 45 | var new_destination_bytecodes = Object.getOwnPropertyNames(new_counters_row); |
| 46 | |
| 47 | // Check that all the keys in old_ are in new_ too |
| 48 | old_destination_bytecodes.forEach(function (name) { |
| 49 | assertTrue(new_destination_bytecodes.indexOf(name) > -1); |
| 50 | }); |
| 51 | |
| 52 | // Check that for each source-destination pair, the counter has either |
| 53 | // appeared (was undefined before calling f()), is unchanged, or incremented. |
| 54 | new_destination_bytecodes.forEach(function (destination_bytecode) { |
| 55 | var new_counter = new_counters_row[destination_bytecode]; |
| 56 | var old_counter = old_counters_row[destination_bytecode]; |
| 57 | assertTrue(typeof new_counter === "number"); |
| 58 | if (typeof old_counter === "number") { |
| 59 | assertTrue(new_counter >= old_counter); |
| 60 | } |
| 61 | }); |
| 62 | }); |