| 1 |
global success |
| 2 |
|
| 3 |
probe module("memory1_module").function("stp_memory1_set_str") |
| 4 |
{ |
| 5 |
actualLength = $bytes |
| 6 |
if (actualLength <= 5 || actualLength >= 15) |
| 7 |
next |
| 8 |
|
| 9 |
string_copy = kernel_string($string); |
| 10 |
four = 4; |
| 11 |
five = 5; |
| 12 |
fifteen = 15; |
| 13 |
success = 1; |
| 14 |
|
| 15 |
expected_1_1 = sprintf ("%.1s", string_copy); |
| 16 |
testName = "%m default width and precision"; |
| 17 |
result = sprintf ("%m", $string); |
| 18 |
if (result != expected_1_1) { |
| 19 |
printf ("Test %s failed\n", testName); |
| 20 |
success = 0; |
| 21 |
} |
| 22 |
|
| 23 |
expected_5_5 = sprintf ("%.5s", string_copy); |
| 24 |
testName = "%m static precision smaller than input"; |
| 25 |
result = sprintf ("%.5m", $string); |
| 26 |
if (result != expected_5_5) { |
| 27 |
printf ("Test %s failed\n", testName); |
| 28 |
success = 0; |
| 29 |
} |
| 30 |
|
| 31 |
testName = "%m dynamic precision smaller than input"; |
| 32 |
result = sprintf ("%.*m", five, $string); |
| 33 |
if (result != expected_5_5) { |
| 34 |
printf ("Test %s failed\n", testName); |
| 35 |
success = 0; |
| 36 |
} |
| 37 |
|
| 38 |
testName = "%m dynamic precision equal to input"; |
| 39 |
expected_actual_actual = string_copy; |
| 40 |
result = sprintf ("%.*m", actualLength, $string); |
| 41 |
if (result != expected_actual_actual) { |
| 42 |
printf ("Test %s failed\n", testName); |
| 43 |
success = 0; |
| 44 |
} |
| 45 |
|
| 46 |
expected_5_1 = sprintf (" %.1s", string_copy); |
| 47 |
testName = "%m static width default precision"; |
| 48 |
result = sprintf ("%5m", $string); |
| 49 |
if (result != expected_5_1) { |
| 50 |
printf ("Test %s failed\n", testName); |
| 51 |
success = 0; |
| 52 |
} |
| 53 |
|
| 54 |
testName = "%m dynamic width default precision"; |
| 55 |
result = sprintf ("%*m", five, $string); |
| 56 |
if (result != expected_5_1) { |
| 57 |
printf ("Test %s failed\n", testName); |
| 58 |
success = 0; |
| 59 |
} |
| 60 |
|
| 61 |
expected_4_5 = expected_5_5; |
| 62 |
testName = "%m static width smaller than static precision"; |
| 63 |
result = sprintf ("%4.5m", $string); |
| 64 |
if (result != expected_4_5) { |
| 65 |
printf ("Test %s failed\n", testName); |
| 66 |
success = 0; |
| 67 |
} |
| 68 |
|
| 69 |
expected_15_5 = sprintf (" %.5s", string_copy); |
| 70 |
testName = "%m static width larger than static precision"; |
| 71 |
result = sprintf ("%15.5m", $string); |
| 72 |
if (result != expected_15_5) { |
| 73 |
printf ("Test %s failed\n", testName); |
| 74 |
success = 0; |
| 75 |
} |
| 76 |
|
| 77 |
testName = "%m dynamic width smaller than static precision"; |
| 78 |
result = sprintf ("%*.5m", four, $string); |
| 79 |
if (result != expected_4_5) { |
| 80 |
printf ("Test %s failed\n", testName); |
| 81 |
success = 0; |
| 82 |
} |
| 83 |
|
| 84 |
testName = "%m dynamic width larger than static precision"; |
| 85 |
result = sprintf ("%*.5m", fifteen, $string); |
| 86 |
if (result != expected_15_5) { |
| 87 |
printf ("Test %s failed\n", testName); |
| 88 |
success = 0; |
| 89 |
} |
| 90 |
|
| 91 |
expected_4_actual = expected_actual_actual; |
| 92 |
testName = "%m static width smaller than dynamic precision"; |
| 93 |
result = sprintf ("%4.*m", actualLength, $string); |
| 94 |
if (result != expected_4_actual) { |
| 95 |
printf ("Test %s failed\n", testName); |
| 96 |
success = 0; |
| 97 |
} |
| 98 |
|
| 99 |
expected_15_actual = sprintf ("%15s", string_copy); |
| 100 |
testName = "%m static width larger than dynamic precision"; |
| 101 |
result = sprintf ("%15.*m", actualLength, $string); |
| 102 |
if (result != expected_15_actual) { |
| 103 |
printf ("Test %s failed\n", testName); |
| 104 |
success = 0; |
| 105 |
} |
| 106 |
|
| 107 |
testName = "%m dynamic width smaller than dynamic precision"; |
| 108 |
result = sprintf ("%*.*m", four, actualLength, $string); |
| 109 |
if (result != expected_4_actual) { |
| 110 |
printf ("Test %s failed\n", testName); |
| 111 |
success = 0; |
| 112 |
} |
| 113 |
|
| 114 |
testName = "%m dynamic width larger than dynamic precision"; |
| 115 |
result = sprintf ("%*.*m", fifteen, actualLength, $string); |
| 116 |
if (result != expected_15_actual) { |
| 117 |
printf ("Test %s failed\n", testName); |
| 118 |
success = 0; |
| 119 |
} |
| 120 |
|
| 121 |
expected_16_actual = sprintf (" %02x%02x%02x%02x%02x%02x", |
| 122 |
stringat(string_copy, 0), |
| 123 |
stringat(string_copy, 1), |
| 124 |
stringat(string_copy, 2), |
| 125 |
stringat(string_copy, 3), |
| 126 |
stringat(string_copy, 4), |
| 127 |
stringat(string_copy, 5)); |
| 128 |
testName = "%M dynamic width larger than dynamic precision"; |
| 129 |
result = sprintf ("%*.*M", 14, 6, $string); |
| 130 |
if (result != expected_16_actual) { |
| 131 |
printf ("Test %s failed\n", testName); |
| 132 |
success = 0; |
| 133 |
} |
| 134 |
exit(); |
| 135 |
} |
| 136 |
|
| 137 |
probe timer.s(10) { |
| 138 |
// If the script runs this long, something has gone wrong |
| 139 |
println ("timeout") |
| 140 |
exit() |
| 141 |
} |
| 142 |
|
| 143 |
probe begin |
| 144 |
{ |
| 145 |
println("systemtap starting probe") |
| 146 |
} |
| 147 |
|
| 148 |
probe end |
| 149 |
{ |
| 150 |
println("systemtap ending probe") |
| 151 |
if (success) |
| 152 |
print ("Test passed\n"); |
| 153 |
} |