Skip to content

Commit e674d73

Browse files
committed
Add xrt_test option for vf concurrency test
Signed-off-by: Hayden Laccabue <[email protected]>
1 parent 2a9ecf9 commit e674d73

File tree

1 file changed

+53
-11
lines changed

1 file changed

+53
-11
lines changed

test/xrt_test/xrt_test.cpp

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ unsigned s_rounds = 128;
3232
unsigned m_rounds = 32;
3333
unsigned device_index = 0;
3434
unsigned threads = 2;
35+
unsigned vf_cnt;
36+
bool vf_test = false;
3537
std::vector<unsigned> exec_list;
3638
std::string dpu = "nop";
3739

@@ -58,6 +60,8 @@ usage(const std::string& prog)
5860
std::cout << "\t" << "-i" << ": specify device index (0 for non-sriov or VF0, 1, 2, 3 for VFs)\n";
5961
std::cout << "\t" << "-t" << ": n thread to be created in thread test (default 2)\n";
6062
std::cout << "\t" << "-e" << ": specify tests to add to thread test (default vadd) [-e test1 -e test2 ...]\n";
63+
std::cout << "\t" << "-v" << ": apply each thread to corresponding vf, max 4\n";
64+
std::cout << "\t" << "-l" << ": use xclbin flow if available\n";
6165
std::cout << "\t" << "-h" << ": print this help message\n\n";
6266
std::cout << "\t" << "Example Usage: ./xrt_test <# for stress test> -s 20 -d vadd -x vadd\n";
6367
std::cout << "\t" << " Run stress test with Vadd kernel and xclbin for 20 rounds\n";
@@ -1026,6 +1030,7 @@ void
10261030
TEST_xrt_threads(int device_index, arg_type& arg)
10271031
{
10281032
std::vector<std::thread> m_threads;
1033+
std::vector<bool> m_failed(threads, false);
10291034

10301035
if (exec_list.empty())
10311036
exec_list.insert(exec_list.begin(), threads, 0);
@@ -1034,16 +1039,42 @@ TEST_xrt_threads(int device_index, arg_type& arg)
10341039
else
10351040
threads = exec_list.size(); // if more tests than threads, increase threads to run all tests
10361041

1037-
for (int i = 0; i < threads; i++) {
1038-
m_threads.push_back(std::thread([&, i](){
1039-
std::cout << "Thread " << i << " started" << std::endl;
1040-
test_list[exec_list[i]].func(device_index, test_list[exec_list[i]].arg);
1041-
})
1042-
);
1042+
if (vf_test) {
1043+
for (int i = 0; i < threads; i++) {
1044+
m_threads.push_back(std::thread([&, i](){
1045+
std::cout << "Thread " << i << " started" << std::endl;
1046+
try {
1047+
test_list[exec_list[i]].func(i % vf_cnt, test_list[exec_list[i]].arg);
1048+
} catch (const std::exception& ex) {
1049+
m_failed[i] = true;
1050+
std::cerr << "Thread " << i << " failed: " << ex.what() << std::endl;
1051+
}
1052+
})
1053+
);
1054+
}
1055+
}
1056+
else {
1057+
for (int i = 0; i < threads; i++) {
1058+
m_threads.push_back(std::thread([&, i](){
1059+
std::cout << "Thread " << i << " started" << std::endl;
1060+
try {
1061+
test_list[exec_list[i]].func(device_index, test_list[exec_list[i]].arg);
1062+
} catch (const std::exception& ex) {
1063+
m_failed[i] = true;
1064+
std::cerr << "Thread " << i << " failed: " << ex.what() << std::endl;
1065+
}
1066+
})
1067+
);
1068+
}
10431069
}
10441070

10451071
for (int i = 0; i < threads; i++)
1046-
m_threads[i].join();
1072+
m_threads[i].join();
1073+
1074+
for (int i = 0; i < threads; i++) {
1075+
if (m_failed[i])
1076+
throw std::runtime_error("At least one thread has failed");
1077+
}
10471078

10481079
}
10491080

@@ -1108,7 +1139,7 @@ main(int argc, char **argv)
11081139

11091140
try {
11101141
int option, val;
1111-
while ((option = getopt(argc, argv, ":c:s:m:x:d:i:t:e:lh")) != -1) {
1142+
while ((option = getopt(argc, argv, ":c:s:m:x:d:i:t:e:v:lh")) != -1) {
11121143
switch (option) {
11131144
case 'c': {
11141145
val = std::stoi(optarg);
@@ -1169,10 +1200,21 @@ main(int argc, char **argv)
11691200
return 1;
11701201
}
11711202
}
1172-
case 'l':
1173-
std::cout << "swtiching to xclbin flow" << std::endl;
1174-
elf_flow = false;
1203+
case 'l': {
1204+
std::cout << "swtiching to xclbin flow" << std::endl;
1205+
elf_flow = false;
11751206
break;
1207+
}
1208+
case 'v': {
1209+
val = std::stoi(optarg);
1210+
if (val > 4 || val < 1) {
1211+
std::cout << "VF count is between 1-4" << std::endl;
1212+
return 1;
1213+
}
1214+
vf_cnt = val;
1215+
vf_test = true;
1216+
break;
1217+
}
11761218
case 'h':
11771219
usage(program);
11781220
return 0;

0 commit comments

Comments
 (0)