test: Replace "/proc/self/exe" with path to test binary

When tests are run under valgrind, /proc/self/exe points to valgrind,
not to the test binary. This results in failures for tests that need to
fork processes. Fix it by replacing "/proc/self/exe" with the path to
the test binary.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart 2021-11-29 23:16:35 +02:00
parent b24d9c4413
commit 59002a9e9d
5 changed files with 7 additions and 8 deletions

View file

@ -180,7 +180,7 @@ protected:
} }
/* Test size(). */ /* Test size(). */
file.setFileName("/proc/self/exe"); file.setFileName(self());
if (file.size() >= 0) { if (file.size() >= 0) {
cerr << "File has valid size before open" << endl; cerr << "File has valid size before open" << endl;
@ -277,7 +277,7 @@ protected:
file.close(); file.close();
/* Test mapping and unmapping. */ /* Test mapping and unmapping. */
file.setFileName("/proc/self/exe"); file.setFileName(self());
file.open(File::OpenModeFlag::ReadOnly); file.open(File::OpenModeFlag::ReadOnly);
Span<uint8_t> data = file.map(); Span<uint8_t> data = file.map();

View file

@ -209,8 +209,7 @@ protected:
if (!pid_) { if (!pid_) {
std::string arg = std::to_string(fd); std::string arg = std::to_string(fd);
execl("/proc/self/exe", "/proc/self/exe", execl(self().c_str(), self().c_str(), arg.c_str(), nullptr);
arg.c_str(), nullptr);
/* Only get here if exec fails. */ /* Only get here if exec fails. */
exit(TestFail); exit(TestFail);
@ -464,7 +463,7 @@ private:
int prepareFDs(IPCUnixSocket::Payload *message, unsigned int num) int prepareFDs(IPCUnixSocket::Payload *message, unsigned int num)
{ {
int fd = open("/proc/self/exe", O_RDONLY); int fd = open(self().c_str(), O_RDONLY);
if (fd < 0) if (fd < 0)
return fd; return fd;

View file

@ -173,7 +173,7 @@ protected:
int run() int run()
{ {
ipc_ = std::make_unique<IPCPipeUnixSocket>("", "/proc/self/exe"); ipc_ = std::make_unique<IPCPipeUnixSocket>("", self().c_str());
if (!ipc_->isConnected()) { if (!ipc_->isConnected()) {
cerr << "Failed to create IPCPipe" << endl; cerr << "Failed to create IPCPipe" << endl;
return TestFail; return TestFail;

View file

@ -74,7 +74,7 @@ protected:
vector<std::string> args; vector<std::string> args;
args.push_back(to_string(exitCode)); args.push_back(to_string(exitCode));
args.push_back(to_string(num_)); args.push_back(to_string(num_));
int ret = proc_.start("/proc/self/exe", args); int ret = proc_.start(self(), args);
if (ret) { if (ret) {
cerr << "failed to start process" << endl; cerr << "failed to start process" << endl;
return TestFail; return TestFail;

View file

@ -55,7 +55,7 @@ protected:
proc_.kill(); proc_.kill();
/* Test starting the process and retrieving the exit code. */ /* Test starting the process and retrieving the exit code. */
int ret = proc_.start("/proc/self/exe", args); int ret = proc_.start(self(), args);
if (ret) { if (ret) {
cerr << "failed to start process" << endl; cerr << "failed to start process" << endl;
return TestFail; return TestFail;