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