diff mbox

[kvm-unit-tests,9/9] s390x: add test for (v)malloc

Message ID 20180110215348.315-10-david@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

David Hildenbrand Jan. 10, 2018, 9:53 p.m. UTC
Let's test if basic allocation works and we get virtual addresses.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 s390x/selftest.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Thomas Huth Jan. 11, 2018, 12:09 p.m. UTC | #1
On 10.01.2018 22:53, David Hildenbrand wrote:
> Let's test if basic allocation works and we get virtual addresses.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  s390x/selftest.c | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/s390x/selftest.c b/s390x/selftest.c
> index 76ed4bf..bf72d32 100644
> --- a/s390x/selftest.c
> +++ b/s390x/selftest.c
> @@ -10,6 +10,7 @@
>   */
>  #include <libcflat.h>
>  #include <util.h>
> +#include <alloc.h>
>  #include <asm/interrupt.h>
>  
>  static void test_fp(void)
> @@ -37,6 +38,21 @@ static void test_pgm_int(void)
>  	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
>  }
>  
> +static void test_malloc(void)
> +{
> +	int *tmp = malloc(sizeof(int));
> +	int *tmp2 = malloc(sizeof(int));
> +
> +	report("malloc: got vaddr", (uintptr_t)tmp & 0xffffffff00000000ul);
> +	report("malloc: access works", (*tmp = 123456789));

Using the *tmp = 123456789 as condition for report() here looks somewhat
weird. What about:

	*tmp = 123456789;
	mb();
	report("malloc: access works", (*tmp == 123456789));

?

> +	report("malloc: got 2nd vaddr", (uintptr_t)tmp2 & 0xffffffff00000000ul);
> +	report("malloc: access works", (*tmp2 = 123456789));
> +	report("malloc: addresses differ", tmp != tmp2);

Would it make sense to use the LOAD REAL ADDRESS instruction here to
check that the VA != PA ?

 Thomas
David Hildenbrand Jan. 11, 2018, 12:13 p.m. UTC | #2
On 11.01.2018 13:09, Thomas Huth wrote:
> On 10.01.2018 22:53, David Hildenbrand wrote:
>> Let's test if basic allocation works and we get virtual addresses.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>  s390x/selftest.c | 17 +++++++++++++++++
>>  1 file changed, 17 insertions(+)
>>
>> diff --git a/s390x/selftest.c b/s390x/selftest.c
>> index 76ed4bf..bf72d32 100644
>> --- a/s390x/selftest.c
>> +++ b/s390x/selftest.c
>> @@ -10,6 +10,7 @@
>>   */
>>  #include <libcflat.h>
>>  #include <util.h>
>> +#include <alloc.h>
>>  #include <asm/interrupt.h>
>>  
>>  static void test_fp(void)
>> @@ -37,6 +38,21 @@ static void test_pgm_int(void)
>>  	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
>>  }
>>  
>> +static void test_malloc(void)
>> +{
>> +	int *tmp = malloc(sizeof(int));
>> +	int *tmp2 = malloc(sizeof(int));
>> +
>> +	report("malloc: got vaddr", (uintptr_t)tmp & 0xffffffff00000000ul);
>> +	report("malloc: access works", (*tmp = 123456789));
> 
> Using the *tmp = 123456789 as condition for report() here looks somewhat
> weird. What about:

Can do that.

> 
> 	*tmp = 123456789;
> 	mb();
> 	report("malloc: access works", (*tmp == 123456789));
> 
> ?
> 
>> +	report("malloc: got 2nd vaddr", (uintptr_t)tmp2 & 0xffffffff00000000ul);
>> +	report("malloc: access works", (*tmp2 = 123456789));
>> +	report("malloc: addresses differ", tmp != tmp2);
> 
> Would it make sense to use the LOAD REAL ADDRESS instruction here to
> check that the VA != PA ?

As an alternative, I can disable DAT an make sure that I no longer can
access the value (PGM ADRESSING).

Thanks!

> 
>  Thomas
>
diff mbox

Patch

diff --git a/s390x/selftest.c b/s390x/selftest.c
index 76ed4bf..bf72d32 100644
--- a/s390x/selftest.c
+++ b/s390x/selftest.c
@@ -10,6 +10,7 @@ 
  */
 #include <libcflat.h>
 #include <util.h>
+#include <alloc.h>
 #include <asm/interrupt.h>
 
 static void test_fp(void)
@@ -37,6 +38,21 @@  static void test_pgm_int(void)
 	check_pgm_int_code(PGM_INT_CODE_ADDRESSING);
 }
 
+static void test_malloc(void)
+{
+	int *tmp = malloc(sizeof(int));
+	int *tmp2 = malloc(sizeof(int));
+
+	report("malloc: got vaddr", (uintptr_t)tmp & 0xffffffff00000000ul);
+	report("malloc: access works", (*tmp = 123456789));
+	report("malloc: got 2nd vaddr", (uintptr_t)tmp2 & 0xffffffff00000000ul);
+	report("malloc: access works", (*tmp2 = 123456789));
+	report("malloc: addresses differ", tmp != tmp2);
+
+	free(tmp);
+	free(tmp2);
+}
+
 int main(int argc, char**argv)
 {
 	report_prefix_push("selftest");
@@ -49,6 +65,7 @@  int main(int argc, char**argv)
 
 	test_fp();
 	test_pgm_int();
+	test_malloc();
 
 	return report_summary();
 }