Skip to contentSkip to conversation

tests/pc8+: Only skip i2c subtest if i2c /dev interface is unavailable

PATCH New Daniel Vetter 1 participant 2 messages Oct 4, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 tests/pc8+: Only skip i2c subtest if i2c /dev interface is unavailable

Through the magic of igt_skip we only need to fail this subtest, not the entire thing.

---
 tests/pc8.c | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)
tests/pc8.c +13 -22
index 9070a6b..e93d928 100644
@@ -580,10 +580,6 @@ static bool test_i2c(struct mode_set_data *data)
 
 static bool setup_environment(void)
 {
-	int i2c_dev_files;
-	DIR *dev_dir;
-	struct dirent *dirent;
-
 	drm_fd = drm_open_any();
 	if (drm_fd <= 0)
 		return false;
@@ -603,23 +599,6 @@ static bool setup_environment(void)
 		return false;
 	}
 
-	/* Make sure the /dev/i2c-* files exist. */
-	dev_dir = opendir("/dev");
-	if (!dev_dir) {
-		printf("Can't open /dev.\n");
-		return false;
-	}
-	i2c_dev_files = 0;
-	while ((dirent = readdir(dev_dir))) {
-		if (strncmp(dirent->d_name, "i2c-", 4) == 0)
-			i2c_dev_files++;
-	}
-	closedir(dev_dir);
-	if (!i2c_dev_files) {
-		printf("No /dev/i2c-* files.\n");
-		return false;
-	}
-
 	/* Non-ULT machines don't support PC8+. */
 	if (!supports_pc8_plus_residencies()) {
 		printf("Machine doesn't support PC8+ residencies.\n");
@@ -701,7 +680,19 @@ static void batch_subtest(void)
 /* Try to use raw I2C, which also needs interrupts. */
 static void i2c_subtest(void)
 {
-	printf("Testing raw i2c protocol calls.\n");
+	int i2c_dev_files = 0;
+	DIR *dev_dir;
+	struct dirent *dirent;
+
+	/* Make sure the /dev/i2c-* files exist. */
+	dev_dir = opendir("/dev");
+	igt_assert(dev_dir);
+	while ((dirent = readdir(dev_dir))) {
+		if (strncmp(dirent->d_name, "i2c-", 4) == 0)
+			i2c_dev_files++;
+	}
+	closedir(dev_dir);
+	igt_require(i2c_dev_files);
 
 	enable_one_screen(&ms_data);
 	igt_assert(pc8_plus_disabled());
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 2/2 tests/pc8: Fail harder

If the test enviroment isn't properly set up we should fail the testcase, since otherwise there's no way to make sure a feature actually works.

To cut down on bug triaging time extract the basic test (which was previously used to skip all subtests) into a "basic" subtest.

Also fail the test hard if the msr interface isn't available. And switch all other check in setup_enviroment to igt_require.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=69838

---
 tests/pc8.c | 40 +++++++++++++---------------------------
 1 file changed, 13 insertions(+), 27 deletions(-)
tests/pc8.c +13 -27
index e93d928..79c64fc 100644
@@ -578,49 +578,33 @@ static bool test_i2c(struct mode_set_data *data)
 	return i2c_edids == drm_edids;
 }
 
-static bool setup_environment(void)
+static void setup_environment(void)
 {
 	drm_fd = drm_open_any();
-	if (drm_fd <= 0)
-		return false;
+	igt_assert(drm_fd >= 0);
 
 	init_mode_set_data(&ms_data);
 
 	/* Only Haswell supports the PC8 feature. */
-	if (!IS_HASWELL(ms_data.devid)) {
-		printf("PC8+ feature only supported on Haswell.\n");
-		return false;
-	}
+	igt_require(IS_HASWELL(ms_data.devid));
 
 	/* Make sure our Kernel supports MSR and the module is loaded. */
 	msr_fd = open("/dev/cpu/0/msr", O_RDONLY);
-	if (msr_fd == -1) {
-		printf("Can't open /dev/cpu/0/msr.\n");
-		return false;
-	}
+	igt_assert(msr_fd >= 0);
 
 	/* Non-ULT machines don't support PC8+. */
-	if (!supports_pc8_plus_residencies()) {
-		printf("Machine doesn't support PC8+ residencies.\n");
-		return false;
-	}
+	igt_require(supports_pc8_plus_residencies());
+}
 
+static void basic_subtest(void)
+{
 	/* Make sure PC8+ residencies move! */
 	disable_all_screens(&ms_data);
-	if (!pc8_plus_enabled()) {
-		printf("Machine is not reaching PC8+ states, please check its "
-		       "configuration.\n");
-		return false;
-	}
+	igt_assert(pc8_plus_enabled());
 
 	/* Make sure PC8+ residencies stop! */
 	enable_one_screen(&ms_data);
-	if (!pc8_plus_disabled()) {
-		printf("PC8+ residency didn't stop with screen enabled.\n");
-		return false;
-	}
-
-	return true;
+	igt_assert(pc8_plus_disabled());
 }
 
 static void teardown_environment(void)
@@ -758,8 +742,10 @@ int main(int argc, char *argv[])
 	 * PC8+. We don't want bug reports from cases where the machine is just
 	 * not properly configured. */
 	igt_fixture
-		igt_require(setup_environment());
+		setup_environment();
 
+	igt_subtest("basic")
+		basic_subtest();
 	igt_subtest("drm-resources-equal")
 		drm_resources_equal_subtest();
 	igt_subtest("batch")
Signature · 1 line
1.8.3.2