Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / dhat / tests / acc.c
blobef6693e00ed3231949aeb4cfb886b1dfc49b9a05
1 // Testing accesses of blocks.
3 #include <stdint.h>
4 #include <stdlib.h>
5 #include <string.h>
7 void* m1(size_t n) { return malloc(n); }
9 void* m2(size_t n) { return malloc(n); }
11 int main(void)
13 // 0th char is written 0 times, 1st char is written once, etc.
14 char* a = malloc(32);
15 for (int i = 1; i < 32; i++) {
16 for (int j = 0; j < i; j++) {
17 a[i] = 0;
20 free(a);
22 // Repetition and gaps.
23 int* b = malloc(20);
24 b[0] = 1;
25 b[2] = b[0];
26 for (int i = 0; i < 10; i++) {
27 b[4] = 99;
29 free(b);
31 // 33 bytes, goes onto a second line in dh_view.
32 char* c = calloc(33, 1);
33 c[32] = 0;
34 free(c);
36 // 1024 bytes, accesses are shown.
37 char* d = malloc(1024);
38 for (int i = 0; i < 1024; i++) {
39 d[i] = d[1023 - i];
41 for (int i = 500; i < 600; i++) {
42 d[i] = 0;
44 free(d);
46 // 1025 bytes, accesses aren't shown.
47 char* e = calloc(1025, 1);
48 for (int i = 0; i < 1025; i++) {
49 e[i] += 1;
51 free(e);
53 // Lots of accesses, but fewer than the 0xffff max value.
54 int* f1 = m1(100);
55 int* f2 = m1(100);
56 for (int i = 0; i < 50000; i++) {
57 f1[0] = 0;
58 f2[0] = 0;
60 free(f1);
61 free(f2);
63 // Lots of accesses, more than the 0xffff max value: treated as Infinity.
64 int* g1 = m2(100);
65 int* g2 = m2(100);
66 for (int i = 0; i < 100000; i++) {
67 g1[0] = 0;
68 g2[0] = 0;
70 free(g1);
71 free(g2);
73 return 0;