diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2014-10-26 12:33:50 +0400 |
commit | 47e6e7c84f008a53061e661f31ae96629bc694ef (patch) | |
tree | 648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /qa/src/pv.c | |
download | pcp-debian.tar.gz |
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'qa/src/pv.c')
-rw-r--r-- | qa/src/pv.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/qa/src/pv.c b/qa/src/pv.c new file mode 100644 index 0000000..a290aa7 --- /dev/null +++ b/qa/src/pv.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 1997-2001 Silicon Graphics, Inc. All Rights Reserved. + */ + +#include <stdio.h> +#include <string.h> +#include "pcp/pmapi.h" + +/* + * exercise pmPrintValue() ... should produce very similar answers + * when compiled both 32 and 64 bit ... see pv and pv64 targets in + * the Makefile + */ + +int +main(void) +{ + pmValue v; + int l; + unsigned int ul; + long long ll; + unsigned long long ull; + float f; + float *fp; + double d; + struct { + int len; + char vbuf[sizeof(double)]; + } vb; + + v.inst = 1; + + l = -1 & (~0xffff); + memcpy((void *)&v.value.lval, (void *)&l, sizeof(l)); + printf("PM_TYPE_32: "); + pmPrintValue(stdout, PM_VAL_INSITU, PM_TYPE_32, &v, 1); + printf(" correct: %i (0x%x)\n", l, l); + + ul = 0x87654321; + memcpy((void *)&v.value.lval, (void *)&ul, sizeof(ul)); + printf("PM_TYPE_U32: "); + pmPrintValue(stdout, PM_VAL_INSITU, PM_TYPE_U32, &v, 1); + printf(" correct: %u (0x%x)\n", ul, ul); + + f = 123456.78; + fp = (float *)&v.value.lval; + *fp = f; + printf("PM_TYPE_FLOAT: "); + pmPrintValue(stdout, PM_VAL_INSITU, PM_TYPE_FLOAT, &v, 9); + printf(" correct: %.2f\n", (double)f); + + d = 123456.789012345; + memcpy((void *)vb.vbuf, (void *)&d, sizeof(double)); + vb.len = sizeof(vb.len) + sizeof(double); + v.value.pval = (pmValueBlock *)&vb; + printf("PM_TYPE_DOUBLE: "); + pmPrintValue(stdout, PM_VAL_SPTR, PM_TYPE_DOUBLE, &v, 16); + printf(" correct: %.9f\n", d); + + ll = -1 & (~0xffff); + memcpy((void *)vb.vbuf, (void *)&ll, sizeof(long long)); + vb.len = sizeof(vb.len) + sizeof(long long); + v.value.pval = (pmValueBlock *)&vb; + printf("PM_TYPE_64: "); + pmPrintValue(stdout, PM_VAL_SPTR, PM_TYPE_64, &v, 1); + printf(" correct: %lli (0x%llx)\n", ll, ll); + + ull = 0x8765432112340000LL; + memcpy((void *)vb.vbuf, (void *)&ull, sizeof(unsigned long long)); + vb.len = sizeof(vb.len) + sizeof(unsigned long long); + v.value.pval = (pmValueBlock *)&vb; + printf("PM_TYPE_U64: "); + pmPrintValue(stdout, PM_VAL_SPTR, PM_TYPE_U64, &v, 1); + printf(" correct: %llu (0x%llx)\n", ull, ull); + + exit(0); +} |