Merge "Use __ANDROID__ instead of HAVE_ANDROID_OS."
diff --git a/ext4_utils/contents.c b/ext4_utils/contents.c
index 8b2b0fd..2e3d903 100644
--- a/ext4_utils/contents.c
+++ b/ext4_utils/contents.c
@@ -18,7 +18,7 @@
#include <string.h>
#include <stdio.h>
-#ifdef HAVE_ANDROID_OS
+#ifdef __ANDROID__
#include <linux/capability.h>
#else
#include <private/android_filesystem_capability.h>
diff --git a/tests/bionic/libc/other/test_jpeg.c b/tests/bionic/libc/other/test_jpeg.c
deleted file mode 100644
index f481b9a..0000000
--- a/tests/bionic/libc/other/test_jpeg.c
+++ /dev/null
@@ -1,362 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* this small program is used to measure the performance of libjpeg decompression
- * algorithm...
- */
-
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include "jpeglib.h"
-#include <setjmp.h>
-#ifdef HAVE_ANDROID_OS
-#include <hardware_legacy/qemu_tracing.h>
-#endif
-
-#define USE_STDIO
-
-#define CHUNK 32768
-
-typedef struct {
- struct jpeg_source_mgr jpeg_mgr;
- char* base;
- char* cursor;
- char* end;
-} SourceMgrRec, *SourceMgr;
-
-static void
-_source_init_source(j_decompress_ptr cinfo)
-{
- SourceMgr src = (SourceMgr) cinfo->src;
-
- src->jpeg_mgr.next_input_byte = (unsigned char*)src->base,
- src->jpeg_mgr.bytes_in_buffer = src->end - src->base;
-}
-
-static int
-_source_fill_input_buffer(j_decompress_ptr cinfo)
-{
- SourceMgr src = (SourceMgr) cinfo->src;
-
- cinfo->err->error_exit((j_common_ptr)cinfo);
- return FALSE;
-}
-
-static void
-_source_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
-{
- SourceMgr src = (SourceMgr) cinfo->src;
-
- if (src->jpeg_mgr.next_input_byte + num_bytes > (unsigned char*)src->end ) {
- cinfo->err->error_exit((j_common_ptr)cinfo);
- }
-
- src->jpeg_mgr.next_input_byte += num_bytes;
- src->jpeg_mgr.bytes_in_buffer -= num_bytes;
-}
-
-static int
-_source_resync_to_restart( j_decompress_ptr cinfo, int desired)
-{
- SourceMgr src = (SourceMgr) cinfo->src;
-
- src->jpeg_mgr.next_input_byte = (unsigned char*)src->base;
- src->jpeg_mgr.bytes_in_buffer = src->end - src->base;
- return TRUE;
-}
-
-static void
-_source_term_source(j_decompress_ptr cinfo)
-{
- // nothing to do
-}
-
-static void
-_source_init( SourceMgr src, char* base, long size )
-{
- src->base = base;
- src->cursor = base;
- src->end = base + size;
-
- src->jpeg_mgr.init_source = _source_init_source;
- src->jpeg_mgr.fill_input_buffer = _source_fill_input_buffer;
- src->jpeg_mgr.skip_input_data = _source_skip_input_data;
- src->jpeg_mgr.resync_to_restart = _source_resync_to_restart;
- src->jpeg_mgr.term_source = _source_term_source;
-}
-
-
-typedef struct {
- struct jpeg_error_mgr jpeg_mgr;
- jmp_buf jumper;
- int volatile error;
-
-} ErrorMgrRec, *ErrorMgr;
-
-static void _error_exit(j_common_ptr cinfo)
-{
- ErrorMgr error = (ErrorMgr) cinfo->err;
-
- (*error->jpeg_mgr.output_message) (cinfo);
-
- /* Let the memory manager delete any temp files before we die */
- longjmp(error->jumper, -1);
-}
-
-#ifdef USE_STDIO
-int decompress(FILE* input_file, int dct_method, int disable_rgb)
-#else
-int decompress(char* data, long fsize)
-#endif
-{
- ErrorMgrRec errmgr;
- SourceMgrRec sourcemgr;
- struct jpeg_decompress_struct cinfo;
- int volatile error = 0;
- jmp_buf jumper;
- int isRGB;
- char* pixels;
- JSAMPLE* temprow;
-
- memset( &cinfo, 0, sizeof(cinfo) );
- memset( &errmgr, 0, sizeof(errmgr) );
- jpeg_create_decompress(&cinfo);
- cinfo.err = jpeg_std_error(&errmgr.jpeg_mgr);
-#if 0
- errmgr.jpeg_mgr.error_exit = _error_exit;
- errmgr.error = 0;
-#endif
-
- if (setjmp(errmgr.jumper) != 0) {
- fprintf(stderr, "returning error from jpeglib ---\n" );
- goto Exit;
- }
-
-#ifdef USE_STDIO
- /* Specify data source for decompression */
- jpeg_stdio_src(&cinfo, input_file);
-#else
- _source_init( &sourcemgr, data, fsize );
- cinfo.src = &sourcemgr.jpeg_mgr;
-#endif
-
- jpeg_read_header(&cinfo, 1);
-
- if (3 == cinfo.num_components && JCS_RGB == cinfo.out_color_space)
- isRGB = 1;
- else if (1 == cinfo.num_components && JCS_GRAYSCALE == cinfo.out_color_space)
- isRGB = 0; // could use Index8 config if we want...
- else {
- fprintf( stderr, "unsupported jpeg colorspace %d with %d components\n",
- cinfo.jpeg_color_space, cinfo.num_components );
- goto Exit;
- }
-
- cinfo.dct_method = dct_method;
- if (disable_rgb)
- cinfo.out_color_space = JCS_YCbCr;
-
- jpeg_start_decompress(&cinfo);
-
- temprow = calloc( cinfo.num_components * cinfo.output_width, sizeof(JSAMPLE) );
-
- {
- unsigned y;
- for (y = 0; y < cinfo.output_height; y++) {
- JSAMPLE* rowptr = temprow;
- (void)jpeg_read_scanlines(&cinfo, &rowptr, 1);
- }
- }
- jpeg_finish_decompress(&cinfo);
-
- free( temprow );
-Exit:
- jpeg_destroy_decompress(&cinfo);
- return error;
-}
-
-
-#define DEFAULT_REPEAT 10
-
-static void usage(void)
-{
- fprintf(stderr, "usage: test_jpeg [options] filename.jpg [filename2.jpg ...]\n" );
- fprintf(stderr, "options: -r NN repeat count (default %d)\n", DEFAULT_REPEAT );
- fprintf(stderr, " -d N idct method (0=default, 1=fastest, 2=slow, 3=float)\n" );
- fprintf(stderr, " -C no RGB color conversion (YCbCr instead)\n" );
- exit(1);
-}
-
-static double
-get_time_usec( void )
-{
-#ifdef HAVE_ANDROID_OS
- struct timespec ts;
-
- if ( clock_gettime( CLOCK_MONOTONIC, &ts ) < 0 )
- fprintf(stderr, "clock_gettime: %s\n", strerror(errno) );
-
- return ts.tv_sec*1e6 + ts.tv_nsec*1e-3;
-#else
- struct timeval tv;
- if (gettimeofday( &tv, NULL ) < 0)
- fprintf(stderr, "gettimeofday: %s\n", strerror(errno) );
-
- return tv.tv_sec*1000000. + tv.tv_usec*1.0;
-#endif
-}
-
-
-int main( int argc, char** argv )
-{
- FILE* f;
- int repeat_count = DEFAULT_REPEAT;
- int dct_method = JDCT_DEFAULT;
- int disable_rgb = 0;
- double usec0, usec1;
-
- if (argc < 2)
- usage();
-
- for ( ; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
- const char* arg = &argv[1][1];
- switch (arg[0]) {
- case 'r':
- if (arg[1] == 0) {
- if (argc < 3)
- usage();
- arg = argv[2];
- argc--;
- argv++;
- } else
- arg += 1;
-
- repeat_count = strtol(arg, NULL, 10);
-
- if (repeat_count <= 0)
- repeat_count = 1;
- break;
-
- case 'C':
- disable_rgb = 1;
- break;
-
- case 'd':
- if (arg[1] == 0) {
- if (argc < 3)
- usage();
- arg = argv[2];
- argc--;
- argv++;
- } else
- arg += 1;
-
- dct_method = strtol(arg, NULL, 10);
- switch (dct_method) {
- case 0:
- dct_method = JDCT_DEFAULT;
- break;
- case 1:
- dct_method = JDCT_IFAST;
- break;
- case 2:
- dct_method = JDCT_ISLOW;
- break;
- case 3:
- dct_method = JDCT_FLOAT;
- break;
- default:
- usage();
- }
- break;
-
- default:
- usage();
- }
- }
-
- for ( ; argc > 1; argc--, argv++ )
- {
- long fsize;
- char* data;
- FILE* f = fopen( argv[1], "rb" );
- int rr;
-
- if (f == NULL) {
- fprintf(stderr, "could not open '%s': %s\n", argv[1], strerror(errno) );
- continue;
- }
-
- fseek( f, 0, SEEK_END );
- fsize = ftell(f);
- fseek( f, 0, SEEK_SET );
-
- usec0 = get_time_usec();
-#ifdef HAVE_ANDROID_OS
- qemu_start_tracing();
-#endif
-#ifdef USE_STDIO
- for ( rr = repeat_count; rr > 0; rr-- ) {
- fseek( f, 0, SEEK_SET );
- decompress(f, dct_method, disable_rgb);
- }
- fclose( f );
-#else
-
- data = malloc( fsize );
- if (data == NULL) {
- if (fsize > 0)
- fprintf(stderr, "could not allocate %ld bytes to load '%s'\n", fsize, argv[1] );
- fclose(f);
- continue;
- }
- fread( data, 1, fsize, f );
- fclose(f);
-
- usec1 = get_time_usec() - usec0;
- printf( "compressed load: %10.2f ms (%ld bytes)\n", usec1*1e-3, fsize );
-
- usec0 = get_time_usec();
- for ( rr = repeat_count; rr > 0; rr -- )
- {
- decompress( data, fsize );
- }
- free( data );
-#endif
-#ifdef HAVE_ANDROID_OS
- qemu_stop_tracing();
-#endif
- usec1 = get_time_usec() - usec0;
- printf( "decompression took: %10.3f ms (%.2f KB/s, %d passes)\n", usec1/1e3, fsize*(1e6/1024)*repeat_count/usec1, repeat_count );
- }
- return 0;
-}
diff --git a/tests/bionic/libc/other/test_zlib.c b/tests/bionic/libc/other/test_zlib.c
deleted file mode 100644
index 3eae827..0000000
--- a/tests/bionic/libc/other/test_zlib.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-/* this small program is used to measure the performance of zlib's inflate
- * algorithm...
- */
-
-/* most code lifted from the public-domain http://www.zlib.net/zpipe.c */
-
-#include <zlib.h>
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#define CHUNK 32768
-
-int def(FILE *source, FILE *dest, int level)
-{
- int ret, flush;
- unsigned have;
- z_stream strm;
- unsigned char in[CHUNK];
- unsigned char out[CHUNK];
-
- /* allocate deflate state */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- ret = deflateInit(&strm, level);
- if (ret != Z_OK)
- return ret;
-
- /* compress until end of file */
- do {
- strm.avail_in = fread(in, 1, CHUNK, source);
- if (ferror(source)) {
- (void)deflateEnd(&strm);
- return Z_ERRNO;
- }
- flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
- strm.next_in = in;
-
- /* run deflate() on input until output buffer not full, finish
- compression if all of source has been read in */
- do {
- strm.avail_out = CHUNK;
- strm.next_out = out;
- ret = deflate(&strm, flush); /* no bad return value */
- have = CHUNK - strm.avail_out;
- if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
- (void)deflateEnd(&strm);
- return Z_ERRNO;
- }
- } while (strm.avail_out == 0);
-
- /* done when last data in file processed */
- } while (flush != Z_FINISH);
-
- /* clean up and return */
- (void)deflateEnd(&strm);
- return Z_OK;
-}
-
-
-int inf(FILE *source)
-{
- int ret;
- unsigned have;
- z_stream strm;
- static unsigned char in[CHUNK];
- static unsigned char out[CHUNK];
-
- /* allocate inflate state */
- strm.zalloc = Z_NULL;
- strm.zfree = Z_NULL;
- strm.opaque = Z_NULL;
- strm.avail_in = 0;
- strm.next_in = Z_NULL;
- ret = inflateInit(&strm);
- if (ret != Z_OK)
- return ret;
-
- /* decompress until deflate stream ends or end of file */
- do {
- strm.avail_in = fread(in, 1, CHUNK, source);
- if (ferror(source)) {
- (void)inflateEnd(&strm);
- return Z_ERRNO;
- }
- if (strm.avail_in == 0)
- break;
- strm.next_in = in;
-
- /* run inflate() on input until output buffer not full */
- do {
- strm.avail_out = CHUNK;
- strm.next_out = out;
- ret = inflate(&strm, Z_NO_FLUSH);
- switch (ret) {
- case Z_NEED_DICT:
- ret = Z_DATA_ERROR; /* and fall through */
- case Z_DATA_ERROR:
- case Z_MEM_ERROR:
- (void)inflateEnd(&strm);
- return ret;
- }
- } while (strm.avail_out == 0);
-
- /* done when inflate() says it's done */
- } while (ret != Z_STREAM_END);
-
- /* clean up and return */
- (void)inflateEnd(&strm);
- return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
-}
-
-#define DEFAULT_REPEAT 10
-#define DEFAULT_LEVEL 9
-
-static void usage(void)
-{
- fprintf(stderr, "usage: test_zlib [options] filename [filename2 ...]\n" );
- fprintf(stderr, "options: -r NN repeat count (default %d)\n", DEFAULT_REPEAT );
- fprintf(stderr, " -N set compression level (default %d)\n", DEFAULT_LEVEL );
- exit(1);
-}
-
-static double
-get_time_usec( void )
-{
-#ifdef HAVE_ANDROID_OS
- struct timespec ts;
-
- if ( clock_gettime( CLOCK_MONOTONIC, &ts ) < 0 )
- fprintf(stderr, "clock_gettime: %s\n", strerror(errno) );
-
- return ts.tv_sec*1e6 + ts.tv_nsec*1e-3;
-#else
- struct timeval tv;
- if (gettimeofday( &tv, NULL ) < 0)
- fprintf(stderr, "gettimeofday: %s\n", strerror(errno) );
-
- return tv.tv_sec*1000000. + tv.tv_usec*1.0;
-#endif
-}
-
-int main( int argc, char** argv )
-{
- FILE* f;
- char tempfile[256];
- int repeat_count = DEFAULT_REPEAT;
- int compression_level = DEFAULT_LEVEL;
- double usec0, usec1;
-
- if (argc < 2)
- usage();
-
- for ( ; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
- const char* arg = &argv[1][1];
- switch (arg[0]) {
- case 'r':
- if (arg[1] == 0) {
- if (argc < 3)
- usage();
- arg = argv[2];
- argc--;
- argv++;
- } else
- arg += 1;
-
- repeat_count = strtol(arg, NULL, 10);
-
- if (repeat_count <= 0)
- repeat_count = 1;
- break;
-
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- compression_level = arg[0] - '0';
- break;
-
- default:
- usage();
- }
- }
-
- sprintf(tempfile, "/tmp/ztest.%d", getpid() );
-
- for ( ; argc > 1; argc--, argv++ )
- {
- /* first, compress the file into a temporary storage */
- FILE* f = fopen(argv[1], "rb");
- FILE* out = NULL;
- long fsize;
- int ret, rr;
-
- if (f == NULL) {
- fprintf(stderr, "could not open '%s': %s\n", argv[1], strerror(errno) );
- continue;
- }
-
- printf( "testing %s\n", argv[1] );
- fseek( f, 0, SEEK_END );
- fsize = ftell(f);
- fseek( f, 0, SEEK_SET );
-
- out = fopen( tempfile, "wb" );
- if (out == NULL) {
- fprintf(stderr, "could not create '%s': %s\n", tempfile, strerror(errno));
- fclose(f);
- continue;
- }
-
- usec0 = get_time_usec();
-
- ret = def( f, out, compression_level );
-
- usec1 = get_time_usec() - usec0;
- printf( "compression took: %10.3f ms (%.2f KB/s)\n", usec1/1e3, fsize*(1e6/1024)/usec1 );
-
- fclose( out );
- fclose(f);
-
- usec0 = get_time_usec();
- f = fopen( tempfile, "rb" );
-
- for ( rr = repeat_count; rr > 0; rr -- )
- {
- fseek( f, 0, SEEK_SET );
- inf(f);
- }
- fclose( f );
- usec1 = get_time_usec() - usec0;
- printf( "decompression took: %10.3f ms (%.2f KB/s, %d passes)\n", usec1/1e3, fsize*(1e6/1024)*repeat_count/usec1, repeat_count );
- }
-
- unlink(tempfile);
- return 0;
-}