mirror of
https://github.com/intel/isa-l.git
synced 2024-12-12 09:23:50 +01:00
igzip:use fgetpos() to replace ftell() to get file's length.
Change-Id: Ia1f3c06e92c01da9d22b3d70b2b05fe4808c9f2c Signed-off-by: Hailiang Wang <hailiangx.e.wang@intel.com>
This commit is contained in:
parent
ff9c0c1842
commit
52f644d3ff
@ -115,9 +115,9 @@ other_src += igzip/crc_inflate.h
|
||||
igzip_inflate_perf: LDLIBS += -lz
|
||||
igzip_igzip_inflate_perf_LDADD = libisal.la
|
||||
igzip_igzip_inflate_perf_LDFLAGS = -lz
|
||||
igzip_inflate_test: LDLIBS += -lz -D_FILE_OFFSET_BITS=64
|
||||
igzip_inflate_test: LDLIBS += -lz
|
||||
igzip_igzip_inflate_test_LDADD = libisal.la
|
||||
igzip_igzip_inflate_test_LDFLAGS = -lz -D_FILE_OFFSET_BITS=64
|
||||
igzip_igzip_inflate_test_LDFLAGS = -lz
|
||||
igzip_igzip_hist_perf_LDADD = libisal.la
|
||||
igzip_fuzz_inflate: LDLIBS += -lz
|
||||
igzip_igzip_fuzz_inflate_LDADD = libisal.la
|
||||
|
@ -27,6 +27,7 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
@ -55,22 +56,12 @@ int usage(void)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int get_filesize(FILE * f)
|
||||
{
|
||||
int curr, end;
|
||||
|
||||
curr = ftell(f); /* Save current position */
|
||||
fseek(f, 0L, SEEK_END);
|
||||
end = ftell(f);
|
||||
fseek(f, curr, SEEK_SET); /* Restore position */
|
||||
return end;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in, *out = NULL;
|
||||
unsigned char *inbuf, *outbuf, *level_buf = NULL;
|
||||
int i, c, infile_size, iterations = 0, outbuf_size, inbuf_size = 0;
|
||||
int i, c, iterations = 0, inbuf_size = 0;
|
||||
uint64_t infile_size, outbuf_size;
|
||||
struct isal_huff_histogram histogram;
|
||||
struct isal_hufftables hufftables_custom;
|
||||
int level = 0, level_size = 0, avail_in;
|
||||
@ -203,7 +194,7 @@ int main(int argc, char *argv[])
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf(" file %s - in_size=%d out_size=%d iter=%d ratio=%3.1f%%",
|
||||
printf(" file %s - in_size=%lu out_size=%d iter=%d ratio=%3.1f%%",
|
||||
in_file_name, infile_size, stream.total_out, i,
|
||||
100.0 * stream.total_out / infile_size);
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <zlib.h>
|
||||
@ -6,22 +7,13 @@
|
||||
#include "test.h"
|
||||
|
||||
#define OUT_BUFFER_SIZE 64*1024
|
||||
int get_filesize(FILE * f)
|
||||
{
|
||||
int curr, end;
|
||||
|
||||
curr = ftell(f); /* Save current position */
|
||||
fseek(f, 0L, SEEK_END);
|
||||
end = ftell(f);
|
||||
fseek(f, curr, SEEK_SET); /* Restore position */
|
||||
return end;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in = NULL;
|
||||
unsigned char *in_buf = NULL, *isal_out_buf = NULL, *zlib_out_buf = NULL;
|
||||
int in_file_size, out_buf_size, zret, iret;
|
||||
uint64_t in_file_size;
|
||||
int out_buf_size, zret, iret;
|
||||
struct inflate_state *state = NULL;
|
||||
z_stream zstate;
|
||||
char z_msg_invalid_code_set[] = "invalid code lengths set";
|
||||
@ -53,7 +45,7 @@ int main(int argc, char *argv[])
|
||||
zlib_out_buf = malloc(OUT_BUFFER_SIZE);
|
||||
|
||||
if (state == NULL || in_buf == NULL || isal_out_buf == NULL || zlib_out_buf == NULL) {
|
||||
fprintf(stderr, "Failed to malloc input and outputs buffers");
|
||||
fprintf(stderr, "Failed to malloc input and outputs buffers\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
@ -40,17 +41,6 @@
|
||||
# define RUN_MEM_SIZE 2000000000
|
||||
#endif
|
||||
|
||||
int get_filesize(FILE * f)
|
||||
{
|
||||
int curr, end;
|
||||
|
||||
curr = ftell(f); /* Save current position */
|
||||
fseek(f, 0L, SEEK_END);
|
||||
end = ftell(f);
|
||||
fseek(f, curr, SEEK_SET); /* Restore position */
|
||||
return end;
|
||||
}
|
||||
|
||||
void print_histogram(struct isal_huff_histogram *histogram)
|
||||
{
|
||||
int i;
|
||||
@ -79,7 +69,8 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in;
|
||||
unsigned char *inbuf, *outbuf;
|
||||
int i, infile_size, outbuf_size, iterations, avail_in;
|
||||
int i, iterations, avail_in;
|
||||
uint64_t infile_size, outbuf_size;
|
||||
struct isal_huff_histogram histogram1, histogram2;
|
||||
|
||||
memset(&histogram1, 0, sizeof(histogram1));
|
||||
@ -136,7 +127,7 @@ int main(int argc, char *argv[])
|
||||
isal_update_histogram(inbuf, infile_size, &histogram1);
|
||||
perf_stop(&stop);
|
||||
|
||||
printf(" file %s - in_size=%d iter=%d\n", argv[1], infile_size, i);
|
||||
printf(" file %s - in_size=%lu iter=%d\n", argv[1], infile_size, i);
|
||||
printf("igzip_file: ");
|
||||
perf_print(stop, start, (long long)infile_size * i);
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "huff_codes.h"
|
||||
@ -43,23 +44,12 @@
|
||||
# define RUN_MEM_SIZE 1000000000
|
||||
#endif
|
||||
|
||||
int get_filesize(FILE * f)
|
||||
{
|
||||
int curr, end;
|
||||
|
||||
curr = ftell(f); /* Save current position */
|
||||
fseek(f, 0L, SEEK_END);
|
||||
end = ftell(f);
|
||||
fseek(f, curr, SEEK_SET); /* Restore position */
|
||||
return end;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in, *out = NULL;
|
||||
unsigned char *inbuf, *outbuf, *tempbuf;
|
||||
int i, infile_size, iterations, outbuf_size, check;
|
||||
uint64_t inbuf_size;
|
||||
int i, iterations, check;
|
||||
uint64_t infile_size, outbuf_size, inbuf_size;
|
||||
struct inflate_state state;
|
||||
|
||||
if (argc > 3 || argc < 2) {
|
||||
@ -192,7 +182,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf(" file %s - in_size=%d out_size=%lu iter=%d\n", argv[1],
|
||||
printf(" file %s - in_size=%lu out_size=%lu iter=%d\n", argv[1],
|
||||
infile_size, gstream.total_out, i);
|
||||
|
||||
printf("igzip_file: ");
|
||||
@ -221,7 +211,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
perf_stop(&stop);
|
||||
printf(" file %s - in_size=%d out_size=%d iter=%d\n", argv[1],
|
||||
printf(" file %s - in_size=%lu out_size=%d iter=%d\n", argv[1],
|
||||
infile_size, state.total_out, i);
|
||||
|
||||
printf("igzip_file: ");
|
||||
|
@ -27,17 +27,19 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <zlib.h>
|
||||
#include "igzip_lib.h"
|
||||
#include "huff_codes.h"
|
||||
#include "test.h"
|
||||
|
||||
/*Don't use file larger memory can support because compression and decompression
|
||||
* are done in a stateless manner. */
|
||||
# if __WORDSIZE == 64
|
||||
#if __WORDSIZE == 64
|
||||
#define MAX_INPUT_FILE_SIZE 2L*1024L*1024L*1024L
|
||||
# else
|
||||
#else
|
||||
#define MAX_INPUT_FILE_SIZE 512L*1024L*1024L
|
||||
#endif
|
||||
|
||||
@ -234,13 +236,10 @@ int main(int argc, char **argv)
|
||||
} else
|
||||
printf("Starting file %s", argv[i]);
|
||||
fflush(0);
|
||||
fseek(file, 0, SEEK_END);
|
||||
file_length = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
file_length -= ftell(file);
|
||||
file_length = get_filesize(file);
|
||||
if (file_length > MAX_INPUT_FILE_SIZE) {
|
||||
printf("\nFile too large to run on this test,"
|
||||
" Max 512MB for 32bit OS, 2GB for 64bit OS.\n");
|
||||
" Max 512MB for 32bit OS, 2GB for 64bit OS.\n");
|
||||
printf(" ... Fail\n");
|
||||
fclose(file);
|
||||
continue;
|
||||
|
@ -27,6 +27,7 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -35,6 +36,7 @@
|
||||
#include "crc_inflate.h"
|
||||
#include "inflate_std_vects.h"
|
||||
#include <math.h>
|
||||
#include "test.h"
|
||||
|
||||
#ifndef RANDOMS
|
||||
# define RANDOMS 0x40
|
||||
@ -1751,22 +1753,11 @@ int test_inflate(struct vect_result *in_vector)
|
||||
|
||||
}
|
||||
|
||||
int get_filesize(FILE * f)
|
||||
{
|
||||
int curr, end;
|
||||
|
||||
curr = ftell(f); /* Save current position */
|
||||
fseek(f, 0L, SEEK_END);
|
||||
end = ftell(f);
|
||||
fseek(f, curr, SEEK_SET); /* Restore position */
|
||||
return end;
|
||||
}
|
||||
|
||||
/* Run multiple compression tests on data stored in a file */
|
||||
int test_compress_file(char *file_name)
|
||||
{
|
||||
int ret = IGZIP_COMP_OK;
|
||||
uint32_t in_size;
|
||||
uint64_t in_size;
|
||||
uint8_t *in_buf = NULL;
|
||||
FILE *in_file = NULL;
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -89,22 +90,12 @@ int str_to_i(char *s)
|
||||
return i;
|
||||
}
|
||||
|
||||
int get_filesize(FILE * f)
|
||||
{
|
||||
int curr, end;
|
||||
|
||||
curr = ftell(f); /* Save current position */
|
||||
fseek(f, 0L, SEEK_END);
|
||||
end = ftell(f);
|
||||
fseek(f, curr, SEEK_SET); /* Restore position */
|
||||
return end;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in = stdin, *out = NULL;
|
||||
unsigned char *inbuf, *outbuf;
|
||||
int i = 0, c, infile_size, outbuf_size;
|
||||
int i = 0, c;
|
||||
uint64_t infile_size, outbuf_size;
|
||||
int segment_size = DEFAULT_SEG_SIZE;
|
||||
int sample_size = DEFAULT_SAMPLE_SIZE;
|
||||
int check_output = 1;
|
||||
@ -293,7 +284,7 @@ int main(int argc, char *argv[])
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
printf(" file %s - in_size=%d out_size=%d iter=%d ratio=%3.1f%%\n", argv[optind],
|
||||
printf(" file %s - in_size=%lu out_size=%d iter=%d ratio=%3.1f%%\n", argv[optind],
|
||||
infile_size, stream.total_out, i, 100.0 * stream.total_out / infile_size);
|
||||
|
||||
printf("igzip_file: ");
|
||||
|
@ -27,6 +27,7 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
@ -54,22 +55,12 @@ int usage(void)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int get_filesize(FILE * f)
|
||||
{
|
||||
int curr, end;
|
||||
|
||||
curr = ftell(f); /* Save current position */
|
||||
fseek(f, 0L, SEEK_END);
|
||||
end = ftell(f);
|
||||
fseek(f, curr, SEEK_SET); /* Restore position */
|
||||
return end;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in, *out = NULL;
|
||||
unsigned char *inbuf, *outbuf, *level_buf = NULL;
|
||||
int i, c, infile_size, iterations = 0, outbuf_size;
|
||||
int i, c, iterations = 0;
|
||||
uint64_t infile_size, outbuf_size;
|
||||
struct isal_huff_histogram histogram;
|
||||
struct isal_hufftables hufftables_custom;
|
||||
int level = 0, level_size = 0;
|
||||
@ -185,7 +176,7 @@ int main(int argc, char *argv[])
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf(" file %s - in_size=%d out_size=%d iter=%d ratio=%3.1f%%", in_file_name,
|
||||
printf(" file %s - in_size=%lu out_size=%d iter=%d ratio=%3.1f%%", in_file_name,
|
||||
infile_size, stream.total_out, i, 100.0 * stream.total_out / infile_size);
|
||||
|
||||
if (level == 0) {
|
||||
|
@ -27,6 +27,7 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
@ -41,22 +42,12 @@
|
||||
|
||||
struct isal_zstream stream;
|
||||
|
||||
int get_filesize(FILE * f)
|
||||
{
|
||||
int curr, end;
|
||||
|
||||
curr = ftell(f); /* Save current position */
|
||||
fseek(f, 0L, SEEK_END);
|
||||
end = ftell(f);
|
||||
fseek(f, curr, SEEK_SET); /* Restore position */
|
||||
return end;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
FILE *in, *out = NULL;
|
||||
unsigned char *inbuf, *outbuf;
|
||||
int i, infile_size, iterations, outbuf_size;
|
||||
int i, iterations;
|
||||
uint64_t infile_size, outbuf_size;
|
||||
|
||||
if (argc > 3 || argc < 2) {
|
||||
fprintf(stderr, "Usage: igzip_sync_flush_file_perf infile [outfile]\n"
|
||||
@ -144,7 +135,7 @@ int main(int argc, char *argv[])
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf(" file %s - in_size=%d out_size=%d iter=%d ratio=%3.1f%%\n", argv[1],
|
||||
printf(" file %s - in_size=%lu out_size=%d iter=%d ratio=%3.1f%%\n", argv[1],
|
||||
infile_size, stream.total_out, i, 100.0 * stream.total_out / infile_size);
|
||||
|
||||
printf("igzip_file: ");
|
||||
|
@ -27,7 +27,6 @@
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
#ifndef _TEST_H
|
||||
#define _TEST_H
|
||||
|
||||
@ -36,14 +35,16 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
// Use sys/time.h functions for time
|
||||
|
||||
#ifdef __unix__
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
struct perf{
|
||||
struct timeval tv;
|
||||
};
|
||||
|
||||
|
||||
#ifdef __unix__
|
||||
inline int perf_start(struct perf *p)
|
||||
{
|
||||
return gettimeofday(&(p->tv), 0);
|
||||
@ -72,7 +73,21 @@ inline void perf_print(struct perf stop, struct perf start, long long dsize)
|
||||
else
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
inline uint64_t get_filesize(FILE *fp)
|
||||
{
|
||||
uint64_t file_size;
|
||||
fpos_t pos, pos_curr;
|
||||
|
||||
fgetpos(fp, &pos_curr); /* Save current position */
|
||||
fseeko(fp, 0, SEEK_END);
|
||||
fgetpos(fp, &pos);
|
||||
file_size = *(uint64_t *)&pos;
|
||||
fsetpos(fp, &pos_curr); /* Restore position */
|
||||
|
||||
return file_size;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user