From patchwork Fri Dec 22 13:50:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13503353 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03F451A703; Fri, 22 Dec 2023 13:52:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HATSugPj" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1d422c9f894so3609125ad.3; Fri, 22 Dec 2023 05:52:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703253123; x=1703857923; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2A8b0YOIg6lGChxKQRkSufzy4suZ23mRhNBzFJEEdSM=; b=HATSugPjwW98sa4TEqdWh09cf0coyqv5YGZp6mfUpSry6BBk9YDkbKzQpqvjYA+CfH aSMqPymVMrIGaC5A/RZ0Q3HJ1GvW+PusGNtaxBShHveriLWTo4GQ4FlDP9hj6E/gmUsp bRoXACPnZhys7oPMfOS++PFYDNI4/XbkJPj7C42bET9JGZUSMosl9vPbwjDZ4WCgAscu nzORWSeXiMoBZSqsiVbzgZzCv8T+6z7YmJv99tPkPN32/0FjZW62Hky9VOtd8sl4vfwQ fO9f0uvUnUBesYM/ZndmY5PgP08yCrnPoZfKa92xH3JAnqF8K9TlDJIQbz3BS7m3TA88 rqIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703253123; x=1703857923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2A8b0YOIg6lGChxKQRkSufzy4suZ23mRhNBzFJEEdSM=; b=jveB4eR1BH98/AX1v2ZjRpB2X0ps8YGKZaXSxNxbBxGZHEsLzMVMg6RuH5AVO0bT7l tHLfl9kkaciPsjE5556qazd7g+/3ys7l1cs2S36vOzPp3YavrrJaWgyuSDVvt7Hj8ZLF vvn7QznjjmMJAqsMi0gk5Mw/Pg14K89XS6ol23w4jyvuoccMkxRCMyRRfF9Az/rB4giZ MxMeYMEcIBPnqVH0glaPNcHtiAkbrSHnrqKNruaDNMq3z3Ac2+Tv29IetpbiZQHjyf/Y ARLCWWN7pEGsnWZHD/sPeLskYViOYmS7rDxK2jYOYxbS3Y9g//mGXryHx6IWHQTjZ6Fs 735A== X-Gm-Message-State: AOJu0YxcsURejoTJ7JSaZAkVBkue8IZkMs+QXV6M+yRtzj93X+kOOVJu pyefOXVI5og/AfPL5X8N3KRibuQKYcs= X-Google-Smtp-Source: AGHT+IFQvmq4OO8RZRqoYdZH+NyCux5jSToZv3wFAzfmemzYuCnTc4PXXs3gZ8OTO3g8gRr8Oh1Jgg== X-Received: by 2002:a17:903:32ce:b0:1d4:223f:3c26 with SMTP id i14-20020a17090332ce00b001d4223f3c26mr829886plr.38.1703253123349; Fri, 22 Dec 2023 05:52:03 -0800 (PST) Received: from wheely.local0.net ([203.220.145.68]) by smtp.gmail.com with ESMTPSA id n12-20020a17090ac68c00b0028ae54d988esm3629280pjt.48.2023.12.22.05.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 05:52:02 -0800 (PST) From: Nicholas Piggin To: Thomas Huth Cc: Nicholas Piggin , kvm@vger.kernel.org, Laurent Vivier , "Shaoqin Huang" , Andrew Jones , Nico Boehr , Paolo Bonzini , Alexandru Elisei , Eric Auger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, kvmarm@lists.linux.dev Subject: [kvm-unit-tests PATCH 8/9] Add common/ directory for architecture-independent tests Date: Fri, 22 Dec 2023 23:50:47 +1000 Message-ID: <20231222135048.1924672-9-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231222135048.1924672-1-npiggin@gmail.com> References: <20231222135048.1924672-1-npiggin@gmail.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 x86/sieve.c is used by s390x and arm via symbolic link. Make a new directory common/ for architecture-independent tests and move sieve.c here. Signed-off-by: Nicholas Piggin --- arm/sieve.c | 2 +- common/sieve.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ s390x/sieve.c | 2 +- x86/sieve.c | 52 +------------------------------------------------- 4 files changed, 54 insertions(+), 53 deletions(-) create mode 100644 common/sieve.c mode change 100644 => 120000 x86/sieve.c diff --git a/arm/sieve.c b/arm/sieve.c index 8f14a5c3..fe299f30 120000 --- a/arm/sieve.c +++ b/arm/sieve.c @@ -1 +1 @@ -../x86/sieve.c \ No newline at end of file +../common/sieve.c \ No newline at end of file diff --git a/common/sieve.c b/common/sieve.c new file mode 100644 index 00000000..8150f2d9 --- /dev/null +++ b/common/sieve.c @@ -0,0 +1,51 @@ +#include "alloc.h" +#include "libcflat.h" + +static int sieve(char* data, int size) +{ + int i, j, r = 0; + + for (i = 0; i < size; ++i) + data[i] = 1; + + data[0] = data[1] = 0; + + for (i = 2; i < size; ++i) + if (data[i]) { + ++r; + for (j = i*2; j < size; j += i) + data[j] = 0; + } + return r; +} + +static void test_sieve(const char *msg, char *data, int size) +{ + int r; + + printf("%s:", msg); + r = sieve(data, size); + printf("%d out of %d\n", r, size); +} + +#define STATIC_SIZE 1000000 +#define VSIZE 100000000 +char static_data[STATIC_SIZE]; + +int main(void) +{ + void *v; + int i; + + printf("starting sieve\n"); + test_sieve("static", static_data, STATIC_SIZE); + setup_vm(); + test_sieve("mapped", static_data, STATIC_SIZE); + for (i = 0; i < 3; ++i) { + v = malloc(VSIZE); + test_sieve("virtual", v, VSIZE); + free(v); + } + + return 0; +} diff --git a/s390x/sieve.c b/s390x/sieve.c index 8f14a5c3..fe299f30 120000 --- a/s390x/sieve.c +++ b/s390x/sieve.c @@ -1 +1 @@ -../x86/sieve.c \ No newline at end of file +../common/sieve.c \ No newline at end of file diff --git a/x86/sieve.c b/x86/sieve.c deleted file mode 100644 index 8150f2d9..00000000 --- a/x86/sieve.c +++ /dev/null @@ -1,51 +0,0 @@ -#include "alloc.h" -#include "libcflat.h" - -static int sieve(char* data, int size) -{ - int i, j, r = 0; - - for (i = 0; i < size; ++i) - data[i] = 1; - - data[0] = data[1] = 0; - - for (i = 2; i < size; ++i) - if (data[i]) { - ++r; - for (j = i*2; j < size; j += i) - data[j] = 0; - } - return r; -} - -static void test_sieve(const char *msg, char *data, int size) -{ - int r; - - printf("%s:", msg); - r = sieve(data, size); - printf("%d out of %d\n", r, size); -} - -#define STATIC_SIZE 1000000 -#define VSIZE 100000000 -char static_data[STATIC_SIZE]; - -int main(void) -{ - void *v; - int i; - - printf("starting sieve\n"); - test_sieve("static", static_data, STATIC_SIZE); - setup_vm(); - test_sieve("mapped", static_data, STATIC_SIZE); - for (i = 0; i < 3; ++i) { - v = malloc(VSIZE); - test_sieve("virtual", v, VSIZE); - free(v); - } - - return 0; -} diff --git a/x86/sieve.c b/x86/sieve.c new file mode 120000 index 00000000..fe299f30 --- /dev/null +++ b/x86/sieve.c @@ -0,0 +1 @@ +../common/sieve.c \ No newline at end of file