From 0f528df7611e79f3c2b913e39e39561a99a720d3 Mon Sep 17 00:00:00 2001 From: Robert Grosse Date: Mon, 25 Jan 2016 17:15:41 -0800 Subject: [PATCH] Add change-detector script --- .gitattributes | 1 + enjarify/hashtests.py | 39 +++++++++++++++++++++++++++++ enjarify/jvm/optimization/consts.py | 8 +++--- enjarify/jvm/writeclass.py | 2 +- 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 enjarify/hashtests.py diff --git a/.gitattributes b/.gitattributes index 170a37e..6e2588c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,4 @@ .gitignore export-ignore tests/** export-ignore enjarify/runtests.py export-ignore +enjarify/hashtests.py export-ignore diff --git a/enjarify/hashtests.py b/enjarify/hashtests.py new file mode 100644 index 0000000..70ce956 --- /dev/null +++ b/enjarify/hashtests.py @@ -0,0 +1,39 @@ +# Copyright 2015 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import hashlib, os + +from .main import read, translate +from .jvm.optimization import options + +# Hash outputs of all tests in order to easily detect changes between versions +fullhash = b'' + +for i in range(1, 7): + name = 'test{}'.format(i) + print(name) + dir = os.path.join('tests', name) + rawdex = read(os.path.join(dir, 'classes.dex'), 'rb') + + for bits in range(256): + opts = options.Options(*[bool(bits & (1 << b)) for b in range(8)]) + classes, errors = translate(rawdex, opts=opts) + assert(not errors) + + for cls in classes.values(): + print('{:08b}'.format(bits), hashlib.sha256(cls).hexdigest()) + fullhash = hashlib.sha256(fullhash + cls).digest() + +print('done!') +print('Final hash:', hashlib.sha256(fullhash).hexdigest()) diff --git a/enjarify/jvm/optimization/consts.py b/enjarify/jvm/optimization/consts.py index 094dc2d..8196334 100644 --- a/enjarify/jvm/optimization/consts.py +++ b/enjarify/jvm/optimization/consts.py @@ -24,10 +24,10 @@ def allocateRequiredConstants(pool, long_irs): # in the first place. In fact, there are no known real world classes that # even come close to exhausting the constant pool. - print('{} methods potentially too long'.format(len(long_irs))) - print(sorted([_ir.upper_bound for _ir in long_irs], reverse=True)) - for _ir in long_irs: - print(_ir.method.id.triple(), _ir.upper_bound) + # print('{} methods potentially too long'.format(len(long_irs))) + # print(sorted([_ir.upper_bound for _ir in long_irs], reverse=True)) + # for _ir in long_irs: + # print(_ir.method.id.triple(), _ir.upper_bound) narrow_pairs = collections.Counter() wide_pairs = collections.Counter() diff --git a/enjarify/jvm/writeclass.py b/enjarify/jvm/writeclass.py index f907839..6247bc2 100644 --- a/enjarify/jvm/writeclass.py +++ b/enjarify/jvm/writeclass.py @@ -109,7 +109,7 @@ def toClassFile(cls, opts): try: pool, rest_stream = classFileAfterPool(cls, opts=opts) except error.ClassfileLimitExceeded: - print('Retrying {} with optimization enabled'.format(cls.name)) + # print('Retrying {} with optimization enabled'.format(cls.name)) pool, rest_stream = classFileAfterPool(cls, opts=options.ALL) # write constant pool