Skip to content

Instantly share code, notes, and snippets.

@chantra
Created October 7, 2022 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chantra/5c7dd823e2b7c9419ef55d8139e82010 to your computer and use it in GitHub Desktop.
Save chantra/5c7dd823e2b7c9419ef55d8139e82010 to your computer and use it in GitHub Desktop.
#!/bin/bash
declare -a TEST_NAMES_FROM_BOOT
read_test_from_boot() {
# Check if test names were passed as boot parameter.
# We expect `run_tests` to be a comma-separated list of test names.
IFS=',' read -r -a TEST_NAMES_FROM_BOOT <<< \
"$(sed -n 's/.*run_tests=\([^ ]*\).*/\1/p' /tmp/a)"
echo "${TEST_NAMES_FROM_BOOT[@]}"
}
# Expect 2 tests
echo "BOOT_IMAGE=(hd0,gpt2)/vmlinuz-5.19.11-300.fc37.x86_64 root=UUID=ac6e459c-7981-469d-916a-58ed2b23a3ef ro rootflags=subvol=root rd.luks.uuid=luks-e2fb3dac-2da5-4503-a4b8-b55de838800a rhgb quiet run_tests=test_progs,test_progs2" > /tmp/a
read_test_from_boot
echo "${#TEST_NAMES_FROM_BOOT[@]}"
# Expect 0 test
echo "BOOT_IMAGE=(hd0,gpt2)/vmlinuz-5.19.11-300.fc37.x86_64 root=UUID=ac6e459c-7981-469d-916a-58ed2b23a3ef ro rootflags=subvol=root rd.luks.uuid=luks-e2fb3dac-2da5-4503-a4b8-b55de838800a rhgb quiet abc" > /tmp/a
read_test_from_boot
echo "${#TEST_NAMES_FROM_BOOT[@]}"
# Expect 2 tests, some trailing content
echo "BOOT_IMAGE=(hd0,gpt2)/vmlinuz-5.19.11-300.fc37.x86_64 root=UUID=ac6e459c-7981-469d-916a-58ed2b23a3ef ro rootflags=subvol=root rd.luks.uuid=luks-e2fb3dac-2da5-4503-a4b8-b55de838800a rhgb quiet run_tests=test_progs,test_progs2 abc" > /tmp/a
read_test_from_boot
echo "${#TEST_NAMES_FROM_BOOT[@]}"
@chantra
Copy link
Author

chantra commented Oct 7, 2022

$ /tmp/example.sh
test_progs test_progs2
2

0
test_progs test_progs2
2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment