From patchwork Mon May 11 13:36:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 11540733 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CBDFB139A for ; Mon, 11 May 2020 13:36:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B44242075E for ; Mon, 11 May 2020 13:36:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589204194; bh=8DynboS6OUq8obog0yLupsM4d16CMsXlKuWciX/Red8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dh6VaqoITWWeEi/6OhInNV6oH6WLxgtJqiIlACV21x+edTJLFM62S2/TGaQavIyKa r3Xi3jS6PmwLT9TgQqncgv5GhS2yv5webfm7H0Ta80Abf3gZthS2bwA2zPg6jr27Ik O87bxi8OAz+Ho+D8Ckq0qPvzJRZ0T2nN4bnWQxQk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728683AbgEKNge (ORCPT ); Mon, 11 May 2020 09:36:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:43354 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729546AbgEKNge (ORCPT ); Mon, 11 May 2020 09:36:34 -0400 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 50C88206F9; Mon, 11 May 2020 13:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589204193; bh=8DynboS6OUq8obog0yLupsM4d16CMsXlKuWciX/Red8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aCmXliY0Luuna4EBlNA170YSeDStzaq/FBchKGaD1YBe5XzWo0xCbYQvOuuL4lFef AFHvZOHpDFaVsi3i2X182LMexoAFz7oX3lPFIVKK6SKrvCi0ye34B65xH2kW0J8PY6 EcbzeOkJrfdpIeNZE9sTe62aRqptPpDoJ92nR7y4= From: Masami Hiramatsu To: Shuah Khan , Steven Rostedt Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Zanussi , Masami Hiramatsu , Li Philip , Liu Yiding , Xiao Yang , Andreas Schwab , David Laight Subject: [PATCH v2] selftests/ftrace: Use printf for backslash included command Date: Mon, 11 May 2020 22:36:27 +0900 Message-Id: <158920418730.16156.8299185499520876735.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <87imh21x6f.fsf@igel.home> References: <87imh21x6f.fsf@igel.home> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Since the built-in echo has different behavior in POSIX shell (dash) and bash, kprobe_syntax_errors.tc can fail on dash which interpret backslash escape automatically. To fix this issue, we explicitly use printf "%s" (not interpret backslash escapes) if the command string can include backslash. Reported-by: Liu Yiding Suggested-by: Xiao Yang Signed-off-by: Masami Hiramatsu --- tools/testing/selftests/ftrace/test.d/functions | 8 +++++--- .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/ftrace/test.d/functions b/tools/testing/selftests/ftrace/test.d/functions index 61a3c7e2634d..697c77ef2e2b 100644 --- a/tools/testing/selftests/ftrace/test.d/functions +++ b/tools/testing/selftests/ftrace/test.d/functions @@ -119,12 +119,14 @@ yield() { ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1 } +# Since probe event command may include backslash, explicitly use printf "%s" +# to NOT interpret it. ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file - pos=$(echo -n "${2%^*}" | wc -c) # error position - command=$(echo "$2" | tr -d ^) + pos=$(printf "%s" "${2%^*}" | wc -c) # error position + command=$(printf "%s" "$2" | tr -d ^) echo "Test command: $command" echo > error_log - (! echo "$command" >> "$3" ) 2> /dev/null + (! printf "%s" "$command" >> "$3" ) 2> /dev/null grep "$1: error:" -A 3 error_log N=$(tail -n 1 error_log | wc -c) # " Command: " and "^\n" => 13 diff --git a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc index ef1e9bafb098..eb0f4ab4e070 100644 --- a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +++ b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc @@ -91,7 +91,9 @@ esac if grep -q "Create/append/" README && grep -q "imm-value" README; then echo 'p:kprobes/testevent _do_fork' > kprobe_events check_error '^r:kprobes/testevent do_exit' # DIFF_PROBE_TYPE -echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events + +# Explicitly use printf "%s" to not interpret \1 +printf "%s" 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events check_error 'p:kprobes/testevent _do_fork ^bcd=\1' # DIFF_ARG_TYPE check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8' # DIFF_ARG_TYPE check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"' # DIFF_ARG_TYPE