summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2005-09-09 09:08:26 +0000
committerhunt <hunt>2005-09-09 09:08:26 +0000
commit60a1b0ceedecf422af6b043186092986685efb59 (patch)
tree6cacf4a3815465e55b60755297dbcb477cd44c3b
parent41f7eadf3e5e6b42ecd54c53adab112253122e34 (diff)
downloadsystemtap-steved-60a1b0ceedecf422af6b043186092986685efb59.tar.gz
systemtap-steved-60a1b0ceedecf422af6b043186092986685efb59.tar.xz
systemtap-steved-60a1b0ceedecf422af6b043186092986685efb59.zip
2005-09-09 Martin Hunt <hunt@redhat.com>
* README: Update. * math/div64.c: New file. 64-bit division tests.
-rw-r--r--runtime/tests/ChangeLog5
-rw-r--r--runtime/tests/README7
-rw-r--r--runtime/tests/math/Makefile5
-rw-r--r--runtime/tests/math/all.tcl4
-rw-r--r--runtime/tests/math/div64.c169
-rw-r--r--runtime/tests/math/math.test19
6 files changed, 208 insertions, 1 deletions
diff --git a/runtime/tests/ChangeLog b/runtime/tests/ChangeLog
new file mode 100644
index 00000000..709a1906
--- /dev/null
+++ b/runtime/tests/ChangeLog
@@ -0,0 +1,5 @@
+2005-09-09 Martin Hunt <hunt@redhat.com>
+
+ * README: Update.
+ * math/div64.c: New file. 64-bit division tests.
+
diff --git a/runtime/tests/README b/runtime/tests/README
index b38eb212..000f1017 100644
--- a/runtime/tests/README
+++ b/runtime/tests/README
@@ -1,2 +1,7 @@
This directory contains the user-levels tests.
-To run, just type "make".
+
+Before running these for the first time,
+> cd ../user
+> ./recreate_links
+
+To run the test here, just type "make".
diff --git a/runtime/tests/math/Makefile b/runtime/tests/math/Makefile
new file mode 100644
index 00000000..c396c132
--- /dev/null
+++ b/runtime/tests/math/Makefile
@@ -0,0 +1,5 @@
+default: tests
+
+tests:
+ tclsh all.tcl
+
diff --git a/runtime/tests/math/all.tcl b/runtime/tests/math/all.tcl
new file mode 100644
index 00000000..23757202
--- /dev/null
+++ b/runtime/tests/math/all.tcl
@@ -0,0 +1,4 @@
+package require tcltest
+namespace import -force tcltest::*
+tcltest::testsDirectory [file dir [info script]]
+tcltest::runAllTests
diff --git a/runtime/tests/math/div64.c b/runtime/tests/math/div64.c
new file mode 100644
index 00000000..ce637a92
--- /dev/null
+++ b/runtime/tests/math/div64.c
@@ -0,0 +1,169 @@
+/* test of 64-bit division */
+#include "runtime.h"
+#define LLONG_MAX 9223372036854775807LL
+#define LLONG_MIN (-LLONG_MAX - 1LL)
+
+/* This tests a lot of edge conditions.*/
+/* Then it does 10 million random divisions, comparing the result */
+/* with the results from glibc */
+
+int main()
+{
+ int64_t x, y, div1, mod1, div2, mod2;
+ const char *error;
+ int i;
+
+ x = 0;
+ y = 0;
+ div1 = _stp_div64(&error, x, y);
+ if (div1 != 0 || *error != 'd') {
+ printf("Failed 0/0 test\n");
+ exit(-1);
+ }
+ error = "";
+
+ mod1 = _stp_mod64(&error, x, y);
+ if (mod1 != 0 || *error != 'd') {
+ printf("Failed 0%0 test\n");
+ exit(-1);
+ }
+ error = "";
+
+ x = 1;
+ y = 0;
+ div1 = _stp_div64(&error, x, y);
+ if (div1 != 0 || *error != 'd') {
+ printf("Failed 1/0 test\n");
+ exit(-1);
+ }
+ error = "";
+
+ mod1 = _stp_mod64(&error, x, y);
+ if (mod1 != 0 || *error != 'd') {
+ printf("Failed 1%0 test\n");
+ exit(-1);
+ }
+ error = "";
+
+ x = 0;
+ y = 1;
+
+ div1 = _stp_div64(&error, x, y);
+ if (*error || div1 != 0) {
+ printf("Failed 0/1 test\n");
+ exit(-1);
+ }
+
+ mod1 = _stp_mod64(&error, x, y);
+ if (*error || mod1 != 0) {
+ printf("Failed 0%1 test\n");
+ exit(-1);
+ }
+
+ x = -1;
+ y = -1;
+
+ div1 = _stp_div64(&error, x, y);
+ if (*error || div1 != 1) {
+ printf("Failed -1/-1 test\n");
+ exit(-1);
+ }
+
+ mod1 = _stp_mod64(&error, x, y);
+ if (*error || mod1 != 0) {
+ printf("Failed -1%-1 test\n");
+ exit(-1);
+ }
+
+
+ for (y = -1; y < 2; y++) {
+ if (y == 0)
+ continue;
+
+ for (x = LONG_MIN - 1LL; x < LONG_MIN + 2LL; x++ ) {
+ div1 = _stp_div64(&error, x, y);
+ mod1 = _stp_mod64(&error, x, y);
+ div2 = x/y;
+ mod2 = x%y;
+ if (div1 != div2) {
+ printf ("%lld/%lld was %lld and should have been %lld\n", x,y,div1,div2);
+ exit (-1);
+ }
+ if (mod1 != mod2) {
+ printf ("%lld\%%lld was %lld and should have been %lld\n", x,y,mod1,mod2);
+ exit (-1);
+ }
+ }
+
+ for (x = LONG_MAX - 1LL; x < LONG_MAX + 2LL; x++ ) {
+ div1 = _stp_div64(&error, x, y);
+ mod1 = _stp_mod64(&error, x, y);
+ div2 = x/y;
+ mod2 = x%y;
+ if (div1 != div2) {
+ printf ("%lld/%lld was %lld and should have been %lld\n", x,y,div1,div2);
+ exit (-1);
+ }
+ if (mod1 != mod2) {
+ printf ("%lld\%%lld was %lld and should have been %lld\n", x,y,mod1,mod2);
+ exit (-1);
+ }
+ }
+
+ for (x = LLONG_MIN; x <= LLONG_MIN + 1LL; x++ ) {
+ div1 = _stp_div64(&error, x, y);
+ mod1 = _stp_mod64(&error, x, y);
+ div2 = x/y;
+ mod2 = x%y;
+ if (div1 != div2) {
+ printf ("%lld/%lld was %lld and should have been %lld\n", x,y,div1,div2);
+ exit (-1);
+ }
+ if (mod1 != mod2) {
+ printf ("%lld\%%lld was %lld and should have been %lld\n", x,y,mod1,mod2);
+ exit (-1);
+ }
+ }
+
+ for (x = LONG_MAX - 1; x <= LONG_MAX; x++ ) {
+ div1 = _stp_div64(&error, x, y);
+ mod1 = _stp_mod64(&error, x, y);
+ div2 = x/y;
+ mod2 = x%y;
+ if (div1 != div2) {
+ printf ("%lld/%lld was %lld and should have been %lld\n", x,y,div1,div2);
+ exit (-1);
+ }
+ if (mod1 != mod2) {
+ printf ("%lld\%%lld was %lld and should have been %lld\n", x,y,mod1,mod2);
+ exit (-1);
+ }
+ }
+ }
+
+ /* now do ten million random divisions and mods */
+ for (i = 0; i < 10000000; i++) {
+ x = mrand48();
+ y = mrand48();
+ if (y == 0) {
+ i--;
+ continue;
+ }
+
+ div1 = _stp_div64(NULL, x, y);
+ mod1 = _stp_mod64(NULL, x, y);
+ div2 = x/y;
+ mod2 = x%y;
+
+ if (div1 != div2) {
+ printf ("%lld/%lld was %lld and should have been %lld\n", x,y,div1,div2);
+ exit (-1);
+ }
+ if (mod1 != mod2) {
+ printf ("%lld\%%lld was %lld and should have been %lld\n", x,y,mod1,mod2);
+ exit (-1);
+ }
+ }
+ printf("OK\n");
+ return 0;
+}
diff --git a/runtime/tests/math/math.test b/runtime/tests/math/math.test
new file mode 100644
index 00000000..e7c58ba0
--- /dev/null
+++ b/runtime/tests/math/math.test
@@ -0,0 +1,19 @@
+package require tcltest
+namespace import -force tcltest::*
+
+cd $tcltest::testsDirectory
+
+set CFLAGS "-Os"
+set KPATH "/lib/modules/[exec uname -r]/build/include"
+set MPATH "/lib/modules/[exec uname -r]/build/include/asm/mach-default"
+set PATH "../../user"
+
+test printf_A {Basic printf test} -setup {
+ exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test div64.c
+} -body {
+ exec ./test
+} -result {OK}
+
+exec rm test
+
+cleanupTests