File: sriov_basic.c

package info (click to toggle)
intel-gpu-tools 2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 62,024 kB
  • sloc: xml: 769,439; ansic: 348,692; python: 8,307; yacc: 2,781; perl: 1,196; sh: 1,178; lex: 487; asm: 227; makefile: 27; lisp: 11
file content (222 lines) | stat: -rw-r--r-- 6,314 bytes parent folder | download
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// SPDX-License-Identifier: MIT
/*
 * Copyright(c) 2023 Intel Corporation. All rights reserved.
 */

#include "drmtest.h"
#include "igt_core.h"
#include "igt_sriov_device.h"

IGT_TEST_DESCRIPTION("Basic tests for enabling SR-IOV Virtual Functions");

/**
 * TEST: sriov_basic
 * Category: Core
 * Mega feature: SR-IOV
 * Sub-category: VFs enabling
 * Functionality: configure / enable VFs
 * Description: Validate SR-IOV VFs enabling
 */

/**
 * SUBTEST: enable-vfs-autoprobe-off
 * Description:
 *   Verify VFs enabling without probing VF driver
 */
static void enable_vfs_autoprobe_off(int pf_fd, unsigned int num_vfs)
{
	igt_debug("Testing %u VFs\n", num_vfs);

	igt_require(igt_sriov_get_enabled_vfs(pf_fd) == 0);
	igt_sriov_disable_driver_autoprobe(pf_fd);
	igt_sriov_enable_vfs(pf_fd, num_vfs);
	igt_assert_eq(num_vfs, igt_sriov_get_enabled_vfs(pf_fd));
	igt_sriov_disable_vfs(pf_fd);
}

/**
 * SUBTEST: enable-vfs-autoprobe-on
 * Description:
 *   Verify VFs enabling and auto-probing VF driver
 */
static void enable_vfs_autoprobe_on(int pf_fd, unsigned int num_vfs)
{
	bool err = false;

	igt_debug("Testing %u VFs\n", num_vfs);

	igt_require(igt_sriov_get_enabled_vfs(pf_fd) == 0);
	igt_sriov_enable_driver_autoprobe(pf_fd);
	igt_sriov_enable_vfs(pf_fd, num_vfs);
	igt_assert_eq(num_vfs, igt_sriov_get_enabled_vfs(pf_fd));
	for (int vf_num = 1; vf_num <= num_vfs; ++vf_num) {
		if (!igt_sriov_is_vf_drm_driver_probed(pf_fd, vf_num)) {
			igt_debug("VF%u probe failed\n", vf_num);
			err = true;
		}
	}
	igt_sriov_disable_vfs(pf_fd);
	igt_assert(!err);
}

/**
 * SUBTEST: enable-vfs-bind-unbind-each
 * Description:
 *   Verify VFs enabling with binding and unbinding the driver one by one to each of them.
 *   Version includes dynamic subtests that allow specifying the number of enabled VFs as numvfs-N.
 *
 * SUBTEST: enable-vfs-bind-unbind-each-numvfs-all
 * Description:
 *   Verify the enabling of all VFs and the sequential binding and unbinding of the driver to each one.
 */
static void enable_vfs_bind_unbind_each(int pf_fd, unsigned int num_vfs)
{
	igt_debug("Testing %u VFs\n", num_vfs);

	igt_require(igt_sriov_get_enabled_vfs(pf_fd) == 0);

	igt_sriov_disable_driver_autoprobe(pf_fd);
	igt_sriov_enable_vfs(pf_fd, num_vfs);
	igt_sriov_enable_driver_autoprobe(pf_fd);

	for (int i = 1; i <= num_vfs; i++) {
		igt_assert(!igt_sriov_is_vf_drm_driver_probed(pf_fd, i));

		igt_sriov_bind_vf_drm_driver(pf_fd, i);
		igt_assert(igt_sriov_is_vf_drm_driver_probed(pf_fd, i));

		igt_sriov_unbind_vf_drm_driver(pf_fd, i);
		igt_assert(!igt_sriov_is_vf_drm_driver_probed(pf_fd, i));
	}

	igt_sriov_disable_vfs(pf_fd);
}

/**
 * SUBTEST: bind-unbind-vf
 * Description:
 *   Verify binding and unbinding the driver to specific VF
 */
static void bind_unbind_vf(int pf_fd, unsigned int vf_num)
{
	igt_debug("Testing VF%u\n", vf_num);

	igt_require(igt_sriov_get_enabled_vfs(pf_fd) == 0);

	igt_sriov_disable_driver_autoprobe(pf_fd);
	igt_sriov_enable_vfs(pf_fd, vf_num);
	igt_sriov_enable_driver_autoprobe(pf_fd);

	igt_assert(!igt_sriov_is_vf_drm_driver_probed(pf_fd, vf_num));

	igt_sriov_bind_vf_drm_driver(pf_fd, vf_num);
	igt_assert(igt_sriov_is_vf_drm_driver_probed(pf_fd, vf_num));

	igt_sriov_unbind_vf_drm_driver(pf_fd, vf_num);
	igt_assert(!igt_sriov_is_vf_drm_driver_probed(pf_fd, vf_num));

	igt_sriov_disable_vfs(pf_fd);
}

