diff mbox

[i-g-t,4/8] tests/perf: Add testcase to verify pid

Message ID 1504778877-18822-5-git-send-email-sagar.a.kamble@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

sagar.a.kamble@intel.com Sept. 7, 2017, 10:07 a.m. UTC
Signed-off-by: Sagar Arun Kamble <sagar.a.kamble@intel.com>
---
 tests/intel_perf_dapc.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
diff mbox

Patch

diff --git a/tests/intel_perf_dapc.c b/tests/intel_perf_dapc.c
index 82cb8e6..afd49f4 100644
--- a/tests/intel_perf_dapc.c
+++ b/tests/intel_perf_dapc.c
@@ -862,6 +862,79 @@  test_perf_ctxid(void)
 	igt_waitchildren();
 }
 
+struct oa_pid_sample {
+	uint64_t pid;
+	uint8_t oa_report[];
+};
+
+static void
+verify_pid(uint8_t *perf_reports, int num_reports, size_t report_size,
+	   uint64_t pid)
+{
+	struct oa_pid_sample *sample;
+	uint32_t *oa_report;
+
+	for (int i = 0; i < num_reports; i++) {
+		size_t offset = i * report_size;
+
+		sample = (struct oa_pid_sample *) (perf_reports + offset);
+		oa_report = (uint32_t *) sample->oa_report;
+
+		igt_debug("read report: pid= %lu, reason = %x, "
+			  "timestamp = %x\n",
+			  sample->pid, oa_report[0], oa_report[1]);
+
+		if (!oa_report[0])
+			igt_assert(sample->pid == pid);
+	}
+}
+
+static void
+test_perf_pid(void)
+{
+	uint64_t properties[] = {
+		/* Include OA reports in samples */
+		DRM_I915_PERF_PROP_SAMPLE_OA, true,
+
+		/* OA unit configuration */
+		DRM_I915_PERF_PROP_OA_METRICS_SET, test_metric_set_id,
+		DRM_I915_PERF_PROP_OA_FORMAT, test_oa_format,
+		DRM_I915_PERF_PROP_OA_EXPONENT, oa_exp_1_millisec,
+
+		/* CS parameters */
+		DRM_I915_PERF_PROP_ENGINE, I915_EXEC_RENDER,
+		DRM_I915_PERF_PROP_SAMPLE_PID, true,
+	};
+	struct drm_i915_perf_open_param param = {
+		.flags = I915_PERF_FLAG_FD_CLOEXEC,
+		.num_properties = sizeof(properties) / 16,
+		.properties_ptr = to_user_pointer(properties),
+	};
+
+	/* should be default, but just to be sure... */
+	write_u64_file("/proc/sys/dev/i915/perf_stream_paranoid", 1);
+
+	igt_fork(child, 1) {
+		int prop_size = ARRAY_SIZE(properties);
+		int num_reports = 10;
+		int report_size = get_perf_report_size(properties, prop_size,
+						       test_oa_format);
+		int total_size = num_reports * report_size;
+		uint8_t *perf_reports = malloc(total_size);
+		uint64_t pid = getpid();
+
+		igt_assert(perf_reports);
+
+		perf_stream_capture_workload_samples(&param, perf_reports,
+						     num_reports, report_size,
+						     NULL);
+		verify_pid(perf_reports, num_reports, report_size, pid);
+		free(perf_reports);
+	}
+
+	igt_waitchildren();
+}
+
 igt_main
 {
 	igt_skip_on_simulation();
@@ -886,6 +959,9 @@  igt_main
 	igt_subtest("perf-ctxid")
 		test_perf_ctxid();
 
+	igt_subtest("perf-pid")
+		test_perf_pid();
+
 	igt_fixture {
 		close(drm_fd);
 	}