summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDerek Morton <derek.j.morton@intel.com>2015-12-14 09:59:17 +0000
committerDaniel Vetter <daniel.vetter@ffwll.ch>2015-12-16 10:21:14 +0100
commit3953d2dd22ea1c87aa77e3a9415aaf767d2ec3ed (patch)
tree5d12d427bfa4543d7ed445f082a0b1e984716e16 /lib
parent5a8d063e42c7b5843a0f069d4c2216f8f4fb81fe (diff)
gem_flink_race/prime_self_import: Improve test reliability
gem_flink_race and prime_self_import have subtests which read the number of open gem objects from debugfs to determine if objects have leaked during the test. However the test can fail sporadically if the number of gem objects changes due to other process activity. This patch introduces a change to check the number of gem objects several times to filter out any fluctuations. v2: Moved the common code to a library and made the loop android specific (Daniel Vetter) v3: Renamed get_stable_obj_count -> igt_get_stable_obj_count Signed-off-by: Derek Morton <derek.j.morton@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_debugfs.c58
-rw-r--r--lib/igt_debugfs.h6
2 files changed, 64 insertions, 0 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 2c3b1cfe..4322e8ee 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -667,3 +667,61 @@ void igt_enable_prefault(void)
{
igt_prefault_control(true);
}
+
+static int get_object_count(void)
+{
+ FILE *file;
+ int ret, scanned;
+
+ igt_drop_caches_set(DROP_RETIRE | DROP_ACTIVE);
+
+ file = igt_debugfs_fopen("i915_gem_objects", "r");
+
+ scanned = fscanf(file, "%i objects", &ret);
+ igt_assert_eq(scanned, 1);
+
+ return ret;
+}
+
+/**
+ * igt_get_stable_obj_count:
+ * @driver: fd to drm/i915 GEM driver
+ *
+ * This puts the driver into a stable (quiescent) state and then returns the
+ * current number of gem buffer objects as reported in the i915_gem_objects
+ * debugFS interface.
+ */
+int igt_get_stable_obj_count(int driver)
+{
+ int obj_count;
+ gem_quiescent_gpu(driver);
+ obj_count = get_object_count();
+ /* The test relies on the system being in the same state before and
+ * after the test so any difference in the object count is a result of
+ * leaks during the test. gem_quiescent_gpu() mostly achieves this but
+ * on android occasionally obj_count can still change briefly.
+ * The loop ensures obj_count has remained stable over several checks
+ */
+#ifdef ANDROID
+ {
+ int loop_count = 0;
+ int prev_obj_count = obj_count;
+ while (loop_count < 4) {
+ usleep(200000);
+ gem_quiescent_gpu(driver);
+ obj_count = get_object_count();
+ if (obj_count == prev_obj_count) {
+ loop_count++;
+ } else {
+ igt_debug("loop_count=%d, obj_count=%d, prev_obj_count=%d\n",
+ loop_count, obj_count, prev_obj_count);
+ loop_count = 0;
+ prev_obj_count = obj_count;
+ }
+
+ }
+ }
+#endif
+ return obj_count;
+}
+
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index bbf7f697..24018eb3 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -165,4 +165,10 @@ void igt_drop_caches_set(uint64_t val);
void igt_disable_prefault(void);
void igt_enable_prefault(void);
+/*
+ * Put the driver into a stable (quiescent) state and get the current number of
+ * gem buffer objects
+ */
+int igt_get_stable_obj_count(int driver);
+
#endif /* __IGT_DEBUGFS_H__ */