xref: /aosp_15_r20/system/logging/liblog/tests/liblog_device_preparer.sh (revision 598139dc91b21518d67c408eaea2644226490971)
1*598139dcSAndroid Build Coastguard Worker#!/bin/sh
2*598139dcSAndroid Build Coastguard Worker#
3*598139dcSAndroid Build Coastguard Worker# Copyright 2023 - The Android Open Source Project
4*598139dcSAndroid Build Coastguard Worker#
5*598139dcSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*598139dcSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*598139dcSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*598139dcSAndroid Build Coastguard Worker#
9*598139dcSAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
10*598139dcSAndroid Build Coastguard Worker#
11*598139dcSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*598139dcSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*598139dcSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*598139dcSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*598139dcSAndroid Build Coastguard Worker# limitations under the License.
16*598139dcSAndroid Build Coastguard Worker
17*598139dcSAndroid Build Coastguard Worker# Setups the device before running liblog tests. Recovers the state after the
18*598139dcSAndroid Build Coastguard Worker# tests are done. The setup and the tead-down phases are distinguished via the
19*598139dcSAndroid Build Coastguard Worker# first argument: [setup|teardown].
20*598139dcSAndroid Build Coastguard Worker
21*598139dcSAndroid Build Coastguard Workerif [ "$1" != setup -a "$1" != teardown ]; then
22*598139dcSAndroid Build Coastguard Worker    echo "Usage: $0 [setup|teardown]"
23*598139dcSAndroid Build Coastguard Worker    exit 1
24*598139dcSAndroid Build Coastguard Workerfi
25*598139dcSAndroid Build Coastguard Worker
26*598139dcSAndroid Build Coastguard Worker# b/279123901: If persist.log.tag is set, remove the sysprop during the test.
27*598139dcSAndroid Build Coastguard WorkerPROP=persist.log.tag
28*598139dcSAndroid Build Coastguard WorkerSAVED=/data/local/tests/persist.log.tag.saved
29*598139dcSAndroid Build Coastguard Workerif [ "$1" = setup ]; then
30*598139dcSAndroid Build Coastguard Worker    if [ -n "$(getprop ${PROP})" ]; then
31*598139dcSAndroid Build Coastguard Worker        getprop ${PROP} > ${SAVED}
32*598139dcSAndroid Build Coastguard Worker        setprop ${PROP} ""
33*598139dcSAndroid Build Coastguard Worker    fi
34*598139dcSAndroid Build Coastguard Workerelif [ "$1" = teardown ]; then
35*598139dcSAndroid Build Coastguard Worker    if [ -e ${SAVED} ]; then
36*598139dcSAndroid Build Coastguard Worker        setprop ${PROP} $(cat ${SAVED})
37*598139dcSAndroid Build Coastguard Worker        rm ${SAVED}
38*598139dcSAndroid Build Coastguard Worker    fi
39*598139dcSAndroid Build Coastguard Workerfi
40