The libcamera internal headers are located in src/libcamera/include/. The directory is added to the compiler headers search path with a meson include_directories() directive, and internal headers are included with (e.g. for the internal semaphore.h header) #include "semaphore.h" All was well, until libcxx decided to implement the C++20 synchronization library. The __threading_support header gained a #include <semaphore.h> to include the pthread's semaphore support. As include_directories() adds src/libcamera/include/ to the compiler search path with -I, the internal semaphore.h is included instead of the pthread version. Needless to say, the compiler isn't happy. Three options have been considered to fix this issue: - Use -iquote instead of -I. The -iquote option instructs gcc to only consider the header search path for headers included with the "" version. Meson unfortunately doesn't support this option. - Rename the internal semaphore.h header. This was deemed to be the beginning of a long whack-a-mole game, where namespace clashes with system libraries would appear over time (possibly dependent on particular system configurations) and would need to be constantly fixed. - Move the internal headers to another directory to create a unique namespace through path components. This causes lots of churn in all the existing source files through the all project. The first option would be best, but isn't available to us due to missing support in meson. Even if -iquote support was added, we would need to fix the problem before a new version of meson containing the required support would be released. The third option is thus the only practical solution available. Bite the bullet, and do it, moving headers to include/libcamera/internal/. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
170 lines
3.8 KiB
C++
170 lines
3.8 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* ipa_interface_test.cpp - Test the IPA interface
|
|
*/
|
|
|
|
#include <fcntl.h>
|
|
#include <iostream>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
|
|
#include <libcamera/event_dispatcher.h>
|
|
#include <libcamera/event_notifier.h>
|
|
#include <libcamera/timer.h>
|
|
|
|
#include <ipa/ipa_vimc.h>
|
|
|
|
#include "libcamera/internal/device_enumerator.h"
|
|
#include "libcamera/internal/ipa_manager.h"
|
|
#include "libcamera/internal/ipa_module.h"
|
|
#include "libcamera/internal/pipeline_handler.h"
|
|
#include "libcamera/internal/thread.h"
|
|
|
|
#include "test.h"
|
|
|
|
using namespace std;
|
|
using namespace libcamera;
|
|
|
|
class IPAInterfaceTest : public Test, public Object
|
|
{
|
|
public:
|
|
IPAInterfaceTest()
|
|
: trace_(IPAOperationNone), notifier_(nullptr), fd_(-1)
|
|
{
|
|
}
|
|
|
|
~IPAInterfaceTest()
|
|
{
|
|
delete notifier_;
|
|
}
|
|
|
|
protected:
|
|
int init() override
|
|
{
|
|
/* Create a pipeline handler for vimc. */
|
|
std::vector<PipelineHandlerFactory *> &factories =
|
|
PipelineHandlerFactory::factories();
|
|
for (PipelineHandlerFactory *factory : factories) {
|
|
if (factory->name() == "PipelineHandlerVimc") {
|
|
pipe_ = factory->create(nullptr);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!pipe_) {
|
|
cerr << "Vimc pipeline not found" << endl;
|
|
return TestPass;
|
|
}
|
|
|
|
/* Create and open the communication FIFO. */
|
|
int ret = mkfifo(VIMC_IPA_FIFO_PATH, S_IRUSR | S_IWUSR);
|
|
if (ret) {
|
|
ret = errno;
|
|
cerr << "Failed to create IPA test FIFO at '"
|
|
<< VIMC_IPA_FIFO_PATH << "': " << strerror(ret)
|
|
<< endl;
|
|
return TestFail;
|
|
}
|
|
|
|
ret = open(VIMC_IPA_FIFO_PATH, O_RDONLY | O_NONBLOCK);
|
|
if (ret < 0) {
|
|
ret = errno;
|
|
cerr << "Failed to open IPA test FIFO at '"
|
|
<< VIMC_IPA_FIFO_PATH << "': " << strerror(ret)
|
|
<< endl;
|
|
unlink(VIMC_IPA_FIFO_PATH);
|
|
return TestFail;
|
|
}
|
|
fd_ = ret;
|
|
|
|
notifier_ = new EventNotifier(fd_, EventNotifier::Read, this);
|
|
notifier_->activated.connect(this, &IPAInterfaceTest::readTrace);
|
|
|
|
return TestPass;
|
|
}
|
|
|
|
int run() override
|
|
{
|
|
EventDispatcher *dispatcher = thread()->eventDispatcher();
|
|
Timer timer;
|
|
|
|
ipa_ = IPAManager::instance()->createIPA(pipe_.get(), 0, 0);
|
|
if (!ipa_) {
|
|
cerr << "Failed to create VIMC IPA interface" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test initialization of IPA module. */
|
|
std::string conf = ipa_->configurationFile("vimc.conf");
|
|
int ret = ipa_->init(IPASettings{ conf });
|
|
if (ret < 0) {
|
|
cerr << "IPA interface init() failed" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
timer.start(1000);
|
|
while (timer.isRunning() && trace_ != IPAOperationInit)
|
|
dispatcher->processEvents();
|
|
|
|
if (trace_ != IPAOperationInit) {
|
|
cerr << "Failed to test IPA initialization sequence"
|
|
<< endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test start of IPA module. */
|
|
ipa_->start();
|
|
timer.start(1000);
|
|
while (timer.isRunning() && trace_ != IPAOperationStart)
|
|
dispatcher->processEvents();
|
|
|
|
if (trace_ != IPAOperationStart) {
|
|
cerr << "Failed to test IPA start sequence" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test stop of IPA module. */
|
|
ipa_->stop();
|
|
timer.start(1000);
|
|
while (timer.isRunning() && trace_ != IPAOperationStop)
|
|
dispatcher->processEvents();
|
|
|
|
if (trace_ != IPAOperationStop) {
|
|
cerr << "Failed to test IPA stop sequence" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
return TestPass;
|
|
}
|
|
|
|
void cleanup() override
|
|
{
|
|
close(fd_);
|
|
unlink(VIMC_IPA_FIFO_PATH);
|
|
}
|
|
|
|
private:
|
|
void readTrace(EventNotifier *notifier)
|
|
{
|
|
ssize_t s = read(notifier->fd(), &trace_, sizeof(trace_));
|
|
if (s < 0) {
|
|
int ret = errno;
|
|
cerr << "Failed to read from IPA test FIFO at '"
|
|
<< VIMC_IPA_FIFO_PATH << "': " << strerror(ret)
|
|
<< endl;
|
|
trace_ = IPAOperationNone;
|
|
}
|
|
}
|
|
|
|
std::shared_ptr<PipelineHandler> pipe_;
|
|
std::unique_ptr<IPAProxy> ipa_;
|
|
enum IPAOperationCode trace_;
|
|
EventNotifier *notifier_;
|
|
int fd_;
|
|
};
|
|
|
|
TEST_REGISTER(IPAInterfaceTest)
|