From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Hildenbrand Subject: [PATCH kvm-unit-tests v3 10/11] s390x: add test for (v)malloc Date: Tue, 13 Feb 2018 17:23:20 +0100 Message-ID: <20180213162321.20522-11-david@redhat.com> References: <20180213162321.20522-1-david@redhat.com> Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Huth , Cornelia Huck , Christian Borntraeger , David Hildenbrand To: kvm@vger.kernel.org Return-path: Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35644 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934896AbeBMQXj (ORCPT ); Tue, 13 Feb 2018 11:23:39 -0500 In-Reply-To: <20180213162321.20522-1-david@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Let's test if basic allocation works and we get virtual addresses. Reviewed-by: Thomas Huth Signed-off-by: David Hildenbrand --- s390x/selftest.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/s390x/selftest.c b/s390x/selftest.c index 905713f..18a40e1 100644 --- a/s390x/selftest.c +++ b/s390x/selftest.c @@ -10,7 +10,10 @@ */ #include #include +#include #include +#include +#include static void test_fp(void) { @@ -37,6 +40,31 @@ 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)); + + *tmp = 123456789; + *tmp2 = 123456789; + mb(); + + report("malloc: got vaddr", (uintptr_t)tmp & 0xf000000000000000ul); + report("malloc: access works", *tmp == 123456789); + report("malloc: got 2nd vaddr", (uintptr_t)tmp2 & 0xf000000000000000ul); + report("malloc: access works", (*tmp2 == 123456789)); + report("malloc: addresses differ", tmp != tmp2); + + expect_pgm_int(); + configure_dat(0); + *tmp = 987654321; + configure_dat(1); + check_pgm_int_code(PGM_INT_CODE_ADDRESSING); + + free(tmp); + free(tmp2); +} + int main(int argc, char**argv) { report_prefix_push("selftest"); @@ -49,6 +77,7 @@ int main(int argc, char**argv) test_fp(); test_pgm_int(); + test_malloc(); return report_summary(); } -- 2.14.3