forked from enlightenment/efl
* src/bin/evil_suite.c:
* src/bin/evil_suite.h: * src/bin/evil_test_memcpy.c: * src/bin/evil_test_memcpy.h: clean suite and memcpy test code SVN revision: 36835
This commit is contained in:
parent
f3acb81ceb
commit
e67164459d
|
@ -1,3 +1,11 @@
|
|||
2008-10-20 Vincent Torri <doursse at users dot sf dot net>
|
||||
|
||||
* src/bin/evil_suite.c:
|
||||
* src/bin/evil_suite.h:
|
||||
* src/bin/evil_test_memcpy.c:
|
||||
* src/bin/evil_test_memcpy.h:
|
||||
clean suite and memcpy test code
|
||||
|
||||
2008-10-19 Vincent Torri <doursse at users dot sf dot net>
|
||||
|
||||
* src/lib/errno.h:
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "evil_test_memcpy.h"
|
||||
|
||||
|
||||
typedef void(*function)(void);
|
||||
typedef int(*function)(suite *s);
|
||||
|
||||
struct test
|
||||
{
|
||||
|
@ -20,41 +20,35 @@ struct test
|
|||
struct list
|
||||
{
|
||||
void *data;
|
||||
int succeed;
|
||||
list *next;
|
||||
};
|
||||
|
||||
struct suite
|
||||
{
|
||||
LARGE_INTEGER freq;
|
||||
LARGE_INTEGER start;
|
||||
LARGE_INTEGER end;
|
||||
|
||||
list *first;
|
||||
list *l;
|
||||
};
|
||||
|
||||
|
||||
unsigned char *buf1 = NULL;
|
||||
unsigned char *buf2 = NULL;
|
||||
size_t page_size = 0;
|
||||
|
||||
|
||||
#ifdef __MINGW32CE__
|
||||
static int
|
||||
getpagesize()
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
#endif /* __MINGW32CE__ */
|
||||
|
||||
|
||||
suite *
|
||||
suite_new(void)
|
||||
{
|
||||
suite *s;
|
||||
|
||||
if (!QueryPerformanceFrequency(&freq))
|
||||
return NULL;
|
||||
|
||||
s = (suite *)malloc(sizeof(suite));
|
||||
if (!s) return NULL;
|
||||
|
||||
if (!QueryPerformanceFrequency(&s->freq))
|
||||
{
|
||||
free(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
s->first = NULL;
|
||||
s->l = NULL;
|
||||
|
||||
|
@ -82,21 +76,21 @@ suite_del(suite *s)
|
|||
}
|
||||
|
||||
void
|
||||
suite_time_start()
|
||||
suite_time_start(suite *s)
|
||||
{
|
||||
QueryPerformanceCounter(&start);
|
||||
QueryPerformanceCounter(&s->start);
|
||||
}
|
||||
|
||||
void
|
||||
suite_time_stop()
|
||||
suite_time_stop(suite *s)
|
||||
{
|
||||
QueryPerformanceCounter(&end);
|
||||
QueryPerformanceCounter(&s->end);
|
||||
}
|
||||
|
||||
double
|
||||
suite_time_get()
|
||||
suite_time_get(suite *s)
|
||||
{
|
||||
return (double)(end.QuadPart - start.QuadPart) / (double)freq.QuadPart;
|
||||
return (double)(s->end.QuadPart - s->start.QuadPart) / (double)s->freq.QuadPart;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -119,6 +113,7 @@ suite_test_add(suite *s, const char *name, function fct)
|
|||
t->fct = fct;
|
||||
|
||||
l->data = t;
|
||||
l->succeed = 0;
|
||||
l->next = NULL;
|
||||
|
||||
if (!s->first) s->first = l;
|
||||
|
@ -143,8 +138,8 @@ suite_run(suite *s)
|
|||
test *t;
|
||||
|
||||
t = (test *)l->data;
|
||||
printf("%s test\n", t->name);
|
||||
t->fct();
|
||||
l->succeed = t->fct(s);
|
||||
printf("%s test: %s\n", t->name, l->succeed ? "success" : "failure");
|
||||
l = l->next;
|
||||
}
|
||||
}
|
||||
|
@ -153,34 +148,15 @@ int
|
|||
main()
|
||||
{
|
||||
test tests[] = {
|
||||
{ "memcpy", test_memcpy },
|
||||
{ NULL, NULL },
|
||||
{ "memcpy", test_memcpy },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
suite *s;
|
||||
int i;
|
||||
|
||||
page_size = 2 * 1024;
|
||||
|
||||
buf1 = (unsigned char *)malloc(16 * getpagesize());
|
||||
if (!buf1) return EXIT_FAILURE;
|
||||
|
||||
buf2 = (unsigned char *)malloc(16 * getpagesize());
|
||||
if (!buf2)
|
||||
{
|
||||
free(buf1);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
memset (buf1, 0xa5, page_size);
|
||||
memset (buf2, 0x5a, page_size);
|
||||
|
||||
s = suite_new();
|
||||
if (!s)
|
||||
{
|
||||
free(buf2);
|
||||
free(buf1);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
|
||||
for (i = 0; ; ++i)
|
||||
{
|
||||
|
@ -193,8 +169,6 @@ main()
|
|||
suite_run(s);
|
||||
|
||||
suite_del(s);
|
||||
free(buf2);
|
||||
free(buf1);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -6,13 +6,9 @@ typedef struct test test;
|
|||
typedef struct list list;
|
||||
typedef struct suite suite;
|
||||
|
||||
LARGE_INTEGER freq;
|
||||
LARGE_INTEGER start;
|
||||
LARGE_INTEGER end;
|
||||
|
||||
void suite_time_start();
|
||||
void suite_time_stop();
|
||||
double suite_time_get();
|
||||
void suite_time_start(suite *s);
|
||||
void suite_time_stop(suite *s);
|
||||
double suite_time_get(suite *s);
|
||||
|
||||
|
||||
#endif /* __EVIL_SUITE_H__ */
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
@ -20,13 +19,22 @@ typedef void *(*memcpy_decl)(void *dest, const void *src, size_t n);
|
|||
void *memcpy_glibc(void *dest, const void *src, size_t n);
|
||||
|
||||
|
||||
extern unsigned char *buf1;
|
||||
extern unsigned char *buf2;
|
||||
extern size_t page_size;
|
||||
static unsigned char *buf1 = NULL;
|
||||
static unsigned char *buf2 = NULL;
|
||||
static size_t page_size = 0;
|
||||
|
||||
|
||||
#ifdef __MINGW32CE__
|
||||
static int
|
||||
getpagesize()
|
||||
{
|
||||
return 1024;
|
||||
}
|
||||
#endif /* __MINGW32CE__ */
|
||||
|
||||
|
||||
static void
|
||||
test_memcpy_test_run(memcpy_decl fct, char *dst, const char *src, size_t len)
|
||||
test_memcpy_test_run(suite *s, memcpy_decl fct, char *dst, const char *src, size_t len)
|
||||
{
|
||||
double start;
|
||||
double end;
|
||||
|
@ -39,10 +47,10 @@ test_memcpy_test_run(memcpy_decl fct, char *dst, const char *src, size_t len)
|
|||
{
|
||||
double time;
|
||||
|
||||
suite_time_start();
|
||||
suite_time_start(s);
|
||||
fct(dst, src, len);
|
||||
suite_time_stop();
|
||||
time = suite_time_get();
|
||||
suite_time_stop(s);
|
||||
time = suite_time_get(s);
|
||||
if (time < best) best = time;
|
||||
}
|
||||
|
||||
|
@ -50,7 +58,7 @@ test_memcpy_test_run(memcpy_decl fct, char *dst, const char *src, size_t len)
|
|||
}
|
||||
|
||||
static void
|
||||
test_memcpy_tests_run(size_t align1, size_t align2, size_t len)
|
||||
test_memcpy_tests_run(suite *s, size_t align1, size_t align2, size_t len)
|
||||
{
|
||||
size_t i, j;
|
||||
char *s1, *s2;
|
||||
|
@ -73,48 +81,68 @@ test_memcpy_tests_run(size_t align1, size_t align2, size_t len)
|
|||
|
||||
printf ("length: %6d, align %2d/%2d:", (int)len, align1, align2);
|
||||
|
||||
test_memcpy_test_run(memcpy, s2, s1, len);
|
||||
test_memcpy_test_run(s, memcpy, s2, s1, len);
|
||||
#ifdef EVIL_HAVE_WINCE
|
||||
test_memcpy_test_run(memcpy_glibc, s2, s1, len);
|
||||
test_memcpy_test_run(s, memcpy_glibc, s2, s1, len);
|
||||
#endif /* EVIL_HAVE_WINCE */
|
||||
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
void
|
||||
test_memcpy(void)
|
||||
int
|
||||
test_memcpy(suite *s)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
page_size = 2 * 1024;
|
||||
|
||||
buf1 = (unsigned char *)malloc(16 * getpagesize());
|
||||
if (!buf1) return 0;
|
||||
|
||||
buf2 = (unsigned char *)malloc(16 * getpagesize());
|
||||
if (!buf2)
|
||||
{
|
||||
free(buf1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset (buf1, 0xa5, page_size);
|
||||
memset (buf2, 0x5a, page_size);
|
||||
|
||||
for (i = 0; i < 18; ++i)
|
||||
{
|
||||
test_memcpy_tests_run(0, 0, 1 << i);
|
||||
test_memcpy_tests_run(i, 0, 1 << i);
|
||||
test_memcpy_tests_run(0, i, 1 << i);
|
||||
test_memcpy_tests_run(i, i, 1 << i);
|
||||
test_memcpy_tests_run(s, 0, 0, 1 << i);
|
||||
test_memcpy_tests_run(s, i, 0, 1 << i);
|
||||
test_memcpy_tests_run(s, 0, i, 1 << i);
|
||||
test_memcpy_tests_run(s, i, i, 1 << i);
|
||||
}
|
||||
|
||||
for (i = 0; i < 32; ++i)
|
||||
{
|
||||
test_memcpy_tests_run(0, 0, i);
|
||||
test_memcpy_tests_run(i, 0, i);
|
||||
test_memcpy_tests_run(0, i, i);
|
||||
test_memcpy_tests_run(i, i, i);
|
||||
test_memcpy_tests_run(s, 0, 0, i);
|
||||
test_memcpy_tests_run(s, i, 0, i);
|
||||
test_memcpy_tests_run(s, 0, i, i);
|
||||
test_memcpy_tests_run(s, i, i, i);
|
||||
}
|
||||
|
||||
for (i = 3; i < 32; ++i)
|
||||
{
|
||||
if ((i & (i - 1)) == 0)
|
||||
continue;
|
||||
test_memcpy_tests_run(0, 0, 16 * i);
|
||||
test_memcpy_tests_run(i, 0, 16 * i);
|
||||
test_memcpy_tests_run(0, i, 16 * i);
|
||||
test_memcpy_tests_run(i, i, 16 * i);
|
||||
test_memcpy_tests_run(s, 0, 0, 16 * i);
|
||||
test_memcpy_tests_run(s, i, 0, 16 * i);
|
||||
test_memcpy_tests_run(s, 0, i, 16 * i);
|
||||
test_memcpy_tests_run(s, i, i, 16 * i);
|
||||
}
|
||||
|
||||
test_memcpy_tests_run(0, 0, getpagesize ());
|
||||
test_memcpy_tests_run(0, 0, 2 * getpagesize ());
|
||||
test_memcpy_tests_run(0, 0, 4 * getpagesize ());
|
||||
test_memcpy_tests_run(0, 0, 8 * getpagesize ());
|
||||
test_memcpy_tests_run(0, 0, 16 * getpagesize ());
|
||||
test_memcpy_tests_run(s, 0, 0, getpagesize ());
|
||||
test_memcpy_tests_run(s, 0, 0, 2 * getpagesize ());
|
||||
test_memcpy_tests_run(s, 0, 0, 4 * getpagesize ());
|
||||
test_memcpy_tests_run(s, 0, 0, 8 * getpagesize ());
|
||||
test_memcpy_tests_run(s, 0, 0, 16 * getpagesize ());
|
||||
|
||||
free(buf2);
|
||||
free(buf1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define __EVIL_TEST_MEMCPY__
|
||||
|
||||
|
||||
void test_memcpy(void);
|
||||
int test_memcpy(suite *s);
|
||||
|
||||
|
||||
#endif /* __EVIL_TEST_MEMCPY__ */
|
||||
|
|
Loading…
Reference in New Issue