From: Josef Weidendorfer Date: Sun, 2 Apr 2006 22:23:27 +0000 (+0000) Subject: Callgrind: add 4 regression tests X-Git-Tag: svn/VALGRIND_3_2_0~143 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efa0f1d7bda5da5c2db4d0bfc1d491ca820c00f4;p=thirdparty%2Fvalgrind.git Callgrind: add 4 regression tests 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 --- diff --git a/callgrind/main.c b/callgrind/main.c index d2e208d105..c031f1f9b0 100644 --- a/callgrind/main.c +++ b/callgrind/main.c @@ -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'."); } diff --git a/callgrind/tests/Makefile.am b/callgrind/tests/Makefile.am index ce7337c0eb..85a487fca3 100644 --- a/callgrind/tests/Makefile.am +++ b/callgrind/tests/Makefile.am @@ -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 diff --git a/callgrind/tests/clreq.stderr.exp b/callgrind/tests/clreq.stderr.exp index e69de29bb2..d0b7820ae3 100644 --- a/callgrind/tests/clreq.stderr.exp +++ b/callgrind/tests/clreq.stderr.exp @@ -0,0 +1,6 @@ + + +Events : Ir +Collected : + +I refs: diff --git a/callgrind/tests/clreq.vgtest b/callgrind/tests/clreq.vgtest index 2ec453a9d5..397437197e 100644 --- a/callgrind/tests/clreq.vgtest +++ b/callgrind/tests/clreq.vgtest @@ -1,3 +1,3 @@ prog: clreq -vgopts: -q +vgopts: cleanup: rm callgrind.out.* diff --git a/callgrind/tests/filter_stderr b/callgrind/tests/filter_stderr index 6e6000c1c4..7b69674f50 100755 --- a/callgrind/tests/filter_stderr +++ b/callgrind/tests/filter_stderr @@ -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 index 0000000000..02197fc415 --- /dev/null +++ b/callgrind/tests/simwork.c @@ -0,0 +1,66 @@ +// Some work exercising the cache simulator +// with a simple call graph + +#include "../callgrind.h" + +#include +#include + +#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 index 0000000000..0705c1c849 --- /dev/null +++ b/callgrind/tests/simwork1.stderr.exp @@ -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 index 0000000000..d4c867cc82 --- /dev/null +++ b/callgrind/tests/simwork1.stdout.exp @@ -0,0 +1 @@ +Sum: 1000000 diff --git a/callgrind/tests/simwork1.vgtest b/callgrind/tests/simwork1.vgtest new file mode 100644 index 0000000000..2add1bb63c --- /dev/null +++ b/callgrind/tests/simwork1.vgtest @@ -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 index 0000000000..90da3e4cec --- /dev/null +++ b/callgrind/tests/simwork2.stderr.exp @@ -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 index 0000000000..d4c867cc82 --- /dev/null +++ b/callgrind/tests/simwork2.stdout.exp @@ -0,0 +1 @@ +Sum: 1000000 diff --git a/callgrind/tests/simwork2.vgtest b/callgrind/tests/simwork2.vgtest new file mode 100644 index 0000000000..47a5146ad5 --- /dev/null +++ b/callgrind/tests/simwork2.vgtest @@ -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 index 0000000000..ea9acc89b5 --- /dev/null +++ b/callgrind/tests/simwork3.stderr.exp @@ -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 index 0000000000..d4c867cc82 --- /dev/null +++ b/callgrind/tests/simwork3.stdout.exp @@ -0,0 +1 @@ +Sum: 1000000 diff --git a/callgrind/tests/simwork3.vgtest b/callgrind/tests/simwork3.vgtest new file mode 100644 index 0000000000..a51a67f9ba --- /dev/null +++ b/callgrind/tests/simwork3.vgtest @@ -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 index 0000000000..b38c0a3e60 --- /dev/null +++ b/callgrind/tests/threads.c @@ -0,0 +1,47 @@ +/* A simple example with 4 threads */ + +#include +#include + +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 index 0000000000..d0b7820ae3 --- /dev/null +++ b/callgrind/tests/threads.stderr.exp @@ -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 index 0000000000..d015eebb5e --- /dev/null +++ b/callgrind/tests/threads.vgtest @@ -0,0 +1,3 @@ +prog: threads +vgopts: --separate-threads=yes +cleanup: rm callgrind.out.*