Skip to content

Commit

Permalink
Merge tag 'linux-kselftest-4.15-rc1' of git://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…linux/kernel/git/shuah/linux-kselftest

Pull kselftest updates from Shuah Khan:
 "This update to Kselftest consists of cleanup patches, fixes, and a new
  test for ion buffer sharing.

  Fixes include changes to skip firmware tests on systems that aren't
  configured to support them, as opposed to failing them"

* tag 'linux-kselftest-4.15-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests: firmware: skip unsupported custom firmware fallback tests
  selftests: firmware: skip unsupported async loading tests
  selftests: memfd_test.c: fix compilation warning.
  selftests/ftrace: Introduce exit_pass and exit_fail
  selftests: ftrace: add more config fragments
  android/ion: userspace test utility for ion buffer sharing
  selftests: remove obsolete kconfig fragment for cpu-hotplug
  selftests: vdso_test: support ARM64 targets
  selftests/ftrace: Do not use arch dependent do_IRQ as a target function
  selftests: breakpoints: fix compile error on breakpoint_test_arm64
  selftests: add missing test result status in memory-hotplug test
  selftests/exec: include cwd in long path calculation
  selftests: seccomp: update .gitignore with newly added tests
  selftests: vm: Update .gitignore with newly added tests
  selftests: timers: Update .gitignore with newly added tests
  • Loading branch information
Linus Torvalds committed Nov 17, 2017
2 parents 190b103 + c3e0d17 commit b1c2a34
Show file tree
Hide file tree
Showing 55 changed files with 1,303 additions and 71 deletions.
3 changes: 2 additions & 1 deletion tools/testing/selftests/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
TARGETS = bpf
TARGETS = android
TARGETS += bpf
TARGETS += breakpoints
TARGETS += capabilities
TARGETS += cpufreq
Expand Down
46 changes: 46 additions & 0 deletions tools/testing/selftests/android/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
SUBDIRS := ion

TEST_PROGS := run.sh

.PHONY: all clean

include ../lib.mk

all:
@for DIR in $(SUBDIRS); do \
BUILD_TARGET=$(OUTPUT)/$$DIR; \
mkdir $$BUILD_TARGET -p; \
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
#SUBDIR test prog name should be in the form: SUBDIR_test.sh
TEST=$$DIR"_test.sh"; \
if [ -e $$DIR/$$TEST ]; then
rsync -a $$DIR/$$TEST $$BUILD_TARGET/;
fi
done

override define RUN_TESTS
@cd $(OUTPUT); ./run.sh
endef

override define INSTALL_RULE
mkdir -p $(INSTALL_PATH)
install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)

@for SUBDIR in $(SUBDIRS); do \
BUILD_TARGET=$(OUTPUT)/$$SUBDIR; \
mkdir $$BUILD_TARGET -p; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$SUBDIR INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \
done;
endef

override define EMIT_TESTS
echo "./run.sh"
endef

override define CLEAN
@for DIR in $(SUBDIRS); do \
BUILD_TARGET=$(OUTPUT)/$$DIR; \
mkdir $$BUILD_TARGET -p; \
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
done
endef
2 changes: 2 additions & 0 deletions tools/testing/selftests/android/ion/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ionapp_export
ionapp_import
16 changes: 16 additions & 0 deletions tools/testing/selftests/android/ion/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

INCLUDEDIR := -I. -I../../../../../drivers/staging/android/uapi/
CFLAGS := $(CFLAGS) $(INCLUDEDIR) -Wall -O2 -g

TEST_GEN_FILES := ionapp_export ionapp_import

all: $(TEST_GEN_FILES)

$(TEST_GEN_FILES): ipcsocket.c ionutils.c

TEST_PROGS := ion_test.sh

include ../../lib.mk

$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c
$(OUTPUT)/ionapp_import: ionapp_import.c ipcsocket.c ionutils.c
101 changes: 101 additions & 0 deletions tools/testing/selftests/android/ion/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
ION BUFFER SHARING UTILITY
==========================
File: ion_test.sh : Utility to test ION driver buffer sharing mechanism.
Author: Pintu Kumar <pintu.ping@gmail.com>

