Skip to contentSkip to conversation

Convert sh scripts to C variants.

PATCH Superseded Marius Vlad 2 participants 5 messages Oct 25, 2016 Library code

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover Convert sh scripts to C variants.

This series adds some library support to help converting sh scripts to C version. Based on that I've converted drv_module_reload_basic and kms_sysfs_edid_timing. Other tests should follow. drv_module_reload requires the most boilerplate code.

The reason for so many changes is the fact that some code got moved so other users can use it. Secondly wrappers around libkmod and procps in igt_aux. Thirdly drv_module_reload has embedded tools/gem_info and tests/gem_exec_store in it, with minor modifications to allow running them as subtests. Finally, C is more verbose than sh.

Changes since v1:
lib/igt_aux: Addressed comments from Chris Wilson tests/drv_module_reload: Addressed comments from Chris Wilson and Petri Latvala tests/kms_sysfs_edid_timing: Addressed comments from Chris Wilson (Hopefully): Addressed comments from Jani Nikula.

Marius Vlad (3):
lib/{igt_sysfs,igt_aux}: Make available to other users kick_fbcon()
(unbind_fbcon()), and added helpers to igt_aux
(module loading/unloading, pkill)
tests/drv_module_reload: Convert sh script to C version. tests/kms_sysfs_edid_timing: Convert sh to C version.

 configure.ac                          |   2 +
 lib/Makefile.am                       |   2 +
 lib/igt_aux.c                         | 185 ++++++++++++++++
 lib/igt_aux.h                         |   6 +
 lib/igt_gvt.c                         |  43 +---
 lib/igt_sysfs.c                       |  54 +++++
 lib/igt_sysfs.h                       |   2 +
 tests/Makefile.am                     |   1 -
 tests/Makefile.sources                |   4 +-
 tests/drv_module_reload.c             | 394 ++++++++++++++++++++++++++++++++++
 tests/drv_module_reload_basic         | 105 ---------
 tests/gem_alive.c                     |  35 ---
 tests/intel-ci/fast-feedback.testlist |  13 +-
 tests/kms_sysfs_edid_timing           |  25 ---
 tests/kms_sysfs_edid_timing.c         | 107 +++++++++
 tools/Makefile.sources                |   1 +
 tools/intel_gem_info.c                |  35 +++
 17 files changed, 804 insertions(+), 210 deletions(-)
 create mode 100644 tests/drv_module_reload.c
 delete mode 100755 tests/drv_module_reload_basic
 delete mode 100644 tests/gem_alive.c
 delete mode 100755 tests/kms_sysfs_edid_timing
 create mode 100644 tests/kms_sysfs_edid_timing.c
 create mode 100644 tools/intel_gem_info.c
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH v2 1/3 lib/{igt_sysfs, igt_aux}: Make available to other users kick_fbcon() (unbind_fbcon()), and added helpers to igt_aux.

Previously under unbind_fbcon(), to disable/enable framebuffer console.

lib/igt_aux: Added helpers to help convert sh scripts to C version. libkmod and procps interface.

v2:
- Renamed libkmod helpers (Chris Wilson)
- Removed SIGTERM/SIGKILL case where we repeatedly tried to terminate the
process: just call kill(2) once (Chris Wilson)
- Removed redundant check in igt_kmod_unload(), igt_module_in_use() (Chris Wilson)
- Pass flags to igt_kmod_unload() from the caller (Chris Wilson)
- Removed useless function igt_kill() which acts just as kill(2) (Chris Wilson)

---
 configure.ac    |   2 +
 lib/Makefile.am |   2 +
 lib/igt_aux.c   | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_aux.h   |   6 ++
 lib/igt_gvt.c   |  43 +------------
 lib/igt_sysfs.c |  54 +++++++++++++++++
 lib/igt_sysfs.h |   2 +
 7 files changed, 253 insertions(+), 41 deletions(-)
configure.ac +2 -0
index 735cfd5..2c6e49d 100644
@@ -121,6 +121,8 @@ AC_SUBST(ASSEMBLER_WARN_CFLAGS)
 
 PKG_CHECK_MODULES(DRM, [libdrm])
 PKG_CHECK_MODULES(PCIACCESS, [pciaccess >= 0.10])
+PKG_CHECK_MODULES(KMOD, [libkmod])
+PKG_CHECK_MODULES(PROCPS, [libprocps])
 
 case "$target_cpu" in
 	x86*|i?86)
lib/Makefile.am +2 -0
index 4c0893d..e1737bd 100644
@@ -34,6 +34,8 @@ AM_CFLAGS += $(CAIRO_CFLAGS)
 libintel_tools_la_LIBADD = \
 	$(DRM_LIBS) \
 	$(PCIACCESS_LIBS) \
