Skip to content

Commit 8b77e96

Browse files
committed
fix: 优化RunfilePath函数,自动去除测试文件路径前缀
1 parent ce2346b commit 8b77e96

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

test/util/test_util_runfiles.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
#include <iostream>
1616
#include <string>
17-
17+
#include <unistd.h>
18+
#include <limits.h>
1819
#include "test/util/fs_util.h"
1920
#include "test/util/test_util.h"
2021
#include "tools/cpp/runfiles/runfiles.h"
@@ -23,6 +24,17 @@ namespace gvisor {
2324
namespace testing {
2425

2526
std::string RunfilePath(std::string path) {
27+
// Fix for DragonOS syscall test
28+
static const std::string prefix = "test/syscalls/linux/";
29+
if (path.substr(0, prefix.length()) == prefix) {
30+
// Get current working directory
31+
char cwd[PATH_MAX];
32+
if (getcwd(cwd, sizeof(cwd)) != nullptr) {
33+
return std::string(cwd) + "/" + path.substr(prefix.length());
34+
}
35+
return path.substr(prefix.length());
36+
}
37+
2638
static const bazel::tools::cpp::runfiles::Runfiles* const runfiles = [] {
2739
std::string error;
2840
auto* runfiles =

0 commit comments

Comments
 (0)