projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
unittests: add unittest suite for lib/strntol.c
[fio.git]
/
lib
/
memcpy.c
diff --git
a/lib/memcpy.c
b/lib/memcpy.c
index 8164ba0913e45880341c67c528a2cff2f0a1e0d6..cf8572e270898a14c3fb3daf8be047c3bbcedd1c 100644
(file)
--- a/
lib/memcpy.c
+++ b/
lib/memcpy.c
@@
-1,3
+1,4
@@
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@
-6,7
+7,7
@@
#include "rand.h"
#include "../fio_time.h"
#include "../gettime.h"
#include "rand.h"
#include "../fio_time.h"
#include "../gettime.h"
-#include "../
fio
.h"
+#include "../
os/os
.h"
#define BUF_SIZE 32 * 1024 * 1024ULL
#define BUF_SIZE 32 * 1024 * 1024ULL
@@
-72,16
+73,17
@@
static struct memcpy_test tests[] = {
struct memcpy_type {
const char *name;
unsigned int mask;
struct memcpy_type {
const char *name;
unsigned int mask;
- void (*fn)(struct memcpy_t
ype *, struct memcpy_t
est *);
+ void (*fn)(struct memcpy_test *);
};
enum {
T_MEMCPY = 1U << 0,
T_MEMMOVE = 1U << 1,
T_SIMPLE = 1U << 2,
};
enum {
T_MEMCPY = 1U << 0,
T_MEMMOVE = 1U << 1,
T_SIMPLE = 1U << 2,
+ T_HYBRID = 1U << 3,
};
};
-#define do_test(t
, test, fn)
do { \
+#define do_test(t
est, fn)
do { \
size_t left, this; \
void *src, *dst; \
int i; \
size_t left, this; \
void *src, *dst; \
int i; \
@@
-102,14
+104,14
@@
enum {
} \
} while (0)
} \
} while (0)
-static void t_memcpy(struct memcpy_t
ype *t, struct memcpy_t
est *test)
+static void t_memcpy(struct memcpy_test *test)
{
{
- do_test(t
, t
est, memcpy);
+ do_test(test, memcpy);
}
}
-static void t_memmove(struct memcpy_t
ype *t, struct memcpy_t
est *test)
+static void t_memmove(struct memcpy_test *test)
{
{
- do_test(t
, t
est, memmove);
+ do_test(test, memmove);
}
static void simple_memcpy(void *dst, void const *src, size_t len)
}
static void simple_memcpy(void *dst, void const *src, size_t len)
@@
-121,9
+123,17
@@
static void simple_memcpy(void *dst, void const *src, size_t len)
*d++ = *s++;
}
*d++ = *s++;
}
-static void t_simple(struct memcpy_t
ype *t, struct memcpy_t
est *test)
+static void t_simple(struct memcpy_test *test)
{
{
- do_test(t, test, simple_memcpy);
+ do_test(test, simple_memcpy);
+}
+
+static void t_hybrid(struct memcpy_test *test)
+{
+ if (test->size >= 64)
+ do_test(test, simple_memcpy);
+ else
+ do_test(test, memcpy);
}
static struct memcpy_type t[] = {
}
static struct memcpy_type t[] = {
@@
-142,7
+152,11
@@
static struct memcpy_type t[] = {
.mask = T_SIMPLE,
.fn = t_simple,
},
.mask = T_SIMPLE,
.fn = t_simple,
},
-
+ {
+ .name = "hybrid",
+ .mask = T_HYBRID,
+ .fn = t_hybrid,
+ },
{
.name = NULL,
},
{
.name = NULL,
},
@@
-189,8
+203,11
@@
static int setup_tests(void)
src = malloc(BUF_SIZE);
dst = malloc(BUF_SIZE);
src = malloc(BUF_SIZE);
dst = malloc(BUF_SIZE);
- if (!src || !dst)
+ if (!src || !dst) {
+ free(src);
+ free(dst);
return 1;
return 1;
+ }
init_rand_seed(&state, 0x8989, 0);
fill_random_buf(&state, src, BUF_SIZE);
init_rand_seed(&state, 0x8989, 0);
fill_random_buf(&state, src, BUF_SIZE);
@@
-245,13
+262,13
@@
int fio_memcpy_test(const char *type)
* we've touched the data.
*/
usec_spin(100000);
* we've touched the data.
*/
usec_spin(100000);
- t[i].fn(&t
[i], &t
ests[0]);
+ t[i].fn(&tests[0]);
printf("%s\n", t[i].name);
for (j = 0; tests[j].name; j++) {
fio_gettime(&ts, NULL);
printf("%s\n", t[i].name);
for (j = 0; tests[j].name; j++) {
fio_gettime(&ts, NULL);
- t[i].fn(&t
[i], &t
ests[j]);
+ t[i].fn(&tests[j]);
usec = utime_since_now(&ts);
if (usec) {
usec = utime_since_now(&ts);
if (usec) {