[DTrace-devel] [PATCH CORRECTED] Implement normalize() and denormalize()

Kris Van Hees kris.van.hees at oracle.com
Thu Jan 14 09:04:24 PST 2021


The implementation follows the legacy implementation.  One adjustment
that was needed is to retrieve the aggregation data snapshot from
dt_normalize() to ensure that we have the latest data to work on.  This
is needed due to the on-demand data retrieval that the new aggregation
implementation uses.

Tests are simplified to specifically test the functionality they are
intended for, and some tests are added to cover gaps in the testing of
normalize() and denormalize().

Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
---
 libdtrace/dt_aggregate.c                      |   4 -
 libdtrace/dt_cg.c                             |  68 +++++++++---
 libdtrace/dt_consume.c                        | 104 ++++++++++--------
 libdtrace/dtrace.h                            |   3 +-
 .../aggs/err.D_NORMALIZE_AGGARG.bad.d         |  43 --------
 .../err.D_NORMALIZE_AGGARG.denorm_no_agg.d    |  18 +++
 .../aggs/err.D_NORMALIZE_AGGARG.norm_no_agg.d |  18 +++
 .../unittest/aggs/err.D_NORMALIZE_PROTO.bad.d |  42 -------
 .../err.D_NORMALIZE_PROTO.norm_too_few_args.d |  21 ++++
 .../aggs/err.D_NORMALIZE_SCALAR.bad.d         |  42 -------
 .../err.D_PROTO_ARG.norm_non_scalar_normal.d  |  19 ++++
 .../err.D_PROTO_LEN.denorm_too_few_args.d     |  19 ++++
 .../err.D_PROTO_LEN.denorm_too_many_args.d    |  19 ++++
 .../aggs/err.D_PROTO_LEN.norm_too_many_args.d |  19 ++++
 test/unittest/aggs/tst.denormalize.d          |  18 +--
 test/unittest/aggs/tst.denormalize.r          |   8 +-
 test/unittest/aggs/tst.normalize.d            |  19 ++--
 test/unittest/aggs/tst.normalize.r            |   8 +-
 18 files changed, 265 insertions(+), 227 deletions(-)
 delete mode 100644 test/unittest/aggs/err.D_NORMALIZE_AGGARG.bad.d
 create mode 100644 test/unittest/aggs/err.D_NORMALIZE_AGGARG.denorm_no_agg.d
 create mode 100644 test/unittest/aggs/err.D_NORMALIZE_AGGARG.norm_no_agg.d
 delete mode 100644 test/unittest/aggs/err.D_NORMALIZE_PROTO.bad.d
 create mode 100644 test/unittest/aggs/err.D_NORMALIZE_PROTO.norm_too_few_args.d
 delete mode 100644 test/unittest/aggs/err.D_NORMALIZE_SCALAR.bad.d
 create mode 100644 test/unittest/aggs/err.D_PROTO_ARG.norm_non_scalar_normal.d
 create mode 100644 test/unittest/aggs/err.D_PROTO_LEN.denorm_too_few_args.d
 create mode 100644 test/unittest/aggs/err.D_PROTO_LEN.denorm_too_many_args.d
 create mode 100644 test/unittest/aggs/err.D_PROTO_LEN.norm_too_many_args.d

diff --git a/libdtrace/dt_aggregate.c b/libdtrace/dt_aggregate.c
index 6e12ffd5..d601f07e 100644
--- a/libdtrace/dt_aggregate.c
+++ b/libdtrace/dt_aggregate.c
@@ -1116,10 +1116,6 @@ dt_aggwalk_rval(dtrace_hdl_t *dtp, dt_ahashent_t *h, int rval)
 	case DTRACE_AGGWALK_ABORT:
 		return dt_set_errno(dtp, EDT_DIRABORT);
 
-	case DTRACE_AGGWALK_DENORMALIZE:
-		h->dtahe_data.dtada_normal = 1;
-		return 0;
-
 	case DTRACE_AGGWALK_NORMALIZE:
 		if (h->dtahe_data.dtada_normal == 0) {
 			h->dtahe_data.dtada_normal = 1;
diff --git a/libdtrace/dt_cg.c b/libdtrace/dt_cg.c
index 2eef89e4..2753eeac 100644
--- a/libdtrace/dt_cg.c
+++ b/libdtrace/dt_cg.c
@@ -609,33 +609,36 @@ dt_cg_act_commit(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 static void
 dt_cg_act_denormalize(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 {
-	dt_node_t *anp;
-	dt_ident_t *aid;
-	char n[DT_TYPE_NAMELEN];
+	dt_node_t	*anp;
+	int		argc = 0;
+	char		n[DT_TYPE_NAMELEN];
+	dt_ident_t	*aid;
+
+	/* Count the arguments. */
+	for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
+		argc++;
+
+	if (argc != 1)
+		dnerror(dnp, D_NORMALIZE_PROTO,
+		    "%s( ) prototype mismatch: %d args passed, %d expected\n",
+		    dnp->dn_ident->di_name, argc, 1);
 
 	anp = dnp->dn_args;
 	assert(anp != NULL);
-	if (anp->dn_kind != DT_NODE_AGG) {
+	if (anp->dn_kind != DT_NODE_AGG)
 		dnerror(dnp, D_NORMALIZE_AGGARG,
 			"%s( ) argument #1 is incompatible with prototype:\n"
 			"\tprototype: aggregation\n\t argument: %s\n",
 			dnp->dn_ident->di_name,
 			dt_node_type_name(anp, n, sizeof(n)));
-	}
 
 	aid = anp->dn_ident;
 	if (aid->di_gen == pcb->pcb_hdl->dt_gen &&
-	    !(aid->di_flags & DT_IDFLG_MOD)) {
+	    !(aid->di_flags & DT_IDFLG_MOD))
 		dnerror(dnp, D_NORMALIZE_AGGBAD,
 			"undefined aggregation: @%s\n", aid->di_name);
-	}
 
-	/*
-	 * FIXME: Needs implementation
-	 * TODO: Emit code to clear the given aggregation.
-	 * DEPENDS ON: How aggregations are implemented using eBPF (hashmap?).
-	 * AGGID = aid->di_id
-	 */
+	dt_cg_store_val(pcb, anp, DTRACEACT_LIBACT, NULL, DT_ACT_DENORMALIZE);
 }
 
 /*
@@ -730,6 +733,43 @@ dt_cg_act_jstack(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 static void
 dt_cg_act_normalize(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 {
+	dt_node_t	*anp, *normal;
+	int		argc = 0;
+	char		n[DT_TYPE_NAMELEN];
+	dt_ident_t	*aid;
+
+	/* Count the arguments. */
+	for (anp = dnp->dn_args; anp != NULL; anp = anp->dn_list)
+		argc++;
+
+	if (argc != 2)
+		dnerror(dnp, D_NORMALIZE_PROTO,
+		    "%s( ) prototype mismatch: %d args passed, %d expected\n",
+		    dnp->dn_ident->di_name, argc, 2);
+
+	anp = dnp->dn_args;
+	assert(anp != NULL);
+	if (anp->dn_kind != DT_NODE_AGG)
+		dnerror(dnp, D_NORMALIZE_AGGARG,
+			"%s( ) argument #1 is incompatible with prototype:\n"
+			"\tprototype: aggregation\n\t argument: %s\n",
+			dnp->dn_ident->di_name,
+			dt_node_type_name(anp, n, sizeof(n)));
+
+	normal = anp->dn_list;
+	if (!dt_node_is_scalar(normal))
+		dnerror(dnp, D_NORMALIZE_SCALAR,
+			"%s( ) argument #2 must be of scalar type\n",
+			dnp->dn_ident->di_name);
+
+	aid = anp->dn_ident;
+	if (aid->di_gen == pcb->pcb_hdl->dt_gen &&
+	    !(aid->di_flags & DT_IDFLG_MOD))
+		dnerror(dnp, D_NORMALIZE_AGGBAD,
+			"undefined aggregation: @%s\n", aid->di_name);
+
+	dt_cg_store_val(pcb, anp, DTRACEACT_LIBACT, NULL, DT_ACT_NORMALIZE);
+	dt_cg_store_val(pcb, normal, DTRACEACT_LIBACT, NULL, DT_ACT_NORMALIZE);
 }
 
 static void
@@ -747,8 +787,8 @@ dt_cg_act_printa(dt_pcb_t *pcb, dt_node_t *dnp, dtrace_actkind_t kind)
 {
 	dt_node_t	*anp, *proto = NULL;
 	dt_pfargv_t	*pfp = NULL;
-	int		argc = 0, argr;
 	const char	*fmt;
+	int		argc = 0, argr;
 	char		n[DT_TYPE_NAMELEN];
 	dt_ident_t	*aid, *fid;
 	int		*cfp = &pcb->pcb_stmt->dtsd_clauseflags;
diff --git a/libdtrace/dt_consume.c b/libdtrace/dt_consume.c
index b3aea54f..d9cc5089 100644
--- a/libdtrace/dt_consume.c
+++ b/libdtrace/dt_consume.c
@@ -1404,7 +1404,6 @@ dt_print_pcap(dtrace_hdl_t *dtp, FILE *fp, dtrace_recdesc_t *rec,
 	return 0;
 }
 
-#ifdef FIXME
 typedef struct dt_normal {
 	dtrace_aggid_t	dtnd_id;
 	uint64_t	dtnd_normal;
@@ -1427,11 +1426,16 @@ dt_normalize_agg(const dtrace_aggdata_t *aggdata, void *arg)
 	return DTRACE_AGGWALK_NORMALIZE;
 }
 
+/*
+ * This function is also used to denormalize aggregations, because that is
+ * equivalent to normalizing them using normal = 1.
+ */
 static int
 dt_normalize(dtrace_hdl_t *dtp, caddr_t base, dtrace_recdesc_t *rec)
 {
-	dt_normal_t normal;
-	caddr_t addr;
+	int		act = rec->dtrd_arg;
+	dt_normal_t	normal;
+	caddr_t		addr;
 
 	/*
 	 * We (should) have two records:  the aggregation ID followed by the
@@ -1442,58 +1446,49 @@ dt_normalize(dtrace_hdl_t *dtp, caddr_t base, dtrace_recdesc_t *rec)
 	if (rec->dtrd_size != sizeof(dtrace_aggid_t))
 		return dt_set_errno(dtp, EDT_BADNORMAL);
 
-	/* LINTED - alignment */
 	normal.dtnd_id = *((dtrace_aggid_t *)addr);
-	rec++;
 
-	if (rec->dtrd_action != DTRACEACT_LIBACT)
-		return dt_set_errno(dtp, EDT_BADNORMAL);
+	if (act == DT_ACT_NORMALIZE) {
+		rec++;
 
-	if (rec->dtrd_arg != DT_ACT_NORMALIZE)
-		return dt_set_errno(dtp, EDT_BADNORMAL);
+		if (rec->dtrd_action != DTRACEACT_LIBACT)
+			return dt_set_errno(dtp, EDT_BADNORMAL);
 
-	addr = base + rec->dtrd_offset;
+		if (rec->dtrd_arg != DT_ACT_NORMALIZE)
+			return dt_set_errno(dtp, EDT_BADNORMAL);
 
-	switch (rec->dtrd_size) {
-	case sizeof(uint64_t):
-		/* LINTED - alignment */
-		normal.dtnd_normal = *((uint64_t *)addr);
-		break;
-	case sizeof(uint32_t):
-		/* LINTED - alignment */
-		normal.dtnd_normal = *((uint32_t *)addr);
-		break;
-	case sizeof(uint16_t):
-		/* LINTED - alignment */
-		normal.dtnd_normal = *((uint16_t *)addr);
-		break;
-	case sizeof(uint8_t):
-		normal.dtnd_normal = *((uint8_t *)addr);
-		break;
-	default:
-		return dt_set_errno(dtp, EDT_BADNORMAL);
-	}
+		addr = base + rec->dtrd_offset;
 
+		switch (rec->dtrd_size) {
+		case sizeof(uint64_t):
+			normal.dtnd_normal = *((uint64_t *)addr);
+			break;
+		case sizeof(uint32_t):
+			normal.dtnd_normal = *((uint32_t *)addr);
+			break;
+		case sizeof(uint16_t):
+			normal.dtnd_normal = *((uint16_t *)addr);
+			break;
+		case sizeof(uint8_t):
+			normal.dtnd_normal = *((uint8_t *)addr);
+			break;
+		default:
+			return dt_set_errno(dtp, EDT_BADNORMAL);
+		}
+	} else
+		normal.dtnd_normal = 1;
+
+	/*
+	 * Retrieve a snapshot of the aggregation data, and apply the normal
+	 * to all aggregations that need it.
+	 */
+	dtrace_aggregate_snap(dtp);
 	dtrace_aggregate_walk(dtp, dt_normalize_agg, &normal);
 
 	return 0;
 }
 
-static int
-dt_denormalize_agg(const dtrace_aggdata_t *aggdata, void *arg)
-{
-	dtrace_aggdesc_t	*agg = aggdata->dtada_desc;
-	dtrace_aggid_t		id = *((dtrace_aggid_t *)arg);
-
-	if (agg->dtagd_nrecs == 0)
-		return DTRACE_AGGWALK_NEXT;
-
-	if (agg->dtagd_varid != id)
-		return DTRACE_AGGWALK_NEXT;
-
-	return DTRACE_AGGWALK_DENORMALIZE;
-}
-
+#ifdef FIXME
 static int
 dt_clear_agg(const dtrace_aggdata_t *aggdata, void *arg)
 {
@@ -2020,6 +2015,27 @@ dt_consume_one(dtrace_hdl_t *dtp, FILE *fp, char *buf,
 
 			rec = &pdat->dtpda_ddesc->dtdd_recs[i];
 			pdat->dtpda_data = data + rec->dtrd_offset;
+
+			if (rec->dtrd_action == DTRACEACT_LIBACT) {
+				switch (rec->dtrd_arg) {
+				case DT_ACT_DENORMALIZE:
+					if (dt_normalize(dtp, data, rec) != 0)
+						return -1;
+
+					continue;
+				case DT_ACT_NORMALIZE:
+					if (i == pdat->dtpda_ddesc->dtdd_nrecs - 1)
+						return dt_set_errno(dtp,
+								EDT_BADNORMAL);
+
+					if (dt_normalize(dtp, data, rec) != 0)
+						return -1;
+
+					i++;
+					continue;
+				}
+			}
+
 			rval = (*rfunc)(pdat, rec, arg);
 
 			if (rval == DTRACE_CONSUME_NEXT)
diff --git a/libdtrace/dtrace.h b/libdtrace/dtrace.h
index 050795b1..9b426ca0 100644
--- a/libdtrace/dtrace.h
+++ b/libdtrace/dtrace.h
@@ -356,8 +356,7 @@ extern int dtrace_handle_setopt(dtrace_hdl_t *dtp,
 #define	DTRACE_AGGWALK_ABORT		1	/* abort aggregation walk */
 #define	DTRACE_AGGWALK_CLEAR		2	/* clear this element */
 #define	DTRACE_AGGWALK_NORMALIZE	3	/* normalize this element */
-#define	DTRACE_AGGWALK_DENORMALIZE	4	/* denormalize this element */
-#define	DTRACE_AGGWALK_REMOVE		5	/* remove this element */
+#define	DTRACE_AGGWALK_REMOVE		4	/* remove this element */
 
 struct dtrace_aggdata {
 	dtrace_hdl_t *dtada_hdl;		/* handle to DTrace library */
diff --git a/test/unittest/aggs/err.D_NORMALIZE_AGGARG.bad.d b/test/unittest/aggs/err.D_NORMALIZE_AGGARG.bad.d
deleted file mode 100644
index 224bed88..00000000
--- a/test/unittest/aggs/err.D_NORMALIZE_AGGARG.bad.d
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-/* @@xfail: dtv2 */
-
-/*
- * ASSERTION:
- *	The first argument to normalize() should be an aggregation.
- *
- * SECTION: Aggregations/Aggregations
- *
- *
- */
-
-
-#pragma D option quiet
-#pragma D option aggrate=1ms
-#pragma D option switchrate=1ms
-
-BEGIN
-{
-	i = 0;
-	start = timestamp;
-}
-
-tick-100ms
-/i < 20/
-{
-	@func[i % 5] = sum(i * 100);
-	i++;
-}
-
-tick-100ms
-/i == 20/
-{
-
-	printf("normalized data:\n");
-	normalize(count(), 4);
-	exit(0);
-}
diff --git a/test/unittest/aggs/err.D_NORMALIZE_AGGARG.denorm_no_agg.d b/test/unittest/aggs/err.D_NORMALIZE_AGGARG.denorm_no_agg.d
new file mode 100644
index 00000000..e7b193f1
--- /dev/null
+++ b/test/unittest/aggs/err.D_NORMALIZE_AGGARG.denorm_no_agg.d
@@ -0,0 +1,18 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The first argument to denormalize() should be an aggregation.
+ *
+ * SECTION: Aggregations/Data Normalization
+ */
+
+BEGIN
+{
+	denormalize(count());
+	exit(0);
+}
diff --git a/test/unittest/aggs/err.D_NORMALIZE_AGGARG.norm_no_agg.d b/test/unittest/aggs/err.D_NORMALIZE_AGGARG.norm_no_agg.d
new file mode 100644
index 00000000..5b9402a3
--- /dev/null
+++ b/test/unittest/aggs/err.D_NORMALIZE_AGGARG.norm_no_agg.d
@@ -0,0 +1,18 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The first argument to normalize() should be an aggregation.
+ *
+ * SECTION: Aggregations/Data Normalization
+ */
+
+BEGIN
+{
+	normalize(count(), 4);
+	exit(0);
+}
diff --git a/test/unittest/aggs/err.D_NORMALIZE_PROTO.bad.d b/test/unittest/aggs/err.D_NORMALIZE_PROTO.bad.d
deleted file mode 100644
index c8dc344e..00000000
--- a/test/unittest/aggs/err.D_NORMALIZE_PROTO.bad.d
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-/* @@xfail: dtv2 */
-
-/*
- * ASSERTION:
- *	normalize() accepts 2 args - passing fewer is an error.
- *
- * SECTION: Aggregations/Aggregations
- *
- *
- */
-
-
-#pragma D option quiet
-#pragma D option aggrate=1ms
-#pragma D option switchrate=1ms
-
-BEGIN
-{
-	i = 0;
-	start = timestamp;
-}
-
-tick-100ms
-/i < 20/
-{
-	@func[i % 5] = sum(i * 100);
-	i++;
-}
-
-tick-100ms
-/i == 20/
-{
-	printf("normalized data:\n");
-	normalize(@func);
-	exit(0);
-}
diff --git a/test/unittest/aggs/err.D_NORMALIZE_PROTO.norm_too_few_args.d b/test/unittest/aggs/err.D_NORMALIZE_PROTO.norm_too_few_args.d
new file mode 100644
index 00000000..e886590c
--- /dev/null
+++ b/test/unittest/aggs/err.D_NORMALIZE_PROTO.norm_too_few_args.d
@@ -0,0 +1,21 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: THe normalize() action requires 2 arguments (agg and normal).
+ *
+ * SECTION: Aggregations/Data Normalization
+ */
+
+#pragma D option quiet
+
+BEGIN
+{
+	@a = count();
+	normalize(@a);
+	exit(0);
+}
diff --git a/test/unittest/aggs/err.D_NORMALIZE_SCALAR.bad.d b/test/unittest/aggs/err.D_NORMALIZE_SCALAR.bad.d
deleted file mode 100644
index 0e14b77a..00000000
--- a/test/unittest/aggs/err.D_NORMALIZE_SCALAR.bad.d
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Oracle Linux DTrace.
- * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
- * Licensed under the Universal Permissive License v 1.0 as shown at
- * http://oss.oracle.com/licenses/upl.
- */
-/* @@xfail: dtv2 */
-
-/*
- * ASSERTION:
- *	The second argument to normalize() should be a scalar.
- *
- * SECTION: Aggregations/Aggregations
- *
- *
- */
-
-
-#pragma D option quiet
-#pragma D option aggrate=1ms
-#pragma D option switchrate=1ms
-
-BEGIN
-{
-	i = 0;
-	start = timestamp;
-}
-
-tick-100ms
-/i < 20/
-{
-	@func[i % 5] = sum(i * 100);
-	i++;
-}
-
-tick-100ms
-/i == 20/
-{
-	printf("normalized data:\n");
-	normalize(@func, "hello");
-	exit(0);
-}
diff --git a/test/unittest/aggs/err.D_PROTO_ARG.norm_non_scalar_normal.d b/test/unittest/aggs/err.D_PROTO_ARG.norm_non_scalar_normal.d
new file mode 100644
index 00000000..c5b317ed
--- /dev/null
+++ b/test/unittest/aggs/err.D_PROTO_ARG.norm_non_scalar_normal.d
@@ -0,0 +1,19 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The second argument to normalize() should be a scalar.
+ *
+ * SECTION: Aggregations/Data Nonmalization
+ */
+
+BEGIN
+{
+	@a = count();
+	normalize(@a, "a");
+	exit(0);
+}
diff --git a/test/unittest/aggs/err.D_PROTO_LEN.denorm_too_few_args.d b/test/unittest/aggs/err.D_PROTO_LEN.denorm_too_few_args.d
new file mode 100644
index 00000000..c2854d39
--- /dev/null
+++ b/test/unittest/aggs/err.D_PROTO_LEN.denorm_too_few_args.d
@@ -0,0 +1,19 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The denormalize() action requires one argument (agg).
+ *
+ * SECTION: Aggregations/Data Normalization
+ */
+
+BEGIN
+{
+	@a = count();
+	denormalize();
+	exit(0);
+}
diff --git a/test/unittest/aggs/err.D_PROTO_LEN.denorm_too_many_args.d b/test/unittest/aggs/err.D_PROTO_LEN.denorm_too_many_args.d
new file mode 100644
index 00000000..65ca70b3
--- /dev/null
+++ b/test/unittest/aggs/err.D_PROTO_LEN.denorm_too_many_args.d
@@ -0,0 +1,19 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The denormalize() action accepts only one argument (agg).
+ *
+ * SECTION: Aggregations/Data Normalization
+ */
+
+BEGIN
+{
+	@a = count();
+	denormalize(@a, 1);
+	exit(0);
+}
diff --git a/test/unittest/aggs/err.D_PROTO_LEN.norm_too_many_args.d b/test/unittest/aggs/err.D_PROTO_LEN.norm_too_many_args.d
new file mode 100644
index 00000000..eb0941d0
--- /dev/null
+++ b/test/unittest/aggs/err.D_PROTO_LEN.norm_too_many_args.d
@@ -0,0 +1,19 @@
+/*
+ * Oracle Linux DTrace.
+ * Copyright (c) 2006, 2020, Oracle and/or its affiliates. All rights reserved.
+ * Licensed under the Universal Permissive License v 1.0 as shown at
+ * http://oss.oracle.com/licenses/upl.
+ */
+
+/*
+ * ASSERTION: The normalize() action accepts just 2 arguments (agg and normal).
+ *
+ * SECTION: Aggregations/Data Normalization
+ */
+
+BEGIN
+{
+	@a = count();
+	normalize(@a, 4, 1);
+	exit(0);
+}
diff --git a/test/unittest/aggs/tst.denormalize.d b/test/unittest/aggs/tst.denormalize.d
index 94f82775..f138eae3 100644
--- a/test/unittest/aggs/tst.denormalize.d
+++ b/test/unittest/aggs/tst.denormalize.d
@@ -4,39 +4,33 @@
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
-/* @@xfail: dtv2 */
 
 /*
- * ASSERTION:
- *   Simple denormalization test
+ * ASSERTION: Simple denormalization test
  *
- * SECTION: Aggregations/Normalization
+ * SECTION: Aggregations/Data Normalization
  *
  */
 
 #pragma D option quiet
 
-
 BEGIN
 {
 	i = 0;
-	start = timestamp;
 }
 
 tick-10ms
 /i < 20/
 {
-	@func[i % 5] = sum(i * 100);
+	@a = sum(i * 100);
+	@b = sum(i * 100);
 	i++;
 }
 
 tick-10ms
 /i == 20/
 {
-	normalize(@func, 5);
-
-	printf("denormalized:");
-	denormalize(@func);
-	printa(@func);
+	normalize(@a, 5);
+	denormalize(@a);
 	exit(0);
 }
diff --git a/test/unittest/aggs/tst.denormalize.r b/test/unittest/aggs/tst.denormalize.r
index fa4d0da7..7c07a511 100644
--- a/test/unittest/aggs/tst.denormalize.r
+++ b/test/unittest/aggs/tst.denormalize.r
@@ -1,7 +1,3 @@
-denormalized:
-        0             3000
-        1             3400
-        2             3800
-        3             4200
-        4             4600
 
+            19000
+            19000
diff --git a/test/unittest/aggs/tst.normalize.d b/test/unittest/aggs/tst.normalize.d
index cd61de56..d7db1e4d 100644
--- a/test/unittest/aggs/tst.normalize.d
+++ b/test/unittest/aggs/tst.normalize.d
@@ -4,37 +4,32 @@
  * Licensed under the Universal Permissive License v 1.0 as shown at
  * http://oss.oracle.com/licenses/upl.
  */
-/* @@xfail: dtv2 */
 
 /*
- * ASSERTION:
- *   Positive test for normalization()
+ * ASSERTION: Simple normalization test
  *
- * SECTION: Aggregations/Normalization
+ * SECTION: Aggregations/Data Normalization
  *
  */
 
 #pragma D option quiet
-#pragma D option aggrate=1ms
-#pragma D option switchrate=50ms
 
 BEGIN
 {
 	i = 0;
-	start = timestamp;
 }
 
-tick-100ms
+tick-10ms
 /i < 20/
 {
-	@func[i % 5] = sum(i * 100);
+	@a = sum(i * 100);
+	@b = sum(i * 100);
 	i++;
 }
 
-tick-100ms
+tick-10ms
 /i == 20/
 {
-	printf("normalized data:\n");
-	normalize(@func, 5);
+	normalize(@a, 5);
 	exit(0);
 }
diff --git a/test/unittest/aggs/tst.normalize.r b/test/unittest/aggs/tst.normalize.r
index 11193e65..ed467ce1 100644
--- a/test/unittest/aggs/tst.normalize.r
+++ b/test/unittest/aggs/tst.normalize.r
@@ -1,7 +1,3 @@
-normalized data:
 
-        0              600
-        1              680
-        2              760
-        3              840
-        4              920
+             3800
+            19000
-- 
2.28.0




More information about the DTrace-devel mailing list