test: Extract CameraTest class out of camera tests to libtest
Many tests other than the camera/ tests use a camera. To increase code sharing, move the base CameraTest class to the test library. The class becomes a helper that doesn't inherit from Test anymore (to avoid diamond inheritance issues when more such helpers will exist). Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
6b3308ba1b
commit
fac471e812
10 changed files with 77 additions and 76 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include "v4l2_videodevice.h"
|
#include "v4l2_videodevice.h"
|
||||||
|
|
||||||
#include "camera_test.h"
|
#include "camera_test.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
|
@ -254,11 +255,11 @@ private:
|
||||||
bool done_;
|
bool done_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BufferImportTest : public CameraTest
|
class BufferImportTest : public CameraTest, public Test
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BufferImportTest()
|
BufferImportTest()
|
||||||
: CameraTest()
|
: CameraTest("VIMC Sensor B")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,11 +351,10 @@ protected:
|
||||||
|
|
||||||
int init()
|
int init()
|
||||||
{
|
{
|
||||||
int ret = CameraTest::init();
|
if (status_ != TestPass)
|
||||||
if (ret)
|
return status_;
|
||||||
return ret;
|
|
||||||
|
|
||||||
ret = sink_.init();
|
int ret = sink_.init();
|
||||||
if (ret != TestPass) {
|
if (ret != TestPass) {
|
||||||
cleanup();
|
cleanup();
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -422,8 +422,6 @@ protected:
|
||||||
|
|
||||||
camera_->stop();
|
camera_->stop();
|
||||||
camera_->freeBuffers();
|
camera_->freeBuffers();
|
||||||
|
|
||||||
CameraTest::cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -8,13 +8,20 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "camera_test.h"
|
#include "camera_test.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class Capture : public CameraTest
|
class Capture : public CameraTest, public Test
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
Capture()
|
||||||
|
: CameraTest("VIMC Sensor B")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
unsigned int completeBuffersCount_;
|
unsigned int completeBuffersCount_;
|
||||||
unsigned int completeRequestsCount_;
|
unsigned int completeRequestsCount_;
|
||||||
|
@ -48,14 +55,12 @@ protected:
|
||||||
|
|
||||||
int init() override
|
int init() override
|
||||||
{
|
{
|
||||||
int ret = CameraTest::init();
|
if (status_ != TestPass)
|
||||||
if (ret)
|
return status_;
|
||||||
return ret;
|
|
||||||
|
|
||||||
config_ = camera_->generateConfiguration({ StreamRole::VideoRecording });
|
config_ = camera_->generateConfiguration({ StreamRole::VideoRecording });
|
||||||
if (!config_ || config_->size() != 1) {
|
if (!config_ || config_->size() != 1) {
|
||||||
cout << "Failed to generate default configuration" << endl;
|
cout << "Failed to generate default configuration" << endl;
|
||||||
CameraTest::cleanup();
|
|
||||||
return TestFail;
|
return TestFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,27 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "camera_test.h"
|
#include "camera_test.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class ConfigurationDefault : public CameraTest
|
class ConfigurationDefault : public CameraTest, public Test
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
ConfigurationDefault()
|
||||||
|
: CameraTest("VIMC Sensor B")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int run()
|
int init() override
|
||||||
|
{
|
||||||
|
return status_;
|
||||||
|
}
|
||||||
|
|
||||||
|
int run() override
|
||||||
{
|
{
|
||||||
std::unique_ptr<CameraConfiguration> config;
|
std::unique_ptr<CameraConfiguration> config;
|
||||||
|
|
||||||
|
|
|
@ -8,24 +8,29 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "camera_test.h"
|
#include "camera_test.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class ConfigurationSet : public CameraTest
|
class ConfigurationSet : public CameraTest, public Test
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
ConfigurationSet()
|
||||||
|
: CameraTest("VIMC Sensor B")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int init() override
|
int init() override
|
||||||
{
|
{
|
||||||
int ret = CameraTest::init();
|
if (status_ != TestPass)
|
||||||
if (ret)
|
return status_;
|
||||||
return ret;
|
|
||||||
|
|
||||||
config_ = camera_->generateConfiguration({ StreamRole::VideoRecording });
|
config_ = camera_->generateConfiguration({ StreamRole::VideoRecording });
|
||||||
if (!config_ || config_->size() != 1) {
|
if (!config_ || config_->size() != 1) {
|
||||||
cout << "Failed to generate default configuration" << endl;
|
cout << "Failed to generate default configuration" << endl;
|
||||||
CameraTest::cleanup();
|
|
||||||
return TestFail;
|
return TestFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ camera_tests = [
|
||||||
]
|
]
|
||||||
|
|
||||||
foreach t : camera_tests
|
foreach t : camera_tests
|
||||||
exe = executable(t[0], [t[1], 'camera_test.cpp'],
|
exe = executable(t[0], t[1],
|
||||||
dependencies : libcamera_dep,
|
dependencies : libcamera_dep,
|
||||||
link_with : test_libraries,
|
link_with : test_libraries,
|
||||||
include_directories : test_includes_internal)
|
include_directories : test_includes_internal)
|
||||||
|
|
|
@ -8,13 +8,20 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "camera_test.h"
|
#include "camera_test.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class Statemachine : public CameraTest
|
class Statemachine : public CameraTest, public Test
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
Statemachine()
|
||||||
|
: CameraTest("VIMC Sensor B")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int testAvailable()
|
int testAvailable()
|
||||||
{
|
{
|
||||||
|
@ -233,14 +240,12 @@ protected:
|
||||||
|
|
||||||
int init() override
|
int init() override
|
||||||
{
|
{
|
||||||
int ret = CameraTest::init();
|
if (status_ != TestPass)
|
||||||
if (ret)
|
return status_;
|
||||||
return ret;
|
|
||||||
|
|
||||||
defconf_ = camera_->generateConfiguration({ StreamRole::VideoRecording });
|
defconf_ = camera_->generateConfiguration({ StreamRole::VideoRecording });
|
||||||
if (!defconf_) {
|
if (!defconf_) {
|
||||||
cout << "Failed to generate default configuration" << endl;
|
cout << "Failed to generate default configuration" << endl;
|
||||||
CameraTest::cleanup();
|
|
||||||
return TestFail;
|
return TestFail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,32 +13,22 @@
|
||||||
#include <libcamera/controls.h>
|
#include <libcamera/controls.h>
|
||||||
|
|
||||||
#include "camera_controls.h"
|
#include "camera_controls.h"
|
||||||
|
|
||||||
|
#include "camera_test.h"
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
class ControlListTest : public Test
|
class ControlListTest : public CameraTest, public Test
|
||||||
{
|
{
|
||||||
protected:
|
public:
|
||||||
int init()
|
ControlListTest()
|
||||||
|
: CameraTest("VIMC Sensor B")
|
||||||
{
|
{
|
||||||
cm_ = new CameraManager();
|
|
||||||
|
|
||||||
if (cm_->start()) {
|
|
||||||
cout << "Failed to start camera manager" << endl;
|
|
||||||
return TestFail;
|
|
||||||
}
|
|
||||||
|
|
||||||
camera_ = cm_->get("VIMC Sensor B");
|
|
||||||
if (!camera_) {
|
|
||||||
cout << "Can not find VIMC camera" << endl;
|
|
||||||
return TestSkip;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TestPass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
int run()
|
int run()
|
||||||
{
|
{
|
||||||
CameraControlValidator validator(camera_.get());
|
CameraControlValidator validator(camera_.get());
|
||||||
|
@ -156,21 +146,6 @@ protected:
|
||||||
|
|
||||||
return TestPass;
|
return TestPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup()
|
|
||||||
{
|
|
||||||
if (camera_) {
|
|
||||||
camera_->release();
|
|
||||||
camera_.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
cm_->stop();
|
|
||||||
delete cm_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
CameraManager *cm_;
|
|
||||||
std::shared_ptr<Camera> camera_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_REGISTER(ControlListTest)
|
TEST_REGISTER(ControlListTest)
|
||||||
|
|
|
@ -8,35 +8,39 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "camera_test.h"
|
#include "camera_test.h"
|
||||||
|
#include "test.h"
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int CameraTest::init()
|
CameraTest::CameraTest(const char *name)
|
||||||
{
|
{
|
||||||
cm_ = new CameraManager();
|
cm_ = new CameraManager();
|
||||||
|
|
||||||
if (cm_->start()) {
|
if (cm_->start()) {
|
||||||
cout << "Failed to start camera manager" << endl;
|
cerr << "Failed to start camera manager" << endl;
|
||||||
return TestFail;
|
status_ = TestFail;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
camera_ = cm_->get("VIMC Sensor B");
|
camera_ = cm_->get(name);
|
||||||
if (!camera_) {
|
if (!camera_) {
|
||||||
cout << "Can not find VIMC camera" << endl;
|
cerr << "Can not find '" << name << "' camera" << endl;
|
||||||
return TestSkip;
|
status_ = TestSkip;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sanity check that the camera has streams. */
|
/* Sanity check that the camera has streams. */
|
||||||
if (camera_->streams().empty()) {
|
if (camera_->streams().empty()) {
|
||||||
cout << "Camera has no stream" << endl;
|
cerr << "Camera has no stream" << endl;
|
||||||
return TestFail;
|
status_ = TestFail;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TestPass;
|
status_ = TestPass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CameraTest::cleanup()
|
CameraTest::~CameraTest()
|
||||||
{
|
{
|
||||||
if (camera_) {
|
if (camera_) {
|
||||||
camera_->release();
|
camera_->release();
|
|
@ -9,22 +9,18 @@
|
||||||
|
|
||||||
#include <libcamera/libcamera.h>
|
#include <libcamera/libcamera.h>
|
||||||
|
|
||||||
#include "test.h"
|
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
class CameraTest : public Test
|
class CameraTest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CameraTest()
|
CameraTest(const char *name);
|
||||||
: cm_(nullptr) {}
|
~CameraTest();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int init();
|
|
||||||
void cleanup();
|
|
||||||
|
|
||||||
CameraManager *cm_;
|
CameraManager *cm_;
|
||||||
std::shared_ptr<Camera> camera_;
|
std::shared_ptr<Camera> camera_;
|
||||||
|
int status_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __LIBCAMERA_CAMERA_TEST_H__ */
|
#endif /* __LIBCAMERA_CAMERA_TEST_H__ */
|
|
@ -1,4 +1,5 @@
|
||||||
libtest_sources = files([
|
libtest_sources = files([
|
||||||
|
'camera_test.cpp',
|
||||||
'test.cpp',
|
'test.cpp',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue