[libcamera-devel,1/2] test: libtest: Add path_exists helper

Message ID 20181221123724.27290-2-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: Initial v4l2device object
Related show

Commit Message

Kieran Bingham Dec. 21, 2018, 12:37 p.m. UTC
We will frequently need to validate the existance of a target for
testing. Add a helper to wrap this.

This could be extended or replaced to ensure we have access to the path
as well as it existing.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 test/libtest/test.cpp | 11 +++++++++++
 test/libtest/test.h   |  2 ++
 2 files changed, 13 insertions(+)

Comments

Laurent Pinchart Jan. 3, 2019, 1:53 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Friday, 21 December 2018 14:37:23 EET Kieran Bingham wrote:
> We will frequently need to validate the existance of a target for
> testing. Add a helper to wrap this.
> 
> This could be extended or replaced to ensure we have access to the path
> as well as it existing.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  test/libtest/test.cpp | 11 +++++++++++
>  test/libtest/test.h   |  2 ++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/test/libtest/test.cpp b/test/libtest/test.cpp
> index 9d537ea08698..ff0c9fc02e15 100644
> --- a/test/libtest/test.cpp
> +++ b/test/libtest/test.cpp
> @@ -5,6 +5,7 @@
>   * test.cpp - libcamera test base class
>   */
> 
> +#include <sys/stat.h>
>  #include "test.h"
> 
>  Test::Test()
> @@ -29,3 +30,13 @@ int Test::execute()
> 
>  	return ret;
>  }
> +
> +bool Test::path_exists(const char *p)

This should be called pathExists(), and should be a static function.

I wonder whether this feature will be useful as part of libcamera, in a File 
helper class. I suppose we'll find out later.

> +{
> +	struct stat sb;
> +
> +	if (stat(p, &sb) == 0)
> +		return true;

Should we also check whether the file can be accessed ? Or should that be a 
separate function ?

> +	return false;
> +}
> diff --git a/test/libtest/test.h b/test/libtest/test.h
> index 18b430f428c7..f21cc15e8743 100644
> --- a/test/libtest/test.h
> +++ b/test/libtest/test.h
> @@ -21,6 +21,8 @@ public:
> 
>  	int execute();
> 
> +	bool path_exists(const char *p);
> +
>  protected:
>  	virtual int init() { return 0; }
>  	virtual int run() = 0;

Patch

diff --git a/test/libtest/test.cpp b/test/libtest/test.cpp
index 9d537ea08698..ff0c9fc02e15 100644
--- a/test/libtest/test.cpp
+++ b/test/libtest/test.cpp
@@ -5,6 +5,7 @@ 
  * test.cpp - libcamera test base class
  */
 
+#include <sys/stat.h>
 #include "test.h"
 
 Test::Test()
@@ -29,3 +30,13 @@  int Test::execute()
 
 	return ret;
 }
+
+bool Test::path_exists(const char *p)
+{
+	struct stat sb;
+
+	if (stat(p, &sb) == 0)
+		return true;
+
+	return false;
+}
diff --git a/test/libtest/test.h b/test/libtest/test.h
index 18b430f428c7..f21cc15e8743 100644
--- a/test/libtest/test.h
+++ b/test/libtest/test.h
@@ -21,6 +21,8 @@  public:
 
 	int execute();
 
+	bool path_exists(const char *p);
+
 protected:
 	virtual int init() { return 0; }
 	virtual int run() = 0;