Skip to content

Commit

Permalink
Add script to run kunit-tests for evdi module
Browse files Browse the repository at this point in the history
Run ./ci/run_kunit to execute unit tests for evdi module
  • Loading branch information
synaptics-lspintzyk committed May 13, 2024
1 parent c27c9b7 commit 9884501
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ pipeline {
}
}
}
stage ('Run KUnit tests') {
steps {
sh '''#!/usr/bin/env bash
[ -d tmp/linux ] && (cd tmp/linux; git checkout -f master; git reset --hard origin/master)
./ci/run_kunit'''
}
}
stage ('Build against released kernels') {
steps {
sh '''#!/usr/bin/env bash
Expand Down
44 changes: 44 additions & 0 deletions ci/run_kunit
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#! /usr/bin/env bash
# Copyright (c) 2024 DisplayLink (UK) Ltd.

set -e
set -u

clone_linux()
{
echo "Clone linux repository"
local linux_mirror="https://oauth2:glpat-jeZZawHtkoZ3xLHWGCJQ@gitlab/ppd_posix/linux.git"
if curl -k --output /dev/null --silent --head --fail "$linux_mirror"; then
git -c http.sslVerify=false clone --depth 1 "$linux_mirror"
(cd linux; git config http.sslVerify false)
else
git clone --depth 1 https://github.com/torvalds/linux
fi
}

patch_linux_with_evdi_module()
{
local EVDI_REPO_DIR="$1"
local LINUX_DIR="$2"

[ -f "$LINUX_DIR/drivers/gpu/drm/evdi/Kconfig" ] && return

(cd "$LINUX_DIR"
ln -s -T "${EVDI_REPO_DIR}"/module drivers/gpu/drm/evdi
echo -e "\nsource \"drivers/gpu/drm/evdi/Kconfig\"" >> drivers/gpu/drm/Kconfig
echo "obj-\$(CONFIG_DRM_EVDI) += evdi/" >> drivers/gpu/drm/Makefile

make ARCH=um mrproper)
}

EVDI_REPO_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.."; pwd)
LINUX_DIR=$EVDI_REPO_DIR/tmp/linux
mkdir -p "$EVDI_REPO_DIR/tmp"
[ -d "${EVDI_REPO_DIR}"/tmp/linux ] || (cd "$EVDI_REPO_DIR/tmp"; clone_linux)

patch_linux_with_evdi_module "$EVDI_REPO_DIR" "$LINUX_DIR"

echo "Run kunit tests for evdi module"
(cd "${LINUX_DIR}"
./tools/testing/kunit/kunit.py run --kunitconfig=drivers/gpu/drm/evdi/tests/.kunitconfig)

2 changes: 1 addition & 1 deletion ci/run_style_check
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ result=0
./checkpatch.pl --terse --no-tree --ignore NEW_TYPEDEFS -f ./library/*
result=$((result || $?))

./checkpatch.pl --terse --no-tree --ignore LINUX_VERSION_CODE,PREFER_PR_LEVEL -f ./module/*
find ./module -type f -exec ./checkpatch.pl --terse --no-tree --ignore LINUX_VERSION_CODE,PREFER_PR_LEVEL -f {} +
result=$((result || $?))

rm "${files[@]}"
Expand Down
11 changes: 11 additions & 0 deletions module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,14 @@ config DRM_EVDI
retrieve contents (as a frame buffer) that system renders on it.
Say M/Y to add support for these devices via DRM/KMS interfaces.

config DRM_EVDI_KUNIT_TEST
tristate "KUnit tests for evdi" if !KUNIT_ALL_TESTS
depends on DRM_EVDI && KUNIT
default KUNIT_ALL_TESTS
help
KUnit tests for evdi DRM module.
This option is useful for kernel developers.
Please remember to provide tests for code you add.

If in doubt, say "N".

2 changes: 1 addition & 1 deletion module/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ ifneq ($(KERNELRELEASE),)

# inside kbuild
# Note: this can be removed once it is in kernel tree and Kconfig is properly used
CONFIG_DRM_EVDI := m

This comment has been minimized.

Copy link
@drupol

drupol Jul 19, 2024

This removal break the build on Gentoo and on Nix... and probably on some other distros.

Context: NixOS/nixpkgs#328219, #476

ccflags-y := -isystem include/uapi/drm $(CFLAGS) $(EL8FLAG) $(EL9FLAG) $(RPIFLAG)
evdi-y := evdi_platform_drv.o evdi_platform_dev.o evdi_sysfs.o evdi_modeset.o evdi_connector.o evdi_encoder.o evdi_drm_drv.o evdi_fb.o evdi_gem.o evdi_painter.o evdi_params.o evdi_cursor.o evdi_debug.o evdi_i2c.o
evdi-$(CONFIG_COMPAT) += evdi_ioc32.o
obj-$(CONFIG_DRM_EVDI) := evdi.o
obj-y += tests/

else

Expand Down
8 changes: 8 additions & 0 deletions module/tests/.kunitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CONFIG_KUNIT=y

CONFIG_DRM=y
CONFIG_MODULES=y
CONFIG_DRM_EVDI=y

CONFIG_DRM_KUNIT_TEST=y
CONFIG_DRM_EVDI_KUNIT_TEST=y
4 changes: 4 additions & 0 deletions module/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

ccflags-$(CONFIG_DRM_EVDI_KUNIT_TEST) += -I $(srctree)/$(src)/..
obj-$(CONFIG_DRM_EVDI_KUNIT_TEST) += evdi_test.o

39 changes: 39 additions & 0 deletions module/tests/evdi_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2024 DisplayLink (UK) Ltd.
*
* This file is subject to the terms and conditions of the GNU General Public
* License v2. See the file COPYING in the main directory of this archive for
* more details.
*/


#include <kunit/test.h>
#include <kunit/device.h>
#include "evdi_drm_drv.h"

static void test_evdi_create_drm_device(struct kunit *test)
{
struct device* parent = kunit_device_register(test, "/dev/card1");
struct drm_device* dev = evdi_drm_device_create(parent);

KUNIT_EXPECT_NOT_NULL(test, dev);

evdi_drm_device_remove(dev);

kunit_device_unregister(test, parent);
}

static struct kunit_case evdi_test_cases[] = {
KUNIT_CASE(test_evdi_create_drm_device),
{}
};

static struct kunit_suite evdi_test_suite = {
.name = "drm_evdi_tests",
.test_cases = evdi_test_cases,
};

kunit_test_suite(evdi_test_suite);

MODULE_LICENSE("GPL");

0 comments on commit 9884501

Please sign in to comment.