1#!/bin/bash
2#
3# Copyright (C) 2010 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# The awk fun here tries to cull out all but the salient bits. The aim
18# is to check to see that there are two invoke-static instructions, each
19# followed directly by a move-result-object.
20
21jasmin -d . blort.j
22dx --debug --dex --dump-to=- --dump-method=blort.zorch --dump-width=200 \
23    blort.class | awk '
24
25BEGIN {
26    invokeAt = -1;
27    moveAt = -1;
28    invokeCount = 0;
29    failed = 0;
30}
31
32# Note: This has to be done before the test clause below.
33/move-result-object/ {
34    moveAt = NR;
35}
36
37(invokeAt > 0) {
38    if (moveAt != (invokeAt + 1)) {
39        failed = 1;
40    }
41    invokeAt = -1;
42    moveAt = -1;
43}
44
45# Note: This has to be done after the test clause above.
46/invoke-static/ {
47    invokeAt = NR;
48    invokeCount++;
49}
50
51END {
52    printf("total invokes: %d\n", invokeCount);
53    if (failed) {
54        exit 1;
55    }
56}
57'
58
59if [ "$?" = "1" ]; then
60    # The test failed. Be helpful and print the entire method body.
61    dx --debug --dex --dump-to=- --dump-method=blort.zorch --dump-width=200 \
62        blort.class
63fi
64