diff options
-rw-r--r-- | tapset/random.stp | 18 | ||||
-rw-r--r-- | testsuite/systemtap.base/rand.exp | 3 | ||||
-rw-r--r-- | testsuite/systemtap.base/rand.stp | 41 |
3 files changed, 62 insertions, 0 deletions
diff --git a/tapset/random.stp b/tapset/random.stp new file mode 100644 index 00000000..e0a89d19 --- /dev/null +++ b/tapset/random.stp @@ -0,0 +1,18 @@ +/** @addtogroup library +* The library tapset is a collection of standard functions. +* @{ +*/ + +function randint:long(min:long, max:long) +%{ + + unsigned long difference = (unsigned long)(THIS->max - THIS->min); + + if ( THIS->min >= THIS->max || (THIS->max -THIS->min) > (1024*1024) ){ + CONTEXT->last_error = "either first argument was not strictly less than the second argument, or their difference was greater than (1024*1024)"; + } + THIS->__retvalue = THIS->min + ( _stp_random_pm_u(2147483646) % (difference + 1) ); + +%} + +/** @} */ diff --git a/testsuite/systemtap.base/rand.exp b/testsuite/systemtap.base/rand.exp new file mode 100644 index 00000000..9b372e18 --- /dev/null +++ b/testsuite/systemtap.base/rand.exp @@ -0,0 +1,3 @@ +set test "rand" +set ::result_string {PASS} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.base/rand.stp b/testsuite/systemtap.base/rand.stp new file mode 100644 index 00000000..aca80877 --- /dev/null +++ b/testsuite/systemtap.base/rand.stp @@ -0,0 +1,41 @@ +function checkStatus(status:long){ + if (status == 1){ + printf("%s\n","FAIL") + }else{ + printf("%s\n","PASS") + } +} + +probe begin +{ + + for (i = 0; i < 100; i ++) { + num = randint(-5, 5) + if (num > 5) { + printf("NUMBER TOO HIGH\n") + } + if (num < -5) { + printf("NUMBER TOO LOW\n") + } + } + + for (i = 0; i < 500; i ++) { + num = randint(-3, 3) + if (num > 3) { + printf("NUMBER TOO HIGH\n") + } + if (num < -3) { + printf("NUMBER TOO LOW\n") + } + } + + status = 0 + for (i=1; i <= 100; i++){ + if ( randint(-1*i,i) < (-1*i) || randint(-1*i,i) > i ){ + status = 1 + } + } + checkStatus(status) + + exit() +} |