public inbox for dtrace@lists.linux.dev
 help / color / mirror / Atom feed
From: Alan Maguire <alan.maguire@oracle.com>
To: dtrace@lists.linux.dev
Cc: dtrace-devel@oss.oracle.com,
	Alan Maguire <alan.maguire@oracle.com>,
	Eugene Loh <eugene.loh@oracle.com>
Subject: [PATCH v3 3/7] test/operators: extend ternary tests to cover inet_ntoa*()s
Date: Wed,  9 Jul 2025 15:09:44 +0100	[thread overview]
Message-ID: <20250709140948.15090-4-alan.maguire@oracle.com> (raw)
In-Reply-To: <20250709140948.15090-1-alan.maguire@oracle.com>

inet_ntoa*() require temporary strings and ternary operators
need temporaries for left and right; ensure ternary ops succeed
with inet_ntoa*()s.

Suggested-by: Eugene Loh <eugene.loh@oracle.com>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
 test/unittest/operators/tst.ternary.d | 20 +++++++++++++++++++-
 test/unittest/operators/tst.ternary.r |  2 ++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/test/unittest/operators/tst.ternary.d b/test/unittest/operators/tst.ternary.d
index 9d47fcc2..aeced7ac 100644
--- a/test/unittest/operators/tst.ternary.d
+++ b/test/unittest/operators/tst.ternary.d
@@ -8,7 +8,10 @@
 /*
  * ASSERTION:
  *  Test the ternary operator.  Test left-hand side true, right-hand side true,
- *  and multiple nested instances of the ternary operator.
+ *  and multiple nested instances of the ternary operator.  Since inet_ntoa*()
+ *  relies on temporary strings, and ternary operators need both left- and
+ *  right-side temporaries, test ternary inet_ntoa*() also.
+ *
  *
  * SECTION:  Types, Operators, and Expressions/Conditional Expressions
  */
@@ -18,10 +21,25 @@
 BEGIN
 {
 	x = 0;
+	y = 1;
 	printf("x is %s\n", x == 0 ? "zero" : "one");
 	x = 1;
 	printf("x is %s\n", x == 0 ? "zero" : "one");
 	x = 2;
 	printf("x is %s\n", x == 0 ? "zero" : x == 1 ? "one" : "two");
+	ipaddr = (ipaddr_t *)alloca(sizeof(ipaddr_t));
+	ipaddr2 = (in6_addr_t *)alloca(sizeof(in6_addr_t));
+	ipaddr2->in6_u.u6_addr32[0] = 0xffffffff;
+	ipaddr2->in6_u.u6_addr32[1] = 0xffffffff;
+	ipaddr2->in6_u.u6_addr32[2] = 0xffffffff;
+	ipaddr2->in6_u.u6_addr32[3] = 0xffffffff;
+	printf("ipaddr is %s\n", x > 1 ? inet_ntoa(ipaddr) :
+				 x > 2 ? inet_ntoa(ipaddr) :
+				 x > 3 ? inet_ntoa(ipaddr) :
+				 inet_ntoa(ipaddr));
+	printf("ipaddr2 is %s\n", x > 1 ? inet_ntoa6(ipaddr2) :
+				  x > 2 ? inet_ntoa6(ipaddr2) :
+				  x > 3 ? inet_ntoa6(ipaddr2) :
+				  inet_ntoa6(ipaddr2));
 	exit(0);
 }
diff --git a/test/unittest/operators/tst.ternary.r b/test/unittest/operators/tst.ternary.r
index ec30800e..72201682 100644
--- a/test/unittest/operators/tst.ternary.r
+++ b/test/unittest/operators/tst.ternary.r
@@ -1,4 +1,6 @@
 x is zero
 x is one
 x is two
+ipaddr is 0.0.0.0
+ipaddr2 is ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
 
-- 
2.39.3


  parent reply	other threads:[~2025-07-09 14:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-09 14:09 [PATCH v3 0/7] DTrace TCP provider Alan Maguire
2025-07-09 14:09 ` [PATCH v3 1/7] cg: move get_member() to dt_cg.c Alan Maguire
2025-07-21 20:37   ` [DTrace-devel] " Kris Van Hees
2025-07-09 14:09 ` [PATCH v3 2/7] cg: bump number of TSLOTS to 6 Alan Maguire
2025-07-21 20:39   ` [DTrace-devel] " Kris Van Hees
2025-07-09 14:09 ` Alan Maguire [this message]
2025-07-09 14:09 ` [PATCH v3 4/7] providers: move network-generic definitions to net.d Alan Maguire
2025-07-09 14:09 ` [PATCH v3 5/7] tcp: new provider Alan Maguire
2025-07-09 14:09 ` [PATCH v3 6/7] dlibs: sync ip.d, net.d and tcp.d Alan Maguire
2025-07-09 14:09 ` [PATCH v3 7/7] unittest/tcp: update test.x Alan Maguire

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250709140948.15090-4-alan.maguire@oracle.com \
    --to=alan.maguire@oracle.com \
    --cc=dtrace-devel@oss.oracle.com \
    --cc=dtrace@lists.linux.dev \
    --cc=eugene.loh@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox