Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / dhat / tests / copy.c
blob18479d782b39090434dceed82844afe720402c3d
1 // This tests --mode=copy with various copying functions.
3 #define _GNU_SOURCE // For mempcpy.
4 #include <stdlib.h>
5 #include <string.h>
6 #include <wchar.h>
7 #include <strings.h>
8 #include "../../config.h"
10 void f(char* a, char* b, wchar_t* wa, wchar_t* wb);
11 void test_malloc();
13 int main(void) {
14 char a[1000];
15 char b[1000];
16 for (int i = 0; i < 1000; i++) {
17 a[i] = 'a';
18 b[i] = 'b';
20 a[999] = '\0';
21 b[999] = '\0';
23 wchar_t wa[250];
24 wchar_t wb[250];
25 for (int i = 0; i < 250; i++) {
26 wa[i] = L'A';
27 wb[i] = L'B';
29 wa[249] = L'\0';
30 wb[249] = L'\0';
32 for (int i = 0; i < 100; i++) {
33 f(a, b, wa, wb);
36 test_malloc();
37 return 0;
40 void f(char* a, char* b, wchar_t* wa, wchar_t* wb) {
41 // The memcpy is duplicated so we have 10 calls, which makes for nice round
42 // numbers in the totals.
43 memcpy (a, b, 1000); // Redirects to memmove
44 memcpy (a, b, 1000); // Redirects to memmove
45 memmove(a, b, 1000);
46 #if defined(HAVE_MEMPCPY)
47 mempcpy(a, b, 1000);
48 #else
49 memcpy(a, b, 1000);
50 #endif
51 bcopy (a, b, 1000); // Redirects to memmove
52 strcpy (a, b);
53 strncpy(a, b, 1000);
54 stpcpy (a, b); // Redirects to strcpy
55 stpncpy(a, b, 1000);
56 wcscpy (wa, wb);
59 void test_malloc() {
60 // At one point malloc was broken with --mode=copy(!), and Valgrind was
61 // printing messages like "VG_USERREQ__CLIENT_CALL1: func=0x0" when malloc
62 // was called. So check that it's basically working...
63 char* p = malloc(100);
64 p = realloc(p, 200);
65 free(p);