Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe: Move test infra out of xe_pci.[ch]

Move code out of xe_pci.[ch] into tests/*.[ch], like is done in other
similar compilation units. Even if this is not part of "tests for
xe_pci.c", they are functions exported and required by other tests. It's
better not to clutter the module headers and sources with them.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
Link: https://lore.kernel.org/r/20230401085151.1786204-3-lucas.demarchi@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

authored by

Lucas De Marchi and committed by
Rodrigo Vivi
af049be5 d19ad0e8

+82 -60
+2
drivers/gpu/drm/xe/tests/xe_bo.c
··· 6 6 #include <kunit/test.h> 7 7 8 8 #include "tests/xe_bo_test.h" 9 + #include "tests/xe_pci_test.h" 10 + #include "tests/xe_test.h" 9 11 10 12 #include "xe_bo_evict.h" 11 13 #include "xe_pci.h"
+1
drivers/gpu/drm/xe/tests/xe_dma_buf.c
··· 6 6 #include <kunit/test.h> 7 7 8 8 #include "tests/xe_dma_buf_test.h" 9 + #include "tests/xe_pci_test.h" 9 10 10 11 #include "xe_pci.h" 11 12
+1
drivers/gpu/drm/xe/tests/xe_migrate.c
··· 6 6 #include <kunit/test.h> 7 7 8 8 #include "tests/xe_migrate_test.h" 9 + #include "tests/xe_pci_test.h" 9 10 10 11 #include "xe_pci.h" 11 12
+62
drivers/gpu/drm/xe/tests/xe_pci.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 AND MIT 2 + /* 3 + * Copyright © 2023 Intel Corporation 4 + */ 5 + 6 + #include "tests/xe_pci_test.h" 7 + 8 + #include "tests/xe_test.h" 9 + 10 + #include <kunit/test.h> 11 + 12 + struct kunit_test_data { 13 + int ndevs; 14 + xe_device_fn xe_fn; 15 + }; 16 + 17 + static int dev_to_xe_device_fn(struct device *dev, void *__data) 18 + 19 + { 20 + struct drm_device *drm = dev_get_drvdata(dev); 21 + struct kunit_test_data *data = __data; 22 + int ret = 0; 23 + int idx; 24 + 25 + data->ndevs++; 26 + 27 + if (drm_dev_enter(drm, &idx)) 28 + ret = data->xe_fn(to_xe_device(dev_get_drvdata(dev))); 29 + drm_dev_exit(idx); 30 + 31 + return ret; 32 + } 33 + 34 + /** 35 + * xe_call_for_each_device - Iterate over all devices this driver binds to 36 + * @xe_fn: Function to call for each device. 37 + * 38 + * This function iterated over all devices this driver binds to, and calls 39 + * @xe_fn: for each one of them. If the called function returns anything else 40 + * than 0, iteration is stopped and the return value is returned by this 41 + * function. Across each function call, drm_dev_enter() / drm_dev_exit() is 42 + * called for the corresponding drm device. 43 + * 44 + * Return: Zero or the error code of a call to @xe_fn returning an error 45 + * code. 46 + */ 47 + int xe_call_for_each_device(xe_device_fn xe_fn) 48 + { 49 + int ret; 50 + struct kunit_test_data data = { 51 + .xe_fn = xe_fn, 52 + .ndevs = 0, 53 + }; 54 + 55 + ret = driver_for_each_device(&xe_pci_driver.driver, NULL, 56 + &data, dev_to_xe_device_fn); 57 + 58 + if (!data.ndevs) 59 + kunit_skip(current->kunit_test, "test runs only on hardware\n"); 60 + 61 + return ret; 62 + }
+15
drivers/gpu/drm/xe/tests/xe_pci_test.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 AND MIT */ 2 + /* 3 + * Copyright © 2023 Intel Corporation 4 + */ 5 + 6 + #ifndef _XE_PCI_TEST_H_ 7 + #define _XE_PCI_TEST_H_ 8 + 9 + struct xe_device; 10 + 11 + typedef int (*xe_device_fn)(struct xe_device *); 12 + 13 + int xe_call_for_each_device(xe_device_fn xe_fn); 14 + 15 + #endif
+1 -51
drivers/gpu/drm/xe/xe_pci.c
··· 627 627 } 628 628 629 629 #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) 630 - struct kunit_test_data { 631 - int ndevs; 632 - xe_device_fn xe_fn; 633 - }; 634 - 635 - static int dev_to_xe_device_fn(struct device *dev, void *__data) 636 - 637 - { 638 - struct drm_device *drm = dev_get_drvdata(dev); 639 - struct kunit_test_data *data = __data; 640 - int ret = 0; 641 - int idx; 642 - 643 - data->ndevs++; 644 - 645 - if (drm_dev_enter(drm, &idx)) 646 - ret = data->xe_fn(to_xe_device(dev_get_drvdata(dev))); 647 - drm_dev_exit(idx); 648 - 649 - return ret; 650 - } 651 - 652 - /** 653 - * xe_call_for_each_device - Iterate over all devices this driver binds to 654 - * @xe_fn: Function to call for each device. 655 - * 656 - * This function iterated over all devices this driver binds to, and calls 657 - * @xe_fn: for each one of them. If the called function returns anything else 658 - * than 0, iteration is stopped and the return value is returned by this 659 - * function. Across each function call, drm_dev_enter() / drm_dev_exit() is 660 - * called for the corresponding drm device. 661 - * 662 - * Return: Zero or the error code of a call to @xe_fn returning an error 663 - * code. 664 - */ 665 - int xe_call_for_each_device(xe_device_fn xe_fn) 666 - { 667 - int ret; 668 - struct kunit_test_data data = { 669 - .xe_fn = xe_fn, 670 - .ndevs = 0, 671 - }; 672 - 673 - ret = driver_for_each_device(&xe_pci_driver.driver, NULL, 674 - &data, dev_to_xe_device_fn); 675 - 676 - if (!data.ndevs) 677 - kunit_skip(current->kunit_test, "test runs only on hardware\n"); 678 - 679 - return ret; 680 - } 630 + #include "tests/xe_pci.c" 681 631 #endif
-9
drivers/gpu/drm/xe/xe_pci.h
··· 6 6 #ifndef _XE_PCI_H_ 7 7 #define _XE_PCI_H_ 8 8 9 - #include "tests/xe_test.h" 10 - 11 9 int xe_register_pci_driver(void); 12 10 void xe_unregister_pci_driver(void); 13 11 14 - #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) 15 - struct xe_device; 16 - 17 - typedef int (*xe_device_fn)(struct xe_device *); 18 - 19 - int xe_call_for_each_device(xe_device_fn xe_fn); 20 - #endif 21 12 #endif