| 
									
										
										
										
											2010-04-26 11:44:05 +02:00
										 |  |  | #!/bin/bash | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | # | 
					
						
							|  |  |  | # Copyright (C) 2009 Red Hat, Inc. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  | # it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  | # the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  | # (at your option) any later version. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | # GNU General Public License for more details. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # You should have received a copy of the GNU General Public License | 
					
						
							| 
									
										
										
										
											2009-07-16 19:26:54 +02:00
										 |  |  | # along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-16 19:11:09 +02:00
										 |  |  | function do_is_allocated() { | 
					
						
							|  |  |  |     local start=$1 | 
					
						
							|  |  |  |     local size=$(( $2 / 512)) | 
					
						
							|  |  |  |     local step=$3 | 
					
						
							|  |  |  |     local count=$4 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for i in `seq 1 $count`; do | 
					
						
							| 
									
										
											  
											
												qemu-iotests: Use zero-based offsets for IO patterns
The io_pattern style functions have the following loop:
  for i in `seq 1 $count`; do
      echo ... $(( start + i * step )) ...
  done
Offsets are 1-based so start=1024, step=512, count=4 yields:
1536, 2048, 2560, 3072
Normally we expect:
1024, 1536, 2048, 2560
Most tests ignore this detail, which means that they perform I/O to a
slightly different range than expected by the test author.
Later on things got less innocent and tests started trying to compensate
for the 1-based indexing.  This included negative start values in test
024 and my own attempt with count-1 in test 028!
The end result is that tests that use io_pattern are hard to reason
about and don't work the way you'd expect.  It's time to clean this mess
up.
This patch switches io_pattern to 0-based offsets.  This requires
adjusting the golden outputs since I/O ranges are now shifted and output
differs.
Verifying these output diffs is easy, however.  Each diff hunk moves one
I/O from beyond the end of the pattern range to the beginning.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
											
										 
											2011-02-04 12:55:02 +00:00
										 |  |  |         echo alloc $(( start + (i - 1) * step )) $size | 
					
						
							| 
									
										
										
										
											2009-07-16 19:11:09 +02:00
										 |  |  |     done | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function is_allocated() { | 
					
						
							| 
									
										
										
										
											2013-10-31 11:57:36 -04:00
										 |  |  |     do_is_allocated "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io | 
					
						
							| 
									
										
										
										
											2009-07-16 19:11:09 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | function do_io() { | 
					
						
							|  |  |  |     local op=$1 | 
					
						
							|  |  |  |     local start=$2 | 
					
						
							|  |  |  |     local size=$3 | 
					
						
							|  |  |  |     local step=$4 | 
					
						
							|  |  |  |     local count=$5 | 
					
						
							|  |  |  |     local pattern=$6 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     echo === IO: pattern $pattern >&2 | 
					
						
							|  |  |  |     for i in `seq 1 $count`; do | 
					
						
							| 
									
										
											  
											
												qemu-iotests: Use zero-based offsets for IO patterns
The io_pattern style functions have the following loop:
  for i in `seq 1 $count`; do
      echo ... $(( start + i * step )) ...
  done
Offsets are 1-based so start=1024, step=512, count=4 yields:
1536, 2048, 2560, 3072
Normally we expect:
1024, 1536, 2048, 2560
Most tests ignore this detail, which means that they perform I/O to a
slightly different range than expected by the test author.
Later on things got less innocent and tests started trying to compensate
for the 1-based indexing.  This included negative start values in test
024 and my own attempt with count-1 in test 028!
The end result is that tests that use io_pattern are hard to reason
about and don't work the way you'd expect.  It's time to clean this mess
up.
This patch switches io_pattern to 0-based offsets.  This requires
adjusting the golden outputs since I/O ranges are now shifted and output
differs.
Verifying these output diffs is easy, however.  Each diff hunk moves one
I/O from beyond the end of the pattern range to the beginning.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
											
										 
											2011-02-04 12:55:02 +00:00
										 |  |  |         echo $op -P $pattern $(( start + (i - 1) * step )) $size | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  |     done | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function io_pattern() { | 
					
						
							| 
									
										
										
										
											2013-10-31 11:57:36 -04:00
										 |  |  |     do_io "$@" | $QEMU_IO "$TEST_IMG" | _filter_qemu_io | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function io() { | 
					
						
							|  |  |  |     local start=$2 | 
					
						
							|  |  |  |     local pattern=$(( (start >> 9) % 256 )) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-31 11:57:36 -04:00
										 |  |  |     do_io "$@" $pattern | $QEMU_IO "$TEST_IMG" | _filter_qemu_io | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function io_zero() { | 
					
						
							| 
									
										
										
										
											2013-10-31 11:57:36 -04:00
										 |  |  |     do_io "$@" 0 | $QEMU_IO "$TEST_IMG" | _filter_qemu_io | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function io_test() { | 
					
						
							|  |  |  |     local op=$1 | 
					
						
							|  |  |  |     local offset=$2 | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     local cluster_size=$3 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     local num_large=$4 | 
					
						
							|  |  |  |     local num_medium=$((num_large * num_large)) | 
					
						
							|  |  |  |     local num_small=$((4 * num_medium)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     local half_cluster=$((cluster_size / 2)) | 
					
						
							|  |  |  |     local quarter_cluster=$((cluster_size / 4)) | 
					
						
							|  |  |  |     local l2_size=$((cluster_size * cluster_size / 8)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Complete clusters | 
					
						
							|  |  |  |     io "$op" $offset $cluster_size $cluster_size $num_small | 
					
						
							|  |  |  |     offset=$((offset + num_small * $cluster_size)) | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # From somewhere in the middle to the end of a cluster | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io "$op" $((offset + $half_cluster)) $half_cluster $cluster_size $num_small | 
					
						
							|  |  |  |     offset=$((offset + num_small * $cluster_size)) | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # From the start to somewhere in the middle of a cluster | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io "$op" $offset $half_cluster $cluster_size $num_small | 
					
						
							|  |  |  |     offset=$((offset + num_small * $cluster_size)) | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Completely misaligned (and small) | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io "$op" $((offset + $quarter_cluster)) $half_cluster $cluster_size $num_small | 
					
						
							|  |  |  |     offset=$((offset + num_small * $cluster_size)) | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Spanning multiple clusters | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io "$op" $((offset + $half_cluster)) $((cluster_size * 2)) $((cluster_size * 3)) $num_medium | 
					
						
							|  |  |  |     offset=$((offset + num_medium * 3 * $cluster_size)) | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Spanning multiple L2 tables | 
					
						
							|  |  |  |     # L2 table size: 512 clusters of 4k = 2M | 
					
						
							| 
									
										
										
										
											2009-10-01 14:30:19 -03:00
										 |  |  |     offset=$(( ((offset + l2_size - 1) & ~(l2_size - 1)) - (3 * half_cluster) )) | 
					
						
							|  |  |  |     io "$op" $offset $((6 * half_cluster)) $(( l2_size + half_cluster )) $num_large | 
					
						
							|  |  |  |     offset=$((offset + num_large * ( l2_size + half_cluster ))) | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function io_test2() { | 
					
						
							|  |  |  |     local orig_offset=$1 | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     local cluster_size=$2 | 
					
						
							|  |  |  |     local num=$3 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Pattern (repeat after 9 clusters): | 
					
						
							| 
									
										
										
										
											2013-09-04 13:16:04 +02:00
										 |  |  |     #        used - used - free - used - compressed - compressed - | 
					
						
							|  |  |  |     #        free - free - compressed | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Write the clusters to be compressed | 
					
						
							|  |  |  |     echo === Clusters to be compressed [1] | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io_pattern writev $((offset + 4 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  |     echo === Clusters to be compressed [2] | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io_pattern writev $((offset + 5 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  |     echo === Clusters to be compressed [3] | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io_pattern writev $((offset + 8 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-31 11:57:36 -04:00
										 |  |  |     mv "$TEST_IMG" "$TEST_IMG.orig" | 
					
						
							|  |  |  |     $QEMU_IMG convert -f $IMGFMT -O $IMGFMT -c "$TEST_IMG.orig" "$TEST_IMG" | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Write the used clusters | 
					
						
							|  |  |  |     echo === Used clusters [1] | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io_pattern writev $((offset + 0 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  |     echo === Used clusters [2] | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io_pattern writev $((offset + 1 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  |     echo === Used clusters [3] | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io_pattern writev $((offset + 3 * $cluster_size)) $cluster_size $((9 * $cluster_size)) $num 165 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Read them | 
					
						
							|  |  |  |     echo === Read used/compressed clusters | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io_pattern readv $((offset + 0 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num 165 | 
					
						
							|  |  |  |     io_pattern readv $((offset + 3 * $cluster_size)) $((3 * $cluster_size)) $((9 * $cluster_size)) $num 165 | 
					
						
							|  |  |  |     io_pattern readv $((offset + 8 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num 165 | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     echo === Read zeros | 
					
						
							| 
									
										
										
										
											2009-10-01 14:29:59 -03:00
										 |  |  |     io_zero readv $((offset + 2 * $cluster_size)) $((1 * $cluster_size)) $((9 * $cluster_size)) $num | 
					
						
							|  |  |  |     io_zero readv $((offset + 6 * $cluster_size)) $((2 * $cluster_size)) $((9 * $cluster_size)) $num | 
					
						
							| 
									
										
										
										
											2009-06-22 18:29:05 +02:00
										 |  |  | } |