13298bea7Sopenharmony_ci#!/bin/bash
23298bea7Sopenharmony_ci################################################################################
33298bea7Sopenharmony_ci#
43298bea7Sopenharmony_ci# Copyright (C) 2022 Huawei Device Co., Ltd.
53298bea7Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
63298bea7Sopenharmony_ci#
73298bea7Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
83298bea7Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS,
93298bea7Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
103298bea7Sopenharmony_ci# See the License for the specific language governing permissions and
113298bea7Sopenharmony_ci# limitations under the License.
123298bea7Sopenharmony_ci#
133298bea7Sopenharmony_ci################################################################################
143298bea7Sopenharmony_ci# File: generate_config.sh
153298bea7Sopenharmony_ci#
163298bea7Sopenharmony_ci# Description: generate config for linux test project
173298bea7Sopenharmony_ci#
183298bea7Sopenharmony_ci# Authors:     Wu Fan
193298bea7Sopenharmony_ci#
203298bea7Sopenharmony_ci# History:     August 4 2022 - generate config
213298bea7Sopenharmony_ci#
223298bea7Sopenharmony_ci################################################################################
233298bea7Sopenharmony_ciset -e
243298bea7Sopenharmony_ciIFS=$'\n'
253298bea7Sopenharmony_ciinput_file=$2/macrolists
263298bea7Sopenharmony_cichange_file=$3/ltp/include/config.h
273298bea7Sopenharmony_ci
283298bea7Sopenharmony_cifunction chang_config()
293298bea7Sopenharmony_ci{
303298bea7Sopenharmony_ci    while read line; do
313298bea7Sopenharmony_ci        if [[ "${line}" == *"#"* ]]; then
323298bea7Sopenharmony_ci            continue
333298bea7Sopenharmony_ci        else
343298bea7Sopenharmony_ci            macro=$(echo $line | awk -F "'" '{print $2}')
353298bea7Sopenharmony_ci            flag=$(echo $line | awk -F "'" '{print $4}')
363298bea7Sopenharmony_ci	    set +e
373298bea7Sopenharmony_ci            if [ "${flag}" == "true" ]; then
383298bea7Sopenharmony_ci                lines=$(sed -n "/${macro}/=" $change_file)
393298bea7Sopenharmony_ci                if [[ "${lines}" > 0 ]]; then
403298bea7Sopenharmony_ci                    sed -i "/${macro}/c\#define ${macro} 1" $change_file
413298bea7Sopenharmony_ci                else
423298bea7Sopenharmony_ci                    echo "#define ${macro} 1" >> $change_file
433298bea7Sopenharmony_ci                fi
443298bea7Sopenharmony_ci            else
453298bea7Sopenharmony_ci                sed -i "/${macro}/c\/\* \#undef ${macro} \*\/" $change_file
463298bea7Sopenharmony_ci            fi
473298bea7Sopenharmony_ci            set -e
483298bea7Sopenharmony_ci        fi
493298bea7Sopenharmony_ci    done < $input_file
503298bea7Sopenharmony_ci    echo "typedef unsigned int __u32;" >> $change_file
513298bea7Sopenharmony_ci    echo "typedef signed int __s32;" >> $change_file
523298bea7Sopenharmony_ci}
533298bea7Sopenharmony_ci
543298bea7Sopenharmony_cimkdir -p $(pwd)/tests/ltp_testcases/ltp
553298bea7Sopenharmony_cicp -r $(pwd)/../../third_party/ltp $(pwd)/tests/ltp_testcases
563298bea7Sopenharmony_cicd $(pwd)/tests/ltp_testcases/ltp
573298bea7Sopenharmony_cimake autotools
583298bea7Sopenharmony_ci./configure --without-numa
593298bea7Sopenharmony_ciadd_notation=./include/tst_clone.h
603298bea7Sopenharmony_cised -i "/^\#define clone/c\/\/ \#define clone(...) (use_the_ltp_clone_functions__do_not_use_clone)" $add_notation
613298bea7Sopenharmony_cichang_config
62