1*7594170eSAndroid Build Coastguard Worker#!/bin/bash 2*7594170eSAndroid Build Coastguard Worker# 3*7594170eSAndroid Build Coastguard Worker# Copyright 2021 Google Inc. All rights reserved. 4*7594170eSAndroid Build Coastguard Worker# 5*7594170eSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License"); 6*7594170eSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License. 7*7594170eSAndroid Build Coastguard Worker# You may obtain a copy of the License at 8*7594170eSAndroid Build Coastguard Worker# 9*7594170eSAndroid Build Coastguard Worker# http://www.apache.org/licenses/LICENSE-2.0 10*7594170eSAndroid Build Coastguard Worker# 11*7594170eSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software 12*7594170eSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS, 13*7594170eSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*7594170eSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and 15*7594170eSAndroid Build Coastguard Worker# limitations under the License. 16*7594170eSAndroid Build Coastguard Worker 17*7594170eSAndroid Build Coastguard Workerset -euo pipefail 18*7594170eSAndroid Build Coastguard Worker 19*7594170eSAndroid Build Coastguard Workersource "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" 20*7594170eSAndroid Build Coastguard Worker 21*7594170eSAndroid Build Coastguard Worker# Smoke test to check that the stripped libc.so is smaller than the unstripped one. 22*7594170eSAndroid Build Coastguard Workerfunction test_libc_stripping_basic() { 23*7594170eSAndroid Build Coastguard Worker local readonly base="__main__/bionic/libc" 24*7594170eSAndroid Build Coastguard Worker local readonly stripped_path="${base}/libc/libc.so" 25*7594170eSAndroid Build Coastguard Worker local readonly unstripped_path="${base}/liblibc_unstripped.so" 26*7594170eSAndroid Build Coastguard Worker local stripped="$(rlocation $stripped_path)" 27*7594170eSAndroid Build Coastguard Worker local unstripped="$(rlocation $unstripped_path)" 28*7594170eSAndroid Build Coastguard Worker 29*7594170eSAndroid Build Coastguard Worker if [ ! -e "$stripped" ]; then 30*7594170eSAndroid Build Coastguard Worker >&2 echo "Missing stripped file; expected '$stripped_path'; got '$stripped'" 31*7594170eSAndroid Build Coastguard Worker exit 2 32*7594170eSAndroid Build Coastguard Worker fi 33*7594170eSAndroid Build Coastguard Worker if [ ! -e "$unstripped" ]; then 34*7594170eSAndroid Build Coastguard Worker >&2 echo "Missing unstripped file; expected '$unstripped_path'; got '$unstripped'" 35*7594170eSAndroid Build Coastguard Worker exit 2 36*7594170eSAndroid Build Coastguard Worker fi 37*7594170eSAndroid Build Coastguard Worker 38*7594170eSAndroid Build Coastguard Worker local stripped_size=$(stat -L -c %s "${stripped}") 39*7594170eSAndroid Build Coastguard Worker local unstripped_size=$(stat -L -c %s "${unstripped}") 40*7594170eSAndroid Build Coastguard Worker 41*7594170eSAndroid Build Coastguard Worker # Check that the unstripped size is not greater or equal to the stripped size. 42*7594170eSAndroid Build Coastguard Worker if [ "${stripped_size}" -ge "${unstripped_size}" ]; then 43*7594170eSAndroid Build Coastguard Worker echo "Expected the size of stripped libc.so to be strictly smaller than the unstripped one." 44*7594170eSAndroid Build Coastguard Worker exit 1 45*7594170eSAndroid Build Coastguard Worker fi 46*7594170eSAndroid Build Coastguard Worker} 47*7594170eSAndroid Build Coastguard Worker 48*7594170eSAndroid Build Coastguard Workertest_libc_stripping_basic 49