rtc: rtc-ab-b5ze-s3: add sub-minute alarm support
[linux/fpc-iii.git] / tools / testing / selftests / powerpc / stringloops / memcmp.c
blob17417dd707084766bfeaf1ccfaba684b3b3c8893
1 #include <malloc.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "../utils.h"
6 #define SIZE 256
7 #define ITERATIONS 10000
9 int test_memcmp(const void *s1, const void *s2, size_t n);
11 /* test all offsets and lengths */
12 static void test_one(char *s1, char *s2)
14 unsigned long offset, size;
16 for (offset = 0; offset < SIZE; offset++) {
17 for (size = 0; size < (SIZE-offset); size++) {
18 int x, y;
19 unsigned long i;
21 y = memcmp(s1+offset, s2+offset, size);
22 x = test_memcmp(s1+offset, s2+offset, size);
24 if (((x ^ y) < 0) && /* Trick to compare sign */
25 ((x | y) != 0)) { /* check for zero */
26 printf("memcmp returned %d, should have returned %d (offset %ld size %ld)\n", x, y, offset, size);
28 for (i = offset; i < offset+size; i++)
29 printf("%02x ", s1[i]);
30 printf("\n");
32 for (i = offset; i < offset+size; i++)
33 printf("%02x ", s2[i]);
34 printf("\n");
35 abort();
41 static int testcase(void)
43 char *s1;
44 char *s2;
45 unsigned long i;
47 s1 = memalign(128, SIZE);
48 if (!s1) {
49 perror("memalign");
50 exit(1);
53 s2 = memalign(128, SIZE);
54 if (!s2) {
55 perror("memalign");
56 exit(1);
59 srandom(1);
61 for (i = 0; i < ITERATIONS; i++) {
62 unsigned long j;
63 unsigned long change;
65 for (j = 0; j < SIZE; j++)
66 s1[j] = random();
68 memcpy(s2, s1, SIZE);
70 /* change one byte */
71 change = random() % SIZE;
72 s2[change] = random() & 0xff;
74 test_one(s1, s2);
77 srandom(1);
79 for (i = 0; i < ITERATIONS; i++) {
80 unsigned long j;
81 unsigned long change;
83 for (j = 0; j < SIZE; j++)
84 s1[j] = random();
86 memcpy(s2, s1, SIZE);
88 /* change multiple bytes, 1/8 of total */
89 for (j = 0; j < SIZE / 8; j++) {
90 change = random() % SIZE;
91 s2[change] = random() & 0xff;
94 test_one(s1, s2);
97 return 0;
100 int main(void)
102 return test_harness(testcase, "memcmp");