From patchwork Wed Aug 4 11:35:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 13194 X-Patchwork-Delegate: paul.elder@ideasonboard.com Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 848ECC3235 for ; Wed, 4 Aug 2021 11:35:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EE7676881B; Wed, 4 Aug 2021 13:35:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZdHqVRk6"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9DBD66026E for ; Wed, 4 Aug 2021 13:35:40 +0200 (CEST) Received: from pyrite.rasen.tech (unknown [IPv6:2400:4051:61:600:2c71:1b79:d06d:5032]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 083DA24F; Wed, 4 Aug 2021 13:35:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1628076940; bh=iG0f1hBGfnkDqbPb1ee7MfWAWErBD/J/9JbzJj42HvM=; h=From:To:Cc:Subject:Date:From; b=ZdHqVRk6uU6lV4l+H14L0GQh6bP8yvWzGbR32kBYwq1gDI5QmIeqT6RdScmx95x/E nq+NccG31C/TdfTfh7pibEyQ7is78sifTPMA4c7nnpxe1JE+ts4nN35ck/eU3wMYJp ToxhSFX/2/aQ3ZHeC/MJlLtAB/0uo0631rOJTyFk= From: Paul Elder To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Aug 2021 20:35:29 +0900 Message-Id: <20210804113529.418162-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH] tests: ipa_data_serializer_test: Test serializing fds X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add tests to test IPADataSerializer serializing FileDescriptors. Signed-off-by: Paul Elder Reviewed-by: Umang Jain --- include/libcamera/file_descriptor.h | 1 + src/libcamera/file_descriptor.cpp | 9 ++++ .../ipa_data_serializer_test.cpp | 43 +++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/include/libcamera/file_descriptor.h b/include/libcamera/file_descriptor.h index d514aac7..8f1d6f21 100644 --- a/include/libcamera/file_descriptor.h +++ b/include/libcamera/file_descriptor.h @@ -22,6 +22,7 @@ public: FileDescriptor &operator=(const FileDescriptor &other); FileDescriptor &operator=(FileDescriptor &&other); + bool operator==(const FileDescriptor &other) const; bool isValid() const { return fd_ != nullptr; } int fd() const { return fd_ ? fd_->fd() : -1; } diff --git a/src/libcamera/file_descriptor.cpp b/src/libcamera/file_descriptor.cpp index 638b3bbe..f1394153 100644 --- a/src/libcamera/file_descriptor.cpp +++ b/src/libcamera/file_descriptor.cpp @@ -191,6 +191,15 @@ FileDescriptor &FileDescriptor::operator=(FileDescriptor &&other) return *this; } +/** + * \brief Compare FileDescriptor instances for equality + * \return True if the underlying file descriptor is equal, false otherwise + */ +bool FileDescriptor::operator==(const FileDescriptor &other) const +{ + return this->fd() == other.fd(); +} + /** * \fn FileDescriptor::isValid() * \brief Check if the FileDescriptor instance is valid diff --git a/test/serialization/ipa_data_serializer_test.cpp b/test/serialization/ipa_data_serializer_test.cpp index 1e8f7e21..9c8ff69c 100644 --- a/test/serialization/ipa_data_serializer_test.cpp +++ b/test/serialization/ipa_data_serializer_test.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,10 @@ protected: if (ret != TestPass) return ret; + ret = testFd(); + if (ret != TestPass) + return ret; + return TestPass; } @@ -435,6 +440,44 @@ private: return TestPass; } + + int testFd() + { + /* Test serdes of single fd */ + int memfd = memfd_create("test", 0); + if (memfd < 0) { + cerr << "Failed to create memfd" << endl; + return TestFail; + } + + FileDescriptor fd = FileDescriptor(std::move(memfd)); + if (memfd != -1) { + cerr << "FileDescriptor move constructor failed" << endl; + return TestFail; + } + + if (testPodSerdes(fd) != TestPass) + return TestFail; + + /* Test serdes of vector of fds */ + std::vector vecFds; + + for (unsigned int i = 0; i < 10; i++) { + std::string name = "test" + std::to_string(i); + int mfd = memfd_create(name.c_str(), 0); + if (mfd < 0) + return TestFail; + + vecFds.push_back(FileDescriptor(std::move(mfd))); + if (mfd != -1) + return TestFail; + } + + if (testVectorSerdes(vecFds) != TestPass) + return TestFail; + + return TestPass; + } }; TEST_REGISTER(IPADataSerializerTest)