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>
152 lines
2.8 KiB
C++
152 lines
2.8 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* log.cpp - log API test
|
|
*/
|
|
|
|
#include <algorithm>
|
|
#include <fcntl.h>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <sstream>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
|
|
#include <libcamera/logging.h>
|
|
|
|
#include "libcamera/internal/log.h"
|
|
|
|
#include "test.h"
|
|
|
|
using namespace std;
|
|
using namespace libcamera;
|
|
|
|
LOG_DEFINE_CATEGORY(LogAPITest)
|
|
|
|
class LogAPITest : public Test
|
|
{
|
|
protected:
|
|
void doLogging()
|
|
{
|
|
logSetLevel("LogAPITest", "DEBUG");
|
|
LOG(LogAPITest, Info) << "good 1";
|
|
|
|
logSetLevel("LogAPITest", "WARN");
|
|
LOG(LogAPITest, Info) << "bad";
|
|
|
|
logSetLevel("LogAPITest", "ERROR");
|
|
LOG(LogAPITest, Error) << "good 3";
|
|
LOG(LogAPITest, Info) << "bad";
|
|
|
|
logSetLevel("LogAPITest", "WARN");
|
|
LOG(LogAPITest, Warning) << "good 5";
|
|
LOG(LogAPITest, Info) << "bad";
|
|
}
|
|
|
|
int verifyOutput(istream &is)
|
|
{
|
|
list<int> goodList = { 1, 3, 5 };
|
|
string line;
|
|
while (getline(is, line)) {
|
|
if (goodList.empty()) {
|
|
cout << "Too many log lines" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
unsigned int digit = line.back() - '0';
|
|
unsigned int expect = goodList.front();
|
|
goodList.pop_front();
|
|
if (digit != expect) {
|
|
cout << "Incorrect log line" << endl;
|
|
return TestFail;
|
|
}
|
|
}
|
|
|
|
if (!goodList.empty()) {
|
|
cout << "Too few log lines" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
return TestPass;
|
|
}
|
|
|
|
int testFile()
|
|
{
|
|
int fd = open("/tmp", O_TMPFILE | O_RDWR, S_IRUSR | S_IWUSR);
|
|
if (fd < 0) {
|
|
cerr << "Failed to open tmp log file" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
char path[32];
|
|
snprintf(path, sizeof(path), "/proc/self/fd/%u", fd);
|
|
|
|
if (logSetFile(path) < 0) {
|
|
cerr << "Failed to set log file" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
doLogging();
|
|
|
|
char buf[1000];
|
|
memset(buf, 0, sizeof(buf));
|
|
lseek(fd, 0, SEEK_SET);
|
|
if (read(fd, buf, sizeof(buf)) < 0) {
|
|
cerr << "Failed to read tmp log file" << endl;
|
|
return TestFail;
|
|
}
|
|
close(fd);
|
|
|
|
istringstream iss(buf);
|
|
return verifyOutput(iss);
|
|
}
|
|
|
|
int testStream()
|
|
{
|
|
stringstream log;
|
|
/* Never fails, so no need to check return value */
|
|
logSetStream(&log);
|
|
|
|
doLogging();
|
|
|
|
return verifyOutput(log);
|
|
}
|
|
|
|
int testTarget()
|
|
{
|
|
logSetTarget(LoggingTargetNone);
|
|
logSetLevel("LogAPITest", "DEBUG");
|
|
LOG(LogAPITest, Info) << "don't crash please";
|
|
|
|
if (!logSetTarget(LoggingTargetFile))
|
|
return TestFail;
|
|
|
|
if (!logSetTarget(LoggingTargetStream))
|
|
return TestFail;
|
|
|
|
return TestPass;
|
|
}
|
|
|
|
int run() override
|
|
{
|
|
int ret = testFile();
|
|
if (ret != TestPass)
|
|
return TestFail;
|
|
|
|
ret = testStream();
|
|
if (ret != TestPass)
|
|
return TestFail;
|
|
|
|
ret = testTarget();
|
|
if (ret != TestPass)
|
|
return TestFail;
|
|
|
|
return TestPass;
|
|
}
|
|
};
|
|
|
|
TEST_REGISTER(LogAPITest)
|