]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Callgrind: add 4 regression tests
authorJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Sun, 2 Apr 2006 22:23:27 +0000 (22:23 +0000)
committerJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Sun, 2 Apr 2006 22:23:27 +0000 (22:23 +0000)
The simwork tests check different cache simulator
options/modes. These tests should be extended to
check for the produced call graph.

The threads check tests the callgrind mode where
counts are aggregated separate per thread.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5816

18 files changed:
callgrind/main.c
callgrind/tests/Makefile.am
callgrind/tests/clreq.stderr.exp
callgrind/tests/clreq.vgtest
callgrind/tests/filter_stderr
callgrind/tests/simwork.c [new file with mode: 0644]
callgrind/tests/simwork1.stderr.exp [new file with mode: 0644]
callgrind/tests/simwork1.stdout.exp [new file with mode: 0644]
callgrind/tests/simwork1.vgtest [new file with mode: 0644]
callgrind/tests/simwork2.stderr.exp [new file with mode: 0644]
callgrind/tests/simwork2.stdout.exp [new file with mode: 0644]
callgrind/tests/simwork2.vgtest [new file with mode: 0644]
callgrind/tests/simwork3.stderr.exp [new file with mode: 0644]
callgrind/tests/simwork3.stdout.exp [new file with mode: 0644]
callgrind/tests/simwork3.vgtest [new file with mode: 0644]
callgrind/tests/threads.c [new file with mode: 0644]
callgrind/tests/threads.stderr.exp [new file with mode: 0644]
callgrind/tests/threads.vgtest [new file with mode: 0644]

index d2e208d105e9abd14bc4da188dcf8782b269815b..c031f1f9b0532c32b3f8d5e31a3563c81c812110 100644 (file)
@@ -1046,7 +1046,6 @@ void CLG_(post_clo_init)(void)
    CLG_(instrument_state) = CLG_(clo).instrument_atstart;
 
    if (VG_(clo_verbosity > 0)) {
-      VG_(message)(Vg_UserMsg, "");
       VG_(message)(Vg_UserMsg,
                    "For interactive control, run 'callgrind_control -h'.");
    }
index ce7337c0eb8ffcb23080508a2b79d6b932a67323..85a487fca3f57d648dd31bcc025289febef47fd9 100644 (file)
@@ -6,11 +6,15 @@ DIST_SUBDIRS = .
 
 noinst_SCRIPTS = filter_stderr
 
-EXTRA_DIST = clreq.vgtest clreq.stderr.exp 
+EXTRA_DIST = clreq.vgtest clreq.stderr.exp \
+             simwork1.vgtest simwork1.stdout.exp simwork1.stderr.exp \
+             simwork2.vgtest simwork2.stdout.exp simwork2.stderr.exp \
+             simwork3.vgtest simwork3.stdout.exp simwork3.stderr.exp \
+             threads.vgtest threads.stderr.exp
 
-check_PROGRAMS = clreq
+check_PROGRAMS = clreq simwork threads
 
 AM_CPPFLAGS = -I$(top_srcdir)/include
 AM_CFLAGS   = $(WERROR) -Winline -Wall -Wshadow -g $(AM_FLAG_M3264_PRI)
 
-
+threads_LDADD = -lpthread
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..d0b7820ae3a6bb73ff444c43c5e7985e130a8b02 100644 (file)
@@ -0,0 +1,6 @@
+
+
+Events    : Ir
+Collected :
+
+I   refs:
index 2ec453a9d5cb9361f44e64377ec2fe3ad448bbcf..397437197e8cd1fa71c82271a7e04145decd9a16 100644 (file)
@@ -1,3 +1,3 @@
 prog: clreq
-vgopts: -q
+vgopts:
 cleanup: rm callgrind.out.*
index 6e6000c1c4711a11aa88a64eed5c8f436b71ab07..7b69674f50c758f13538b3ae4def6c29ad7f62f9 100755 (executable)
@@ -7,6 +7,12 @@ $dir/../../tests/filter_stderr_basic                |
 # Remove "Callgrind, ..." line and the following copyright line.
 sed "/^Callgrind, a call-graph generating cache profiler./ , /./ d" |
 
