Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1948638rwl; Thu, 6 Apr 2023 03:51:49 -0700 (PDT) X-Google-Smtp-Source: AKy350bIooejw4Pkv2Ar3nl1Aq8kLGHOkwA9egrtvgRJWuxu82q1i855IY0G8mFxy5/y9r0Xmjee X-Received: by 2002:aa7:9a5c:0:b0:623:cc95:e517 with SMTP id x28-20020aa79a5c000000b00623cc95e517mr9089673pfj.17.1680778308744; Thu, 06 Apr 2023 03:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680778308; cv=none; d=google.com; s=arc-20160816; b=vX5S9ZCQDJ7MWtn1aIgD8S8VCRRAz/QozItiBGbYZiIFQIfjzBIMziF5s+MPFbQIup 5Hc1nfkWy7XGADeGAY+R32BRNFNNNevp5pfMlwrdW6x+3hHYUiDNktwuagikHngz/Eue 0m/uV01+IAlZ7k9mbeNSTzwd5p6YgelD5fEqkULJ8zkbLM05gzc+gq3BlJLmgu8U8ib+ obYrYaADlSTWNBYcS9tARDNTjDODR5YwSC20tzJTOa5XHSNFsPnkaqGFzD/4HB4XEKsX M5k2Yw4POzviT6VAv4coFaClsT7F0Pa9JHHoNZ4VBP6Ok3pAWFUlxKF5gZt+E8BlWDp/ a+og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id; bh=hI4O5e/DgYYkdTU+DPvKGfz3kBYRB95ALLgYX/a7FRo=; b=iCbakHsaUN9gTbqQtgnt1E4ZSdUVC2I+cyWHVZwGeUEOEIgC7feBXf65UwVO2capg1 tw06WC9aQsUniNn3OTGRLJWgVxdHfm5MQfHhyGUOFQlE1LadYCqxXXFiRol+yisaPPL5 PXepce+gTcFa3yminkyqQvXB/tRFN1GWA5/OivftGZAIG/6f8HK4AMjgdfqFkD/DjqwX YmEhpa2ge00KWHttTOL13S9ob+CLLD4iTMeHKFGB3YXhxKKq8bVQeaA/RhebA2OZYe6Q bg3CnAiH+h3zYogawpgJQHKRa1HRVsbBgHkH0CTZiuPfqTcwfHJm7oUBRRJo+fGtK6QU i7+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t38-20020a634466000000b0050f55427e3dsi470143pgk.701.2023.04.06.03.51.37; Thu, 06 Apr 2023 03:51:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sangfor.com.cn Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237230AbjDFKgP (ORCPT + 99 others); Thu, 6 Apr 2023 06:36:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbjDFKgO (ORCPT ); Thu, 6 Apr 2023 06:36:14 -0400 Received: from mail-m118111.qiye.163.com (mail-m118111.qiye.163.com [115.236.118.111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD11C4C08; Thu, 6 Apr 2023 03:36:11 -0700 (PDT) Received: from [172.23.196.59] (unknown [121.32.254.147]) by mail-m118111.qiye.163.com (Hmail) with ESMTPA id 38C2F58045F; Thu, 6 Apr 2023 18:35:53 +0800 (CST) Message-ID: <1ee16ad1-925a-411d-c67e-5ddab2fb6074@sangfor.com.cn> Date: Thu, 6 Apr 2023 18:35:50 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH v10 8/8] selftests/ftrace: Add funcgraph-retval test case From: Donglin Peng To: "Masami Hiramatsu (Google)" Cc: rostedt@goodmis.org, linux@armlinux.org.uk, mark.rutland@arm.com, will@kernel.org, catalin.marinas@arm.com, rmk+kernel@armlinux.org.uk, palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, tglx@linutronix.de, dave.hansen@linux.intel.com, x86@kernel.org, bp@alien8.de, hpa@zytor.com, chenhuacai@kernel.org, zhangqing@loongson.cn, kernel@xen0n.name, mingo@redhat.com, peterz@infradead.org, xiehuan09@gmail.com, dinghui@sangfor.com.cn, huangcun@sangfor.com.cn, dolinux.peng@gmail.com, linux-trace-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20230402070406.177f09cc34f9860baf3e6ec2@kernel.org> <7088643e-400b-4cd4-edd3-63b3baa36a7c@sangfor.com.cn> Content-Language: en-US In-Reply-To: <7088643e-400b-4cd4-edd3-63b3baa36a7c@sangfor.com.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWS1ZQUlXWQ8JGhUIEh9ZQVlCSxhIVktMQktLTUkeGRoaS1UTARMWGhIXJBQOD1 lXWRgSC1lBWUpJSlVISVVJTk9VSk9MWVdZFhoPEhUdFFlBWU9LSFVKSktISkxVSktLVUtZBg++ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PBg6Gjo6Mj0WODNMMDA8CAgy FitPFCpVSlVKTUNLTExMSE5PQ0pMVTMWGhIXVQseFRwfFBUcFxIVOwgaFRwdFAlVGBQWVRgVRVlX WRILWUFZSklKVUhJVUlOT1VKT0xZV1kIAVlBQ01IQzcG X-HM-Tid: 0a8756231c5c2eb7kusn38c2f58045f X-HM-MType: 1 X-Spam-Status: No, score=-2.2 required=5.0 tests=NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/4/3 13:01, Donglin Peng wrote: > On 2023/4/3 10:33, Donglin Peng wrote: >> On 2023/4/2 6:04, Masami Hiramatsu (Google) wrote: >>> On Fri, 31 Mar 2023 05:47:44 -0700 >>> Donglin Peng wrote: >>> >>>> Add a test case for the funcgraph-retval and funcgraph-retval-hex >>>> trace options. >>>> >>>> Signed-off-by: Donglin Peng >>>> --- >>>> v10: >>>>   - Fix issues in selftest >>>> >>>> v8: >>>>   - Fix issues in selftest >>>> --- >>>>   .../ftrace/test.d/ftrace/fgraph-retval.tc     | 43 >>>> +++++++++++++++++++ >>>>   1 file changed, 43 insertions(+) >>>>   create mode 100644 >>>> tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc >>>> >>>> diff --git >>>> a/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc >>>> b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc >>>> new file mode 100644 >>>> index 000000000000..5819aa2dd6ad >>>> --- /dev/null >>>> +++ b/tools/testing/selftests/ftrace/test.d/ftrace/fgraph-retval.tc >>>> @@ -0,0 +1,43 @@ >>>> +#!/bin/sh >>>> +# SPDX-License-Identifier: GPL-2.0 >>>> +# description: ftrace - function graph print function return value >>>> +# requires: options/funcgraph-retval options/funcgraph-retval-hex >>>> function_graph:tracer >>>> + >>>> +# Make sure that funcgraph-retval works >>>> + >>>> +fail() { # msg >>>> +    echo $1 >>>> +    exit_fail >>>> +} >>>> + >>>> +disable_tracing >>>> +clear_trace >>>> + >>>> +read PID _ < /proc/self/stat >>> >>> You can use "$$" for self pid. >> >> Yeah, I will fix it. > > I found that ftracetest used () to launch a new child process for > executing a .tc script file, however the $$ value remains unchanged, > so we can not use $$ here, because it is PPID. Therefore I think we > have to get PID from /proc/self/stat. > > Here is the code from ftracetest that launches a child shell for > executing the .tc file. > > __run_test() { # testfile >   # setup PID and PPID, $$ is *not* updated. >   (cd $TRACING_DIR; read PID _ < /proc/self/stat; set -e; set -x; >    checkreq $1; initialize_ftrace; . $1) >   [ $? -ne 0 ] && kill -s $SIG_FAIL $SIG_PID > } > >> >>> >>>> +[ -f set_ftrace_pid ] && echo ${PID} > set_ftrace_pid >>>> +[ -f set_ftrace_filter ] && echo proc_reg_write > set_ftrace_filter >>>> +[ -f set_graph_function ] && echo proc_reg_write > set_graph_function >>> >>> You should set the required files for this test, so that the test result >>> is always same. BTW, you need to set either 'set_ftrace_filter' or >>> 'set_graph_function'. >> >> Yes, but I discovered that set_ftrace_filter and set_graph_function >> rely on the CONFIG_DYNAMIC_FTRACE configuration, which means that >> these two files are not present when CONFIG_DYNAMIC_FTRACE is >> disabled, even if CONFIG_FUNCTION_GRAPH_RETVAL is enabled. Therefore, >> I think that these two trace files are not necessary for this test. >> >> I will modify the above like this: >> >> [ -f set_ftrace_pid ] && echo $$ > set_ftrace_pid >> [ -f set_ftrace_filter ] && echo proc_reg_write > set_ftrace_filter >> >>> >>>> +echo function_graph > current_tracer >>>> +echo funcgraph-retval > trace_options >>>> + >>>> +set +e >>>> +enable_tracing >>>> +echo > /proc/interrupts >>>> +disable_tracing >>>> +set -e >>>> + >>>> +: "Test printing the error code in signed decimal format" >>>> +echo nofuncgraph-retval-hex > trace_options >>> >>> echo 0 > options/funcgraph-retval-hex >>> >>> If you require 'options/funcgraph-retval-hex' file, you can use the >>> file to set it or clear it. >> >> Yeah. >> >>> >>>> +count=`cat trace | grep 'proc_reg_write' | grep '= -5' | wc -l` >>>> +if [ $count -eq 0 ]; then >>>> +    fail "Return value can not be printed in signed decimal format" >>>> +fi >>>> + >>>> +: "Test printing the error code in hexadecimal format" >>>> +echo funcgraph-retval-hex > trace_options >>> >>> Ditto. >> >> Thanks. >> >>> >>> Thanks, >>> >>>> +count=`cat trace | grep 'proc_reg_write' | grep 'fffffffb' | wc -l` >>>> +if [ $count -eq 0 ]; then >>>> +    fail "Return value can not be printed in hexadecimal format" >>>> +fi >>>> + >>>> +exit 0 >>>> -- >>>> 2.25.1 >>>> >>> >>> >> > Hi Masami, I will update the selftest as follows, according to the comments: #!/bin/sh # SPDX-License-Identifier: GPL-2.0 # description: ftrace - function graph print function return value # requires: options/funcgraph-retval options/funcgraph-retval-hex function_graph:tracer # Make sure that funcgraph-retval works fail() { # msg echo $1 exit_fail } disable_tracing clear_trace # get self PID, can not use $$, because it is PPID read PID _ < /proc/self/stat [ -f set_ftrace_filter ] && echo proc_reg_write > set_ftrace_filter [ -f set_ftrace_pid ] && echo ${PID} > set_ftrace_pid echo function_graph > current_tracer echo 1 > options/funcgraph-retval set +e enable_tracing echo > /proc/interrupts disable_tracing set -e : "Test printing the error code in signed decimal format" echo 0 > options/funcgraph-retval-hex count=`cat trace | grep 'proc_reg_write' | grep '= -5' | wc -l` if [ $count -eq 0 ]; then fail "Return value can not be printed in signed decimal format" fi : "Test printing the error code in hexadecimal format" echo 1 > options/funcgraph-retval-hex count=`cat trace | grep 'proc_reg_write' | grep 'fffffffb' | wc -l` if [ $count -eq 0 ]; then fail "Return value can not be printed in hexadecimal format" fi exit 0