Add dummy trace creator in tests
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 5 May 2011 17:01:22 +0000 (13:01 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 5 May 2011 17:01:22 +0000 (13:01 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/Makefile.am
tests/test-dummytrace.c [new file with mode: 0644]

index 642dd983de46de4edf3a82c1bcfe73242ce6184c..1038535e77d014fc0d9ebd9b4e5699354c269a27 100644 (file)
@@ -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 (file)
index 0000000..81e97b9
--- /dev/null
@@ -0,0 +1,81 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <unistd.h>
+#include <errno.h>
+#include <uuid/uuid.h>
+#include <string.h>
+
+#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;
+}
+
+
This page took 0.034715 seconds and 4 git commands to generate.