#!/bin/bash
#
# Copyright (C) 2025 The Android Open Source Project
#
# 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.

# ahat-test-dump-gen.sh.in is an input template for a script to re-generate
# the test dump hprof files. The files should be regenerated whenever there
# are changes to src/test-dump/*.
#
# To regenerate the test dump files:
# $ m ahat-test-dump-gen
# $ croot
# $ bash out/soong/.intermediates/art/tools/ahat/ahat-test-dump-gen/android_common/gen/ahat-test-dump-gen.sh
#
# The outputs are placed in the etc/ directory where they can be checked in to
# be used by the ahat tests. Note: You'll see a lot of error messages from
# running the script that should be safe to ignore, as long as you see
# etc/test-dump.hprof and etc/test-dump-base.hprof being generated.

AHAT_ETC_DIR=${ANDROID_BUILD_TOP}/art/tools/ahat/etc
AHAT_TEST_DUMP_JAR=@AHAT_TEST_DUMP_JAR@
AHAT_TEST_DUMP_MAP=$(dirname ${AHAT_TEST_DUMP_JAR})/../proguard_dictionary

# Build required dependencies.
m build-art-host libahat-test-jni


# test-dump.hprof
art --no-compile -cp ${AHAT_TEST_DUMP_JAR} Main ${AHAT_ETC_DIR}/test-dump.hprof

# test-dump-base.hprof
art --no-compile -cp ${AHAT_TEST_DUMP_JAR} Main ${AHAT_ETC_DIR}/test-dump-base.hprof --base

# test-dump.map
cp ${AHAT_TEST_DUMP_MAP} ${AHAT_ETC_DIR}/test-dump.map
