summaryrefslogtreecommitdiff
path: root/xdelta3
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2007-02-14 08:42:35 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2007-02-14 08:42:35 +0000
commit6b2bb82f31e71c9e60c132c00db61b51ac907126 (patch)
tree5e8d65360955b73e63ef395b5eae86b41023cc79 /xdelta3
parent8c968ee7b98144c43e7453c026892abee5536e0c (diff)
add small_page_test.c, currently fails
Diffstat (limited to 'xdelta3')
-rw-r--r--xdelta3/Makefile2
-rwxr-xr-xxdelta3/examples/Makefile6
-rwxr-xr-xxdelta3/examples/small_page_test.c169
-rw-r--r--xdelta3/xdelta3.c10
4 files changed, 185 insertions, 2 deletions
diff --git a/xdelta3/Makefile b/xdelta3/Makefile
index cb79e64..2d2b785 100644
--- a/xdelta3/Makefile
+++ b/xdelta3/Makefile
@@ -70,7 +70,7 @@ test:
70 ./xdelta3-debug test 70 ./xdelta3-debug test
71 71
72tar: 72tar:
73 tar --exclude ".svn" -czf /tmp/$(RELDIR)-tmp.tar.gz $(SOURCES) $(PYFILES) $(EXTRA) 73 tar --exclude ".svn" -czf /tmp/$(RELDIR)-tmp.tar.gz $(SOURCES) $(EXTRA)
74 rm -rf /tmp/$(RELDIR) 74 rm -rf /tmp/$(RELDIR)
75 mkdir /tmp/$(RELDIR) 75 mkdir /tmp/$(RELDIR)
76 (cd /tmp/$(RELDIR) && tar -xzf ../$(RELDIR)-tmp.tar.gz) 76 (cd /tmp/$(RELDIR) && tar -xzf ../$(RELDIR)-tmp.tar.gz)
diff --git a/xdelta3/examples/Makefile b/xdelta3/examples/Makefile
new file mode 100755
index 0000000..657e08a
--- /dev/null
+++ b/xdelta3/examples/Makefile
@@ -0,0 +1,6 @@
1CFLAGS = -g -O2 -Wall -I ..
2
3SOURCES = small_page_test.c
4
5small_page_test: $(SOURCES)
6 $(CC) $(CFLAGS) small_page_test.c -o small_page_test -DXD3_USE_LARGEFILE64=1 -DSECONDARY_DJW=1
diff --git a/xdelta3/examples/small_page_test.c b/xdelta3/examples/small_page_test.c
new file mode 100755
index 0000000..16dd1c1
--- /dev/null
+++ b/xdelta3/examples/small_page_test.c
@@ -0,0 +1,169 @@
1/* Copyright (C) 2007 Josh MacDonald */
2
3#include <stdio.h>
4
5#define SPACE_MAX 32768
6#define PAGE_SIZE 4096
7#define OUTPUT_MAX 1024
8#define IOPT_SIZE 1024
9#define XD3_ALLOCSIZE 256
10
11// typedef void* (xd3_alloc_func) (void *opaque,
12// usize_t items,
13// usize_t size);
14// typedef void (xd3_free_func) (void *opaque,
15// void *address);
16
17#include "xdelta3.h"
18#include "xdelta3.c"
19
20typedef struct _context {
21 uint8_t *buffer;
22 int allocated;
23} context_t;
24
25void*
26process_alloc (void* opaque, usize_t items, usize_t size)
27{
28 context_t *ctx = (context_t*) opaque;
29 usize_t t = items * size;
30 void *ret;
31
32 if (ctx->allocated + t > SPACE_MAX)
33 {
34 return NULL;
35 }
36
37 ret = ctx->buffer + ctx->allocated;
38 ctx->allocated += t;
39 return ret;
40}
41
42int
43process_page (int is_encode,
44 int (*func) (xd3_stream *),
45 const uint8_t *input,
46 usize_t input_size,
47 const uint8_t *source,
48 uint8_t *output,
49 usize_t *output_size,
50 usize_t output_size_max,
51 int flags) {
52 xd3_stream *stream;
53 xd3_config *config;
54 xd3_source *src;
55 context_t *ctx = calloc(OUTPUT_MAX, 1);
56 int ret;
57
58 ctx->buffer = ((char*)ctx) + sizeof(*ctx);
59 ctx->allocated = sizeof(*ctx);
60
61 stream = process_alloc (ctx, 1, sizeof(*stream));
62 config = process_alloc (ctx, 1, sizeof(*config));
63 src = process_alloc (ctx, 1, sizeof(*src));
64
65 config->flags = flags;
66 config->winsize = PAGE_SIZE;
67 config->sprevsz = PAGE_SIZE;
68 config->srcwin_maxsz = PAGE_SIZE;
69 config->iopt_size = IOPT_SIZE;
70 config->alloc = &process_alloc;
71
72 src->size = PAGE_SIZE;
73 src->blksize = PAGE_SIZE;
74 src->onblk = PAGE_SIZE;
75 src->curblk = source;
76 src->curblkno = 0;
77
78 if ((ret = xd3_config_stream (stream, config)) != 0 ||
79 (ret = xd3_set_source (stream, src)) != 0 ||
80 (ret = xd3_process_stream (is_encode,
81 stream,
82 func, 1,
83 input, PAGE_SIZE,
84 output, output_size,
85 output_size_max)) != 0)
86 {
87 // (void) 0;
88 }
89
90 xd3_free_stream (stream);
91 return ret;
92}
93
94int test(int stride, int encode_flags)
95{
96 uint8_t frompg[PAGE_SIZE];
97 uint8_t topg[PAGE_SIZE];
98 uint8_t output[OUTPUT_MAX];
99 uint8_t reout[OUTPUT_MAX];
100 usize_t output_size;
101 usize_t re_size;
102 int i, j, ret;
103
104 for (i = 0; i < PAGE_SIZE; i++)
105 {
106 topg[i] = frompg[i] = lrand48();
107 }
108
109 // change 1 byte every stride
110 if (stride > 0)
111 {
112 for (j = stride; j <= PAGE_SIZE; j += stride)
113 {
114 topg[j - 1] ^= 0xff;
115 }
116 }
117
118 if ((ret = process_page (1, xd3_encode_input,
119 topg, PAGE_SIZE,
120 frompg, output,
121 &output_size, OUTPUT_MAX,
122 encode_flags)) != 0)
123 {
124 return ret;
125 }
126
127 if ((ret = process_page (1, xd3_decode_input,
128 output, output_size,
129 frompg, reout,
130 &re_size, PAGE_SIZE,
131 0)) != 0)
132 {
133 return ret;
134 }
135
136 if (output_size > OUTPUT_MAX || re_size != PAGE_SIZE)
137 {
138 printf ("internal error\n");
139 return -1;
140 }
141
142 printf("stride %d flags 0x%x size %u ", stride, encode_flags, output_size);
143 printf("%s\n", (ret == 0) ? "OK" : "FAIL");
144
145 return 0;
146}
147
148int main()
149{
150 int stride;
151 int level;
152 int ret;
153
154 for (level = 1; level < 10; level = (level == 1 ? 3 : level + 3))
155 {
156 int lflag = level << XD3_COMPLEVEL_SHIFT;
157 for (stride = 0; stride <= PAGE_SIZE; stride += PAGE_SIZE / 64)
158 {
159 if ((ret = test(stride, lflag)) ||
160 (ret = test(stride, lflag | XD3_ADLER32)) ||
161 (ret = test(stride, lflag | XD3_SEC_DJW)))
162 {
163 return ret;
164 }
165 }
166 }
167
168 return 0;
169}
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index 32dc8b0..5535d07 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -2357,7 +2357,7 @@ xd3_free_stream (xd3_stream *stream)
2357 memset (stream, 0, sizeof (xd3_stream)); 2357 memset (stream, 0, sizeof (xd3_stream));
2358} 2358}
2359 2359
2360#if (XD3_DEBUG || VCDIFF_TOOLS) 2360#if (VCDIFF_TOOLS)
2361static const char* 2361static const char*
2362xd3_rtype_to_string (xd3_rtype type, int print_mode) 2362xd3_rtype_to_string (xd3_rtype type, int print_mode)
2363{ 2363{
@@ -4124,6 +4124,7 @@ xd3_string_match_init (xd3_stream *stream)
4124 return 0; 4124 return 0;
4125} 4125}
4126 4126
4127#if XD3_USE_LARGEFILE64
4127/* This function handles the 32/64bit ambiguity -- file positions are 64bit but the hash 4128/* This function handles the 32/64bit ambiguity -- file positions are 64bit but the hash
4128 * table for source-offsets is 32bit. */ 4129 * table for source-offsets is 32bit. */
4129static xoff_t 4130static xoff_t
@@ -4146,6 +4147,13 @@ xd3_source_cksum_offset(xd3_stream *stream, usize_t low)
4146 4147
4147 return (s0 << 32) | low; 4148 return (s0 << 32) | low;
4148} 4149}
4150#else
4151static xoff_t
4152xd3_source_cksum_offset(xd3_stream *stream, usize_t low)
4153{
4154 return (xoff_t) low;
4155}
4156#endif
4149 4157
4150/* This function sets up the stream->src fields srcbase, srclen. The call is delayed 4158/* This function sets up the stream->src fields srcbase, srclen. The call is delayed
4151 * until these values are needed to encode a copy address. At this point the decision has 4159 * until these values are needed to encode a copy address. At this point the decision has