From c3207c832c925d26c1a486fb5e3adfa42cb23939 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Wed, 6 Mar 2024 18:48:14 +0100 Subject: [PATCH] Migrate test-sd-card script writeShellApplication --- modules/hardware/raspi4/raspi-base.nix | 63 +++++-------------------- modules/hardware/raspi4/test-sd-card.sh | 50 ++++++++++++++++++++ 2 files changed, 61 insertions(+), 52 deletions(-) create mode 100644 modules/hardware/raspi4/test-sd-card.sh diff --git a/modules/hardware/raspi4/raspi-base.nix b/modules/hardware/raspi4/raspi-base.nix index 91a4dae..afe55fb 100644 --- a/modules/hardware/raspi4/raspi-base.nix +++ b/modules/hardware/raspi4/raspi-base.nix @@ -6,58 +6,17 @@ }: let cfg = config.hardware.az-raspi4-base; - test-sd-card = pkgs.writeShellScriptBin "test-sd-card" '' - # Raspberry Pi microSD card benchmark script. - # - # A script I use to automate the running and reporting of benchmarks I compile - # for: http://www.pidramble.com/wiki/benchmarks/microsd-cards - # - # Usage: - # # Run it locally. - # $ su do ./microsd-benchmarks.sh - # - # # Run it straight from GitHub. - # $ curl https://raw.githubusercontent.com/geerlingguy/raspberry-pi-dramble/master/setup/benchmarks/microsd-benchmarks.sh | sudo bash - # - # Another good benchmark: - # $ curl http://www.nmacleod.com/public/sdbench.sh | sudo bash - # - # Author: Jeff Geerling, 2016 (last updated 2020) - - printf "\n" - printf "Raspberry Pi Dramble microSD benchmarks\n" - - CLOCK="$(${pkgs.gnugrep}/bin/grep "actual clock" /sys/kernel/debug/mmc0/ios 2>/dev/null | ${pkgs.gawk}/bin/awk '{printf("%0.3f MHz", $3/1000000)}')" - if [ -n "$CLOCK" ]; then - echo "microSD clock: $CLOCK" - fi - printf "\n" - - # Fail if $SUDO_USER is empty. - if [ -z "$SUDO_USER" ]; then - printf "This script must be run with sudo.\n" - exit 1 - fi - - # Variables. - USER_HOME_PATH=$(getent passwd $SUDO_USER | cut -d: -f6) - - # Run benchmarks. - printf "Running hdparm test...\n" - ${pkgs.hdparm}/bin/hdparm -t /dev/mmcblk1 - printf "\n" - - printf "Running dd test...\n\n" - ${pkgs.coreutils}/bin/dd if=/dev/zero of=$USER_HOME_PATH/test bs=8k count=50k conv=fsync - rm -f $USER_HOME_PATH/test - printf "\n" - - printf "Running iozone test...\n" - ${pkgs.iozone}/bin/iozone -e -I -a -s 100M -r 4k -i 0 -i 1 -i 2 - printf "\n" - - printf "microSD card benchmark complete!\n\n" - ''; + test-sd-card = pkgs.writeShellApplication { + name = "test-sd-card"; + runtimeInputs = [ + pkgs.coreutils + pkgs.gawk + pkgs.gnugrep + pkgs.hdparm + pkgs.iozone + ]; + text = (builtins.readFile ./test-sd-card.sh); + }; in { options = { diff --git a/modules/hardware/raspi4/test-sd-card.sh b/modules/hardware/raspi4/test-sd-card.sh new file mode 100644 index 0000000..cb1d857 --- /dev/null +++ b/modules/hardware/raspi4/test-sd-card.sh @@ -0,0 +1,50 @@ +# Raspberry Pi microSD card benchmark script. +# +# A script I use to automate the running and reporting of benchmarks I compile +# for: http://www.pidramble.com/wiki/benchmarks/microsd-cards +# +# Usage: +# # Run it locally. +# $ su do ./microsd-benchmarks.sh +# +# # Run it straight from GitHub. +# $ curl https://raw.githubusercontent.com/geerlingguy/raspberry-pi-dramble/master/setup/benchmarks/microsd-benchmarks.sh | sudo bash +# +# Another good benchmark: +# $ curl http://www.nmacleod.com/public/sdbench.sh | sudo bash +# +# Author: Jeff Geerling, 2016 (last updated 2020) + +printf "\n" +printf "Raspberry Pi Dramble microSD benchmarks\n" + +CLOCK="$(grep "actual clock" /sys/kernel/debug/mmc0/ios 2>/dev/null | awk '{printf("%0.3f MHz", $3/1000000)}')" +if [ -n "$CLOCK" ]; then + echo "microSD clock: $CLOCK" +fi +printf "\n" + +# Fail if $SUDO_USER is empty. +if [ -z "$SUDO_USER" ]; then + printf "This script must be run with sudo.\n" + exit 1 +fi + +# Variables. +USER_HOME_PATH=$(getent passwd "$SUDO_USER" | cut -d: -f6) + +# Run benchmarks. +printf "Running hdparm test...\n" +hdparm -t /dev/mmcblk1 +printf "\n" + +printf "Running dd test...\n\n" +dd if=/dev/zero of="$USER_HOME_PATH"/test bs=8k count=50k conv=fsync +rm -f "$USER_HOME_PATH"/test +printf "\n" + +printf "Running iozone test...\n" +iozone -e -I -a -s 100M -r 4k -i 0 -i 1 -i 2 +printf "\n" + +printf "microSD card benchmark complete!\n\n"