+	$(PROCPS_LIBS) \
+	$(KMOD_LIBS) \
 	$(CAIRO_LIBS) \
 	$(LIBUDEV_LIBS) \
 	$(LIBUNWIND_LIBS) \
lib/igt_aux.c +185 -0

197 lines not on this page · raw message

lib/igt_aux.h +6 -0
index d30196b..6dd9bb3 100644
@@ -264,4 +264,10 @@ double igt_stop_siglatency(struct igt_mean *result);
 void igt_set_module_param(const char *name, const char *val);
 void igt_set_module_param_int(const char *name, int val);
 
+int igt_pkill(int sig, const char *comm);
+
+int igt_kmod_is_loaded(const char *mod_name);
+int igt_kmod_load(const char *mod_name, const char *opts);
+int igt_kmod_unload(const char *mod_name, unsigned int flags);
+
 #endif /* IGT_AUX_H */
lib/igt_gvt.c +2 -41

57 lines not on this page · raw message

lib/igt_sysfs.c +54 -0

64 lines not on this page · raw message

lib/igt_sysfs.h +2 -0
index 4820066..a141894 100644
@@ -43,4 +43,6 @@ bool igt_sysfs_set_u32(int dir, const char *attr, uint32_t value);
 bool igt_sysfs_get_boolean(int dir, const char *attr);
 bool igt_sysfs_set_boolean(int dir, const char *attr, bool value);
 
+void kick_fbcon(bool enable);
+
 #endif /* __IGT_SYSFS_H__ */
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [PATCH i-g-t 1/3 v2] lib/{igt_sysfs, igt_aux}: Make available to other users kick_fbcon() (unbind_fbcon()), and added helpers to igt_aux.

Quoted 5 lines · Marius Vlad
lib/igt_aux.c +5 -0
+int
+igt_pkill(int sig, const char *comm)
+{
+	int err = 0;
+	PROCTAB *proc;

lib/igt_aux.c void igt_set_module_param_int(const char *name, int val) · line 1224

Quoted 10 lines
lib/igt_aux.c +10 -0
+	proc_t *proc_info;
+
+	proc = openproc(PROC_FILLCOM | PROC_FILLSTAT | PROC_FILLARG);
+	igt_assert(proc != NULL);
+
+	while ((proc_info = readproc(proc, NULL))) {
+		if (!strncasecmp(proc_info->cmd, comm, sizeof(proc_info->cmd))) {
+
+			if (kill(proc_info->tid, sig) < 0)
+				err = -1;

err = -errno;

(we like to keep kernel conventions where nicely applicable)

lib/igt_aux.c void igt_set_module_param_int(const char *name, int val) · line 1246

Quoted 12 lines
lib/igt_aux.c +11 -0
+
+			freeproc(proc_info);
+			break;
+		}
+		freeproc(proc_info);
+	}
+
+	closeproc(proc);
+	return err;
+}
 
+int

bool

lib/igt_aux.c void igt_set_module_param_int(const char *name, int val) · line 1258

Quoted 12 lines
lib/igt_aux.c +12 -0
+igt_kmod_is_loaded(const char *mod_name)
+{
+	struct kmod_list *mod, *list;
+	struct kmod_ctx *ctx;
+	int ret = 0;
+
+	ctx = kmod_new(NULL, NULL);
+	igt_assert(ctx != NULL);
+
+	if (kmod_module_new_from_loaded(ctx, &list) < 0) {
+		kmod_unref(ctx);
+		return -1;

Too confusing! :)

	if (kmod_module_new_from_loaded(ctx, &list) < 0)
		goto out;

lib/igt_aux.c void igt_set_module_param_int(const char *name, int val) · line 1265

Quoted 7 lines
lib/igt_aux.c +7 -0
+	}
+
+	kmod_list_foreach(mod, list) {
+		struct kmod_module *kmod = kmod_module_get_module(mod);
+		const char *kmod_name = kmod_module_get_name(kmod);
+
+		if (!strncasecmp(kmod_name, mod_name, strlen(kmod_name))) {

strncasecmp? So what happens if we load i915 and I915_bpo ?

lib/igt_aux.c void igt_set_module_param_int(const char *name, int val) · line 1273

Quoted 8 lines
lib/igt_aux.c +8 -0
+			kmod_module_unref(kmod);
+			ret = 1;
+			break;
+		}
+		kmod_module_unref(kmod);
+	}
+
+	kmod_module_unref_list(list);

out:

Quoted 18 lines
lib/igt_aux.c +17 -0
+	kmod_unref(ctx);
+
+	return ret;
+}
 
