From 90219914d718a74f9ce8eaa1a1efd2c4ad6d2384 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Thu, 5 May 2011 13:01:22 -0400 Subject: [PATCH] Add dummy trace creator in tests Signed-off-by: Mathieu Desnoyers --- tests/Makefile.am | 4 +- tests/test-dummytrace.c | 81 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 tests/test-dummytrace.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 642dd983..1038535e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,7 @@ AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -noinst_PROGRAMS = test-bitfield +noinst_PROGRAMS = test-bitfield test-dummytrace test_bitfield_SOURCES = test-bitfield.c + +test_dummytrace_SOURCES = test-dummytrace.c diff --git a/tests/test-dummytrace.c b/tests/test-dummytrace.c new file mode 100644 index 00000000..81e97b98 --- /dev/null +++ b/tests/test-dummytrace.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define FILE_LEN (4 * 4096) + +int main(int argc, char **argv) +{ + char *base, *pos; + int fd, ret; + off_t off; + uuid_t uuid; + + fd = open("dummystream", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); + if (fd < 0) { + perror("open"); + return -1; + } + off = posix_fallocate(fd, 0, FILE_LEN); + if (off < 0) { + printf("Error in fallocate\n"); + return -1; + } +#if 0 + { + ssize_t len; + + off = lseek(fd, FILE_LEN - 1, SEEK_CUR); + if (off < 0) { + perror("lseek"); + return -1; + } + len = write(fd, "", 1); + if (len < 0) { + perror("write"); + return -1; + } + } +#endif + base = mmap(NULL, FILE_LEN, PROT_READ|PROT_WRITE, + MAP_SHARED, fd, 0); + if (!base) { + perror("mmap"); + return -1; + } + pos = base; + + /* magic */ + *(uint32_t *) pos = 0xC1FC1FC1; + pos += sizeof(uint32_t); + + /* trace_uuid */ + ret = uuid_parse("2a6422d0-6cee-11e0-8c08-cb07d7b3a564", uuid); + if (ret) { + printf("uuid parse error\n"); + return -1; + } + memcpy(pos, uuid, 16); + pos += 16; + + /* stream_id */ + *(uint32_t *) pos = 0; + pos += sizeof(uint32_t); + + ret = munmap(base, FILE_LEN); + if (ret) { + perror("munmap"); + return -1; + } + close(fd); + return 0; +} + + -- 2.34.1