//#include <iostream>
//using std::cout;
+// Define this to compile in a dump of all encoded objects to disk to
+// populate ceph-object-corpus. Note that there is an almost
+// identical implementation in encoding.h, but you only need to define
+// ENCODE_DUMP_PATH here.
+//
+// See src/test/encoding/generate-corpus-objects.sh.
+//
+//#define ENCODE_DUMP_PATH /tmp/something
-#ifdef ENCODE_DUMP
+#ifdef ENCODE_DUMP_PATH
# include <stdio.h>
# include <sys/types.h>
# include <sys/stat.h>
# define ENCODE_STRINGIFY(x) ENCODE_STR(x)
# define DENC_DUMP_PRE(Type) \
char *__denc_dump_pre = p.get_pos();
+ // this hackery with bits below is just to get a semi-reasonable
+ // distribution across time. it is somewhat exponential but not
+ // quite.
# define DENC_DUMP_POST(Type) \
do { \
static int i = 0; \
t &= t - 1; \
if (bits > 2) \
break; \
- char fn[200]; \
+ char fn[PATH_MAX]; \
snprintf(fn, sizeof(fn), \
- ENCODE_STRINGIFY(ENCODE_DUMP) "/%s__%d.%x", #Type, \
+ ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", #Type, \
getpid(), i++); \
int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT, 0644); \
if (fd >= 0) { \
WRITE_INTTYPE_ENCODER(uint16_t, le16)
WRITE_INTTYPE_ENCODER(int16_t, le16)
-#ifdef ENCODE_DUMP
-
+// see denc.h for ENCODE_DUMP_PATH discussion and definition.
+#ifdef ENCODE_DUMP_PATH
# define ENCODE_DUMP_PRE() \
unsigned pre_off = bl.length()
-
-// NOTE: This is almost an exponential backoff, but because we count
-// bits we get a better sample of things we encode later on.
# define ENCODE_DUMP_POST(cl) \
do { \
static int i = 0; \
t &= t - 1; \
if (bits > 2) \
break; \
- char fn[200]; \
- snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP) "/%s__%d.%x", #cl, getpid(), i++); \
+ char fn[PATH_MAX]; \
+ snprintf(fn, sizeof(fn), ENCODE_STRINGIFY(ENCODE_DUMP_PATH) "/%s__%d.%x", #cl, getpid(), i++); \
int fd = ::open(fn, O_WRONLY|O_TRUNC|O_CREAT, 0644); \
if (fd >= 0) { \
bufferlist sub; \
# define ENCODE_DUMP_POST(cl)
#endif
+
#define WRITE_CLASS_ENCODER(cl) \
inline void encode(const cl &c, bufferlist &bl, uint64_t features=0) { \
ENCODE_DUMP_PRE(); c.encode(bl); ENCODE_DUMP_POST(cl); } \