246 unsigned char *orig_buf;
249 lzma_stream initial_stream = LZMA_STREAM_INIT;
251 unsigned char *compressed_buf;
252 size_t compressed_bufsize;
253 unsigned char *uncompressed_buf;
254 size_t uncompressed_bufsize;
255 unsigned char *spare_buf;
262 const size_t trials = 16;
265 static const char *
const names[] = {
266 "Isaac.Newton-Opticks.txt",
267 "../libgo/go/testdata/Isaac.Newton-Opticks.txt",
272 uncompressed_buf = NULL;
273 compressed_buf = NULL;
275 for (i = 0; i <
sizeof names /
sizeof names[0]; ++i)
284 len = strlen (SRCDIR) + strlen (
names[i]) + 2;
292 e = fopen (namebuf,
"r");
296 if (fstat (fileno (e), &st) < 0)
302 rbuf =
malloc (st.st_size);
308 got = fread (rbuf, 1, st.st_size, e);
312 orig_buf = (
unsigned char *) rbuf;
319 if (orig_buf == NULL)
322 printf (
"UNSUPPORTED: lzma large\n");
326 stream = initial_stream;
327 r = lzma_easy_encoder (&stream, 6, LZMA_CHECK_CRC32);
330 fprintf (stderr,
"lzma_easy_encoder failed: %d\n", r);
334 compressed_bufsize = orig_bufsize + 100;
335 compressed_buf =
malloc (compressed_bufsize);
336 if (compressed_buf == NULL)
342 stream.next_in = orig_buf;
343 stream.avail_in = orig_bufsize;
344 stream.next_out = compressed_buf;
345 stream.avail_out = compressed_bufsize;
349 r = lzma_code (&stream, LZMA_FINISH);
350 if (r != LZMA_OK && r != LZMA_STREAM_END)
352 fprintf (stderr,
"lzma_code failed: %d\n", r);
356 while (r != LZMA_STREAM_END);
358 compressed_bufsize = stream.total_out;
363 &uncompressed_buf, &uncompressed_bufsize))
365 fprintf (stderr,
"lzma large: backtrace_uncompress_lzma failed\n");
369 if (uncompressed_bufsize != orig_bufsize)
372 "lzma large: got uncompressed length %zu, want %zu\n",
373 uncompressed_bufsize, orig_bufsize);
377 if (memcmp (uncompressed_buf, orig_buf, uncompressed_bufsize) != 0)
379 fprintf (stderr,
"lzma large: uncompressed data mismatch\n");
383 printf (
"PASS: lzma large\n");
385 spare_buf =
malloc (orig_bufsize);
386 if (spare_buf == NULL)
392 for (i = 0; i < trials; ++i)
395 if (clock_gettime (cid, &ts1) < 0)
399 perror (
"clock_gettime");
404 (
unsigned char *) compressed_buf,
408 &uncompressed_bufsize))
412 "benchmark backtrace_uncompress_lzma failed\n"));
416 if (clock_gettime (cid, &ts2) < 0)
418 perror (
"clock_gettime");
422 ctime = (ts2.tv_sec - ts1.tv_sec) * 1000000000;
423 ctime += ts2.tv_nsec - ts1.tv_nsec;
426 stream = initial_stream;
428 r = lzma_auto_decoder (&stream, UINT64_MAX, 0);
431 fprintf (stderr,
"lzma_stream_decoder failed: %d\n", r);
435 stream.next_in = compressed_buf;
436 stream.avail_in = compressed_bufsize;
437 stream.next_out = spare_buf;
438 stream.avail_out = orig_bufsize;
440 if (clock_gettime (cid, &ts1) < 0)
442 perror(
"clock_gettime");
448 r = lzma_code (&stream, LZMA_FINISH);
449 if (r != LZMA_OK && r != LZMA_STREAM_END)
451 fprintf (stderr,
"lzma_code failed: %d\n", r);
455 while (r != LZMA_STREAM_END);
457 if (clock_gettime (cid, &ts2) < 0)
459 perror (
"clock_gettime");
463 ztime = (ts2.tv_sec - ts1.tv_sec) * 1000000000;
464 ztime += ts2.tv_nsec - ts1.tv_nsec;
472 printf (
"backtrace: %zu ns\n", ctime);
473 printf (
"liblzma : %zu ns\n", ztime);
474 printf (
"ratio : %g\n", (
double) ztime / (
double) ctime);
479 printf (
"FAIL: lzma large\n");
482 if (orig_buf != NULL)
484 if (compressed_buf != NULL)
485 free (compressed_buf);
486 if (uncompressed_buf != NULL)
487 free (uncompressed_buf);
491 printf (
"UNSUPPORTED: lzma large\n");
void backtrace_free(struct backtrace_state *state ATTRIBUTE_UNUSED, void *p, size_t size ATTRIBUTE_UNUSED, backtrace_error_callback error_callback ATTRIBUTE_UNUSED, void *data ATTRIBUTE_UNUSED)
int backtrace_uncompress_lzma(struct backtrace_state *state, const unsigned char *compressed, size_t compressed_size, backtrace_error_callback error_callback, void *data, unsigned char **uncompressed, size_t *uncompressed_size)