Linux DTrace development list
 help / color / mirror / Atom feed
* [PATCH] test: ensure casting does not affect value
@ 2024-07-31 19:01 Kris Van Hees
  2024-07-31 19:51 ` Eugene Loh
  2024-08-01 18:44 ` Nick Alcock
  0 siblings, 2 replies; 5+ messages in thread
From: Kris Van Hees @ 2024-07-31 19:01 UTC (permalink / raw)
  To: dtrace, dtrace-devel

On systems without CTF, we do not know the type of kernel variables.
By doing an explicit cast to int64_t a negative int is converted into a
large positive integer.  The proper cast is 'int' of course.

Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
---
 test/unittest/codegen/tst.kernel_read_neg_small_scalar.d | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d b/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
index 7c585d1b..cda6649b 100644
--- a/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
+++ b/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
@@ -1,6 +1,6 @@
 /*
  * Oracle Linux DTrace.
- * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2024, 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.
  */
@@ -11,10 +11,10 @@ BEGIN
 {
 	/*
 	 * Unless we are actually crashing, the `crashing_cpu int will be -1.
-	 * We cast it to int64_t to ensure that the value read from the kernel
+	 * We cast it to int to ensure that the value read from the kernel
 	 * is sign-extended.
 	 */
-	trace((int64_t)`crashing_cpu);
+	trace((int)`crashing_cpu);
 	exit(0);
 }
 
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] test: ensure casting does not affect value
  2024-07-31 19:01 [PATCH] test: ensure casting does not affect value Kris Van Hees
@ 2024-07-31 19:51 ` Eugene Loh
  2024-07-31 20:04   ` Kris Van Hees
  2024-08-01 18:44 ` Nick Alcock
  1 sibling, 1 reply; 5+ messages in thread
From: Eugene Loh @ 2024-07-31 19:51 UTC (permalink / raw)
  To: Kris Van Hees, dtrace, dtrace-devel

What is the point of this test?  If we do not know the type of the 
kernel variable, then what does "kernel_read_neg_small_scalar" mean?

On 7/31/24 15:01, Kris Van Hees wrote:
> On systems without CTF, we do not know the type of kernel variables.
> By doing an explicit cast to int64_t a negative int is converted into a
> large positive integer.  The proper cast is 'int' of course.
>
> Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
> ---
>   test/unittest/codegen/tst.kernel_read_neg_small_scalar.d | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d b/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
> index 7c585d1b..cda6649b 100644
> --- a/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
> +++ b/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
> @@ -1,6 +1,6 @@
>   /*
>    * Oracle Linux DTrace.
> - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> + * Copyright (c) 2022, 2024, 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.
>    */
> @@ -11,10 +11,10 @@ BEGIN
>   {
>   	/*
>   	 * Unless we are actually crashing, the `crashing_cpu int will be -1.
> -	 * We cast it to int64_t to ensure that the value read from the kernel
> +	 * We cast it to int to ensure that the value read from the kernel
>   	 * is sign-extended.
>   	 */
> -	trace((int64_t)`crashing_cpu);
> +	trace((int)`crashing_cpu);
>   	exit(0);
>   }
>   

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] test: ensure casting does not affect value
  2024-07-31 19:51 ` Eugene Loh
@ 2024-07-31 20:04   ` Kris Van Hees
  0 siblings, 0 replies; 5+ messages in thread
From: Kris Van Hees @ 2024-07-31 20:04 UTC (permalink / raw)
  To: Eugene Loh; +Cc: Kris Van Hees, dtrace, dtrace-devel

On Wed, Jul 31, 2024 at 03:51:52PM -0400, Eugene Loh wrote:
> What is the point of this test?  If we do not know the type of the kernel
> variable, then what does "kernel_read_neg_small_scalar" mean?

We *know* the type.  That is why we use that particular kernel symbol.  The
issue is that on kernel without CTF DTrace cannot know the type, so we need
to tell it that it is an int.

	Kris

> On 7/31/24 15:01, Kris Van Hees wrote:
> > On systems without CTF, we do not know the type of kernel variables.
> > By doing an explicit cast to int64_t a negative int is converted into a
> > large positive integer.  The proper cast is 'int' of course.
> > 
> > Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
> > ---
> >   test/unittest/codegen/tst.kernel_read_neg_small_scalar.d | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d b/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
> > index 7c585d1b..cda6649b 100644
> > --- a/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
> > +++ b/test/unittest/codegen/tst.kernel_read_neg_small_scalar.d
> > @@ -1,6 +1,6 @@
> >   /*
> >    * Oracle Linux DTrace.
> > - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
> > + * Copyright (c) 2022, 2024, 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.
> >    */
> > @@ -11,10 +11,10 @@ BEGIN
> >   {
> >   	/*
> >   	 * Unless we are actually crashing, the `crashing_cpu int will be -1.
> > -	 * We cast it to int64_t to ensure that the value read from the kernel
> > +	 * We cast it to int to ensure that the value read from the kernel
> >   	 * is sign-extended.
> >   	 */
> > -	trace((int64_t)`crashing_cpu);
> > +	trace((int)`crashing_cpu);
> >   	exit(0);
> >   }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] test: ensure casting does not affect value
  2024-07-31 19:01 [PATCH] test: ensure casting does not affect value Kris Van Hees
  2024-07-31 19:51 ` Eugene Loh
@ 2024-08-01 18:44 ` Nick Alcock
  2024-08-01 19:03   ` Kris Van Hees
  1 sibling, 1 reply; 5+ messages in thread
From: Nick Alcock @ 2024-08-01 18:44 UTC (permalink / raw)
  To: Kris Van Hees; +Cc: dtrace, dtrace-devel

On 31 Jul 2024, Kris Van Hees outgrape:

> On systems without CTF, we do not know the type of kernel variables.
> By doing an explicit cast to int64_t a negative int is converted into a
> large positive integer.  The proper cast is 'int' of course.
>
> Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>

> -	trace((int64_t)`crashing_cpu);
> +	trace((int)`crashing_cpu);

Hm what type is it actually...

... int, but it's under arch/{x86,mips,powerpc}. Is this test going to
break on other architectures (like arm64)?

I know this is a pre-existing bug. The cast is correct, so

Reviewed-by: Nick Alcock <nick.alcock@oracle.com>

-- 
NULL && (void)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] test: ensure casting does not affect value
  2024-08-01 18:44 ` Nick Alcock
@ 2024-08-01 19:03   ` Kris Van Hees
  0 siblings, 0 replies; 5+ messages in thread
From: Kris Van Hees @ 2024-08-01 19:03 UTC (permalink / raw)
  To: Nick Alcock; +Cc: Kris Van Hees, dtrace, dtrace-devel

On Thu, Aug 01, 2024 at 07:44:35PM +0100, Nick Alcock wrote:
> On 31 Jul 2024, Kris Van Hees outgrape:
> 
> > On systems without CTF, we do not know the type of kernel variables.
> > By doing an explicit cast to int64_t a negative int is converted into a
> > large positive integer.  The proper cast is 'int' of course.
> >
> > Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
> 
> > -	trace((int64_t)`crashing_cpu);
> > +	trace((int)`crashing_cpu);
> 
> Hm what type is it actually...
> 
> ... int, but it's under arch/{x86,mips,powerpc}. Is this test going to
> break on other architectures (like arm64)?

That is why we have tst.kernel_read_neg_small_scalar.aarch64.x

> I know this is a pre-existing bug. The cast is correct, so
> 
> Reviewed-by: Nick Alcock <nick.alcock@oracle.com>
> 
> -- 
> NULL && (void)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-08-01 19:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-31 19:01 [PATCH] test: ensure casting does not affect value Kris Van Hees
2024-07-31 19:51 ` Eugene Loh
2024-07-31 20:04   ` Kris Van Hees
2024-08-01 18:44 ` Nick Alcock
2024-08-01 19:03   ` Kris Van Hees

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox