From: Nicolai Hähnle <nicolai.haeh...@amd.com>

This will be used by shader_runner to check whether SPIRV object files
are up-to-date.
---
 tests/util/piglit-util.c | 34 ++++++++++++++++++++++++++++++++++
 tests/util/piglit-util.h |  1 +
 2 files changed, 35 insertions(+)

diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 3a8f9bcfb..c7398c60a 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -507,6 +507,40 @@ char *piglit_load_text_file(const char *file_name, 
unsigned *size)
 #endif
 }
 
+/**
+ * Return true if file A is older than file B. A file that does not exist is
+ * considered "infinitely old".
+ */
+bool piglit_is_file_older_than(const char *file_name_a, const char 
*file_name_b)
+{
+#ifdef USE_STDIO
+       return false;
+#else
+       struct stat stat_a;
+       struct stat stat_b;
+       int ret;
+
+       ret = stat(file_name_b, &stat_b);
+       if (ret < 0) {
+               printf("Failed to stat %s\n", file_name_b);
+               return false;
+       }
+
+       ret = stat(file_name_a, &stat_a);
+       if (ret < 0) {
+               printf("Failed to stat %s\n", file_name_a);
+               return true;
+       }
+
+       if (stat_a.st_mtim.tv_sec < stat_b.st_mtim.tv_sec ||
+           (stat_a.st_mtim.tv_sec == stat_b.st_mtim.tv_sec &&
+            stat_a.st_mtim.tv_nsec < stat_b.st_mtim.tv_nsec))
+               return true;
+
+       return false;
+#endif
+}
+
 const char*
 piglit_source_dir(void)
 {
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 53cffedbb..70dbfd91f 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -369,6 +369,7 @@ void piglit_general_init(void);
 extern void piglit_set_rlimit(unsigned long lim);
 
 char *piglit_load_text_file(const char *file_name, unsigned *size);
+bool piglit_is_file_older_than(const char *file_name_a, const char 
*file_name_b);
 
 /**
  * \brief Read environment variable PIGLIT_SOURCE_DIR.
-- 
2.19.1

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to