+int
+igt_kmod_load(const char *mod_name, const char *opts)
+{
+	struct kmod_ctx *ctx;
+	struct kmod_module *kmod;
+	int err = 0;
+
+	ctx = kmod_new(NULL, NULL);
+	igt_assert(ctx != NULL);
+
+
+	err = kmod_module_new_from_name(ctx, mod_name, &kmod);
+	if (err < 0) {

lib/igt_aux.c void igt_set_module_param_int(const char *name, int val) · line 1315

Quoted 10 lines
lib/igt_aux.c +10 -0
+		goto out;
+	}
+
+	err = kmod_module_insert_module(kmod, 0, opts);
+	if (err < 0) {
+		switch (err) {
+		case -EEXIST:
+			igt_info("Module %s already inserted\n",
+				 kmod_module_get_name(kmod));
+			err = -1;

Don't reduce the information, just return err; (as elsewhere)

Not sure if igt_info() makes sense, it will be noise for those expecting and handling the error.

Quoted 21 lines
lib/igt_aux.c +21 -0
+			break;
+		case -ENOENT:
+			igt_info("Unknown symbol in module %s or "
+				 "unknown parameter\n",
+				 kmod_module_get_name(kmod));
+			err = -1;
+			break;
+		default:
+			igt_info("Could not insert %s (%s)\n",
+				 kmod_module_get_name(kmod), strerror(-err));
+			err = -1;
+			break;
+		}
+	}
+out:
+	kmod_module_unref(kmod);
+	kmod_unref(ctx);
+
+	return err;
+}
+
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH v2 2/3 tests/drv_module_reload: Convert sh script to C version.

In reply to Marius Vlad

v2:
- embedded gem_alive and gem_exec_store into test (Chris Wilson)
- int main() to igt_main (Chris Wilson)
- moved tests/gem_alive -> tools/gem_info (Chris Wilson)
- added to intel-ci/fast-feedback.testlist (Petri Latvala)
- added hda_dynamic_debug() (Petri Latvala)
- renamed from tests/drv_module_reload_basic to tests/drv_module_reload (all subtests are basic and have been added to fast-feedback.testlist)

---
 tests/Makefile.am                     |   1 -
 tests/Makefile.sources                |   2 +-
 tests/drv_module_reload.c             | 394 ++++++++++++++++++++++++++++++++++
 tests/drv_module_reload_basic         | 105 ---------
 tests/gem_alive.c                     |  35 ---
 tests/intel-ci/fast-feedback.testlist |  13 +-
 tools/Makefile.sources                |   1 +
 tools/intel_gem_info.c                |  35 +++
 8 files changed, 443 insertions(+), 143 deletions(-)
 create mode 100644 tests/drv_module_reload.c
 delete mode 100755 tests/drv_module_reload_basic
 delete mode 100644 tests/gem_alive.c
 create mode 100644 tools/intel_gem_info.c
tests/Makefile.am +0 -1
index a408126..14a41ae 100644
@@ -26,7 +26,6 @@ noinst_PROGRAMS = \
 	$(NULL)
 
 pkglibexec_PROGRAMS = \
-	gem_alive \
 	gem_stress \
 	$(TESTS_progs) \
 	$(TESTS_progs_M) \
tests/Makefile.sources +1 -1
index 6d081c3..b1511c6 100644
@@ -211,6 +211,7 @@ TESTS_progs = \
 	kms_pwrite_crc \
 	kms_sink_crc_basic \
 	prime_udl \
+	drv_module_reload \
 	$(NULL)
 
 # IMPORTANT: The ZZ_ tests need to be run last!
@@ -221,7 +222,6 @@ TESTS_scripts_M = \
 TESTS_scripts = \
 	debugfs_emon_crash \
 	drv_debugfs_reader \
-	drv_module_reload_basic \
 	kms_sysfs_edid_timing \
 	sysfs_l3_parity \
 	test_rte_check \
tests/drv_module_reload.c new file +394 -0

394 lines not on this page · raw message

tests/drv_module_reload_basic deleted +0 -105

105 lines not on this page · raw message

tests/gem_alive.c deleted +0 -35
deleted file mode 100644
index 7544443..0000000
@@ -1,35 +0,0 @@
-#include "igt.h"
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <i915_drm.h>
-
-
-int main(void)
-{
-	struct drm_i915_gem_sw_finish arg = { 0 };
-	int fd;
-
-	signal(SIGALRM, SIG_IGN);
-
-	fd = __drm_open_driver(DRIVER_INTEL);
-	if (fd < 0)
-		return IGT_EXIT_SKIP;
-
-	alarm(1);
-	if (ioctl(fd, DRM_IOCTL_I915_GEM_SW_FINISH, &arg) == 0)
-		return IGT_EXIT_SKIP;
-
-	switch (errno) {
-	case ENOENT:
-		return 0;
-	case EIO:
-		return 1;
-	case EINTR:
-		return 2;
-	default:
-		return 3;
-	}
-}
tests/intel-ci/fast-feedback.testlist +12 -1
index f59ec98..3c516ed 100644
@@ -3,7 +3,18 @@ igt@core_prop_blob@basic
 igt@drv_getparams_basic@basic-eu-total
 igt@drv_getparams_basic@basic-subslice-total
 igt@drv_hangman@error-state-basic
