1#!/bin/sh
2#
3# Copyright (C) 2012 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
17import re
18
19
20def run(ctx, args):
21  bridge_so = "libnativebridgetest.so" if args.O else "libnativebridgetestd.so"
22  test_dir = ctx.env.DEX_LOCATION
23
24  # Use libnativebridgetest as a native bridge, start NativeBridgeMain (Main is JniTest main file).
25  for i, opt in enumerate(args.runtime_option):
26    if opt.startswith("-Djava.library.path="):
27      libpath = opt.split(":")[-1]  # last entry in libpath is nativetest[64]
28      args.runtime_option[i] = "-Djava.library.path=" + test_dir
29
30  assert libpath
31  ctx.run(f"ln -sf {libpath}/{bridge_so} {test_dir}/.")
32  ctx.run(
33      f"touch {test_dir}/libarttest.so {test_dir}/libarttestd.so {test_dir}/libinvalid.so"
34  )
35  ctx.run(f"ln -sf {libpath}/libarttest.so {test_dir}/libarttest2.so")
36  ctx.run(f"ln -sf {libpath}/libarttestd.so {test_dir}/libarttestd2.so")
37
38  ctx.default_run(
39      args,
40      runtime_option=["-Xforce-nb-testing", f"-XX:NativeBridge={bridge_so}"],
41      main="NativeBridgeMain")
42
43  # ASAN prints a warning here.
44  ctx.run(
45      fr"sed -i '/WARNING: ASan is ignoring requested __asan_handle_no_return/,+2d' '{args.stderr_file}'"
46  )
47