llvm.org GIT mirror llvm / a435f21
Fix DynamicLibraryTest.cpp on FreeBSD and NetBSD Summary: After rL301562, on FreeBSD the DynamicLibrary unittests fail, because the test uses getMainExecutable("DynamicLibraryTests", Ptr), and since the path does not contain any slashes, retrieving the main executable will not work. Reimplement getMainExecutable() for FreeBSD and NetBSD using sysctl(3), which is more reliable than fiddling with relative or absolute paths. Also add retrieval of the original argv[] from the GoogleTest framework, to use as a fallback for other OSes. Reviewers: emaste, marsupial, hans, krytarowski Reviewed By: krytarowski Subscribers: krytarowski, llvm-commits Differential Revision: https://reviews.llvm.org/D33171 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303015 91177308-0d34-0410-b5e6-96231b3b80d8 Dimitry Andric 2 years ago
2 changed file(s) with 27 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
102102 #define STATVFS_F_FLAG(vfs) (vfs).f_flags
103103 #endif
104104
105 #if defined(__FreeBSD__) || defined(__NetBSD__)
106 #include
107 #endif
108
105109 using namespace llvm;
106110
107111 namespace llvm {
108112 namespace sys {
109113 namespace fs {
110 #if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \
111 defined(__OpenBSD__) || defined(__minix) || defined(__FreeBSD_kernel__) || \
114 #if defined(__Bitrig__) || defined(__OpenBSD__) || defined(__minix) || \
112115 defined(__linux__) || defined(__CYGWIN__) || defined(__DragonFly__) || \
113116 defined(_AIX)
114117 static int
163166 free(pv);
164167 return nullptr;
165168 }
166 #endif // __FreeBSD__ || __NetBSD__ || __FreeBSD_kernel__
169 #endif // Bitrig || OpenBSD || minix || linux || CYGWIN || DragonFly || AIX
167170
168171 /// GetMainExecutable - Return the path to the main executable, given the
169172 /// value of argv[0] from program startup.
179182 if (realpath(exe_path, link_path))
180183 return link_path;
181184 }
182 #elif defined(__FreeBSD__) || defined (__NetBSD__) || defined(__Bitrig__) || \
183 defined(__OpenBSD__) || defined(__minix) || defined(__DragonFly__) || \
184 defined(__FreeBSD_kernel__) || defined(_AIX)
185 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
186 int mib[4];
187 mib[0] = CTL_KERN;
188 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
189 mib[1] = KERN_PROC;
190 mib[2] = KERN_PROC_PATHNAME;
191 mib[3] = -1;
192 #else
193 mib[1] = KERN_PROC_ARGS;
194 mib[2] = -1;
195 mib[3] = KERN_PROC_PATHNAME;
196 #endif
197 char exe_path[PATH_MAX];
198 size_t cb = sizeof(exe_path);
199 if (sysctl(mib, 4, exe_path, &cb, NULL, 0) == 0)
200 return exe_path;
201 #elif defined(__Bitrig__) || defined(__OpenBSD__) || defined(__minix) || \
202 defined(__DragonFly__) || defined(_AIX)
185203 char exe_path[PATH_MAX];
186204
187205 if (getprogpath(exe_path, argv0) != NULL)
2222 extern "C" PIPSQUEAK_EXPORT const char *TestA() { return "ProcessCall"; }
2323
2424 std::string LibPath() {
25 const std::vector& Argvs = testing::internal::GetArgvs();
26 const char *Argv0 = Argvs.size() > 0 ? Argvs[0].c_str() : "DynamicLibraryTests";
2527 void *Ptr = (void*)(intptr_t)TestA;
26 std::string Path = fs::getMainExecutable("DynamicLibraryTests", Ptr);
28 std::string Path = fs::getMainExecutable(Argv0, Ptr);
2729 llvm::SmallString<256> Buf(path::parent_path(Path));
2830 path::append(Buf, "PipSqueak.so");
2931 return Buf.str();