diff options
Diffstat (limited to 'test/log')
-rw-r--r-- | test/log/log_api.cpp | 7 | ||||
-rw-r--r-- | test/log/log_process.cpp | 42 | ||||
-rw-r--r-- | test/log/meson.build | 14 |
3 files changed, 40 insertions, 23 deletions
diff --git a/test/log/log_api.cpp b/test/log/log_api.cpp index 33622f84..0b999738 100644 --- a/test/log/log_api.cpp +++ b/test/log/log_api.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2019, Google Inc. * - * log.cpp - log API test + * log API test */ #include <algorithm> @@ -16,9 +16,10 @@ #include <sys/types.h> #include <unistd.h> +#include <libcamera/base/log.h> + #include <libcamera/logging.h> -#include "log.h" #include "test.h" using namespace std; @@ -86,6 +87,7 @@ protected: if (logSetFile(path) < 0) { cerr << "Failed to set log file" << endl; + close(fd); return TestFail; } @@ -96,6 +98,7 @@ protected: lseek(fd, 0, SEEK_SET); if (read(fd, buf, sizeof(buf)) < 0) { cerr << "Failed to read tmp log file" << endl; + close(fd); return TestFail; } close(fd); 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(); } diff --git a/test/log/meson.build b/test/log/meson.build index 95f6c1a2..2298ff84 100644 --- a/test/log/meson.build +++ b/test/log/meson.build @@ -1,13 +1,15 @@ +# SPDX-License-Identifier: CC0-1.0 + log_test = [ - ['log_api', 'log_api.cpp'], - ['log_process', 'log_process.cpp'], + {'name': 'log_api', 'sources': ['log_api.cpp']}, + {'name': 'log_process', 'sources': ['log_process.cpp']}, ] -foreach t : log_test - exe = executable(t[0], t[1], - dependencies : libcamera_dep, +foreach test : log_test + exe = executable(test['name'], test['sources'], + dependencies : libcamera_private, link_with : test_libraries, include_directories : test_includes_internal) - test(t[0], exe, suite : 'log') + test(test['name'], exe, suite : 'log') endforeach |