[{"id":2113,"web_url":"https://patchwork.libcamera.org/comment/2113/","msgid":"<20190702002826.GN9228@bigcity.dyn.berto.se>","date":"2019-07-02T00:28:26","subject":"Re: [libcamera-devel] [PATCH v4 12/13] libcamera: test: Add\n\tControlList tests","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Kieran,\n\nThanks for your patch.\n\nOn 2019-07-01 23:15:03 +0300, Laurent Pinchart wrote:\n> From: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> Add tests of the ControlList infrastructure and public API.\n> \n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nReviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\n> ---\n>  test/controls/control_list.cpp | 213 +++++++++++++++++++++++++++++++++\n>  test/controls/meson.build      |   1 +\n>  2 files changed, 214 insertions(+)\n>  create mode 100644 test/controls/control_list.cpp\n> \n> diff --git a/test/controls/control_list.cpp b/test/controls/control_list.cpp\n> new file mode 100644\n> index 000000000000..c834edc352f5\n> --- /dev/null\n> +++ b/test/controls/control_list.cpp\n> @@ -0,0 +1,213 @@\n> +/* SPDX-License-Identifier: GPL-2.0-or-later */\n> +/*\n> + * Copyright (C) 2019, Google Inc.\n> + *\n> + * control_list.cpp - ControlList tests\n> + */\n> +\n> +#include <iostream>\n> +\n> +#include <libcamera/camera.h>\n> +#include <libcamera/camera_manager.h>\n> +#include <libcamera/controls.h>\n> +\n> +#include \"test.h\"\n> +\n> +using namespace std;\n> +using namespace libcamera;\n> +\n> +class ControlListTest : public Test\n> +{\n> +protected:\n> +\tint init()\n> +\t{\n> +\t\tcm_ = CameraManager::instance();\n> +\n> +\t\tif (cm_->start()) {\n> +\t\t\tcout << \"Failed to start camera manager\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tcamera_ = cm_->get(\"VIMC Sensor B\");\n> +\t\tif (!camera_) {\n> +\t\t\tcout << \"Can not find VIMC camera\" << endl;\n> +\t\t\treturn TestSkip;\n> +\t\t}\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tint run()\n> +\t{\n> +\t\tControlList list(camera_.get());\n> +\n> +\t\t/* Test that the list is initially empty. */\n> +\t\tif (!list.empty()) {\n> +\t\t\tcout << \"List should to be empty\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (list.size() != 0) {\n> +\t\t\tcout << \"List should contain zero items\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (list.contains(Brightness)) {\n> +\t\t\tcout << \"List should not contain Brightness control\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tunsigned int count = 0;\n> +\t\tfor (auto iter = list.begin(); iter != list.end(); ++iter)\n> +\t\t\tcount++;\n> +\n> +\t\tif (count != 0) {\n> +\t\t\tcout << \"List iteration should not produce any item\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Set a control, and verify that the list now contains it, and\n> +\t\t * nothing else.\n> +\t\t */\n> +\t\tlist[Brightness] = 255;\n> +\n> +\t\tif (list.empty()) {\n> +\t\t\tcout << \"List should not be empty\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (list.size() != 1) {\n> +\t\t\tcout << \"List should contain one item\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (!list.contains(Brightness)) {\n> +\t\t\tcout << \"List should contain Brightness control\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tcount = 0;\n> +\t\tfor (auto iter = list.begin(); iter != list.end(); ++iter)\n> +\t\t\tcount++;\n> +\n> +\t\tif (count != 1) {\n> +\t\t\tcout << \"List iteration should produce one item\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (list[Brightness].getInt() != 255) {\n> +\t\t\tcout << \"Incorrest Brightness control value\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (list.contains(Contrast)) {\n> +\t\t\tcout << \"List should not contain Contract control\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Set a second control through ControlInfo and retrieve it\n> +\t\t * through both controlId and ControlInfo.\n> +\t\t */\n> +\t\tconst ControlInfoMap &controls = camera_->controls();\n> +\t\tconst ControlInfo *brightness = &controls.find(Brightness)->second;\n> +\t\tconst ControlInfo *contrast = &controls.find(Contrast)->second;\n> +\n> +\t\tlist[brightness] = 64;\n> +\t\tlist[contrast] = 128;\n> +\n> +\t\tif (!list.contains(Contrast) || !list.contains(contrast)) {\n> +\t\t\tcout << \"List should contain Contrast control\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Test control value retrieval and update through ControlInfo.\n> +\t\t */\n> +\t\tif (list[brightness].getInt() != 64 ||\n> +\t\t    list[contrast].getInt() != 128) {\n> +\t\t\tcout << \"Failed to retrieve control value\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tlist[brightness] = 10;\n> +\t\tlist[contrast] = 20;\n> +\n> +\t\tif (list[brightness].getInt() != 10 ||\n> +\t\t    list[contrast].getInt() != 20) {\n> +\t\t\tcout << \"Failed to update control value\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Assert that the container has not grown with the control\n> +\t\t * updated.\n> +\t\t */\n> +\t\tif (list.size() != 2) {\n> +\t\t\tcout << \"List should contain two elements\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\t/*\n> +\t\t * Test list merging. Create a new list, add two controls with\n> +\t\t * one overlapping the existing list, merge the lists and clear\n> +\t\t * the old list. Verify that the new list is empty and that the\n> +\t\t * new list contains the expected items and values.\n> +\t\t */\n> +\t\tControlList newList(camera_.get());\n> +\n> +\t\tnewList[Brightness] = 128;\n> +\t\tnewList[Saturation] = 255;\n> +\t\tnewList.update(list);\n> +\n> +\t\tlist.clear();\n> +\n> +\t\tif (list.size() != 0) {\n> +\t\t\tcout << \"Old List should contain zero items\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (!list.empty()) {\n> +\t\t\tcout << \"Old List should be empty\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (newList.size() != 3) {\n> +\t\t\tcout << \"New list has incorrect size\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (!newList.contains(Brightness) ||\n> +\t\t    !newList.contains(Contrast) ||\n> +\t\t    !newList.contains(Saturation)) {\n> +\t\t\tcout << \"New list contains incorrect items\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\tif (newList[Brightness].getInt() != 10 ||\n> +\t\t    newList[Contrast].getInt() != 20 ||\n> +\t\t    newList[Saturation].getInt() != 255) {\n> +\t\t\tcout << \"New list contains incorrect values\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n> +\t\treturn TestPass;\n> +\t}\n> +\n> +\tvoid cleanup()\n> +\t{\n> +\t\tif (camera_) {\n> +\t\t\tcamera_->release();\n> +\t\t\tcamera_.reset();\n> +\t\t}\n> +\n> +\t\tcm_->stop();\n> +\t}\n> +\n> +private:\n> +\tCameraManager *cm_;\n> +\tstd::shared_ptr<Camera> camera_;\n> +};\n> +\n> +TEST_REGISTER(ControlListTest)\n> diff --git a/test/controls/meson.build b/test/controls/meson.build\n> index f8cda2877e73..f4fc7b947dd9 100644\n> --- a/test/controls/meson.build\n> +++ b/test/controls/meson.build\n> @@ -1,5 +1,6 @@\n>  control_tests = [\n>      [ 'control_info',   'control_info.cpp' ],\n> +    [ 'control_list',   'control_list.cpp' ],\n>      [ 'control_value',  'control_value.cpp' ],\n>  ]\n>  \n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from mail-lj1-x244.google.com (mail-lj1-x244.google.com\n\t[IPv6:2a00:1450:4864:20::244])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0610460C2B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  2 Jul 2019 02:28:28 +0200 (CEST)","by mail-lj1-x244.google.com with SMTP id m23so15030065lje.12\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 01 Jul 2019 17:28:27 -0700 (PDT)","from localhost (customer-145-14-112-32.stosn.net. [145.14.112.32])\n\tby smtp.gmail.com with ESMTPSA id\n\td4sm2748677lfi.91.2019.07.01.17.28.26\n\t(version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256);\n\tMon, 01 Jul 2019 17:28:26 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to\n\t:user-agent; bh=b27X1Mkk/oQw142AAaOl/kQVzmdbySZUp/j00OLua1A=;\n\tb=FXzODfynCQKpReKkW/5vUn0WeDYRuruXuCBm1ehQhkBMPc1ewcH1yvjBJG9SZEEb2l\n\tJ25yNp8nlMGuO/PBTUUmVL6wHfdX2KuiqWV5lNbShCBtP7lYP1yhnAwfR4Q/cqLTJjge\n\t3LMGbcEQnoOJVAAzIUAahKAb9x9SDE/OCzG7E/I9VAlkito0VTjZOQCvho/cDgJ0ZfDf\n\t9bpBwZHcBXjiiSNuVoB0OZ/y/vlsS68JDOYi47KmLZ9VcB27yOHCGKsqQZev6yHfNo+5\n\t4fFYE1L2S/aXdLGN4QydXYCACF3xUzilS4+FHg0npwVUIpJ/eM49gwViQuDKw0DTqtS8\n\tUULQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to:user-agent;\n\tbh=b27X1Mkk/oQw142AAaOl/kQVzmdbySZUp/j00OLua1A=;\n\tb=IqpuoFMSzrA4rtyM9fI9JZxv5yB7IZVEWpbtaGlFC1DUEM0dAxyfucJ9MTPJvrioB1\n\tK8BDaypsAOetw96MGmA4heJJ27dEzkozuQvytW8Mr46g2p6e7ce82rs3x8FqRLoZF8m3\n\t+IisX0UbnLkLzaauH+Xk5JZ6G3WqRpsfezm9yHQk7go0I59hGaKt6qj8Js4eP426d25w\n\tmBlS9khz+1fgfExzTHuBJPxAj1xsMLtNb4xlRAtJa4P52j3a2VShKnUG4IjPWKJDOINx\n\te1fs5jQIP5yeb1isWMfn43scGZ0IAzF1H6E2QHDZDHtors1HBYOjZIz8NonEDltu0UzW\n\t2VWQ==","X-Gm-Message-State":"APjAAAXOprMbSxTeNpOEiDy2KGBrM/OPZo8fcdnA4ctFX2M76u6/w2+o\n\tGwuyuf94IBDHibLeY4NNIIvC+g==","X-Google-Smtp-Source":"APXvYqw2os51ltgZKgDpR9Z0Z/yYIdw13T5yt3ISzOUKIdTGjWvBSZSlSO35yzPaOvWsRrs9wQN8vA==","X-Received":"by 2002:a2e:a16c:: with SMTP id u12mr4318432ljl.59.1562027307395;\n\tMon, 01 Jul 2019 17:28:27 -0700 (PDT)","Date":"Tue, 2 Jul 2019 02:28:26 +0200","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190702002826.GN9228@bigcity.dyn.berto.se>","References":"<20190701201504.28487-1-laurent.pinchart@ideasonboard.com>\n\t<20190701201504.28487-13-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20190701201504.28487-13-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.12.1 (2019-06-15)","Subject":"Re: [libcamera-devel] [PATCH v4 12/13] libcamera: test: Add\n\tControlList tests","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Tue, 02 Jul 2019 00:28:28 -0000"}}]