diff options
author | dsmith <dsmith> | 2006-11-06 19:08:43 +0000 |
---|---|---|
committer | dsmith <dsmith> | 2006-11-06 19:08:43 +0000 |
commit | 2c2b1e9a5eda8415e687350dc35cfb5d8b647c08 (patch) | |
tree | 9c996ef8b9a56d43a5cd72759c5aa40ec76a31d3 /testsuite | |
parent | 3a02f9bf9b9ccf502aa51b80f18be556b493a579 (diff) | |
download | systemtap-steved-2c2b1e9a5eda8415e687350dc35cfb5d8b647c08.tar.gz systemtap-steved-2c2b1e9a5eda8415e687350dc35cfb5d8b647c08.tar.xz systemtap-steved-2c2b1e9a5eda8415e687350dc35cfb5d8b647c08.zip |
2006-11-06 David Smith <dsmith@redhat.com>
* systemtap.maps/foreach_limit.exp: Added new test for foreach
"limit" keyword.
* systemtap.maps/foreach_limit.stp: Ditto.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | testsuite/systemtap.maps/foreach_limit.exp | 83 | ||||
-rw-r--r-- | testsuite/systemtap.maps/foreach_limit.stp | 135 |
3 files changed, 222 insertions, 0 deletions
diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 5ebaec26..ac5c98cb 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2006-11-06 David Smith <dsmith@redhat.com> + * systemtap.maps/foreach_limit.exp: Added new test for foreach + "limit" keyword. + * systemtap.maps/foreach_limit.stp: Ditto. + * parseko/foreachstmt06.stp: Added new test for foreach "limit" keyword. * parseko/foreachstmt07.stp: Ditto. diff --git a/testsuite/systemtap.maps/foreach_limit.exp b/testsuite/systemtap.maps/foreach_limit.exp new file mode 100644 index 00000000..1d98a874 --- /dev/null +++ b/testsuite/systemtap.maps/foreach_limit.exp @@ -0,0 +1,83 @@ +# Test of foreach statements using "limit EXP". + +load_lib "stap_run2.exp" + +set test "foreach_limit" + +set ::result_string {Arrays: +unsorted: +key 9, value 18 +key 1, value 2 +key 8, value 16 +key 2, value 4 +key 7, value 14 +key 3, value 6 +key 6, value 12 +key 5, value 10 +key 4, value 8 +key 10, value 20 + +unsorted limit 5: +key 9, value 18 +key 1, value 2 +key 8, value 16 +key 2, value 4 +key 7, value 14 +loop had 5 iterations + +sorted limit 5: +key 1, value 2 +key 2, value 4 +key 3, value 6 +key 4, value 8 +key 5, value 10 +loop had 5 iterations + +sorted limit x (3): +key 1, value 2 +key 2, value 4 +key 3, value 6 +loop had 3 iterations + +sorted limit x * 2 (6): +key 1, value 2 +key 2, value 4 +key 3, value 6 +key 4, value 8 +key 5, value 10 +key 6, value 12 +loop had 6 iterations + +sorted limit ++x: +key 1, value 2 +key 2, value 4 +key 3, value 6 +key 4, value 8 +loop had 4 iterations +x ended up as 4 + +sorted limit x++: +key 1, value 2 +key 2, value 4 +key 3, value 6 +key 4, value 8 +loop had 4 iterations +x ended up as 5 + +Aggregates: +64 total aggregate entries + +aggregate limit 5: +bucket 0: 0 +bucket 1: 0 +bucket 2: 1 +bucket 3: 4 +bucket 4: 11 +loop had 5 iterations + +Done. +} + +stap_run2 $srcdir/$subdir/$test.stp + + diff --git a/testsuite/systemtap.maps/foreach_limit.stp b/testsuite/systemtap.maps/foreach_limit.stp new file mode 100644 index 00000000..e2957678 --- /dev/null +++ b/testsuite/systemtap.maps/foreach_limit.stp @@ -0,0 +1,135 @@ +global array, agg + +probe begin +{ + # + # Array section + # + printf("\nArrays:\n"); + + # Add elements to the array, but in an unsorted order + array[9] = 18; + array[1] = 2 + array[8] = 16 + array[2] = 4 + array[7] = 14 + array[3] = 6 + array[6] = 12; + array[5] = 10; + array[4] = 8; + array[10] = 20; + + # Print the unsorted array + printf("unsorted:\n"); + foreach (key in array) + printf("key %d, value %d\n", key, array[key]); + + # Print the first 5 unsorted array items + printf("\nunsorted limit 5:\n"); + i = 0 + foreach (key in array limit 5) + { + printf("key %d, value %d\n", key, array[key]); + i++; + } + printf("loop had %d iterations\n", i); + + # Print the first 5 sorted array items + printf("\nsorted limit 5:\n"); + i = 0 + foreach (key in array+ limit 5) + { + printf("key %d, value %d\n", key, array[key]); + i++; + } + printf("loop had %d iterations\n", i); + + # Use a variable reference to limit the loop iteration + x = 3 + printf("\nsorted limit x (%d):\n", x); + i = 0 + foreach (key in array+ limit x) + { + printf("key %d, value %d\n", key, array[key]) + i++; + } + printf("loop had %d iterations\n", i); + + # Use a expression containing a variable reference to limit the + # loop iteration + printf("\nsorted limit x * 2 (%d):\n", (x * 2)); + i = 0 + foreach (key in array+ limit x * 2) + { + printf("key %d, value %d\n", key, array[key]) + i++; + } + printf("loop had %d iterations\n", i); + + # Ensure the expression is only evaluated once + printf("\nsorted limit ++x:\n"); + i = 0 + foreach (key in array+ limit ++x) + { + printf("key %d, value %d\n", key, array[key]) + i++; + } + printf("loop had %d iterations\n", i); + printf("x ended up as %d\n", x); + + # Ensure the expression is only evaluated once + printf("\nsorted limit x++:\n"); + i = 0 + foreach (key in array+ limit x++) + { + printf("key %d, value %d\n", key, array[key]) + i++; + } + printf("loop had %d iterations\n", i); + printf("x ended up as %d\n", x); + + # + # Aggregate section + # + printf("\nAggregates:\n"); + + # Add items to the aggregate + foreach (key in array) + { + agg <<< array[key] + agg <<< array[key] * 2 + agg <<< array[key] * 3 + agg <<< array[key] * 4 + agg <<< array[key] * 5 + agg <<< array[key] * 6 + agg <<< array[key] * 7 + agg <<< array[key] * 8 + agg <<< array[key] * 9 + agg <<< array[key] * 10 + agg <<< array[key] * 11 + agg <<< array[key] * 12 + agg <<< array[key] * 12 + agg <<< array[key] * 13 + agg <<< array[key] * 14 + agg <<< array[key] * 15 + } + + # Find the total number of aggregate entries + i = 0 + foreach (bucket in @hist_log(agg)) + i++; + printf("%d total aggregate entries\n", i); + + # Print the 1st 5 aggregate entries + printf("\naggregate limit 5:\n"); + i = 0 + foreach (bucket in @hist_log(agg) limit 5) + { + printf("bucket %d: %d\n", bucket, @hist_log(agg)[bucket]); + i++; + } + printf("loop had %d iterations\n", i); + + printf("\nDone.\n"); + exit() +} |