+# Remove pointer to callgrind_control
+sed "/^For interactive control,.*$/d" |
+
+# Remove numbers from "Collected" line
+sed "s/^\(Collected *:\)[ 0-9]*$/\1/" |
+
 # Remove numbers from I/D/L2 "refs:" lines
 sed "s/\(\(I\|D\|L2\) *refs:\)[ 0-9,()+rdw]*$/\1/"  |
 
diff --git a/callgrind/tests/simwork.c b/callgrind/tests/simwork.c
new file mode 100644 (file)
index 0000000..02197fc
--- /dev/null
@@ -0,0 +1,66 @@
+// Some work exercising the cache simulator
+// with a simple call graph
+
+#include "../callgrind.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#define SIZE 100000
+
+double *a, *b, *c;
+
+void init()
+{
+   int i;
+   for(i = 0; i< SIZE; i++) a[i] = b[i] = 1.0;
+}
+
+void do_add()
+{
+   int i;
+   for(i = 0; i< SIZE; i++) {
+       a[i] += 1.0;
+       c[i] = a[i] + b[i];
+   }
+}
+
+double do_sum()
+{
+   int i;
+   double sum=0.0;
+
+   do_add();
+   for(i = 0; i< SIZE; i++) sum += c[i];
+
+   return sum;
+}
+
+double do_some_work(int iter)
+{
+   double sum=0.0;
+
+   if (iter > 0) sum += do_some_work(iter-1);
+   do_add();
+   sum += do_sum();
+
+   return sum;
+}
+
+int main(void)
+{
+   double res;
+
+   a = (double*) malloc(SIZE * sizeof(double));
+   b = (double*) malloc(SIZE * sizeof(double));
+   c = (double*) malloc(SIZE * sizeof(double));
+
+   CALLGRIND_ZERO_STATS;
+   init();
+   res = do_some_work(1);
+   CALLGRIND_DUMP_STATS;
+
+   printf("Sum: %.0f\n", res);
+   return RUNNING_ON_VALGRIND;
+}
+
diff --git a/callgrind/tests/simwork1.stderr.exp b/callgrind/tests/simwork1.stderr.exp
new file mode 100644 (file)
index 0000000..0705c1c
--- /dev/null
@@ -0,0 +1,20 @@
+
+
+Events    : Ir Dr Dw I1mr D1mr D1mw I2mr D2mr D2mw
+Collected :
+
+I   refs:
+I1  misses:
+L2i misses:
+I1  miss rate:
+L2i miss rate:
+
+D   refs:
+D1  misses:
+L2d misses:
+D1  miss rate:
+L2d miss rate:
+
+L2 refs:
+L2 misses:
+L2 miss rate:
diff --git a/callgrind/tests/simwork1.stdout.exp b/callgrind/tests/simwork1.stdout.exp
new file mode 100644 (file)
index 0000000..d4c867c
--- /dev/null
@@ -0,0 +1 @@
+Sum: 1000000
diff --git a/callgrind/tests/simwork1.vgtest b/callgrind/tests/simwork1.vgtest
new file mode 100644 (file)
index 0000000..2add1bb
--- /dev/null
@@ -0,0 +1,3 @@
+prog: simwork
+vgopts: --simulate-hwpref=yes
+cleanup: rm callgrind.out.*
diff --git a/callgrind/tests/simwork2.stderr.exp b/callgrind/tests/simwork2.stderr.exp
new file mode 100644 (file)
index 0000000..90da3e4
--- /dev/null
@@ -0,0 +1,20 @@
+
+
+Events    : Ir Dr Dw I1mr D1mr D1mw I2mr D2mr D2mw I2dmr D2dmr D2dmw
+Collected :
+
+I   refs:
+I1  misses:
+L2i misses:
+I1  miss rate:
+L2i miss rate:
+
+D   refs:
+D1  misses:
+L2d misses:
+D1  miss rate:
+L2d miss rate:
+
+L2 refs:
+L2 misses:
+L2 miss rate:
diff --git a/callgrind/tests/simwork2.stdout.exp b/callgrind/tests/simwork2.stdout.exp
new file mode 100644 (file)
index 0000000..d4c867c
--- /dev/null
@@ -0,0 +1 @@
+Sum: 1000000
diff --git a/callgrind/tests/simwork2.vgtest b/callgrind/tests/simwork2.vgtest
new file mode 100644 (file)
index 0000000..47a5146
--- /dev/null
@@ -0,0 +1,3 @@
+prog: simwork
+vgopts: --simulate-wb=yes --simulate-hwpref=yes
+cleanup: rm callgrind.out.*
diff --git a/callgrind/tests/simwork3.stderr.exp b/callgrind/tests/simwork3.stderr.exp
new file mode 100644 (file)
index 0000000..ea9acc8
--- /dev/null
@@ -0,0 +1,20 @@
+
+
+Events    : Ir Dr Dw I1mr D1mr D1mw I2mr D2mr D2mw AcCost1 SpLoss1 AcCost2 SpLoss2
+Collected :
+
+I   refs:
+I1  misses:
+L2i misses:
+I1  miss rate:
+L2i miss rate:
+
+D   refs:
+D1  misses:
+L2d misses:
+D1  miss rate:
+L2d miss rate:
+
+L2 refs:
+L2 misses:
+L2 miss rate:
diff --git a/callgrind/tests/simwork3.stdout.exp b/callgrind/tests/simwork3.stdout.exp
new file mode 100644 (file)
index 0000000..d4c867c
--- /dev/null
@@ -0,0 +1 @@
+Sum: 1000000
diff --git a/callgrind/tests/simwork3.vgtest b/callgrind/tests/simwork3.vgtest
new file mode 100644 (file)
index 0000000..a51a67f
--- /dev/null
@@ -0,0 +1,3 @@
+prog: simwork
+vgopts: --cacheuse=yes
+cleanup: rm callgrind.out.*
diff --git a/callgrind/tests/threads.c b/callgrind/tests/threads.c
new file mode 100644 (file)
index 0000000..b38c0a3
--- /dev/null
@@ -0,0 +1,47 @@
+/* A simple example with 4 threads */
+
+#include <pthread.h>
+#include <unistd.h>
+
+double a[1000];
+
+static void init()
+{
+       int i;
+       for(i=0;i<1000;i++) a[i] = (double)i;
+}
+
+static void *th(void *v)
+{
+       double sum = 0.0;
+       int i,j;
+
+       for(j=0;j<1000;j++)
+               for(i=0;i<1000;i++)
+                       sum += a[i];
+
+       *( (double*)v ) = sum;
+
+       /* make sure that no threads is so fast that it finishes
+         * before last thread is created, thus reusing the TID */
+       sleep(1);
+
+       return 0;
+}
+
+int main()
+{
+       pthread_t t[4];
+       double sum[4];
+       int i;
+
+       init();
+
+       for(i=0;i<4;i++)
+               pthread_create(&t[i], NULL, th, &sum[i]);       
+
+       for(i=0;i<4;i++)
+               pthread_join(t[i], NULL);
+
+       return 0;
+}
diff --git a/callgrind/tests/threads.stderr.exp b/callgrind/tests/threads.stderr.exp
new file mode 100644 (file)
index 0000000..d0b7820
--- /dev/null
@@ -0,0 +1,6 @@
+
+
+Events    : Ir
+Collected :
+
+I   refs:
diff --git a/callgrind/tests/threads.vgtest b/callgrind/tests/threads.vgtest
new file mode 100644 (file)
index 0000000..d015eeb
--- /dev/null
@@ -0,0 +1,3 @@
+prog: threads
+vgopts: --separate-threads=yes
+cleanup: rm callgrind.out.*