Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc22e19a authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'linux-kselftest-4.17-rc1' of...

Merge tag 'linux-kselftest-4.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest update from Shuah Khan:
 "This Kselftest update for 4.17-rc1 consists of:

   - Test build error fixes

   - Fixes to prevent intel_pstate from building on non-x86 systems.

   - New test for ion with vgem driver.

   - Change to print the test name to /dev/kmsg to add context to kernel
     failures if any uncovered from running the test.

   - Kselftest framework enhancements to add KSFT_TAP_LEVEL environment
     variable to prevent nested TAP headers being printed in the
     Kselftest output.

     Nested TAP13 headers could cause problems for some parsers. This
     change suppresses the nested headers from test programs and test
     shell scripts with changes to framework and Makefiles without
     changing the tests"

* tag 'linux-kselftest-4.17-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
  selftests/intel_pstate: Fix build rule for x86
  selftests: Print the test we're running to /dev/kmsg
  selftests/seccomp: Allow get_metadata to XFAIL
  selftests/android/ion: Makefile: fix build error
  selftests: futex Makefile add top level TAP header echo to RUN_TESTS
  selftests: Makefile set KSFT_TAP_LEVEL to prevent nested TAP headers
  selftests: lib.mk set KSFT_TAP_LEVEL to prevent nested TAP headers
  selftests: kselftest framework: add handling for TAP header level
  selftests: ion: Add simple test with the vgem driver
  selftests: ion: Remove some prints
parents 3612605a 6aa69043
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -67,6 +67,12 @@ ifndef BUILD
  BUILD := $(shell pwd)
endif

# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header
# printing from tests. Applicable to run_tests case where run_tests adds
# TAP header prior running tests and when a test program invokes another
# with system() call. Export it here to cover override RUN_TESTS defines.
export KSFT_TAP_LEVEL=`echo 1`

export BUILD
all:
	@for TARGET in $(TARGETS); do		\
@@ -126,11 +132,14 @@ ifdef INSTALL_PATH
	echo "else" >> $(ALL_SCRIPT)
	echo "  OUTPUT=/dev/stdout" >> $(ALL_SCRIPT)
	echo "fi" >> $(ALL_SCRIPT)
	echo "export KSFT_TAP_LEVEL=`echo 1`" >> $(ALL_SCRIPT)

	for TARGET in $(TARGETS); do \
		BUILD_TARGET=$$BUILD/$$TARGET;	\
		echo "echo ; echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
		echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT);	\
		echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
		echo "echo ========================================" >> $(ALL_SCRIPT); \
		echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \
		echo "cd $$TARGET" >> $(ALL_SCRIPT); \
		make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
		echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
+1 −0
Original line number Diff line number Diff line
ionapp_export
ionapp_import
ionmap_test
+3 −2
Original line number Diff line number Diff line

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

TEST_GEN_FILES := ionapp_export ionapp_import
TEST_GEN_FILES := ionapp_export ionapp_import ionmap_test

all: $(TEST_GEN_FILES)

@@ -14,3 +14,4 @@ include ../../lib.mk

$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c
$(OUTPUT)/ionapp_import: ionapp_import.c ipcsocket.c ionutils.c
$(OUTPUT)/ionmap_test: ionmap_test.c ionutils.c
+1 −0
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@ CONFIG_ANDROID=y
CONFIG_STAGING=y
CONFIG_ION=y
CONFIG_ION_SYSTEM_HEAP=y
CONFIG_DRM_VGEM=y
+136 −0
Original line number Diff line number Diff line
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <unistd.h>

#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <linux/dma-buf.h>

#include <drm/drm.h>

#include "ion.h"
#include "ionutils.h"

int check_vgem(int fd)
{
	drm_version_t version = { 0 };
	char name[5];
	int ret;

	version.name_len = 4;
	version.name = name;

	ret = ioctl(fd, DRM_IOCTL_VERSION, &version);
	if (ret)
		return 1;

	return strcmp(name, "vgem");
}

int open_vgem(void)
{
	int i, fd;
	const char *drmstr = "/dev/dri/card";

	fd = -1;
	for (i = 0; i < 16; i++) {
		char name[80];

		sprintf(name, "%s%u", drmstr, i);

		fd = open(name, O_RDWR);
		if (fd < 0)
			continue;

		if (check_vgem(fd)) {
			close(fd);
			continue;
		} else {
			break;
		}

	}
	return fd;
}

int import_vgem_fd(int vgem_fd, int dma_buf_fd, uint32_t *handle)
{
	struct drm_prime_handle import_handle = { 0 };
	int ret;

	import_handle.fd = dma_buf_fd;
	import_handle.flags = 0;
	import_handle.handle = 0;

	ret = ioctl(vgem_fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &import_handle);
	if (ret == 0)
		*handle = import_handle.handle;
	return ret;
}

void close_handle(int vgem_fd, uint32_t handle)
{
	struct drm_gem_close close = { 0 };

	close.handle = handle;
	ioctl(vgem_fd, DRM_IOCTL_GEM_CLOSE, &close);
}

int main()
{
	int ret, vgem_fd;
	struct ion_buffer_info info;
	uint32_t handle = 0;
	struct dma_buf_sync sync = { 0 };

	info.heap_type = ION_HEAP_TYPE_SYSTEM;
	info.heap_size = 4096;
	info.flag_type = ION_FLAG_CACHED;

	ret = ion_export_buffer_fd(&info);
	if (ret < 0) {
		printf("ion buffer alloc failed\n");
		return -1;
	}

	vgem_fd = open_vgem();
	if (vgem_fd < 0) {
		ret = vgem_fd;
		printf("Failed to open vgem\n");
		goto out_ion;
	}

	ret = import_vgem_fd(vgem_fd, info.buffd, &handle);

	if (ret < 0) {
		printf("Failed to import buffer\n");
		goto out_vgem;
	}

	sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_RW;
	ret = ioctl(info.buffd, DMA_BUF_IOCTL_SYNC, &sync);
	if (ret)
		printf("sync start failed %d\n", errno);

	memset(info.buffer, 0xff, 4096);

	sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_RW;
	ret = ioctl(info.buffd, DMA_BUF_IOCTL_SYNC, &sync);
	if (ret)
		printf("sync end failed %d\n", errno);

	close_handle(vgem_fd, handle);
	ret = 0;

out_vgem:
	close(vgem_fd);
out_ion:
	ion_close_buffer_fd(&info);
	printf("done.\n");
	return ret;
}
Loading