diff options
author | Ambroz Bizjak <ambrop7@gmail.com> | 2015-01-23 00:37:29 +0300 |
---|---|---|
committer | Ambroz Bizjak <ambrop7@gmail.com> | 2015-01-23 00:37:29 +0300 |
commit | 8b43112e48b92b4f7907a9065e96583f0532faa6 (patch) | |
tree | d078e5e88beabd05d65978342a33837d69fb2517 | |
parent | 2d242ebc89dbb9aed22b331ef5afb501ed2e4676 (diff) |
ncd: Add clock_get_ms function.
-rw-r--r-- | ncd/modules/basic_functions.c | 18 | ||||
-rw-r--r-- | ncd/tests/clock.ncd | 11 |
2 files changed, 29 insertions, 0 deletions
diff --git a/ncd/modules/basic_functions.c b/ncd/modules/basic_functions.c index 7f3617c..f6ab885 100644 --- a/ncd/modules/basic_functions.c +++ b/ncd/modules/basic_functions.c @@ -34,6 +34,7 @@ #include <misc/ascii_utils.h> #include <ncd/NCDValGenerator.h> #include <ncd/NCDValParser.h> +#include <system/BTime.h> #include <ncd/module_common.h> @@ -676,6 +677,20 @@ static void checksum_eval (NCDCall call) } +// clock_get_ms + +static void clock_get_ms_eval (NCDCall call) +{ + if (NCDCall_ArgCount(&call) != 0) { + FunctionLog(&call, BLOG_ERROR, "clock_get_ms: need zero arguments"); + return; + } + // Convert to unsigned. The time should be non-negative so this is OK. + uintmax_t the_time = btime_gettime(); + NCDCall_SetResult(&call, ncd_make_uintmax(NCDCall_ResMem(&call), the_time)); +} + + static struct NCDModuleFunction const functions[] = { { .func_name = "error", @@ -789,6 +804,9 @@ static struct NCDModuleFunction const functions[] = { .func_name = "checksum", .func_eval = checksum_eval }, { + .func_name = "clock_get_ms", + .func_eval = clock_get_ms_eval + }, { .func_name = NULL } }; diff --git a/ncd/tests/clock.ncd b/ncd/tests/clock.ncd new file mode 100644 index 0000000..08d3e82 --- /dev/null +++ b/ncd/tests/clock.ncd @@ -0,0 +1,11 @@ +process main { + var(@clock_get_ms()) t0; + backtrack_point() again; + var(@clock_get_ms()) t1; + assert(@num_greater_equal(t1, t0)); + If (@num_equal(t1, t0)) { + again->go(); + }; + + exit("0"); +} |