[PATCH] tests/kms_setmode: Dynamic crtc/connector combinations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Create crtc/connector combinations based on actual adapter
information obtained from drmModeRes.

Also set MAX_CRTCs to 6 for AMD GPUs.

Signed-off-by: Harry Wentland <harry.wentland at amd.com>
---
 tests/kms_setmode.c | 52 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/tests/kms_setmode.c b/tests/kms_setmode.c
index 430568a1c24e..3673cfb58951 100644
--- a/tests/kms_setmode.c
+++ b/tests/kms_setmode.c
@@ -31,15 +31,13 @@
 #include <unistd.h>
 #include <string.h>
 #include <sys/time.h>
-
+#include <math.h>
 #include "intel_bufmgr.h"
 
 #define MAX_CONNECTORS  10
-#define MAX_CRTCS       3
+#define MAX_CRTCS       6
 
 /* max combinations with repetitions */
-#define MAX_COMBINATION_COUNT   \
-	(MAX_CONNECTORS * MAX_CONNECTORS * MAX_CONNECTORS)
 #define MAX_COMBINATION_ELEMS   MAX_CRTCS
 
 static int drm_fd;
@@ -702,7 +700,8 @@ struct combination {
 
 struct combination_set {
 	int count;
-	struct combination items[MAX_COMBINATION_COUNT];
+	int capacity;
+	struct combination *items;
 };
 
 /*
@@ -716,7 +715,7 @@ static void iterate_combinations(int n, int k, bool allow_repetitions,
 	int v;
 
 	if (!k) {
-		igt_assert(set->count < ARRAY_SIZE(set->items));
+		igt_assert(set->count < set->capacity);
 		set->items[set->count++] = *comb;
 		return;
 	}
@@ -741,61 +740,74 @@ static void get_combinations(int n, int k, bool allow_repetitions,
 }
 
 static void test_combinations(const struct test_config *tconf,
-			      int connector_count)
+			      int crtc_num)
 {
 	struct combination_set connector_combs;
 	struct combination_set crtc_combs;
 	struct connector_config *cconfs;
 	int i;
 
-	if (connector_count > 2 && (tconf->flags & TEST_STEALING))
+	if (crtc_num > 2 && (tconf->flags & TEST_STEALING))
 		return;
 
-	get_combinations(tconf->resources->count_connectors, connector_count,
+	igt_assert(tconf->resources);
+
+	connector_combs.capacity = pow(tconf->resources->count_connectors,
+				       tconf->resources->count_crtcs + 1);
+	crtc_combs.capacity = pow(tconf->resources->count_crtcs,
+				  tconf->resources->count_crtcs + 1);
+
+	connector_combs.items = malloc(connector_combs.capacity * sizeof(struct combination));
+	crtc_combs.items = malloc(crtc_combs.capacity * sizeof(struct combination));
+
+	get_combinations(tconf->resources->count_connectors, crtc_num,
 			 false, &connector_combs);
-	get_combinations(tconf->resources->count_crtcs, connector_count,
+	get_combinations(tconf->resources->count_crtcs, crtc_num,
 			 true, &crtc_combs);
 
 	igt_info("Testing: %s %d connector combinations\n", tconf->name,
-		 connector_count);
+		 crtc_num);
 	for (i = 0; i < connector_combs.count; i++) {
 		int *connector_idxs;
 		int ret;
 		int j;
 
-		cconfs = malloc(sizeof(*cconfs) * connector_count);
+		cconfs = malloc(sizeof(*cconfs) * crtc_num);
 		igt_assert(cconfs);
 
 		connector_idxs = &connector_combs.items[i].elems[0];
 		ret = get_connectors(tconf->resources, connector_idxs,
-				     connector_count, cconfs);
+				     crtc_num, cconfs);
 		if (ret < 0)
 			goto free_cconfs;
 
 		for (j = 0; j < crtc_combs.count; j++) {
 			int *crtc_idxs = &crtc_combs.items[j].elems[0];
 			ret = assign_crtc_to_connectors(tconf, crtc_idxs,
-							connector_count,
+							crtc_num,
 						        cconfs);
 			if (ret < 0)
 				continue;
 
-			test_one_combination(tconf, cconfs, connector_count);
+			test_one_combination(tconf, cconfs, crtc_num);
 		}
 
-		free_connectors(cconfs, connector_count);
+		free_connectors(cconfs, crtc_num);
 free_cconfs:
 		free(cconfs);
 	}
+
+	free(connector_combs.items);
+	free(crtc_combs.items);
 }
 
 static void run_test(const struct test_config *tconf)
 {
-	int connector_num;
+	int crtc_num;
 
-	connector_num = tconf->flags & TEST_CLONE ? 2 : 1;
-	for (; connector_num <= tconf->resources->count_crtcs; connector_num++)
-		test_combinations(tconf, connector_num);
+	crtc_num = tconf->flags & TEST_CLONE ? 2 : 1;
+	for (; crtc_num <= tconf->resources->count_crtcs; crtc_num++)
+		test_combinations(tconf, crtc_num);
 }
 
 static int opt_handler(int opt, int opt_index, void *data)
-- 
2.11.0



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux