diff options
author | Dmitry Antipov <dmitry.antipov@linaro.org> | 2012-12-10 18:11:42 +0400 |
---|---|---|
committer | Dmitry Antipov <dmitry.antipov@linaro.org> | 2012-12-10 18:11:42 +0400 |
commit | 54df9be8928af8c9e62fbfc144f8e188a9cce880 (patch) | |
tree | 7ee0968095a349ee35785585c7c002e43af35e40 | |
parent | 5aa69d445a8b1cda2c5d04240434706bd1fd7341 (diff) | |
download | linaro-android-kernel-test-54df9be8928af8c9e62fbfc144f8e188a9cce880.tar.gz |
Include Makefile and local copy of ashmem.h for out-of-tree build.
Examine st_dev field of struct stat to check for device major number.
Signed-off-by: Dmitry Antipov <dmitry.antipov@linaro.org>
-rw-r--r-- | ashmemtest-basic/Makefile | 11 | ||||
-rw-r--r-- | ashmemtest-basic/ashmem.h | 45 | ||||
-rw-r--r-- | ashmemtest-basic/ashmemtest.c | 14 |
3 files changed, 68 insertions, 2 deletions
diff --git a/ashmemtest-basic/Makefile b/ashmemtest-basic/Makefile new file mode 100644 index 0000000..7ebe6f2 --- /dev/null +++ b/ashmemtest-basic/Makefile @@ -0,0 +1,11 @@ +# This file is here just to allow compiling the test without full Android setup. + +CROSS_COMPILE = +CC = $(CROSS_COMPILE)gcc +CFLAGS = -O2 -g + +ashmemtest: ashmemtest.c + $(CC) $(CFLAGS) -I. -o $@ $< + +clean: + $(RM) ashmemtest diff --git a/ashmemtest-basic/ashmem.h b/ashmemtest-basic/ashmem.h new file mode 100644 index 0000000..5a14837 --- /dev/null +++ b/ashmemtest-basic/ashmem.h @@ -0,0 +1,45 @@ +/* + * This file is here just to allow debugging the test without full Android setup. + * Original copyright is below. + * + ** utils/ashmem.h + ** + ** Copyright 2008 The Android Open Source Project + ** + ** This file is dual licensed. It may be redistributed and/or modified + ** under the terms of the Apache 2.0 License OR version 2 of the GNU + ** General Public License. + */ + +#ifndef _UTILS_ASHMEM_H +#define _UTILS_ASHMEM_H + +#include <linux/limits.h> +#include <linux/ioctl.h> + +#define ASHMEM_NAME_LEN 256 + +#define ASHMEM_NAME_DEF "dev/ashmem" + +/* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ +#define ASHMEM_NOT_REAPED 0 +#define ASHMEM_WAS_REAPED 1 + +/* Return values from ASHMEM_ISPINNED: Is the mapping now pinned or unpinned? */ +#define ASHMEM_NOW_UNPINNED 0 +#define ASHMEM_NOW_PINNED 1 + +#define __ASHMEMIOC 0x77 + +#define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN]) +#define ASHMEM_GET_NAME _IOR(__ASHMEMIOC, 2, char[ASHMEM_NAME_LEN]) +#define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) +#define ASHMEM_GET_SIZE _IO(__ASHMEMIOC, 4) +#define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) +#define ASHMEM_GET_PROT_MASK _IO(__ASHMEMIOC, 6) +#define ASHMEM_PIN _IOW(__ASHMEMIOC, 7, struct ashmem_pin) +#define ASHMEM_UNPIN _IOW(__ASHMEMIOC, 8, struct ashmem_pin) +#define ASHMEM_ISPINNED _IO(__ASHMEMIOC, 9) +#define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10) + +#endif /* _UTILS_ASHMEM_H */ diff --git a/ashmemtest-basic/ashmemtest.c b/ashmemtest-basic/ashmemtest.c index 7c80095..013bcdd 100644 --- a/ashmemtest-basic/ashmemtest.c +++ b/ashmemtest-basic/ashmemtest.c @@ -1,3 +1,7 @@ +/* + * Test for Android shared memory (ashmem) driver. + */ + #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> @@ -11,7 +15,13 @@ #include <stdint.h> #include <stdarg.h> -#include <utils/ashmem.h> /* frameworks/native/include/utils/ashmem.h */ +#ifdef ANDROID +/* In-tree compilation, use frameworks/native/include/utils/ashmem.h */ +#include <utils/ashmem.h> +#else +/* Freestanding compilation, use local copy */ +#include "ashmem.h" +#endif /* ANDROID */ #ifndef ASHMEM_MAJOR #define ASHMEM_MAJOR 10 /* misc device, should match MISC_DEVICE in linux/major.h */ @@ -72,7 +82,7 @@ void ashmem_basic (char *ashmemdev) fatal (errno, "can't stat %s (fd %d)", ashmemdev, fd); if (!S_ISCHR (st.st_mode)) fatal (0, "%s is not a character device", ashmemdev); - if (major (st.st_dev) != ASHMEM_MAJOR) + if (major (st.st_rdev) != ASHMEM_MAJOR) fatal (0, "%s is not a device with major %d", ashmemdev, ASHMEM_MAJOR); /* check that close works too */ |