| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# Verify that a dynamic variable can be set to the expected range of values. |
| 4 |
# |
| 5 |
# ==== Requirements ==== |
| 6 |
# |
| 7 |
# This verifies the following requirements: |
| 8 |
# |
| 9 |
# R1. The initial value should be equal to the expected default value. |
| 10 |
# |
| 11 |
# R2. A specified set of valid values should be settable and result in |
| 12 |
# the expected values. |
| 13 |
# |
| 14 |
# R3. It is allowed to set the variable to DEFAULT and the result is the |
| 15 |
# expected default value. |
| 16 |
# |
| 17 |
# R4. If the variable has a minimum, then: |
| 18 |
# |
| 19 |
# R4.1. Setting it to the minimum is accepted and results in the |
| 20 |
# minimum value. |
| 21 |
# |
| 22 |
# R4.2. If the minimum is not INT64_MIN, setting it to one less than |
| 23 |
# the minimum is accepted and results in the minimum value. |
| 24 |
# |
| 25 |
# R4.3. If the block_size is not 1, setting it to block_size less than |
| 26 |
# the minimum is accepted and results in the minimum value. |
| 27 |
# |
| 28 |
# R5. If the variable has a maximum, then: |
| 29 |
# |
| 30 |
# R5.1. Setting it to the maximum is accepted and results in the |
| 31 |
# maximum value. |
| 32 |
# |
| 33 |
# R5.2. If the maximum is not INT64_MAX, setting it to one more than |
| 34 |
# the maximum is accepted and results in the maximum value. |
| 35 |
# |
| 36 |
# R5.3. If the block_size is not 1, setting it to block_size more than |
| 37 |
# the maximum is accepted and results in the maximum value. |
| 38 |
# |
| 39 |
# R6. A specified set of invalid values should generate an error when |
| 40 |
# setting them. |
| 41 |
# |
| 42 |
# R7. If block_size is not 1, setting a value that is not a multiple of |
| 43 |
# the block size rounds it down to the next lower value. |
| 44 |
# |
| 45 |
# R8. All values checked above are checked both using the @@variable |
| 46 |
# and using the performance_schema table - either |
| 47 |
# performance_schema.global_variabes or |
| 48 |
# performance_schema.session_variables, depending on the scope. |
| 49 |
# |
| 50 |
# R9. If the variable has an alias, all the values checked above are |
| 51 |
# checked also for the alias. |
| 52 |
# |
| 53 |
# R10. In all cases above: |
| 54 |
# |
| 55 |
# R10.1. A deprecation warning is generated if one is expected, |
| 56 |
# otherwise not. |
| 57 |
# |
| 58 |
# R10.2. A truncation warning is generated when using invalid |
| 59 |
# values, otherwise not. |
| 60 |
# |
| 61 |
# ==== Usage ==== |
| 62 |
# |
| 63 |
# --let $scope = {global|session} |
| 64 |
# --let $name = NAME |
| 65 |
# [--let $alias = NAME] |
| 66 |
# --let $default = VALUE |
| 67 |
# --let $values = JSON_ARRAY |
| 68 |
# --let $invalid = JSON_ARRAY |
| 69 |
# [--let $min = MIN_VALUE] |
| 70 |
# [--let $max = MAX_VALUE] |
| 71 |
# [--let $block_size = BLOCK_SIZE] |
| 72 |
# [--let $mask_value = 1] |
| 73 |
# --source scenarios_for_dynamic_sysvar.inc |
| 74 |
# |
| 75 |
# Parameters: |
| 76 |
# |
| 77 |
# $scope |
| 78 |
# The scope to test. |
| 79 |
# |
| 80 |
# All other parameters |
| 81 |
# See json_sysvar_spec.inc |
| 82 |
|
| 83 |
|
| 84 |
--echo ==== Testing SET @@$scope.$name [allowed values, range, invalid values] ==== |
| 85 |
|
| 86 |
--echo # Initial value is default |
| 87 |
|
| 88 |
--let $expect_value = $default |
| 89 |
--source assertions_for_sysvar_and_alias_value.inc |
| 90 |
|
| 91 |
--echo # Valid values for variable |
| 92 |
# Iterate over values, set the variable, and verify that it worked. |
| 93 |
--let $json_array = $values |
| 94 |
--source $json_value_start |
| 95 |
while (!$json_value_done) { |
| 96 |
if ($mask_value) { |
| 97 |
--replace_result $json_value_value VALUE |
| 98 |
} |
| 99 |
eval SET @@$scope.$name=$json_value_value; |
| 100 |
--source assertions_for_sysvar_warnings.inc |
| 101 |
--let $expect_value = $json_value_value |
| 102 |
--source assertions_for_sysvar_and_alias_value.inc |
| 103 |
|
| 104 |
--source $json_value_next |
| 105 |
} |
| 106 |
|
| 107 |
--echo # Setting default value for variable |
| 108 |
eval SET @@$scope.$name = DEFAULT; |
| 109 |
--source assertions_for_sysvar_warnings.inc |
| 110 |
--let $expect_value = $default |
| 111 |
--source assertions_for_sysvar_and_alias_value.inc |
| 112 |
|
| 113 |
# Do not mask numeric values, as they are assumed to be deterministic. |
| 114 |
# Some numeric values depend on the environment - specifically, debug |
| 115 |
# mode on/off or platform word size 32/64 bits. To test them, you |
| 116 |
# should create different versions of the test for the different |
| 117 |
# environments. (Masking the values does not suffice to make the |
| 118 |
# result files environment-independent for such variables, since the |
| 119 |
# one-more-than maximum case is testable for variables whose maximum |
| 120 |
# is INT32MAX but not for variables whose maximum is INT64MAX, so when |
| 121 |
# the maximum depends on platform word size, the test takes entirely |
| 122 |
# different execution paths.) |
| 123 |
|
| 124 |
--let $_cds_mask_value_save = $mask_value |
| 125 |
--let $mask_value = 0 |
| 126 |
|
| 127 |
if ($min != '') { |
| 128 |
--echo # Minimum value |
| 129 |
eval SET @@$scope.$name = $min; |
| 130 |
--source assertions_for_sysvar_warnings.inc |
| 131 |
--let $expect_value = $min |
| 132 |
--source assertions_for_sysvar_and_alias_value.inc |
| 133 |
|
| 134 |
--let $assert_text = Expected min value should equal min value in performance_schema |
| 135 |
--let $assert_cond = [SELECT MIN_VALUE FROM performance_schema.variables_info WHERE VARIABLE_NAME = '$name'] = $min |
| 136 |
--source include/assert.inc |
| 137 |
|
| 138 |
--let $minint64 = -18446744073709551616 |
| 139 |
# Force mtr to use string comparison instead of numeric comparison, |
| 140 |
# since numeric comparison uses double precision, which may give wrong |
| 141 |
# results for integers of this magnitude. |
| 142 |
--let $xminint64 = x$minint64 |
| 143 |
--let $xmin = x$min |
| 144 |
if ($xmin != $xminint64) { |
| 145 |
--echo # Less-than-minimum values |
| 146 |
--let $expect_truncation_warning = 1 |
| 147 |
|
| 148 |
--let $min_minus_1 = `SELECT $min - 1` |
| 149 |
eval SET @@$scope.$name = $min_minus_1; |
| 150 |
--source assertions_for_sysvar_warnings.inc |
| 151 |
--let $expect_value = $min |
| 152 |
--source assertions_for_sysvar_and_alias_value.inc |
| 153 |
|
| 154 |
if ($block_size != 1) { |
| 155 |
# Can't use mtr's arithmetic since it uses floating-point, which does |
| 156 |
# not have sufficient precision to represent integers of this size. |
| 157 |
--let $value = `SELECT IF($min >= $minint64 + $block_size, $min - $block_size, $minint64)` |
| 158 |
eval SET @@$scope.$name = $value; |
| 159 |
--source assertions_for_sysvar_warnings.inc |
| 160 |
--let $expect_value = $min |
| 161 |
--source assertions_for_sysvar_and_alias_value.inc |
| 162 |
} |
| 163 |
|
| 164 |
--let $expect_truncation_warning = 0 |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
if ($max != '') { |
| 169 |
--echo # Maximum value |
| 170 |
eval SET @@$scope.$name = $max; |
| 171 |
--source assertions_for_sysvar_warnings.inc |
| 172 |
--let $expect_value = $max |
| 173 |
--source assertions_for_sysvar_and_alias_value.inc |
| 174 |
|
| 175 |
--let $assert_text = Expected max value should equal max value in performance_schema |
| 176 |
--let $assert_cond = [SELECT MAX_VALUE FROM performance_schema.variables_info WHERE VARIABLE_NAME = '$name'] = $max |
| 177 |
--source include/assert.inc |
| 178 |
|
| 179 |
--let $maxint64 = 18446744073709551615 |
| 180 |
--let $xmaxint64 = x$maxint64 |
| 181 |
--let $xmax = x$max |
| 182 |
if ($xmax != $xmaxint64) { |
| 183 |
--echo # Greater-than-maximum values |
| 184 |
|
| 185 |
--let $expect_truncation_warning = 1 |
| 186 |
|
| 187 |
--let $max_plus_1 = `SELECT $max + 1` |
| 188 |
eval SET @@$scope.$name = $max_plus_1; |
| 189 |
--source assertions_for_sysvar_warnings.inc |
| 190 |
--let $expect_value = $max |
| 191 |
--source assertions_for_sysvar_and_alias_value.inc |
| 192 |
|
| 193 |
if ($block_size != 1) { |
| 194 |
--let $value = `SELECT IF($max <= $maxint64 - $block_size, $max + $block_size, $maxint64)` |
| 195 |
eval SET @@$scope.$name = $value; |
| 196 |
--source assertions_for_sysvar_warnings.inc |
| 197 |
--let $expect_value = $max |
| 198 |
--source assertions_for_sysvar_and_alias_value.inc |
| 199 |
} |
| 200 |
|
| 201 |
--let $expect_truncation_warning = 0 |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
if ($block_size != 1) { |
| 206 |
--let $expect_truncation_warning = 1 |
| 207 |
|
| 208 |
--echo # Non-block-size value |
| 209 |
--let $value = `SELECT $default + $block_size - 1` |
| 210 |
eval SET @@$scope.$name = $value; |
| 211 |
--source assertions_for_sysvar_warnings.inc |
| 212 |
--let $expect_value = $default |
| 213 |
--source assertions_for_sysvar_and_alias_value.inc |
| 214 |
|
| 215 |
--let $expect_truncation_warning = 0 |
| 216 |
} |
| 217 |
|
| 218 |
--echo # Invalid values |
| 219 |
--let $json_array = $invalid |
| 220 |
--source $json_invalid_start |
| 221 |
while (!$json_invalid_done) { |
| 222 |
--error ER_WRONG_TYPE_FOR_VAR, ER_WRONG_VALUE_FOR_VAR |
| 223 |
eval SET @@$scope.$name = $json_invalid_value; |
| 224 |
|
| 225 |
--source $json_invalid_next |
| 226 |
} |
| 227 |
|
| 228 |
--echo # Restore default |
| 229 |
--let $mask_value = $_cds_mask_value_save |
| 230 |
|
| 231 |
eval SET @@$scope.$name = DEFAULT; |
| 232 |
--source assertions_for_sysvar_warnings.inc |
| 233 |
--let $expect_value = $default |
| 234 |
--source assertions_for_sysvar_and_alias_value.inc |