1#! /bin/bash
2#
3# Copyright 2020 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# Regenerate ART run-tests Blueprint files.
18
19# This script handles only a subset of ART run-tests at the moment; additional
20# cases will be added later.
21
22set -e
23
24if [[ -z "$ANDROID_BUILD_TOP" ]]; then
25  echo 'ANDROID_BUILD_TOP environment variable is empty; did you forget to run `lunch`?'
26  exit 1
27fi
28
29me=$(basename "$0")
30
31# Known failing tests.
32# TODO(rpl): Investigate and address the causes of failures.
33known_failing_tests=(
34  art-run-test-004-SignalTest
35  art-run-test-004-UnsafeTest
36  art-run-test-030-bad-finalizer
37  art-run-test-034-call-null
38  art-run-test-038-inner-null
39  art-run-test-044-proxy
40  art-run-test-051-thread
41  art-run-test-054-uncaught
42  art-run-test-086-null-super
43  art-run-test-087-gc-after-link
44  art-run-test-096-array-copy-concurrent-gc
45  art-run-test-115-native-bridge
46  art-run-test-116-nodex2oat
47  art-run-test-1336-short-finalizer-timeout
48  art-run-test-1337-gc-coverage
49  art-run-test-1339-dead-reference-safe
50  art-run-test-134-nodex2oat-nofallback
51  art-run-test-136-daemon-jni-shutdown
52  art-run-test-139-register-natives
53  art-run-test-148-multithread-gc-annotations
54  art-run-test-149-suspend-all-stress
55  art-run-test-150-loadlibrary
56  art-run-test-154-gc-loop
57  art-run-test-158-app-image-class-table
58  art-run-test-169-threadgroup-jni
59  art-run-test-172-app-image-twice
60  art-run-test-177-visibly-initialized-deadlock
61  art-run-test-178-app-image-native-method
62  art-run-test-179-nonvirtual-jni
63  art-run-test-1900-track-alloc
64  art-run-test-1901-get-bytecodes
65  art-run-test-1902-suspend
66  art-run-test-1903-suspend-self
67  art-run-test-1904-double-suspend
68  art-run-test-1905-suspend-native
69  art-run-test-1906-suspend-list-me-first
70  art-run-test-1907-suspend-list-self-twice
71  art-run-test-1908-suspend-native-resume-self
72  art-run-test-1909-per-agent-tls
73  art-run-test-1910-transform-with-default
74  art-run-test-1911-get-local-var-table
75  art-run-test-1912-get-set-local-primitive
76  art-run-test-1913-get-set-local-objects
77  art-run-test-1914-get-local-instance
78  art-run-test-1915-get-set-local-current-thread
79  art-run-test-1916-get-set-current-frame
80  art-run-test-1917-get-stack-frame
81  art-run-test-1919-vminit-thread-start-timing
82  art-run-test-1920-suspend-native-monitor
83  art-run-test-1921-suspend-native-recursive-monitor
84  art-run-test-1922-owned-monitors-info
85  art-run-test-1923-frame-pop
86  art-run-test-1924-frame-pop-toggle
87  art-run-test-1925-self-frame-pop
88  art-run-test-1926-missed-frame-pop
89  art-run-test-1927-exception-event
90  art-run-test-1928-exception-event-exception
91  art-run-test-1930-monitor-info
92  art-run-test-1931-monitor-events
93  art-run-test-1932-monitor-events-misc
94  art-run-test-1933-monitor-current-contended
95  art-run-test-1934-jvmti-signal-thread
96  art-run-test-1935-get-set-current-frame-jit
97  art-run-test-1936-thread-end-events
98  art-run-test-1937-transform-soft-fail
99  art-run-test-1938-transform-abstract-single-impl
100  art-run-test-1939-proxy-frames
101  art-run-test-1941-dispose-stress
102  art-run-test-1942-suspend-raw-monitor-exit
103  art-run-test-1943-suspend-raw-monitor-wait
104  art-run-test-1945-proxy-method-arguments
105  art-run-test-1947-breakpoint-redefine-deopt
106  art-run-test-1949-short-dex-file
107  art-run-test-1951-monitor-enter-no-suspend
108  art-run-test-1953-pop-frame
109  art-run-test-1954-pop-frame-jit
110  art-run-test-1955-pop-frame-jit-called
111  art-run-test-1956-pop-frame-jit-calling
112  art-run-test-1957-error-ext
113  art-run-test-1958-transform-try-jit
114  art-run-test-1959-redefine-object-instrument
115  art-run-test-1960-obsolete-jit-multithread-native
116  art-run-test-1961-obsolete-jit-multithread
117  art-run-test-1962-multi-thread-events
118  art-run-test-1963-add-to-dex-classloader-in-memory
119  art-run-test-1967-get-set-local-bad-slot
120  art-run-test-1968-force-early-return
121  art-run-test-1969-force-early-return-void
122  art-run-test-1970-force-early-return-long
123  art-run-test-1971-multi-force-early-return
124  art-run-test-1972-jni-id-swap-indices
125  art-run-test-1973-jni-id-swap-pointer
126  art-run-test-1974-resize-array
127  art-run-test-1975-hello-structural-transformation
128  art-run-test-1976-hello-structural-static-methods
129  art-run-test-1977-hello-structural-obsolescence
130  art-run-test-1978-regular-obsolete-then-structural-obsolescence
131  art-run-test-1979-threaded-structural-transformation
132  art-run-test-1980-obsolete-object-cleared
133  art-run-test-1982-no-virtuals-structural-redefinition
134  art-run-test-1984-structural-redefine-field-trace
135  art-run-test-1985-structural-redefine-stack-scope
136  art-run-test-1986-structural-redefine-multi-thread-stack-scope
137  art-run-test-1987-structural-redefine-recursive-stack-scope
138  art-run-test-1988-multi-structural-redefine
139  art-run-test-1989-transform-bad-monitor
140  art-run-test-1990-structural-bad-verify
141  art-run-test-1991-hello-structural-retransform
142  art-run-test-1992-retransform-no-such-field
143  art-run-test-1993-fallback-non-structural
144  art-run-test-1994-final-virtual-structural
145  art-run-test-1995-final-virtual-structural-multithread
146  art-run-test-1996-final-override-virtual-structural
147  art-run-test-1997-structural-shadow-method
148  art-run-test-1998-structural-shadow-field
149  art-run-test-1999-virtual-structural
150  art-run-test-2003-double-virtual-structural
151  art-run-test-2004-double-virtual-structural-abstract
152  art-run-test-2005-pause-all-redefine-multithreaded
153  art-run-test-2008-redefine-then-old-reflect-field
154  art-run-test-2011-stack-walk-concurrent-instrument
155  art-run-test-203-multi-checkpoint
156  art-run-test-2031-zygote-compiled-frame-deopt
157  art-run-test-2033-shutdown-mechanics
158  art-run-test-2036-jni-filechannel
159  art-run-test-305-other-fault-handler
160  art-run-test-449-checker-bce
161  art-run-test-454-get-vreg
162  art-run-test-461-get-reference-vreg
163  art-run-test-466-get-live-vreg
164  art-run-test-497-inlining-and-class-loader
165  art-run-test-530-regression-lse
166  art-run-test-555-UnsafeGetLong-regression
167  art-run-test-566-polymorphic-inlining
168  art-run-test-595-profile-saving
169  art-run-test-597-deopt-busy-loop
170  art-run-test-597-deopt-invoke-stub
171  art-run-test-597-deopt-new-string
172  art-run-test-602-deoptimizeable
173  art-run-test-604-hot-static-interface
174  art-run-test-616-cha-abstract
175  art-run-test-616-cha-interface
176  art-run-test-616-cha-miranda
177  art-run-test-616-cha-native
178  art-run-test-616-cha-regression-proxy-method
179  art-run-test-616-cha
180  art-run-test-623-checker-loop-regressions
181  art-run-test-626-set-resolved-string
182  art-run-test-629-vdex-speed
183  art-run-test-638-checker-inline-cache-intrinsic
184  art-run-test-642-fp-callees
185  art-run-test-647-jni-get-field-id
186  art-run-test-652-deopt-intrinsic
187  art-run-test-655-jit-clinit
188  art-run-test-656-loop-deopt
189  art-run-test-660-clinit
190  art-run-test-661-oat-writer-layout
191  art-run-test-664-aget-verifier
192  art-run-test-667-jit-jni-stub
193  art-run-test-674-hotness-compiled
194  art-run-test-679-locks
195  art-run-test-680-checker-deopt-dex-pc-0
196  art-run-test-685-deoptimizeable
197  art-run-test-687-deopt
198  art-run-test-689-zygote-jit-deopt
199  art-run-test-693-vdex-inmem-loader-evict
200  art-run-test-707-checker-invalid-profile
201  art-run-test-708-jit-cache-churn
202  art-run-test-717-integer-value-of
203  art-run-test-720-thread-priority
204  art-run-test-900-hello-plugin
205  art-run-test-901-hello-ti-agent
206  art-run-test-902-hello-transformation
207  art-run-test-903-hello-tagging
208  art-run-test-904-object-allocation
209  art-run-test-905-object-free
210  art-run-test-906-iterate-heap
211  art-run-test-907-get-loaded-classes
212  art-run-test-908-gc-start-finish
213  art-run-test-910-methods
214  art-run-test-911-get-stack-trace
215  art-run-test-913-heaps
216  art-run-test-914-hello-obsolescence
217  art-run-test-915-obsolete-2
218  art-run-test-916-obsolete-jit
219  art-run-test-917-fields-transformation
220  art-run-test-918-fields
221  art-run-test-919-obsolete-fields
222  art-run-test-920-objects
223  art-run-test-921-hello-failure
224  art-run-test-922-properties
225  art-run-test-923-monitors
226  art-run-test-924-threads
227  art-run-test-925-threadgroups
228  art-run-test-926-multi-obsolescence
229  art-run-test-927-timers
230  art-run-test-928-jni-table
231  art-run-test-930-hello-retransform
232  art-run-test-931-agent-thread
233  art-run-test-932-transform-saves
234  art-run-test-933-misc-events
235  art-run-test-937-hello-retransform-package
236  art-run-test-939-hello-transformation-bcp
237  art-run-test-940-recursive-obsolete
238  art-run-test-941-recursive-obsolete-jit
239  art-run-test-942-private-recursive
240  art-run-test-943-private-recursive-jit
241  art-run-test-944-transform-classloaders
242  art-run-test-945-obsolete-native
243  art-run-test-946-obsolete-throw
244  art-run-test-947-reflect-method
245  art-run-test-949-in-memory-transform
246  art-run-test-950-redefine-intrinsic
247  art-run-test-951-threaded-obsolete
248  art-run-test-982-ok-no-retransform
249  art-run-test-983-source-transform-verify
250  art-run-test-984-obsolete-invoke
251  art-run-test-985-re-obsolete
252  art-run-test-986-native-method-bind
253  art-run-test-987-agent-bind
254  art-run-test-988-method-trace
255  art-run-test-989-method-trace-throw
256  art-run-test-990-field-trace
257  art-run-test-991-field-trace-2
258  art-run-test-992-source-data
259  art-run-test-993-breakpoints
260  art-run-test-994-breakpoint-line
261  art-run-test-995-breakpoints-throw
262  art-run-test-996-breakpoint-obsolete
263  art-run-test-997-single-step
264)
265
266cd "$ANDROID_BUILD_TOP/art"
267
268tests_dir=test
269num_tests=0
270
271# List of tests for which a Blueprint file is generated.
272declare -a handled_tests
273
274# Regenerate Blueprint files.
275# ---------------------------
276
277while read run_test; do
278  ((++num_tests))
279
280  bp_file="$tests_dir/$run_test/Android.bp"
281
282  # Remove any previously generated file.
283  rm -f "$bp_file"
284
285  # Ignore tests with non-default build rules.
286  [[ -f "$tests_dir/$run_test/build" ]] && continue
287  # Ignore tests with no `src` directory.
288  [[ -d "$tests_dir/$run_test/src" ]] || continue
289  # Ignore tests with sources outside the `src` directory.
290  [[ -d "$tests_dir/$run_test/smali" ]] && continue
291  [[ -d "$tests_dir/$run_test/jasmin" ]] && continue
292  [[ -d "$tests_dir/$run_test/src-art" ]] && continue
293  [[ -d "$tests_dir/$run_test/src2" ]] && continue
294  [[ -d "$tests_dir/$run_test/src-multidex" ]] && continue
295  [[ -d "$tests_dir/$run_test/smali-multidex" ]] && continue
296  [[ -d "$tests_dir/$run_test/jasmin-multidex" ]] && continue
297  [[ -d "$tests_dir/$run_test/smali-ex" ]] && continue
298  [[ -d "$tests_dir/$run_test/src-ex" ]] && continue
299  [[ -d "$tests_dir/$run_test/src-dex2oat-unresolved" ]] && continue
300  # Ignore test with a copy of `sun.misc.Unsafe`.
301  [[ -f "$tests_dir/$run_test/src/sun/misc/Unsafe.java" ]] && continue
302  # Ignore tests with Hidden API specs.
303  [[ -f "$tests_dir/$run_test/hiddenapi-flags.csv" ]] && continue
304
305  run_test_name="art-run-test-$run_test"
306  cat >"$bp_file" <<EOF
307// Generated by \`$me\`. Do not edit manually.
308java_test {
309    name: "$run_test_name",
310    defaults: ["art-run-test-defaults"],
311    srcs: ["src/**/*.java"],
312}
313EOF
314  # Record test name.
315  handled_tests+=("$run_test_name")
316done <<< $(ls -1 $tests_dir | grep -E '^[0-9]{3,}-')
317
318handled_tests_percentage=$((${#handled_tests[@]} * 100 / num_tests))
319
320echo "Generated Blueprint files for ${#handled_tests[@]} ART run-tests ouf of $num_tests" \
321  "($handled_tests_percentage%)."
322
323# Regenerate `TEST_MAPPING` file.
324# -------------------------------
325
326# Complement of `known_failing_tests` in `handled_tests`.
327declare -a expected_succeeding_tests
328for run_test in "${handled_tests[@]}"; do
329  for fail in "${known_failing_tests[@]}"; do
330    [[ "$run_test" == "$fail" ]] && continue 2
331  done
332  expected_succeeding_tests+=("$run_test")
333done
334
335# Prologue.
336cat >TEST_MAPPING <<EOF
337// Generated by \`$me\`. Do not edit manually.
338{
339  "presubmit": [
340    {
341      "name": "CtsJdwpTestCases"
342    }
343  ],
344  "postsubmit": [
345    // ART gtests.
346    {
347      "name": "ArtGtestsTarget"
348    },
349    // ART run-tests.
350EOF
351# Only include tests expected to succeed for now.
352trailer=,
353for ((i=0; i < ${#expected_succeeding_tests[@]}; ++i)); do
354  # Do not print a trailing comma for the last test (JSON does not allow
355  # superfluous trailing commas).
356  [[ $((i + 1)) -eq ${#expected_succeeding_tests[@]} ]] && trailer=
357  cat >>TEST_MAPPING <<EOF
358    {
359      "name": "${expected_succeeding_tests[$i]}"
360    }$trailer
361EOF
362done
363# Epilogue.
364cat >>TEST_MAPPING <<EOF
365  ]
366}
367EOF
368
369expected_succeeding_tests_percentage=$((${#expected_succeeding_tests[@]} * 100 / num_tests))
370
371echo "Generated TEST_MAPPING entries for ${#expected_succeeding_tests[@]} ART run-tests ouf of" \
372  "$num_tests ($expected_succeeding_tests_percentage%)."
373