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>
173 lines
4.4 KiB
C++
173 lines
4.4 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C) 2018, Google Inc.
|
|
*
|
|
* byte_stream_buffer.cpp - ByteStreamBuffer tests
|
|
*/
|
|
|
|
#include <array>
|
|
#include <iostream>
|
|
|
|
#include "libcamera/internal/byte_stream_buffer.h"
|
|
|
|
#include "test.h"
|
|
|
|
using namespace std;
|
|
using namespace libcamera;
|
|
|
|
class ByteStreamBufferTest : public Test
|
|
{
|
|
protected:
|
|
int run()
|
|
{
|
|
std::array<uint8_t, 100> data;
|
|
unsigned int i;
|
|
uint32_t value;
|
|
int ret;
|
|
|
|
/*
|
|
* Write mode.
|
|
*/
|
|
ByteStreamBuffer wbuf(data.data(), data.size());
|
|
|
|
if (wbuf.base() != data.data() || wbuf.size() != data.size() ||
|
|
wbuf.offset() != 0 || wbuf.overflow()) {
|
|
cerr << "Write buffer incorrectly constructed" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test write. */
|
|
value = 0x12345678;
|
|
ret = wbuf.write(&value);
|
|
if (ret || wbuf.offset() != 4 || wbuf.overflow() ||
|
|
*reinterpret_cast<uint32_t *>(data.data()) != 0x12345678) {
|
|
cerr << "Write failed on write buffer" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test write carve out. */
|
|
ByteStreamBuffer wco = wbuf.carveOut(10);
|
|
if (wco.base() != wbuf.base() + 4 || wco.size() != 10 ||
|
|
wco.offset() != 0 || wco.overflow() || wbuf.offset() != 14 ||
|
|
wbuf.overflow()) {
|
|
cerr << "Carving out write buffer failed" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test write on the carved out buffer. */
|
|
value = 0x87654321;
|
|
ret = wco.write(&value);
|
|
if (ret || wco.offset() != 4 || wco.overflow() ||
|
|
*reinterpret_cast<uint32_t *>(data.data() + 4) != 0x87654321) {
|
|
cerr << "Write failed on carve out buffer" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
if (wbuf.offset() != 14 || wbuf.overflow()) {
|
|
cerr << "Write on carve out buffer modified write buffer" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test read, this should fail. */
|
|
ret = wbuf.read(&value);
|
|
if (!ret || wbuf.overflow()) {
|
|
cerr << "Read should fail on write buffer" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test overflow on carved out buffer. */
|
|
for (i = 0; i < 2; ++i) {
|
|
ret = wco.write(&value);
|
|
if (ret < 0)
|
|
break;
|
|
}
|
|
|
|
if (i != 1 || !wco.overflow() || !wbuf.overflow()) {
|
|
cerr << "Write on carve out buffer failed to overflow" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test reinitialization of the buffer. */
|
|
wbuf = ByteStreamBuffer(data.data(), data.size());
|
|
if (wbuf.overflow() || wbuf.base() != data.data() ||
|
|
wbuf.offset() != 0) {
|
|
cerr << "Write buffer reinitialization failed" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/*
|
|
* Read mode.
|
|
*/
|
|
ByteStreamBuffer rbuf(const_cast<const uint8_t *>(data.data()),
|
|
data.size());
|
|
|
|
if (rbuf.base() != data.data() || rbuf.size() != data.size() ||
|
|
rbuf.offset() != 0 || rbuf.overflow()) {
|
|
cerr << "Read buffer incorrectly constructed" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test read. */
|
|
value = 0;
|
|
ret = rbuf.read(&value);
|
|
if (ret || rbuf.offset() != 4 || rbuf.overflow() ||
|
|
value != 0x12345678) {
|
|
cerr << "Write failed on write buffer" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test read carve out. */
|
|
ByteStreamBuffer rco = rbuf.carveOut(10);
|
|
if (rco.base() != rbuf.base() + 4 || rco.size() != 10 ||
|
|
rco.offset() != 0 || rco.overflow() || rbuf.offset() != 14 ||
|
|
rbuf.overflow()) {
|
|
cerr << "Carving out read buffer failed" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test read on the carved out buffer. */
|
|
value = 0;
|
|
ret = rco.read(&value);
|
|
if (ret || rco.offset() != 4 || rco.overflow() || value != 0x87654321) {
|
|
cerr << "Read failed on carve out buffer" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
if (rbuf.offset() != 14 || rbuf.overflow()) {
|
|
cerr << "Read on carve out buffer modified read buffer" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test write, this should fail. */
|
|
ret = rbuf.write(&value);
|
|
if (!ret || rbuf.overflow()) {
|
|
cerr << "Write should fail on read buffer" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test overflow on carved out buffer. */
|
|
for (i = 0; i < 2; ++i) {
|
|
ret = rco.read(&value);
|
|
if (ret < 0)
|
|
break;
|
|
}
|
|
|
|
if (i != 1 || !rco.overflow() || !rbuf.overflow()) {
|
|
cerr << "Read on carve out buffer failed to overflow" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
/* Test reinitialization of the buffer. */
|
|
rbuf = ByteStreamBuffer(const_cast<const uint8_t *>(data.data()),
|
|
data.size());
|
|
if (rbuf.overflow() || rbuf.base() != data.data() ||
|
|
rbuf.offset() != 0) {
|
|
cerr << "Read buffer reinitialization failed" << endl;
|
|
return TestFail;
|
|
}
|
|
|
|
return TestPass;
|
|
}
|
|
};
|
|
|
|
TEST_REGISTER(ByteStreamBufferTest)
|