-igt@drv_module_reload_basic
+igt@drv_module_reload@basic-reload
+igt@drv_module_reload@basic-gem-info
+igt@drv_module_reload@basic-exec-store-default
+igt@drv_module_reload@basic-exec-store-render
+igt@drv_module_reload@basic-exec-store-bsd
+igt@drv_module_reload@basic-exec-store-bsd1
+igt@drv_module_reload@basic-exec-store-bsd2
+igt@drv_module_reload@basic-exec-store-blt
+igt@drv_module_reload@basic-exec-store-vebox
+igt@drv_module_reload@basic-exec-store-all
+igt@drv_module_reload@basic-reload-inject
+igt@drv_module_reload@basic-reload-final
 igt@gem_basic@bad-close
 igt@gem_basic@create-close
 igt@gem_basic@create-fd-close
tools/Makefile.sources +1 -0
index 2bb6c8e..b84395c 100644
@@ -28,6 +28,7 @@ tools_prog_lists =		\
 	intel_residency		\
 	intel_stepping		\
 	intel_watermark		\
+	intel_gem_info		\
 	$(NULL)
 
 dist_bin_SCRIPTS = intel_gpu_abrt
tools/intel_gem_info.c new file +35 -0
new file mode 100644
index 0000000..7544443
@@ -0,0 +1,35 @@
+#include "igt.h"
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+#include <i915_drm.h>
+
+
+int main(void)
+{
+	struct drm_i915_gem_sw_finish arg = { 0 };
+	int fd;
+
+	signal(SIGALRM, SIG_IGN);
+
+	fd = __drm_open_driver(DRIVER_INTEL);
+	if (fd < 0)
+		return IGT_EXIT_SKIP;
+
+	alarm(1);
+	if (ioctl(fd, DRM_IOCTL_I915_GEM_SW_FINISH, &arg) == 0)
+		return IGT_EXIT_SKIP;
+
+	switch (errno) {
+	case ENOENT:
+		return 0;
+	case EIO:
+		return 1;
+	case EINTR:
+		return 2;
+	default:
+		return 3;
+	}
+}
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH v3 3/3 tests/kms_sysfs_edid_timing: Convert sh to C version.

In reply to Marius Vlad

v2:
- don't read cached values (Chris Wilson)
- warn on per connector, and fail per mean (Chris Wilson)

These are synthetic: 5us per connector, and 600us for all (as threshold).

---
 tests/Makefile.sources        |   2 +-
 tests/kms_sysfs_edid_timing   |  25 ----------
 tests/kms_sysfs_edid_timing.c | 107 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 26 deletions(-)
 delete mode 100755 tests/kms_sysfs_edid_timing
 create mode 100644 tests/kms_sysfs_edid_timing.c
tests/Makefile.sources +1 -1
index b1511c6..8af455a 100644
@@ -212,6 +212,7 @@ TESTS_progs = \
 	kms_sink_crc_basic \
 	prime_udl \
 	drv_module_reload \
+	kms_sysfs_edid_timing \
 	$(NULL)
 
 # IMPORTANT: The ZZ_ tests need to be run last!
@@ -222,7 +223,6 @@ TESTS_scripts_M = \
 TESTS_scripts = \
 	debugfs_emon_crash \
 	drv_debugfs_reader \
-	kms_sysfs_edid_timing \
 	sysfs_l3_parity \
 	test_rte_check \
 	tools_test \
tests/kms_sysfs_edid_timing deleted +0 -25
deleted file mode 100755
index 46ea540..0000000
@@ -1,25 +0,0 @@
-#!/bin/bash
-#
-# This check the time we take to read the content of all the possible connectors.
-# Without the edid -ENXIO patch (http://permalink.gmane.org/gmane.comp.video.dri.devel/62083),
-# we sometimes take a *really* long time. So let's just check for some reasonable timing here
-#
-
-DRM_LIB_ALLOW_NO_MASTER=1
-
-SOURCE_DIR="$( dirname "${BASH_SOURCE[0]}" )"
-. $SOURCE_DIR/drm_lib.sh
-
-TIME1=$(date +%s%N)
-cat $(find /sys/devices/|grep drm | grep /status) > /dev/null
-TIME2=$(date +%s%N)
-
-# time in ms
-RES=$(((TIME2 - TIME1) / 1000000))
-
-if [ $RES -gt 600 ]; then
-	echo "Talking to outputs took ${RES}ms, something is wrong"
-	exit $IGT_EXIT_FAILURE
-fi
-
-exit $IGT_EXIT_SUCCESS
tests/kms_sysfs_edid_timing.c new file +107 -0

107 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx