open-cas-linux/test/smoke_test/metadata_corrupt/01
Robert Baldyga dc75d76087 Update metadata corruption smoke tests for flapping
Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
2022-01-04 19:33:12 +01:00

128 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright(c) 2012-2021 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#
# DESCRIPTION Swap one random bit in each metadata section and try to load cache.
# The line below says that this test should be included in BVT - it will be launched, when we use "./run_tests -b"
# USE_IN_BVT
# USE_IN_NIGHTLY
# Standard beginning for every test - get the main tests directory and
# link the cas_lib file for CAS API, then use "start_test $*" to pass params
# and do other necessary checks and setup
TESTS_DIR="$(dirname $0)/../"
. $TESTS_DIR/cas_lib
start_test $*
# This is where the real test starts
test_log_start
# Corrupts random bit from byte on given by $1 address from ${CACHE_DEVICE}1
corrupt_byte(){
OFFSET=$1
READ_VALUE=`od -N 1 -j $OFFSET -A n -t x1 ${CACHE_DEVICE}-part1`
READ_VALUE="0x`echo $READ_VALUE`"
RANDOM_UINT32=`od -An -tu4 -N4 /dev/urandom`
MASK=$(( 1 << $(( $RANDOM_UINT32 % 8 )) ))
echo -e "\x$(( ${READ_VALUE} ^ ${MASK} ))"| dd bs=1 count=1 seek=$OFFSET conv=notrunc of=${CACHE_DEVICE}-part1 1>&2 2>/dev/null
}
align(){
VALUE=$1
ALIGNMENT=$2
echo $((($VALUE + $ALIGNMENT - 1) / $ALIGNMENT * $ALIGNMENT))
}
# Use CACHE_DEVICE and CORE_DEVICE provided by configuration file and remove partitions from those devices
TARGET_DEVICE_OPTION="$CACHE_DEVICE" remove_partitions
TARGET_DEVICE_OPTION="$CORE_DEVICE" remove_partitions
# Create 1 primary partition on CACHE_DEVICE, 2000MB
TARGET_DEVICE_OPTION="$CACHE_DEVICE" PARTITION_SIZE_OPTION="2000M" PARTITION_IDS_OPTION="1" make_primary_partitions
# Create 1 primary partition on CORE_DEVICE, 4000M
TARGET_DEVICE_OPTION="$CORE_DEVICE" PARTITION_SIZE_OPTION="4000M" PARTITION_IDS_OPTION="1" make_primary_partitions
METADATA_SECTIONS_NAMES=("Super block config" "Super block runtime" "Reserved" "Part config" "Part runtime" "Core config" "Core runtime" "Core UUID" "Cleaning" "LRU list" "Collision" "List info" "Hash")
for SECTION in "${METADATA_SECTIONS_NAMES[@]}"
do
if [ "$SECTION" == "Reserved" ]
then
continue
fi
if [ "$SECTION" == "Core config" ] || [ "$SECTION" == "Core UUID" ] || [ "$SECTION" == "Part config" ]
then
flapping=1
else
flapping=0
fi
# Start cache on CACHE_DEVICE to repair it and also to make log.
CACHE_ID_OPTION="1" CACHE_FORCE_OPTION="1" CACHE_DEVICE_OPTION="${CACHE_DEVICE}-part1" start_cache
# Stop cache.
CACHE_ID_OPTION="1" stop_cache
# Resolve size and offset of metadata section.
METADATA_SECTION_OFFSET=`dmesg | grep "${SECTION} offset" | tac | sed '1!d' | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/' `
METADATA_SECTION_SIZE=`dmesg | grep "${SECTION} size" | tac | sed '1!d' | sed -e 's/.*[^0-9]\([0-9]\+\)[^0-9]*$/\1/' `
if [ -z ${METADATA_SECTION_OFFSET} ]
then
test_log_trace "Couldn't read ${SECTION} offset"
end_test 1
fi
if [ -z ${METADATA_SECTION_SIZE} ]
then
test_log_trace "Couldn't read ${SECTION} size"
end_test 1
fi
# Choose random bit and corrupt it
RANDOM_UINT32=`od -An -tu4 -N4 /dev/urandom`
# Super block size is in bytes!
if [ "$SECTION" == "Super block config" ] || [ "$SECTION" == "Super block runtime" ]
then
METADATA_SECTION_SIZE_B=$METADATA_SECTION_SIZE
else
METADATA_SECTION_SIZE_B=$(( $METADATA_SECTION_SIZE * 1024 ))
fi
METADATA_SECTION_START_B=$(( ${METADATA_SECTION_OFFSET} * 1024 ))
CORRUPT_OFFSET=$(( $RANDOM_UINT32 % $METADATA_SECTION_SIZE_B ))
if [ "$(( $CORRUPT_OFFSET % 4096 ))" -ge "2048" ]; then
CORRUPT_OFFSET=$(( $CORRUPT_OFFSET - 2048 ))
fi
test_log_trace "Corrupting with offset ${CORRUPT_OFFSET} B from start of ${SECTION}"
CORRUPT_ADDRESS=$(( $METADATA_SECTION_START_B + $CORRUPT_OFFSET ))
corrupt_byte ${CORRUPT_ADDRESS}
if [ "$flapping" -eq "1" ]; then
ALIGNMENT=$(( 128 * 1024 ))
METADATA_SECTION_SIZE_ALIGNED_B=$(align $METADATA_SECTION_SIZE_B $ALIGNMENT)
METADATA_SECTION_START_B=$(( $METADATA_SECTION_START_B + $METADATA_SECTION_SIZE_ALIGNED_B ))
CORRUPT_ADDRESS=$(( $METADATA_SECTION_START_B + $CORRUPT_OFFSET ))
corrupt_byte ${CORRUPT_ADDRESS}
fi
# Start again with load option, this should fail, metadata is corrupted.
NEGATIVE_TEST_OPTION="1" CACHE_ID_OPTION="1" CACHE_LOAD_METADATA_OPTION="1" CACHE_DEVICE_OPTION="${CACHE_DEVICE}-part1" start_cache
done
test_log_stop
# Always return 0 at the end of the test - if at any point something has failed
# in the API functions, test will end and return a proper result.
# If you need to check other things during the test and end the test earlier, you
# should end the test using "end_test $retval" function
end_test 0