summaryrefslogtreecommitdiff
path: root/test/log/log_process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/log/log_process.cpp')
-rw-r--r--test/log/log_process.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/test/log/log_process.cpp b/test/log/log_process.cpp
index 2df4aa43..9609e23d 100644
--- a/test/log/log_process.cpp
+++ b/test/log/log_process.cpp
@@ -2,7 +2,7 @@
/*
* Copyright (C) 2019, Google Inc.
*
- * log_process.cpp - Logging in isolated child process test
+ * Logging in isolated child process test
*/
#include <fcntl.h>
@@ -14,18 +14,21 @@
#include <unistd.h>
#include <vector>
-#include <libcamera/event_dispatcher.h>
#include <libcamera/logging.h>
-#include <libcamera/timer.h>
-#include "log.h"
-#include "process.h"
+#include <libcamera/base/event_dispatcher.h>
+#include <libcamera/base/log.h>
+#include <libcamera/base/thread.h>
+#include <libcamera/base/timer.h>
+#include <libcamera/base/utils.h>
+
+#include "libcamera/internal/process.h"
+
#include "test.h"
-#include "thread.h"
-#include "utils.h"
-using namespace std;
using namespace libcamera;
+using namespace std;
+using namespace std::chrono_literals;
static const string message("hello from the child");
@@ -72,18 +75,19 @@ protected:
vector<std::string> args;
args.push_back(to_string(exitCode));
args.push_back(to_string(num_));
- int ret = proc_.start("/proc/self/exe", args);
+ int ret = proc_.start(self(), args);
if (ret) {
cerr << "failed to start process" << endl;
return TestFail;
}
- timeout.start(200);
+ timeout.start(2s);
while (timeout.isRunning())
dispatcher->processEvents();
if (exitStatus_ != Process::NormalExit) {
- cerr << "process did not exit normally" << endl;
+ cerr << "process did not exit normally: " << exitStatus_
+ << endl;
return TestFail;
}
@@ -106,13 +110,17 @@ protected:
memset(buf, 0, sizeof(buf));
if (read(fd, buf, sizeof(buf)) < 0) {
cerr << "Failed to read tmp log file" << endl;
+ close(fd);
return TestFail;
}
close(fd);
string str(buf);
- if (str.find(message) == string::npos)
+ if (str.find(message) == string::npos) {
+ cerr << "Received message is not correct (received "
+ << str.length() << " bytes)" << endl;
return TestFail;
+ }
return TestPass;
}
@@ -123,14 +131,16 @@ protected:
}
private:
- void procFinished(Process *proc, enum Process::ExitStatus exitStatus, int exitCode)
+ void procFinished(enum Process::ExitStatus exitStatus, int exitCode)
{
exitStatus_ = exitStatus;
exitCode_ = exitCode;
}
+ ProcessManager processManager_;
+
Process proc_;
- Process::ExitStatus exitStatus_;
+ Process::ExitStatus exitStatus_ = Process::NotExited;
string logPath_;
int exitCode_;
int num_;
@@ -149,5 +159,7 @@ int main(int argc, char **argv)
return child.run(status, num);
}
- return LogProcessTest().execute();
+ LogProcessTest test;
+ test.setArgs(argc, argv);
+ return test.execute();
}