• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# Copyright 2021 Google Inc. All rights reserved.
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
17set -euo pipefail
18
19source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash"
20
21# Smoke test to check that the stripped libc.so is smaller than the unstripped one.
22function test_libc_stripping_basic() {
23    local readonly base="__main__/bionic/libc"
24    local readonly stripped_path="${base}/libc.so"
25    local readonly unstripped_path="${base}/liblibc_unstripped.so"
26    local stripped="$(rlocation $stripped_path)"
27    local unstripped="$(rlocation $unstripped_path)"
28
29    if [ ! -e "$stripped" ]; then
30      >&2 echo "Missing stripped file; expected '$stripped_path'; got '$stripped'"
31      exit 2
32    fi
33    if [ ! -e "$unstripped" ]; then
34      >&2 echo "Missing unstripped file; expected '$unstripped_path'; got '$unstripped'"
35      exit 2
36    fi
37
38    local stripped_size=$(stat -c %s "${stripped}")
39    local unstripped_size=$(stat -c %s "${unstripped}")
40
41    # Check that the unstripped size is not greater or equal to the stripped size.
42    if [ "${stripped_size}" -ge "${unstripped_size}"  ]; then
43        echo "Expected the size of stripped libc.so to be strictly smaller than the unstripped one."
44        exit 1
45    fi
46}
47
48test_libc_stripping_basic
49