Skip to contentSkip to conversation

Testing statx syscall Timestamp fields

PATCH Superseded subash 1 participant 1 message Sep 10, 2018 Library code

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

subash

author
#0 lore raw

PATCH v2 1/4 Testing statx syscall Timestamp fields

* statx07.c:The time before and after the execution of the create system call is noted.
It is checked whether the birth time returned by statx lies in this range.

---
 include/safe_macros_fn.h                           |  5 ++
 include/tst_safe_macros.h                          |  6 ++
 lib/safe_macros.c                                  | 23 ++++++
 runtest/syscalls                                   |  1 +
 testcases/kernel/syscalls/statx/.gitignore         |  1 +
 testcases/kernel/syscalls/statx/Makefile           |  4 ++
 testcases/kernel/syscalls/statx/statx07.c          | 84 ++++++++++++++++++++++
 testcases/kernel/syscalls/statx/timestamp_helper.c | 30 ++++++++
 testcases/kernel/syscalls/statx/timestamp_helper.h | 15 ++++
 9 files changed, 169 insertions(+)
 create mode 100644 testcases/kernel/syscalls/statx/statx07.c
 create mode 100644 testcases/kernel/syscalls/statx/timestamp_helper.c
 create mode 100644 testcases/kernel/syscalls/statx/timestamp_helper.h
include/safe_macros_fn.h +5 -0
index 3df952811..578ac08e2 100644
@@ -184,4 +184,9 @@ int safe_closedir(const char *file, const int lineno,
                   void (cleanup_fn)(void),
                   DIR *dirp);
 
+void safe_clock_getres(const char *file, const int lineno,
+		clockid_t clk_id, struct timespec *res);
+
+void safe_clock_gettime(const char *file, const int lineno,
+		clockid_t clk_id, struct timespec *tp);
 #endif /* SAFE_MACROS_FN_H__ */
include/tst_safe_macros.h +6 -0
index 03657a410..c47342446 100644
@@ -512,4 +512,10 @@ int safe_personality(const char *filename, unsigned int lineno,
 	}							\
 	} while (0)
 
+#define SAFE_CLOCK_GETRES(clk_id, res)\
+	safe_clock_getres(__FILE__, __LINE__, (clk_id), (res))
+
+#define SAFE_CLOCK_GETTIME(clk_id, tp)\
+	safe_clock_gettime(__FILE__, __LINE__, (clk_id), (tp))
+
 #endif /* SAFE_MACROS_H__ */
lib/safe_macros.c +23 -0
index 5cc80d035..85643c743 100644
@@ -1048,3 +1048,26 @@ int safe_mincore(const char *file, const int lineno, void *start,
 
 	return rval;
 }
+
+void safe_clock_getres(const char *file, const int lineno,
+	clockid_t clk_id, struct timespec *res)
+{
+	int rval;
+
+	rval = clock_getres(clk_id, res);
+	if (rval == -1)
+		tst_brkm(TBROK | TERRNO, NULL,
+			"%s:%d:, clock_getres() failed", file, lineno);
+
+}
+
+void safe_clock_gettime(const char *file, const int lineno,
+	clockid_t clk_id, struct timespec *tp)
+{
+	int rval;
+
+	rval = clock_gettime(clk_id, tp);
+	if (rval == -1)
+		tst_brkm(TBROK | TERRNO, NULL, 
+			"%s:%d:, clock_gettime() failed", file, lineno);
+}
runtest/syscalls +1 -0
index 0d0be7713..da2f8c090 100644
@@ -1504,3 +1504,4 @@ statx02 statx02
 statx03 statx03
 statx04 statx04
 statx05 statx05
+statx07 statx07
\ No newline at end of file
testcases/kernel/syscalls/statx/.gitignore +1 -0
index 209fc3a33..14cb1ec43 100644
@@ -3,3 +3,4 @@
 /statx03
 /statx04
 /statx05
+/statx07
\ No newline at end of file
testcases/kernel/syscalls/statx/Makefile +4 -0
index 3a9c66d6d..81420497d 100644
@@ -21,6 +21,10 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+FILTER_OUT_MAKE_TARGETS         := timestamp_helper
+
 %_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+$(MAKE_TARGETS): %: %.o timestamp_helper.o
testcases/kernel/syscalls/statx/statx07.c new file +84 -0

84 lines not on this page · raw message

testcases/kernel/syscalls/statx/timestamp_helper.c new file +30 -0
new file mode 100644
index 000000000..cea76b7fa
@@ -0,0 +1,30 @@
+//SPDX-License-Identifier:GPL-2.0-or-later
+/*
+ * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
+ * Email: [email protected]
+ */
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+#include "lapi/stat.h"
+#include "tst_safe_macros.h"
+#include "timestamp_helper.h"
+
+void statx_timestamp_to_timespec(const struct statx_timestamp *timestamp,
+				 struct timespec *timespec)
+{
+	timespec->tv_sec = timestamp->tv_sec;
+	timespec->tv_nsec = timestamp->tv_nsec;
+}
+
+void clock_wait_tick(void)
+{
+	struct timespec res;
+	unsigned int usecs;
+
+	SAFE_CLOCK_GETRES(CLOCK_REALTIME_COARSE, &res);
+	usecs = ((res.tv_sec * 1000000) + (res.tv_nsec / 1000)) * 1.5;
+
+	usleep(usecs);
+}
testcases/kernel/syscalls/statx/timestamp_helper.h new file +15 -0
new file mode 100644
index 000000000..8dcd8d6d8
@@ -0,0 +1,15 @@
+//SPDX-License-Identifier:GPL-2.0-or-later
+/*
+ * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
+ * Email: [email protected]
+ */
+
+#ifndef TIMESTAMP_HELPER
+#define TIMESTAMP_HELPER
+
+#include <time.h>
+
+void statx_timestamp_to_timespec(const struct statx_timestamp *timestamp,
+				struct timespec *timespec);
+void clock_wait_tick(void);
+#endif
Signature · 1 line
2.11.0