From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
To: linux-kernel@vger.kernel.org,
"Paul E. McKenney" <paulmck@kernel.org>,
Josh Triplett <josh@joshtriplett.org>,
Steven Rostedt <rostedt@goodmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Shuah Khan <shuah@kernel.org>
Cc: "Joel Fernandes (Google)" <joel@joelfernandes.org>,
rcu@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH RFC 2/5] rcutorture: Add a stress-ng build script
Date: Thu, 23 Jan 2025 20:58:33 -0500 [thread overview]
Message-ID: <20250124015836.732086-3-joel@joelfernandes.org> (raw)
In-Reply-To: <20250124015836.732086-1-joel@joelfernandes.org>
This script automates the building of stress-ng and can be run from
any directory. It also support cross-compilation. The output is placed
into the initrd directory.
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
.../selftests/rcutorture/bin/mkstress-ng.sh | 86 +++++++++++++++++++
1 file changed, 86 insertions(+)
create mode 100755 tools/testing/selftests/rcutorture/bin/mkstress-ng.sh
diff --git a/tools/testing/selftests/rcutorture/bin/mkstress-ng.sh b/tools/testing/selftests/rcutorture/bin/mkstress-ng.sh
new file mode 100755
index 000000000000..e5a19cca6923
--- /dev/null
+++ b/tools/testing/selftests/rcutorture/bin/mkstress-ng.sh
@@ -0,0 +1,86 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Clone and build the stress-ng tool, placing the binary in the
+# initrd directory. Ensure binary is up-to-date.
+#
+# Usage: ./bin/mkstress-ng.sh (run from any where).
+#
+# Copyright (C) Google LLC, 2024
+# Author: Joel Fernandes (Google) <joel@joelfernandes.org>
+
+# Get the directory where the script is located
+SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
+
+REPO_URL="https://github.com/ColinIanKing/stress-ng.git"
+SRC_DIR="${SCRIPT_DIR}/../res/stress-ng"
+INITRD_DIR="${SCRIPT_DIR}/../initrd"
+BIN_NAME="stress-ng"
+export COMPILER="${CROSS_COMPILE}gcc"
+
+is_statically_linked() {
+ if file "$1" | grep -q "statically linked"; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+needs_build() {
+ if [ ! -f "$INITRD_DIR/$BIN_NAME" ]; then
+ return 0
+ fi
+ if [ "$(find "$SRC_DIR" -newer "$INITRD_DIR/$BIN_NAME")" ]; then
+ return 0
+ fi
+ if ! is_statically_linked "$INITRD_DIR/$BIN_NAME"; then
+ return 0
+ fi
+ return 1
+}
+
+if [ ! -d "$INITRD_DIR" ]; then
+ echo "Error: INITRD_DIR ($INITRD_DIR) does not exist"
+ exit 1
+fi
+
+if ! which "$COMPILER" &> /dev/null; then
+ echo "Error: Compiler $COMPILER not found."
+ exit 1
+fi
+
+if [ ! -d "$SRC_DIR" ]; then
+ echo "Cloning stress-ng repository..."
+ if ! git clone "$REPO_URL" "$SRC_DIR"; then
+ echo "Failed to clone stress-ng repository."
+ rm -rf "$SRC_DIR"
+ exit 1
+ fi
+else
+ echo "Updating stress-ng repository..."
+ cd "$SRC_DIR" || exit 1
+ git pull || { echo "Failed to update stress-ng repository"; exit 1; }
+ cd - > /dev/null || exit 1
+fi
+
+# Build stress-ng binary if needed
+if needs_build; then
+ echo "Building stress-ng binary..."
+ cd "$SRC_DIR" || exit 1
+ STATIC=1 make -j 8 || { echo "stress-ng build failed"; exit 1; }
+ cd - > /dev/null || exit 1
+
+ # Verify the stress-ng binary is static
+ if ! is_statically_linked "$SRC_DIR/$BIN_NAME"; then
+ echo "Error: The stress-ng binary is not statically linked."
+ exit 1
+ fi
+
+ echo "Copying stress-ng binary to initrd directory..."
+ cp "$SRC_DIR/$BIN_NAME" "$INITRD_DIR" || { echo "Failed to copy stress-ng binary"; exit 1; }
+else
+ echo "stress-ng binary is up-to-date, no build needed."
+fi
+
+echo "stress-ng build process completed successfully."
+exit 0
\ No newline at end of file
--
2.34.1
next prev parent reply other threads:[~2025-01-24 1:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250124015836.732086-1-joel@joelfernandes.org>
2025-01-24 1:58 ` [PATCH RFC 1/5] rcutorture: kvm: Simplify invocation of mkinitrd.sh Joel Fernandes (Google)
2025-01-24 1:58 ` Joel Fernandes (Google) [this message]
2025-01-24 1:58 ` [PATCH RFC 3/5] rcutorture: mkinitrd: Allow to run optional commands passed to it Joel Fernandes (Google)
2025-01-24 1:58 ` [PATCH RFC 4/5] rcutorture: mkinitrd: Use previous init.c to check if rebuild needed Joel Fernandes (Google)
2025-01-24 1:58 ` [PATCH RFC 5/5] rcutorture: kvm: Invoke stress-ng building it if necessary Joel Fernandes (Google)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250124015836.732086-3-joel@joelfernandes.org \
--to=joel@joelfernandes.org \
--cc=jiangshanlai@gmail.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox