lib/drmtest: Move open device to separate function
PATCH 1/1 lib/drmtest: Move open device to separate function
While working on IGT code and during reviewes I've noticed that it could be nice to have function that is opening particular device. Let's move out conditions for opening device and rename __open_device to __search_and_open() function.
v2: Refactored open_device even more by getting device name once and returning fd for it. (Chris)
v3: Added name_size to __get_drm_device_name, removed unused is_X_device.
v4: Fixed cases with failing virtio_gpu
v5: Rebase, indent fixes
--- lib/drmtest.c | 108 ++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 60 deletions(-)
lib/drmtest.c +48 -60
@@ -75,12 +75,12 @@* and [batchbuffer](igt-gpu-tools-intel-batchbuffer.html) libraries as dependencies. */ -static int __get_drm_device_name (int fd,char *name) +static int __get_drm_device_name (int fd,char *name,int name_size) {drm_version_t version;memset (&version,0 ,sizeof (version)); - version.name_len =4 ; + version.name_len = name_size; version.name = name;if (!drmIoctl (fd,DRM_IOCTL_VERSION , &version)){
@@ -94,7 +94,7 @@ static bool __is_device(int fd, const char *expect) {char name[5 ] ="" ; -if (__get_drm_device_name (fd, name)) +if (__get_drm_device_name (fd, name,4 ))return false;return strcmp (expect, name) ==0 ;
@@ -105,26 +105,6 @@ bool is_i915_device(int fd)return __is_device (fd,"i915" ); } -static bool is_vc4_device (int fd) -{ -return __is_device (fd,"vc4" ); -} - -static bool is_vgem_device (int fd) -{ -return __is_device (fd,"vgem" ); -} - -static bool is_virtio_device (int fd) -{ -return __is_device (fd,"virt" ); -} - -static bool is_amd_device (int fd) -{ -return __is_device (fd,"amdg" ); -} -static bool has_known_intel_chipset (int fd) {struct drm_i915_getparam gp;
@@ -215,38 +195,58 @@ static void modprobe_i915(const char *name)igt_i915_driver_load (NULL ); } -static int __open_device (const char *base,int offset,unsigned int chipset) +static const struct module { +unsigned int bit; +const char *module; +void (*modprobe)(const char *name); + } modules[] = { + {DRIVER_AMDGPU ,"amdgpu" }, + {DRIVER_INTEL ,"i915" , modprobe_i915 }, + {DRIVER_VC4 ,"vc4" }, + {DRIVER_VGEM ,"vgem" }, + {DRIVER_VIRTIO ,"virtio-gpu" }, + {DRIVER_VIRTIO ,"virtio_gpu" }, + {} + }; + +static int open_device (const char *name,unsigned int chipset) +{ +int fd; +char dev_name[16 ] ="" ; +int chip =DRIVER_ANY ; + + fd =open (name,O_RDWR ); +if (fd ==-1 ) +return -1 ; + +if (__get_drm_device_name (fd, dev_name, (sizeof (dev_name) -1 )) ==-1 ) +return -1 ; + +for (const struct module *m = modules; m->module; m++) { +if (strcmp (m->module, dev_name) ==0 ) { + chip = m->bit; +break ; + } + } +if (chipset & chip) +return fd; + +close (fd); +return -1 ; +} + +static int __search_and_open (const char *base,int offset,unsigned int chipset) {for (int i =0 ; i <16 ; i++) {char name[80 ];int fd;sprintf (name,"%s%u" , base, i + offset); - fd =open (name,O_RDWR ); + fd =open_device (name, chipset);if (fd ==-1 )continue ; - -if (chipset &DRIVER_INTEL &&is_i915_device (fd) && -has_known_intel_chipset (fd)) -return fd; - -if (chipset &DRIVER_VC4 &&is_vc4_device (fd)) -return fd; - -if (chipset &DRIVER_VGEM &&is_vgem_device (fd)) +else return fd; - -if (chipset &DRIVER_VIRTIO &&is_virtio_device (fd)) -return fd; - -if (chipset &DRIVER_AMDGPU &&is_amd_device (fd)) -return fd; - -/* Only VGEM-specific tests should be run on VGEM */ -if (chipset ==DRIVER_ANY && !is_vgem_device (fd)) -return fd; - -close (fd); }return -1 ;
@@ -255,21 +255,9 @@ static int __open_device(const char *base, int offset, unsigned int chipset)static int __open_driver (const char *base,int offset,unsigned int chipset) {static pthread_mutex_t mutex =PTHREAD_MUTEX_INITIALIZER ; -static const struct module { -unsigned int bit; -const char *module; -void (*modprobe)(const char *name); - } modules[] = { - {DRIVER_AMDGPU ,"amdgpu" }, - {DRIVER_INTEL ,"i915" , modprobe_i915 }, - {DRIVER_VC4 ,"vc4" }, - {DRIVER_VGEM ,"vgem" }, - {DRIVER_VIRTIO ,"virtio-gpu" }, - {} - };int fd; - fd =__open_device (base, offset, chipset); + fd =__search_and_open (base, offset, chipset);if (fd !=-1 )return fd;
@@ -284,7 +272,7 @@ static int __open_driver(const char *base, int offset, unsigned int chipset) }pthread_mutex_unlock (&mutex); -return __open_device (base, offset, chipset); +return __search_and_open (base, offset, chipset); }/**
Signature · 6 lines
2.17.1 _______________________________________________ igt-dev mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/igt-dev
Patchwork
CI[igt-dev] ✓ Fi.CI.BAT: success for lib/drmtest: Move open device to separate function (rev5)
== Series Details ==
== Series Details ==
Series: lib/drmtest: Move open device to separate function (rev5)
URL : https://patchwork.freedesktop.org/series/48929/
State : success
== Summary ==
= CI Bug Log - changes from CI_DRM_4749 -> IGTPW_1767 =
== Summary - SUCCESS ==
No regressions found.
External URL: https://patchwork.freedesktop.org/api/1.0/series/48929/revisions/5/mbox/
== Known issues ==
Here are the changes found in IGTPW_1767 that come from known issues:
=== IGT changes ===
==== Issues hit ====
igt@drv_selftest@live_coherency:
fi-gdg-551: PASS -> DMESG-FAIL (fdo#107164)
igt@kms_chamelium@dp-edid-read:
fi-kbl-7500u: PASS -> FAIL (fdo#103841)
igt@kms_pipe_crc_basic@suspend-read-crc-pipe-b:
{fi-byt-clapper}: PASS -> FAIL (fdo#103191, fdo#107362)
fi-snb-2520m: PASS -> INCOMPLETE (fdo#103713)
{igt@pm_rpm@module-reload}:
fi-cnl-psr: PASS -> WARN (fdo#107708, fdo#107602)
==== Possible fixes ====
{igt@kms_psr@primary_page_flip}:
fi-cnl-psr: FAIL (fdo#107336) -> PASS {name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).
fdo#103191 https://bugs.freedesktop.org/show_bug.cgi?id=103191
fdo#103713 https://bugs.freedesktop.org/show_bug.cgi?id=103713
fdo#103841 https://bugs.freedesktop.org/show_bug.cgi?id=103841
fdo#107164 https://bugs.freedesktop.org/show_bug.cgi?id=107164
fdo#107336 https://bugs.freedesktop.org/show_bug.cgi?id=107336
fdo#107362 https://bugs.freedesktop.org/show_bug.cgi?id=107362
fdo#107602 https://bugs.freedesktop.org/show_bug.cgi?id=107602
fdo#107708 https://bugs.freedesktop.org/show_bug.cgi?id=107708
== Participating hosts (52 -> 47) ==
Missing (5): fi-ctg-p8600 fi-ilk-m540 fi-byt-squawks fi-bsw-cyan fi-hsw-4200u
== Build changes ==
* IGT: IGT_4616 -> IGTPW_1767
CI_DRM_4749: 4a46c18fad0de38a78b4b0c848892de494324a17 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_1767: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1767/
IGT_4616: 5800e46c6f851c370c944a7cb169e99657239f8d @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1767/issues.html
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Patchwork
CI[igt-dev] ✓ Fi.CI.IGT: success for lib/drmtest: Move open device to separate function (rev5)
In reply to Katarzyna Dec== Series Details ==
== Series Details ==
Series: lib/drmtest: Move open device to separate function (rev5)
URL : https://patchwork.freedesktop.org/series/48929/
State : success
== Summary ==
= CI Bug Log - changes from IGT_4616_full -> IGTPW_1767_full =
== Summary - SUCCESS ==
No regressions found.
External URL: https://patchwork.freedesktop.org/api/1.0/series/48929/revisions/5/mbox/
== Known issues ==
Here are the changes found in IGTPW_1767_full that come from known issues:
=== IGT changes ===
==== Issues hit ====
igt@gem_exec_schedule@pi-ringfull-blt:
shard-glk: NOTRUN -> FAIL (fdo#103158)
igt@gem_exec_schedule@pi-ringfull-bsd1:
shard-kbl: NOTRUN -> FAIL (fdo#103158)
igt@kms_flip@2x-dpms-vs-vblank-race:
shard-glk: PASS -> FAIL (fdo#103060)
igt@kms_flip@flip-vs-expired-vblank:
shard-glk: PASS -> FAIL (fdo#105363)
igt@kms_frontbuffer_tracking@fbc-1p-primscrn-indfb-msflip-blt:
shard-glk: PASS -> FAIL (fdo#103167) +1
igt@kms_vblank@pipe-c-ts-continuation-dpms-suspend:
shard-kbl: PASS -> INCOMPLETE (fdo#103665)
igt@perf_pmu@rc6-runtime-pm:
shard-glk: PASS -> FAIL (fdo#105010)
shard-apl: PASS -> FAIL (fdo#105010)
shard-kbl: PASS -> FAIL (fdo#105010)
==== Possible fixes ====
igt@drv_suspend@shrink:
shard-snb: INCOMPLETE (fdo#105411, fdo#106886) -> PASS
shard-kbl: INCOMPLETE (fdo#106886, fdo#103665) -> PASS
igt@gem_ppgtt@blt-vs-render-ctxn:
shard-kbl: INCOMPLETE (fdo#103665, fdo#106023) -> PASS
igt@kms_cursor_legacy@2x-long-flip-vs-cursor-atomic:
shard-glk: FAIL (fdo#104873) -> PASS
igt@kms_cursor_legacy@cursor-vs-flip-varying-size:
shard-hsw: FAIL (fdo#103355) -> PASS
igt@kms_frontbuffer_tracking@fbc-1p-primscrn-spr-indfb-draw-mmap-wc:
shard-glk: FAIL (fdo#103167) -> PASS
igt@kms_plane_multiple@atomic-pipe-a-tiling-x:
shard-snb: FAIL (fdo#103166) -> PASS
igt@kms_setmode@basic:
shard-kbl: FAIL (fdo#99912) -> PASS fdo#103060 https://bugs.freedesktop.org/show_bug.cgi?id=103060
fdo#103158 https://bugs.freedesktop.org/show_bug.cgi?id=103158
fdo#103166 https://bugs.freedesktop.org/show_bug.cgi?id=103166
fdo#103167 https://bugs.freedesktop.org/show_bug.cgi?id=103167
fdo#103355 https://bugs.freedesktop.org/show_bug.cgi?id=103355
fdo#103665 https://bugs.freedesktop.org/show_bug.cgi?id=103665
fdo#104873 https://bugs.freedesktop.org/show_bug.cgi?id=104873
fdo#105010 https://bugs.freedesktop.org/show_bug.cgi?id=105010
fdo#105363 https://bugs.freedesktop.org/show_bug.cgi?id=105363
fdo#105411 https://bugs.freedesktop.org/show_bug.cgi?id=105411
fdo#106023 https://bugs.freedesktop.org/show_bug.cgi?id=106023
fdo#106886 https://bugs.freedesktop.org/show_bug.cgi?id=106886
fdo#99912 https://bugs.freedesktop.org/show_bug.cgi?id=99912
== Participating hosts (5 -> 5) ==
No changes in participating hosts
== Build changes ==
* IGT: IGT_4616 -> IGTPW_1767
* Linux: CI_DRM_4748 -> CI_DRM_4749
CI_DRM_4748: 6caeb081ceb9282503439565e7093c1032758289 @ git://anongit.freedesktop.org/gfx-ci/linux
CI_DRM_4749: 4a46c18fad0de38a78b4b0c848892de494324a17 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_1767: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1767/
IGT_4616: 5800e46c6f851c370c944a7cb169e99657239f8d @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
== Logs ==
For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_1767/shards.html
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Quoting Katarzyna Dec (2018-08-31 14:57:16)
Quoted 11 lines
While working on IGT code and during reviewes I've noticed that it could be nice to have function that is opening particular device. Let's move out conditions for opening device and rename
__open_deviceto__search_and_open()function.v2: Refactored
open_deviceeven more by getting device name once and returning fd for it. (Chris)
v3: Addedname_sizeto__get_drm_device_name, removed unusedis_X_device.
v4: Fixed cases with failingvirtio_gpu
v5: Rebase, indent fixes
Quoted 3 lines
Signed-off-by Katarzyna Dec <[email protected]>Cc Daniele Ceraolo Spurio <[email protected]>Cc Chris Wilson <[email protected]>
Tidied, reviewed and pushed.
-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev