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

Kieran Bingham kieran.bingham at ideasonboard.com
Fri Dec 21 13:37:23 CET 2018


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 at 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)
+{
+	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;
-- 
2.17.1



More information about the libcamera-devel mailing list