igt_main
{
	int pf_fd;
	bool autoprobe;

	igt_fixture {
		pf_fd = drm_open_driver(DRIVER_ANY);
		igt_require(igt_sriov_is_pf(pf_fd));
		igt_require(igt_sriov_vfs_supported(pf_fd));
		igt_require(igt_sriov_get_enabled_vfs(pf_fd) == 0);
		autoprobe = igt_sriov_is_driver_autoprobe_enabled(pf_fd);
	}

	igt_describe("Verify VFs enabling without probing VF driver");
	igt_subtest_with_dynamic("enable-vfs-autoprobe-off") {
		for_each_sriov_num_vfs(pf_fd, num_vfs) {
			igt_dynamic_f("numvfs-%u", num_vfs) {
				enable_vfs_autoprobe_off(pf_fd, num_vfs);
			}
		}
		for_random_sriov_num_vfs(pf_fd, num_vfs) {
			igt_dynamic_f("numvfs-random") {
				enable_vfs_autoprobe_off(pf_fd, num_vfs);
			}
		}
		for_max_sriov_num_vfs(pf_fd, num_vfs) {
			igt_dynamic_f("numvfs-all") {
				enable_vfs_autoprobe_off(pf_fd, num_vfs);
			}
		}
	}

	igt_describe("Verify VFs enabling and auto-probing VF driver");
	igt_subtest_with_dynamic("enable-vfs-autoprobe-on") {
		for_each_sriov_num_vfs(pf_fd, num_vfs) {
			igt_dynamic_f("numvfs-%u", num_vfs) {
				enable_vfs_autoprobe_on(pf_fd, num_vfs);
			}
		}
		for_random_sriov_num_vfs(pf_fd, num_vfs) {
			igt_dynamic_f("numvfs-random") {
				enable_vfs_autoprobe_on(pf_fd, num_vfs);
			}
		}
		for_max_sriov_num_vfs(pf_fd, num_vfs) {
			igt_dynamic_f("numvfs-all") {
				enable_vfs_autoprobe_on(pf_fd, num_vfs);
			}
		}
	}

	igt_describe("Verify VFs enabling with binding and unbinding the driver one be one to each of them");
	igt_subtest_with_dynamic("enable-vfs-bind-unbind-each") {
		for_each_sriov_num_vfs(pf_fd, num_vfs) {
			igt_dynamic_f("numvfs-%u", num_vfs) {
				enable_vfs_bind_unbind_each(pf_fd, num_vfs);
			}
		}
		for_random_sriov_num_vfs(pf_fd, num_vfs) {
			igt_dynamic_f("numvfs-random") {
				enable_vfs_bind_unbind_each(pf_fd, num_vfs);
			}
		}
	}

	igt_describe("Verify the enabling of all VFs and the sequential binding and unbinding of the driver to each one");
	igt_subtest("enable-vfs-bind-unbind-each-numvfs-all") {
		for_max_sriov_num_vfs(pf_fd, num_vfs) {
			enable_vfs_bind_unbind_each(pf_fd, num_vfs);
		}
	}

	igt_describe("Test binds and unbinds the driver to specific VF");
	igt_subtest_with_dynamic("bind-unbind-vf") {
		for_each_sriov_vf(pf_fd, vf) {
			igt_dynamic_f("vf-%u", vf) {
				bind_unbind_vf(pf_fd, vf);
			}
		}
		for_random_sriov_vf(pf_fd, vf) {
			igt_dynamic_f("vf-random") {
				bind_unbind_vf(pf_fd, vf);
			}
		}
		for_last_sriov_vf(pf_fd, vf) {
			igt_dynamic_f("vf-last") {
				bind_unbind_vf(pf_fd, vf);
			}
		}
	}

	igt_fixture {
		igt_sriov_disable_vfs(pf_fd);
		/* abort to avoid execution of next tests with enabled VFs */
		igt_abort_on_f(igt_sriov_get_enabled_vfs(pf_fd) > 0, "Failed to disable VF(s)");
		autoprobe ? igt_sriov_enable_driver_autoprobe(pf_fd) :
			    igt_sriov_disable_driver_autoprobe(pf_fd);
		igt_abort_on_f(autoprobe != igt_sriov_is_driver_autoprobe_enabled(pf_fd),
			       "Failed to restore sriov_drivers_autoprobe value\n");
		close(pf_fd);
	}
}