summaryrefslogtreecommitdiffstats
path: root/tests/simple.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/simple.c')
-rw-r--r--tests/simple.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/simple.c b/tests/simple.c
index 921ab6c..85dacb6 100644
--- a/tests/simple.c
+++ b/tests/simple.c
@@ -19,10 +19,37 @@
*************************************************************************/
#include <sandglass.h>
+#include <unistd.h>
+#include <time.h>
#include <stdlib.h>
+#include <stdio.h>
int
main()
{
+ sandglass_t sandglass;
+ sandglass_attributes_t min = { SANDGLASS_MONOTONIC, SANDGLASS_SYSTEM },
+ max = { SANDGLASS_MONOTONIC, SANDGLASS_CPUTIME };
+ struct timespec tosleep = { .tv_sec = 0, .tv_nsec = 100000000 };
+
+ if (sandglass_create(&sandglass, &min, &max) != 0) {
+ perror("sandglass_create()");
+ return EXIT_FAILURE;
+ }
+
+ if (sandglass_begin(&sandglass) != 0) {
+ perror("sandglass_begin()");
+ return EXIT_FAILURE;
+ }
+ while (nanosleep(&tosleep, &tosleep) != 0);
+ if (sandglass_elapse(&sandglass) != 0) {
+ perror("sandglass_elapse()");
+ return EXIT_FAILURE;
+ }
+
+ printf("0.1 seconds timed by sandglass as %ld grains; %g s\n",
+ sandglass.grains,
+ sandglass.grains/sandglass.resolution);
+
return EXIT_SUCCESS;
}