summaryrefslogtreecommitdiff
path: root/test/process
diff options
context:
space:
mode:
Diffstat (limited to 'test/process')
-rw-r--r--test/process/meson.build12
-rw-r--r--test/process/process_test.cpp32
2 files changed, 28 insertions, 16 deletions
diff --git a/test/process/meson.build b/test/process/meson.build
index c4d83d6c..a80dc2d9 100644
--- a/test/process/meson.build
+++ b/test/process/meson.build
@@ -1,12 +1,14 @@
+# SPDX-License-Identifier: CC0-1.0
+
process_tests = [
- [ 'process_test', 'process_test.cpp' ],
+ {'name': 'process_test', 'sources': ['process_test.cpp']},
]
-foreach t : process_tests
- exe = executable(t[0], t[1],
- dependencies : libcamera_dep,
+foreach test : process_tests
+ exe = executable(test['name'], test['sources'],
+ dependencies : libcamera_private,
link_with : test_libraries,
include_directories : test_includes_internal)
- test(t[0], exe, suite : 'process', is_parallel : false)
+ test(test['name'], exe, suite : 'process', is_parallel : false)
endforeach
diff --git a/test/process/process_test.cpp b/test/process/process_test.cpp
index 7e7b3c2c..e9f5e7e9 100644
--- a/test/process/process_test.cpp
+++ b/test/process/process_test.cpp
@@ -2,23 +2,25 @@
/*
* Copyright (C) 2019, Google Inc.
*
- * process_test.cpp - Process test
+ * Process test
*/
#include <iostream>
#include <unistd.h>
#include <vector>
-#include <libcamera/event_dispatcher.h>
-#include <libcamera/timer.h>
+#include <libcamera/base/event_dispatcher.h>
+#include <libcamera/base/thread.h>
+#include <libcamera/base/timer.h>
+#include <libcamera/base/utils.h>
+
+#include "libcamera/internal/process.h"
-#include "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;
class ProcessTestChild
{
@@ -50,13 +52,17 @@ protected:
args.push_back(to_string(exitCode));
proc_.finished.connect(this, &ProcessTest::procFinished);
- int ret = proc_.start("/proc/self/exe", args);
+ /* Test that kill() on an unstarted process is safe. */
+ proc_.kill();
+
+ /* Test starting the process and retrieving the exit code. */
+ int ret = proc_.start(self(), args);
if (ret) {
cerr << "failed to start process" << endl;
return TestFail;
}
- timeout.start(2000);
+ timeout.start(2000ms);
while (timeout.isRunning() && exitStatus_ == Process::NotExited)
dispatcher->processEvents();
@@ -75,12 +81,14 @@ 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_;
enum Process::ExitStatus exitStatus_;
int exitCode_;
@@ -98,5 +106,7 @@ int main(int argc, char **argv)
return child.run(status);
}
- return ProcessTest().execute();
+ ProcessTest test;
+ test.setArgs(argc, argv);
+ return test.execute();
}