File: xe_module_load.c

package info (click to toggle)
intel-gpu-tools 2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 63,368 kB
  • sloc: xml: 781,458; ansic: 360,567; python: 8,336; yacc: 2,781; perl: 1,196; sh: 1,177; lex: 487; asm: 227; lisp: 35; makefile: 30
file content (170 lines) | stat: -rw-r--r-- 3,764 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// SPDX-License-Identifier: MIT
/*
 * Copyright © 2023 Intel Corporation
 */

/**
 * TEST: Tests the xe module loading
 * Category: Core
 * Mega feature: General Core features
 * Sub-category: driver
 * Functionality: module load
 * Test category: functionality test
 */

#include <dirent.h>
#include <fcntl.h>
#include <libgen.h>

#ifdef __linux__
#include <linux/limits.h>
#endif

#include <signal.h>

#include <sys/ioctl.h>
#include <sys/utsname.h>

#include "igt.h"

#include "igt_aux.h"
#include "igt_core.h"
#include "igt_debugfs.h"
#include "igt_kmod.h"
#include "igt_sysfs.h"

#define BAR_SIZE_SHIFT 20
#define MIN_BAR_SIZE 256

static void file_write(const char *ptr, size_t size, size_t nmemb,
                       FILE *fp)
{
	int count;

	count = fwrite(ptr, size, nmemb, fp);
	if (count == size * nmemb)
		return;

	igt_debug("Can't update hda dynamic debug with : %s\n", ptr);
}

static void hda_dynamic_debug(bool enable)
{
	FILE *fp;
	static const char snd_hda_intel_on[] = "module snd_hda_intel +pf";
	static const char snd_hda_core_on[] = "module snd_hda_core +pf";

	static const char snd_hda_intel_off[] = "module snd_hda_intel =_";
	static const char snd_hda_core_off[] = "module snd_hda_core =_";

	fp = fopen("/sys/kernel/debug/dynamic_debug/control", "w");
	if (!fp) {
		igt_debug("hda dynamic debug not available\n");
		return;
	}

	if (enable) {
		file_write(snd_hda_intel_on, 1, sizeof(snd_hda_intel_on), fp);
		file_write(snd_hda_core_on, 1, sizeof(snd_hda_core_on), fp);
	} else {
		file_write(snd_hda_intel_off, 1, sizeof(snd_hda_intel_off), fp);
		file_write(snd_hda_core_off, 1, sizeof(snd_hda_core_off), fp);
	}

	fclose(fp);
}

static void load_and_check_xe(const char *opts)
{
	int error;
	int drm_fd;

	hda_dynamic_debug(true);
	error = igt_xe_driver_load(opts);
	hda_dynamic_debug(false);

	igt_assert_eq(error, 0);

	/* driver is ready, check if it's bound */
	drm_fd = __drm_open_driver(DRIVER_XE);
	igt_fail_on_f(drm_fd < 0, "Cannot open the xe DRM driver after modprobing xe.\n");
	drm_close_driver(drm_fd);
}

static const char * const unwanted_drivers[] = {
	"xe",
	"i915",
	NULL
};

/**
 * SUBTEST: force-load
 * Description: Load the Xe driver passing ``force_probe=*`` parameter
 *
 * SUBTEST: load
 * Description: Load the Xe driver
 *
 * SUBTEST: unload
 * Description: Unload the Xe driver
 *
 * SUBTEST: reload
 * Description: Reload the Xe driver
 *
 * SUBTEST: reload-no-display
 * Description: Reload the Xe driver passing ``probe_display=0`` parameter
 *
 * SUBTEST: many-reload
 * Description: Reload the Xe driver many times
 */
igt_main
{
	igt_describe("Check if xe and friends are not yet loaded, then load them.");
	igt_subtest("load") {
		for (int i = 0; unwanted_drivers[i] != NULL; i++) {
			igt_skip_on_f(igt_kmod_is_loaded(unwanted_drivers[i]),
				      "%s is already loaded\n", unwanted_drivers[i]);
		}

		load_and_check_xe(NULL);
	}

	igt_subtest("unload") {
		igt_xe_driver_unload();
	}

	igt_subtest("force-load") {
		for (int i = 0; unwanted_drivers[i] != NULL; i++) {
			igt_skip_on_f(igt_kmod_is_loaded(unwanted_drivers[i]),
				      "%s is already loaded\n", unwanted_drivers[i]);
		}

		load_and_check_xe("force_probe=*");
		igt_xe_driver_unload();
	}

	igt_subtest("reload-no-display") {
		igt_xe_driver_unload();
		load_and_check_xe("probe_display=0");
		igt_xe_driver_unload();
	}

	igt_subtest("many-reload") {
		int i;

		for (i = 0; i < 10; i++) {
			igt_debug("reload cycle: %d\n", i);
			igt_xe_driver_unload();
			load_and_check_xe(NULL);
			sleep(1);
		}
	}

	igt_subtest("reload") {
		igt_xe_driver_unload();
		load_and_check_xe(NULL);

		/* only default modparams, can leave module loaded */
	}

	/* Subtests should unload the module themselves if they use modparams */
}