[48/63] util: add piglit_is_file_older_than helper

Submitted by apinheiro on Feb. 23, 2019, 11:45 p.m.

Details

Message ID 20190223234551.21111-49-apinheiro@igalia.com
State New
Headers show
Series "ARB_gl_spirv full series" ( rev: 1 ) in Piglit

Not browsing as part of any series.

Commit Message

apinheiro Feb. 23, 2019, 11:45 p.m.
From: Nicolai Hähnle <nicolai.haehnle@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(+)

Patch hide | download patch | download mbox

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.