|
nsz |
49b23c |
#include <string.h>
|
|
nsz |
49b23c |
#include "test.h"
|
|
nsz |
49b23c |
|
|
Szabolcs Nagy |
13492a |
static char buf[512];
|
|
Szabolcs Nagy |
13492a |
|
|
Szabolcs Nagy |
13492a |
static void *aligned(void *p)
|
|
Szabolcs Nagy |
13492a |
{
|
|
Szabolcs Nagy |
c36565 |
return (void*)(((uintptr_t)p + 63) & -64);
|
|
Szabolcs Nagy |
13492a |
}
|
|
Szabolcs Nagy |
13492a |
|
|
Szabolcs Nagy |
13492a |
static void *aligncpy(void *p, size_t len, size_t a)
|
|
Szabolcs Nagy |
13492a |
{
|
|
Szabolcs Nagy |
ea6b2c |
return memcpy((char*)aligned(buf)+a, p, len);
|
|
Szabolcs Nagy |
13492a |
}
|
|
Szabolcs Nagy |
13492a |
|
|
nsz |
49b23c |
#define N(s, c) { \
|
|
Szabolcs Nagy |
13492a |
int align; \
|
|
Szabolcs Nagy |
13492a |
for (align=0; align<8; align++) { \
|
|
Szabolcs Nagy |
13492a |
char *p = aligncpy(s, sizeof s, align); \
|
|
Szabolcs Nagy |
13492a |
char *q = strchr(p, c); \
|
|
Szabolcs Nagy |
13492a |
if (q) \
|
|
Szabolcs Nagy |
13492a |
t_error("strchr(%s,%s) with align=%d returned str+%d, wanted 0\n", #s, #c, align, q-p); \
|
|
Szabolcs Nagy |
13492a |
} \
|
|
nsz |
49b23c |
}
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
#define T(s, c, n) { \
|
|
Szabolcs Nagy |
13492a |
int align; \
|
|
Szabolcs Nagy |
13492a |
for (align=0; align<8; align++) { \
|
|
Szabolcs Nagy |
13492a |
char *p = aligncpy(s, sizeof s, align); \
|
|
Szabolcs Nagy |
13492a |
char *q = strchr(p, c); \
|
|
Szabolcs Nagy |
13492a |
if (q == 0) \
|
|
Szabolcs Nagy |
13492a |
t_error("strchr(%s,%s) with align=%d returned 0, wanted str+%d\n", #s, #c, align, n); \
|
|
Szabolcs Nagy |
13492a |
else if (q - p != n) \
|
|
Szabolcs Nagy |
13492a |
t_error("strchr(%s,%s) with align=%d returned str+%d, wanted str+%d\n", #s, #c, align, q-p, n); \
|
|
Szabolcs Nagy |
13492a |
} \
|
|
nsz |
49b23c |
}
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
int main(void)
|
|
nsz |
49b23c |
{
|
|
nsz |
49b23c |
int i;
|
|
nsz |
49b23c |
char a[128];
|
|
nsz |
49b23c |
char s[256];
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
for (i = 0; i < 128; i++)
|
|
nsz |
49b23c |
a[i] = (i+1) & 127;
|
|
nsz |
49b23c |
for (i = 0; i < 256; i++)
|
|
nsz |
49b23c |
*((unsigned char*)s+i) = i+1;
|
|
nsz |
49b23c |
|
|
Szabolcs Nagy |
13492a |
N("\0aaa", 'a')
|
|
Szabolcs Nagy |
13492a |
N("a\0bb", 'b')
|
|
Szabolcs Nagy |
13492a |
N("ab\0c", 'c')
|
|
Szabolcs Nagy |
13492a |
N("abc\0d", 'd')
|
|
Szabolcs Nagy |
13492a |
N("abc abc\0x", 'x')
|
|
nsz |
49b23c |
N(a, 128)
|
|
nsz |
49b23c |
N(a, 255)
|
|
nsz |
49b23c |
|
|
nsz |
49b23c |
T("", 0, 0)
|
|
nsz |
49b23c |
T("a", 'a', 0)
|
|
nsz |
49b23c |
T("a", 'a'+256, 0)
|
|
nsz |
49b23c |
T("a", 0, 1)
|
|
Szabolcs Nagy |
13492a |
T("abb", 'b', 1)
|
|
Szabolcs Nagy |
13492a |
T("aabb", 'b', 2)
|
|
Szabolcs Nagy |
13492a |
T("aaabb", 'b', 3)
|
|
Szabolcs Nagy |
13492a |
T("aaaabb", 'b', 4)
|
|
Szabolcs Nagy |
13492a |
T("aaaaabb", 'b', 5)
|
|
Szabolcs Nagy |
13492a |
T("aaaaaabb", 'b', 6)
|
|
nsz |
49b23c |
T("abc abc", 'c', 2)
|
|
nsz |
49b23c |
T(s, 1, 0)
|
|
nsz |
49b23c |
T(s, 2, 1)
|
|
nsz |
49b23c |
T(s, 10, 9)
|
|
nsz |
49b23c |
T(s, 11, 10)
|
|
nsz |
49b23c |
T(s, 127, 126)
|
|
nsz |
49b23c |
T(s, 128, 127)
|
|
nsz |
49b23c |
T(s, 255, 254)
|
|
nsz |
49b23c |
T(s, 0, 255)
|
|
nsz |
49b23c |
|
|
Szabolcs Nagy |
cfa23c |
return t_status;
|
|
nsz |
49b23c |
}
|