summaryrefslogtreecommitdiff
path: root/test/camera/statemachine.cpp
blob: 26fb5ca17139b46baf391614cd8fc8e323de12ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14<# SPDX-License-Identifier: CC0-1.0

libipa_test = [
    {'name': 'fixedpoint', 'sources': ['fixedpoint.cpp']},
    {'name': 'interpolator', 'sources': ['interpolator.cpp']},
    {'name': 'vector', 'sources': ['vector.cpp']},
]

foreach test : libipa_test
    exe = executable(test['name'], test['sources'],
                     dependencies : [libcamera_private, libipa_dep],
                     implicit_include_directories : false,
                     link_with : [test_libraries],
                     include_directories : [test_includes_internal,
                                            '../../../src/ipa/libipa/'])

    test(test['name'], exe, suite : 'ipa')
endforeach
' href='#n51'>51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright (C) 2019, Google Inc.
 *
 * libcamera Camera API tests
 */

#include <iostream>

#include <libcamera/framebuffer_allocator.h>

#include "camera_test.h"
#include "test.h"

using namespace std;

namespace {

class Statemachine : public CameraTest, public Test
{
public:
	Statemachine()
		: CameraTest("platform/vimc.0 Sensor B")
	{
	}

protected:
	int testAvailable()
	{
		/* Test operations which should fail. */
		if (camera_->configure(defconf_.get()) != -EACCES)
			return TestFail;

		if (camera_->createRequest())
			return TestFail;

		if (camera_->start() != -EACCES)
			return TestFail;

		Request request(camera_.get());
		if (camera_->queueRequest(&request) != -EACCES)
			return TestFail;

		/* Test operations which should pass. */
		if (camera_->release())
			return TestFail;

		if (camera_->stop())
			return TestFail;

		/* Test valid state transitions, end in Acquired state. */
		if (camera_->acquire())
			return TestFail;

		return TestPass;
	}

	int testAcquired()
	{
		/* Test operations which should fail. */
		if (camera_->acquire() != -EBUSY)
			return TestFail;

		if (camera_->createRequest())
			return TestFail;

		if (camera_->start() != -EACCES)
			return TestFail;

		Request request(camera_.get());
		if (camera_->queueRequest(&request) != -EACCES)
			return TestFail;

		/* Test operations which should pass. */
		if (camera_->stop())
			return TestFail;

		/* Test valid state transitions, end in Configured state. */
		if (camera_->release())
			return TestFail;

		if (camera_->acquire())
			return TestFail;

		if (camera_->configure(defconf_.get()))
			return TestFail;

		return TestPass;
	}

	int testConfigured()
	{
		/* Test operations which should fail. */
		if (camera_->acquire() != -EBUSY)
			return TestFail;

		Request request1(camera_.get());
		if (camera_->queueRequest(&request1) != -EACCES)
			return TestFail;

		/* Test operations which should pass. */
		std::unique_ptr<Request> request2 = camera_->createRequest();
		if (!request2)
			return TestFail;

		if (camera_->stop())
			return TestFail;

		/* Test valid state transitions, end in Running state. */
		if (camera_->release())
			return TestFail;

		if (camera_->acquire())
			return TestFail;

		if (camera_->configure(defconf_.get()))
			return TestFail;

		/* Use internally allocated buffers. */
		allocator_ = new FrameBufferAllocator(camera_);
		Stream *stream = *camera_->streams().begin();
		if (allocator_->allocate(stream) < 0)
			return TestFail;

		if (camera_->start())
			return TestFail;

		return TestPass;
	}

	int testRuning()
	{
		/* Test operations which should fail. */
		if (camera_->acquire() != -EBUSY)
			return TestFail;

		if (camera_->release() != -EBUSY)
			return TestFail;

		if (camera_->configure(defconf_.get()) != -EACCES)
			return TestFail;

		if (camera_->start() != -EACCES)
			return TestFail;

		/* Test operations which should pass. */
		std::unique_ptr<Request> request = camera_->createRequest();
		if (!request)
			return TestFail;

		Stream *stream = *camera_->streams().begin();
		if (request->addBuffer(stream, allocator_->buffers(stream)[0].get()))
			return TestFail;

		if (camera_->queueRequest(request.get()))
			return TestFail;

		/* Test valid state transitions, end in Available state. */
		if (camera_->stop())
			return TestFail;

		delete allocator_;

		if (camera_->release())
			return TestFail;

		return TestPass;
	}

	int init() override
	{
		if (status_ != TestPass)
			return status_;

		defconf_ = camera_->generateConfiguration({ StreamRole::VideoRecording });
		if (!defconf_) {
			cout << "Failed to generate default configuration" << endl;
			return TestFail;
		}

		return TestPass;
	}

	int run() override
	{
		if (testAvailable() != TestPass) {
			cout << "State machine in Available state failed" << endl;
			return TestFail;
		}

		if (testAcquired() != TestPass) {
			cout << "State machine in Acquired state failed" << endl;
			return TestFail;
		}

		if (testConfigured() != TestPass) {
			cout << "State machine in Configured state failed" << endl;
			return TestFail;
		}

		if (testRuning() != TestPass) {
			cout << "State machine in Running state failed" << endl;
			return TestFail;
		}

		return TestPass;
	}

	std::unique_ptr<CameraConfiguration> defconf_;
	FrameBufferAllocator *allocator_;
};

} /* namespace */

TEST_REGISTER(Statemachine)