Introduction:
-------------
This is a test utility to verify ION buffer sharing in user space
between 2 independent processes.
It uses unix domain socket (with SCM_RIGHTS) as IPC to transfer an FD to
another process to share the same buffer.
This utility demonstrates how ION buffer sharing can be implemented between
two user space processes, using various heap types.
The following heap types are supported by ION driver.
ION_HEAP_TYPE_SYSTEM (0)
ION_HEAP_TYPE_SYSTEM_CONTIG (1)
ION_HEAP_TYPE_CARVEOUT (2)
ION_HEAP_TYPE_CHUNK (3)
ION_HEAP_TYPE_DMA (4)

By default only the SYSTEM and SYSTEM_CONTIG heaps are supported.
Each heap is associated with the respective heap id.
This utility is designed in the form of client/server program.
The server part (ionapp_export) is the exporter of the buffer.
It is responsible for creating an ION client, allocating the buffer based on
the heap id, writing some data to this buffer and then exporting the FD
(associated with this buffer) to another process using socket IPC.
This FD is called as buffer FD (which is different than the ION client FD).

The client part (ionapp_import) is the importer of the buffer.
It retrives the FD from the socket data and installs into its address space.
This new FD internally points to the same kernel buffer.
So first it reads the data that is stored in this buffer and prints it.
Then it writes the different size of data (it could be different data) to the
same buffer.
Finally the buffer FD must be closed by both the exporter and importer.
Thus the same kernel buffer is shared among two user space processes using
ION driver and only one time allocation.

Prerequisite:
-------------
This utility works only if /dev/ion interface is present.
The following configs needs to be enabled in kernel to include ion driver.
CONFIG_ANDROID=y
CONFIG_STAGING=y
CONFIG_ION=y
CONFIG_ION_SYSTEM_HEAP=y

This utility requires to be run as root user.


Compile and test:
-----------------
This utility is made to be run as part of kselftest framework in kernel.
To compile and run using kselftest you can simply do the following from the
kernel top directory.
linux$ make TARGETS=android kselftest
Or you can also use:
linux$ make -C tools/testing/selftests TARGETS=android run_tests
Using the selftest it can directly execute the ion_test.sh script to test the
buffer sharing using ion system heap.
Currently the heap size is hard coded as just 10 bytes inside this script.
You need to be a root user to run under selftest.

You can also compile and test manually using the following steps:
ion$ make
These will generate 2 executable: ionapp_export, ionapp_import
Now you can run the export and import manually by specifying the heap type
and the heap size.
You can also directly execute the shell script to run the test automatically.
Simply use the following command to run the test.
ion$ sudo ./ion_test.sh

Test Results:
-------------
The utility is verified on Ubuntu-32 bit system with Linux Kernel 4.14.
Here is the snapshot of the test result using kselftest.

linux# make TARGETS=android kselftest
heap_type: 0, heap_size: 10
--------------------------------------
heap type: 0
heap id: 1
heap name: ion_system_heap
--------------------------------------
Fill buffer content:
0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
Sharing fd: 6, Client fd: 5
<ion_close_buffer_fd>: buffer release successfully....
Received buffer fd: 4
Read buffer content:
0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0x0 0x0 0x0 0x0 0x0 0x0
0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
Fill buffer content:
0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd 0xfd
0xfd 0xfd
<ion_close_buffer_fd>: buffer release successfully....
ion_test.sh: heap_type: 0 - [PASS]

ion_test.sh: done
4 changes: 4 additions & 0 deletions tools/testing/selftests/android/ion/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CONFIG_ANDROID=y
CONFIG_STAGING=y
CONFIG_ION=y
CONFIG_ION_SYSTEM_HEAP=y
143 changes: 143 additions & 0 deletions tools/testing/selftests/android/ion/ion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* ion.h
*
* Copyright (C) 2011 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/

/* This file is copied from drivers/staging/android/uapi/ion.h
* This local copy is required for the selftest to pass, when build
* outside the kernel source tree.
* Please keep this file in sync with its original file until the
* ion driver is moved outside the staging tree.
*/

#ifndef _UAPI_LINUX_ION_H
#define _UAPI_LINUX_ION_H

#include <linux/ioctl.h>
#include <linux/types.h>

/**
* enum ion_heap_types - list of all possible types of heaps
* @ION_HEAP_TYPE_SYSTEM: memory allocated via vmalloc
* @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
* @ION_HEAP_TYPE_CARVEOUT: memory allocated from a prereserved
* carveout heap, allocations are physically
* contiguous
* @ION_HEAP_TYPE_DMA: memory allocated via DMA API
* @ION_NUM_HEAPS: helper for iterating over heaps, a bit mask
* is used to identify the heaps, so only 32
* total heap types are supported
*/
enum ion_heap_type {
ION_HEAP_TYPE_SYSTEM,
ION_HEAP_TYPE_SYSTEM_CONTIG,
ION_HEAP_TYPE_CARVEOUT,
ION_HEAP_TYPE_CHUNK,
ION_HEAP_TYPE_DMA,
ION_HEAP_TYPE_CUSTOM, /*
* must be last so device specific heaps always
* are at the end of this enum
*/
};

#define ION_NUM_HEAP_IDS (sizeof(unsigned int) * 8)

/**
* allocation flags - the lower 16 bits are used by core ion, the upper 16
* bits are reserved for use by the heaps themselves.
*/

/*
* mappings of this buffer should be cached, ion will do cache maintenance
* when the buffer is mapped for dma
*/
#define ION_FLAG_CACHED 1

/**
* DOC: Ion Userspace API
*
* create a client by opening /dev/ion
* most operations handled via following ioctls
*
*/

/**
* struct ion_allocation_data - metadata passed from userspace for allocations
* @len: size of the allocation
* @heap_id_mask: mask of heap ids to allocate from
* @flags: flags passed to heap
* @handle: pointer that will be populated with a cookie to use to
* refer to this allocation
*
* Provided by userspace as an argument to the ioctl
*/
struct ion_allocation_data {
__u64 len;
__u32 heap_id_mask;
__u32 flags;
__u32 fd;
__u32 unused;
};

#define MAX_HEAP_NAME 32

/**
* struct ion_heap_data - data about a heap
* @name - first 32 characters of the heap name
* @type - heap type
* @heap_id - heap id for the heap
*/
struct ion_heap_data {
char name[MAX_HEAP_NAME];
__u32 type;
__u32 heap_id;
__u32 reserved0;
__u32 reserved1;
__u32 reserved2;
};

/**
* struct ion_heap_query - collection of data about all heaps
* @cnt - total number of heaps to be copied
* @heaps - buffer to copy heap data
*/
struct ion_heap_query {
__u32 cnt; /* Total number of heaps to be copied */
__u32 reserved0; /* align to 64bits */
__u64 heaps; /* buffer to be populated */
__u32 reserved1;
__u32 reserved2;
};

#define ION_IOC_MAGIC 'I'

/**
* DOC: ION_IOC_ALLOC - allocate memory
*
* Takes an ion_allocation_data struct and returns it with the handle field
* populated with the opaque handle for the allocation.
*/
#define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, \
struct ion_allocation_data)

/**
* DOC: ION_IOC_HEAP_QUERY - information about available heaps
*
* Takes an ion_heap_query structure and populates information about
* available Ion heaps.
*/
#define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \
struct ion_heap_query)

#endif /* _UAPI_LINUX_ION_H */
55 changes: 55 additions & 0 deletions tools/testing/selftests/android/ion/ion_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

heapsize=4096
TCID="ion_test.sh"
errcode=0

run_test()
{
heaptype=$1
./ionapp_export -i $heaptype -s $heapsize &
sleep 1
./ionapp_import
if [ $? -ne 0 ]; then
echo "$TCID: heap_type: $heaptype - [FAIL]"
errcode=1
else
echo "$TCID: heap_type: $heaptype - [PASS]"
fi
sleep 1
echo ""
}

check_root()
{
uid=$(id -u)
if [ $uid -ne 0 ]; then
echo $TCID: must be run as root >&2
exit 0
fi
}

check_device()
{
DEVICE=/dev/ion
if [ ! -e $DEVICE ]; then
echo $TCID: No $DEVICE device found >&2
echo $TCID: May be CONFIG_ION is not set >&2
exit 0
fi
}

main_function()
{
check_device
check_root

# ION_SYSTEM_HEAP TEST
run_test 0
# ION_SYSTEM_CONTIG_HEAP TEST
run_test 1
}

main_function
echo "$TCID: done"
exit $errcode
Loading

0 comments on commit b1c2a34

Please sign in to comment.