common/fuzzy: if the fuzz verb is random, keep fuzzing until we get a new value
[xfstests-dev.git] / common / fuzzy
index 86492687bfe55cbae4589613a5bf04a5d9579945..d70964f4766133649ddf13e9947f2eafd60a7b94 100644 (file)
@@ -79,6 +79,14 @@ _scratch_scrub() {
        esac
 }
 
+# Filter out any keys with an array index >= 10, collapse any array range
+# ("[1-195]") to the first item, and ignore padding fields.
+__filter_xfs_db_keys() {
+       sed -e '/\([a-z]*\)\[\([0-9][0-9]\+\)\].*/d' \
+           -e 's/\([a-zA-Z0-9_]*\)\[\([0-9]*\)-[0-9]*\]/\1[\2]/g' \
+           -e '/pad/d'
+}
+
 # Filter the xfs_db print command's field debug information
 # into field name and type.
 __filter_xfs_db_print_fields() {
@@ -87,15 +95,13 @@ __filter_xfs_db_print_fields() {
                filter='^'
        fi
        grep ' = ' | while read key equals value; do
-               # Filter out any keys with an array index >= 10, and
-               # collapse any array range ("[1-195]") to the first item.
-               fuzzkey="$(echo "${key}" | sed -e '/\([a-z]*\)\[\([0-9][0-9]\+\)\].*/d' -e 's/\([a-zA-Z0-9_]*\)\[\([0-9]*\)-[0-9]*\]/\1[\2]/g')"
+               fuzzkey="$(echo "${key}" | __filter_xfs_db_keys)"
                if [ -z "${fuzzkey}" ]; then
                        continue
                elif [[ "${value}" == "["* ]]; then
                        echo "${value}" | sed -e 's/^.//g' -e 's/.$//g' -e 's/,/\n/g' | while read subfield; do
                                echo "${fuzzkey}.${subfield}"
-                       done
+                       done | __filter_xfs_db_keys
                else
                        echo "${fuzzkey}"
                fi
@@ -173,9 +179,14 @@ _scratch_xfs_fuzz_metadata_field() {
        for arg in "$@"; do
                cmds+=("-c" "${arg}")
        done
-       _scratch_xfs_db -x "${cmds[@]}" -c "fuzz ${fuzz_arg} ${key} ${value}"
-       echo
-       newval="$(_scratch_xfs_get_metadata_field "${key}" "$@" 2> /dev/null)"
+       while true; do
+               _scratch_xfs_db -x "${cmds[@]}" -c "fuzz ${fuzz_arg} ${key} ${value}"
+               echo
+               newval="$(_scratch_xfs_get_metadata_field "${key}" "$@" 2> /dev/null)"
+               if [ "${key}" != "random" ] || [ "${oldval}" != "${newval}" ]; then
+                       break;
+               fi
+       done
        if [ "${oldval}" = "${newval}" ]; then
                echo "Field ${key} already set to ${newval}, skipping test."
                return 1