Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5424501rdb; Wed, 13 Dec 2023 08:15:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IHF04MnN/FLTCN1Etqes5zUA/eet9QuHP5DKufMyampKOcuQwKjFNZ//mSbwvhnGoOzNLYk X-Received: by 2002:a05:6a00:854:b0:6ce:6901:5611 with SMTP id q20-20020a056a00085400b006ce69015611mr9618737pfk.57.1702484136838; Wed, 13 Dec 2023 08:15:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702484136; cv=none; d=google.com; s=arc-20160816; b=bxgpSx+hRNsqx8WG8hGrO+YoROzpBuwfKQss+fOdXWnYnSb8TOFI9yULF58KPn5kQ8 WAVOlfz1G5fkbqtQyPZvP6OKsa3Z4qLKl8bHZImohVHpR0kaXdr9oqJUz06v4E77mImQ JnwVZuurk7OsKWLAOHfiVB1ItfUkntTwj2e77h+bM2bdKVgX5z5evGEyHD1ZL6EUmAU4 6yV/uY/W7Aa4OSrSJgYoln14IyjQXQswr6XaBevEYTnm6omcUo6Szx6VoHTa8838lsR1 +kgR9T80oCnHz1CrT+h/TFVNhYdGi3Xnt4FNZ+T/7KBGaAMo19wHeJb0sQLTXDZM6yWe B/UQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:subject:cc:to:from:date; bh=RQuU3o7UVkgpC7fr1kM5a65ggNZCNcrvhaOEcgFCcdM=; fh=NdLKlkF21tthkjg7TFYsCcVE9+mNBwBIZGGjccGgMeM=; b=jD73zuhlNb8dITLdsNZ/N6M9ZsisBa4A8qP0WdaoDcXtXH9HZ++PNHWdoH8IRT4PmW LdCmY2zrsYOvuxZ9rueH/w1h2sSG7PndEJdyDbr2Ltgjlugk1V5MROc1L3X7r2qGXZO1 oPOYSnFttFhGEKBOwTRfHar8qqEzbw+DqgHHnAji4bQyeMZKQLlv5yyE/Wq/TxcBEvrF /5HWT2iBrNP+ji7kCARzCZAOnTZQ4dyDBDYO78s8luzAap7M65dJr3QJBtTqi9d7UbpY S95rzvvVfBpTb0OoHGkF1lhWgzm+KGSOddJUrPYulmwrDJF1rmFNj3BsCAoV+KrO11jH SGlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id b5-20020a63eb45000000b0059f0cebd04csi9846669pgk.722.2023.12.13.08.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 08:15:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2C8698077FEB; Wed, 13 Dec 2023 08:15:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235434AbjLMQPF (ORCPT + 99 others); Wed, 13 Dec 2023 11:15:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235448AbjLMQOi (ORCPT ); Wed, 13 Dec 2023 11:14:38 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F5ABFE for ; Wed, 13 Dec 2023 08:14:44 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02B64C433C8; Wed, 13 Dec 2023 16:14:42 +0000 (UTC) Date: Wed, 13 Dec 2023 11:15:27 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH v4] tracing/selftests: Add test to test the trace_marker Message-ID: <20231213111527.6a4c9b58@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 13 Dec 2023 08:15:34 -0800 (PST) From: "Steven Rostedt (Google)" Add a test that writes longs strings, some over the size of the sub buffer and make sure that the entire content is there. Signed-off-by: Steven Rostedt (Google) --- Changes since v3: https://lore.kernel.org/linux-trace-kernel/20231212192317.0fb6b101@gandalf.local.home - Removed / */ from regex, to catch more than one space added to the beginning of the print. This would have caught the bug of using "%*s" instead of "%.*s". Luckily, the trace_printk test caught that. .../ftrace/test.d/00basic/trace_marker.tc | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 tools/testing/selftests/ftrace/test.d/00basic/trace_marker.tc diff --git a/tools/testing/selftests/ftrace/test.d/00basic/trace_marker.tc b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker.tc new file mode 100755 index 000000000000..9aa0db2b84fc --- /dev/null +++ b/tools/testing/selftests/ftrace/test.d/00basic/trace_marker.tc @@ -0,0 +1,82 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: Basic tests on writing to trace_marker +# requires: trace_marker +# flags: instance + +get_buffer_data_size() { + sed -ne 's/^.*data.*size:\([0-9][0-9]*\).*/\1/p' events/header_page +} + +get_buffer_data_offset() { + sed -ne 's/^.*data.*offset:\([0-9][0-9]*\).*/\1/p' events/header_page +} + +get_event_header_size() { + type_len=`sed -ne 's/^.*type_len.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event` + time_len=`sed -ne 's/^.*time_delta.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event` + array_len=`sed -ne 's/^.*array.*:[^0-9]*\([0-9][0-9]*\).*/\1/p' events/header_event` + total_bits=$((type_len+time_len+array_len)) + total_bits=$((total_bits+7)) + echo $((total_bits/8)) +} + +get_print_event_buf_offset() { + sed -ne 's/^.*buf.*offset:\([0-9][0-9]*\).*/\1/p' events/ftrace/print/format +} + +event_header_size=`get_event_header_size` +print_header_size=`get_print_event_buf_offset` + +data_offset=`get_buffer_data_offset` + +marker_meta=$((event_header_size+print_header_size)) + +make_str() { + cnt=$1 + # subtract two for \n\0 as marker adds these + cnt=$((cnt-2)) + printf -- 'X%.0s' $(seq $cnt) +} + +write_buffer() { + size=$1 + + str=`make_str $size` + + # clear the buffer + echo > trace + + # write the string into the marker + echo -n $str > trace_marker + + echo $str +} + +test_buffer() { + + size=`get_buffer_data_size` + oneline_size=$((size-marker_meta)) + echo size = $size + echo meta size = $marker_meta + + # Now add a little more the meta data overhead will overflow + + str=`write_buffer $size` + + # Make sure the line was broken + new_str=`awk ' /tracing_mark_write:/ { sub(/^.*tracing_mark_write: /,"");printf "%s", $0; exit}' trace` + + if [ "$new_str" = "$str" ]; then + exit fail; + fi + + # Make sure the entire line can be found + new_str=`awk ' /tracing_mark_write:/ { sub(/^.*tracing_mark_write: /,"");printf "%s", $0; }' trace` + + if [ "$new_str" != "$str" ]; then + exit fail; + fi +} + +test_buffer -- 2.42.0