File: memalign.c

package info (click to toggle)
njamd 0.9.3pre2-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,704 kB
  • ctags: 1,056
  • sloc: ansic: 9,367; sh: 7,921; makefile: 121; perl: 52
file content (77 lines) | stat: -rwxr-xr-x 1,577 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <config.h>

int posix_memalign (char **memptr, size_t alignment, size_t size);
char chk_buf[3*4096];

int main()
{
	int i;
	char *buf;
	memset(chk_buf, 1, sizeof(chk_buf));
	for(i = 2; i < 4100; i++)
	{
//		fprintf(stderr, "Testing %d bytes\n", i);
		buf = NULL;
		posix_memalign(&buf, NJ_INT_ALIGNMENT, i/2);
		memset(buf, 1, i/2);
		posix_memalign(&buf, 4, i);
		if(memcmp(buf, chk_buf, i/2))
		{
			fprintf(stderr, "Buf not realloced properly\n");
			return 1;
		}
		memset(buf, 1, i);
		posix_memalign(&buf, 8, i/2);
		if(memcmp(buf, chk_buf, i/2))
		{
			fprintf(stderr, "Buf not realloced properly\n");
			return 1;
		}
		memset(buf, 1, i/2);
		free(buf);

		buf = NULL;
		posix_memalign(&buf, 8, i/2);
		memset(buf, 1, i/2);
		posix_memalign(&buf, 4, i);
		if(memcmp(buf, chk_buf, i/2))
		{
			fprintf(stderr, "Buf not realloced properly\n");
			return 1;
		}
		memset(buf, 1, i);
		posix_memalign(&buf, NJ_INT_ALIGNMENT, i/2);
		if(memcmp(buf, chk_buf, i/2))
		{
			fprintf(stderr, "Buf not realloced properly\n");
			return 1;
		}
		memset(buf, 1, i/2);
		free(buf);
		
		buf = NULL;
		posix_memalign(&buf, 16, i/2);
		memset(buf, 1, i/2);
		posix_memalign(&buf, 4, i);
		if(memcmp(buf, chk_buf, i/2))
		{
			fprintf(stderr, "Buf not realloced properly\n");
			return 1;
		}
		memset(buf, 1, i);
		posix_memalign(&buf, 8, i/2);
		if(memcmp(buf, chk_buf, i/2))
		{
			fprintf(stderr, "Buf not realloced properly\n");
			return 1;
		}
		memset(buf, 1, i/2);
		free(buf);
		
	}
	return 0;
}
// vim:ts=4