Received: by 10.192.165.148 with SMTP id m20csp557952imm; Fri, 20 Apr 2018 11:09:53 -0700 (PDT) X-Google-Smtp-Source: AIpwx49uUdrnPyiK046ppx++MiyKmnQW5UgKPqBje0IH7cq6Aq9ItOggUVY1pQ2OL9u9Jm9a5TIf X-Received: by 2002:a17:902:6ac3:: with SMTP id i3-v6mr11270962plt.142.1524247793486; Fri, 20 Apr 2018 11:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524247793; cv=none; d=google.com; s=arc-20160816; b=dT+h3Zq04WBEBhVrEWziAVmfjx7HnMPngkdNRgzRjfLpsUkNHIUGzPrjAOYCENl1ql tZn2U40QQ1M5RIkQZ4/y8YnHnfPMlLftw5mHU1jxCXLXfTJhquhja1CrbkYmmaGbMq6I pqfLri7DeLaTE8zCsmP1efkmA1CDa79szuJUX49VEJUaIYUKqww1bzsDBbMU17EwN7Dv l//ejorupU5IQYVJ5/Pn6vYKGSGvK8u8JIFmVoz5PJ7lID2hnb5ndjDt8RcgGCABvCEb xJZ8V5Lprlx4ULsl6XUVLjAblMmpn4IKJeOmJFJDNrUNK9KFffiJRLxCXnLM9pwaoPP5 dRiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=1f4IRFhItsSOAmteE+ASBywuISzHsVZd49U4myGeCTs=; b=aw9Yqto2s5XtreaffvGfnLuIQ+0J+jLKeUyyK5gqq/aA02dj6dGxPm9+r6US96DQjI ZrTKZa5pI1rL6ViOF4ZEfZgb8RZB/emZO3eTxS+thHyrtekTXGMWD0Mw4Ybl3HdbLGrQ PEDEGgTTW5eYQxdi7RIeL9tVmfwsXuO/IRDac2fTW+zBtbtgGIUOvxkkCvglDyf8EIcY VJVxLj7tqiGwf2eUWGgCvL27Bgz2dGyrwMrPbsMa4p2dBNf0z6X0Kc1110KBIwyH0Y5D 3mEsidi22IjgLrOw8TXAiV0yAQdvxvS5oFW36l9rFIGBa7dp9KXC84UMk5KTcNiB1JkG LsUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=CfWzu273; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k24si5328299pgn.24.2018.04.20.11.09.38; Fri, 20 Apr 2018 11:09:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=CfWzu273; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753608AbeDTSIc (ORCPT + 99 others); Fri, 20 Apr 2018 14:08:32 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:38036 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753475AbeDTSIa (ORCPT ); Fri, 20 Apr 2018 14:08:30 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3KI6b5m108829; Fri, 20 Apr 2018 18:08:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=1f4IRFhItsSOAmteE+ASBywuISzHsVZd49U4myGeCTs=; b=CfWzu273nQZ5W5eIKtzrcf6PEimgeJoo3gnE+jybO/GOU+OhUc1ytoK2rm3DsLG/s7yq 6bKtjIyRfG/AESOnkp0VQp/7I+SeuM3gbLMWapb/qJIMY7xMqJhTlxO+Ms3INJ7d/rII g8p9zdiQvVNLQa9zuq+2mmcehADI/ObBfNjV8T+S0ZZA6IDUg7ig/FEMThDA9JeZymNy JH1KBd9XQCC6L7bAMrB7MLRq0ZQasxLbuVh25AT011aeBYY/V960lE4zHdlVrizSvR0S X2RZymPleBdCuBXwpiIn6NIjUhfo4PVmf5PB5kOKTPRxvAsnmH+2v8VVXQ4HkUYkgRjh 8w== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2hf7amu7s9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Apr 2018 18:08:21 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w3KI8LTm007292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 20 Apr 2018 18:08:21 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w3KI8K20006641; Fri, 20 Apr 2018 18:08:20 GMT Received: from wcoekaer-srv3.us.oracle.com (/10.211.44.40) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 20 Apr 2018 11:08:19 -0700 Subject: Re: [PATCH v2 2/2] selftests: sparc64: char: Selftest for privileged ADI driver To: Tom Hromatka , davem@davemloft.net Cc: sparclinux@vger.kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, allen.pais@oracle.com, khalid.aziz@oracle.com, shannon.nelson@oracle.com, anthony.yznaga@oracle.com References: <20180420173406.485815-1-tom.hromatka@oracle.com> <20180420173406.485815-3-tom.hromatka@oracle.com> From: Wim Coekaerts Message-ID: <96bb0d5c-a936-3d9f-d7e7-3f3536f46612@oracle.com> Date: Fri, 20 Apr 2018 11:08:37 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180420173406.485815-3-tom.hromatka@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8869 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804200182 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Tom, you used the wrong GPL license header. Please fix that to be v2 not v3. The +# SPDX-License-Identifier: GPL-2.0 is correct but the adi-test.c one is not. On 04/20/2018 10:34 AM, Tom Hromatka wrote: > Add a selftest for the sparc64 privileged ADI driver. These > tests verify the read(), pread(), write(), pwrite(), and seek() > functionality of the driver. The tests also report simple > performance statistics: > > Syscall Call AvgTime AvgSize > Count (ticks) (bytes) > ------------------------------- > read 3 119638 8133 > pread 4 118164 6741 > write 3 339442 8133 > pwrite 4 280134 6741 > seek 10 2919 0 > Pass 8 Fail 0 Xfail 0 Xpass 0 Skip 0 Error 0 > > Signed-off-by: Tom Hromatka > Reviewed-by: Allen Pais > --- > tools/testing/selftests/Makefile | 1 + > tools/testing/selftests/sparc64/Makefile | 46 ++ > tools/testing/selftests/sparc64/drivers/.gitignore | 1 + > tools/testing/selftests/sparc64/drivers/Makefile | 15 + > tools/testing/selftests/sparc64/drivers/adi-test.c | 732 +++++++++++++++++++++ > .../selftests/sparc64/drivers/drivers_test.sh | 30 + > tools/testing/selftests/sparc64/run.sh | 3 + > 7 files changed, 828 insertions(+) > create mode 100644 tools/testing/selftests/sparc64/Makefile > create mode 100644 tools/testing/selftests/sparc64/drivers/.gitignore > create mode 100644 tools/testing/selftests/sparc64/drivers/Makefile > create mode 100644 tools/testing/selftests/sparc64/drivers/adi-test.c > create mode 100755 tools/testing/selftests/sparc64/drivers/drivers_test.sh > create mode 100755 tools/testing/selftests/sparc64/run.sh > > diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile > index 7442dfb73b7f..94da632579e7 100644 > --- a/tools/testing/selftests/Makefile > +++ b/tools/testing/selftests/Makefile > @@ -28,6 +28,7 @@ TARGETS += ptrace > TARGETS += seccomp > TARGETS += sigaltstack > TARGETS += size > +TARGETS += sparc64 > TARGETS += splice > TARGETS += static_keys > TARGETS += sync > diff --git a/tools/testing/selftests/sparc64/Makefile b/tools/testing/selftests/sparc64/Makefile > new file mode 100644 > index 000000000000..2082eeffd779 > --- /dev/null > +++ b/tools/testing/selftests/sparc64/Makefile > @@ -0,0 +1,46 @@ > +SUBDIRS := drivers > + > +TEST_PROGS := run.sh > + > +.PHONY: all clean > + > +include ../lib.mk > + > +all: > + @for DIR in $(SUBDIRS); do \ > + BUILD_TARGET=$(OUTPUT)/$$DIR; \ > + mkdir $$BUILD_TARGET -p; \ > + make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\ > + #SUBDIR test prog name should be in the form: SUBDIR_test.sh \ > + TEST=$$DIR"_test.sh"; \ > + if [ -e $$DIR/$$TEST ]; then \ > + rsync -a $$DIR/$$TEST $$BUILD_TARGET/; \ > + fi \ > + done > + > +override define RUN_TESTS > + @cd $(OUTPUT); ./run.sh > +endef > + > +override define INSTALL_RULE > + mkdir -p $(INSTALL_PATH) > + install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) > + > + @for SUBDIR in $(SUBDIRS); do \ > + BUILD_TARGET=$(OUTPUT)/$$SUBDIR; \ > + mkdir $$BUILD_TARGET -p; \ > + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$SUBDIR INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \ > + done; > +endef > + > +override define EMIT_TESTS > + echo "./run.sh" > +endef > + > +override define CLEAN > + @for DIR in $(SUBDIRS); do \ > + BUILD_TARGET=$(OUTPUT)/$$DIR; \ > + mkdir $$BUILD_TARGET -p; \ > + make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\ > + done > +endef > diff --git a/tools/testing/selftests/sparc64/drivers/.gitignore b/tools/testing/selftests/sparc64/drivers/.gitignore > new file mode 100644 > index 000000000000..90e835ed74e6 > --- /dev/null > +++ b/tools/testing/selftests/sparc64/drivers/.gitignore > @@ -0,0 +1 @@ > +adi-test > diff --git a/tools/testing/selftests/sparc64/drivers/Makefile b/tools/testing/selftests/sparc64/drivers/Makefile > new file mode 100644 > index 000000000000..6264f40bbdbc > --- /dev/null > +++ b/tools/testing/selftests/sparc64/drivers/Makefile > @@ -0,0 +1,15 @@ > + > +INCLUDEDIR := -I. > +CFLAGS := $(CFLAGS) $(INCLUDEDIR) -Wall -O2 -g > + > +TEST_GEN_FILES := adi-test > + > +all: $(TEST_GEN_FILES) > + > +$(TEST_GEN_FILES): adi-test.c > + > +TEST_PROGS := drivers_test.sh > + > +include ../../lib.mk > + > +$(OUTPUT)/adi-test: adi-test.c > diff --git a/tools/testing/selftests/sparc64/drivers/adi-test.c b/tools/testing/selftests/sparc64/drivers/adi-test.c > new file mode 100644 > index 000000000000..22ffd06fba24 > --- /dev/null > +++ b/tools/testing/selftests/sparc64/drivers/adi-test.c > @@ -0,0 +1,732 @@ > +/* > + * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. > + * Author: Tom Hromatka > + * > + * This program is free software: you can redistribute it and/or modify > + * it under the terms of the GNU General Public License as published by > + * the Free Software Foundation, either version 3 of the License, or > + * (at your option) any later version. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * You should have received a copy of the GNU General Public License > + * along with this program. If not, see . > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "../../kselftest.h" > + > +#define DEBUG_LEVEL_1_BIT (0x0001) > +#define DEBUG_LEVEL_2_BIT (0x0002) > +#define DEBUG_LEVEL_3_BIT (0x0004) > +#define DEBUG_LEVEL_4_BIT (0x0008) > +#define DEBUG_TIMING_BIT (0x1000) > + > +#ifndef ARRAY_SIZE > +# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) > +#endif > + > +/* bit mask of enabled bits to print */ > +#define DEBUG 0x0001 > + > +#define DEBUG_PRINT_L1(...) debug_print(DEBUG_LEVEL_1_BIT, __VA_ARGS__) > +#define DEBUG_PRINT_L2(...) debug_print(DEBUG_LEVEL_2_BIT, __VA_ARGS__) > +#define DEBUG_PRINT_L3(...) debug_print(DEBUG_LEVEL_3_BIT, __VA_ARGS__) > +#define DEBUG_PRINT_L4(...) debug_print(DEBUG_LEVEL_4_BIT, __VA_ARGS__) > +#define DEBUG_PRINT_T(...) debug_print(DEBUG_TIMING_BIT, __VA_ARGS__) > + > +static void debug_print(int level, const char *s, ...) > +{ > + va_list args; > + > + va_start(args, s); > + > + if (DEBUG & level) > + vfprintf(stdout, s, args); > + va_end(args); > +} > + > +#ifndef min > +#define min(x, y) ((x) < (y) ? x : y) > +#endif > + > +#define RETURN_FROM_TEST(_ret) \ > + do { \ > + DEBUG_PRINT_L1( \ > + "\tTest %s returned %d\n", __func__, _ret); \ > + return _ret; \ > + } while (0) > + > +#define ADI_BLKSZ 64 > +#define ADI_MAX_VERSION 15 > + > +#define TEST_STEP_FAILURE(_ret) \ > + do { \ > + fprintf(stderr, "\tTest step failure: %d at %s:%d\n", \ > + _ret, __func__, __LINE__); \ > + goto out; \ > + } while (0) > + > +#define RDTICK(_x) \ > + asm volatile(" rd %%tick, %0\n" : "=r" (_x)) > + > +static int random_version(void) > +{ > + long tick; > + > + RDTICK(tick); > + > + return tick % (ADI_MAX_VERSION + 1); > +} > + > +#define MAX_RANGES_SUPPORTED 5 > +static const char system_ram_str[] = "System RAM\n"; > +static int range_count; > +static unsigned long long int start_addr[MAX_RANGES_SUPPORTED]; > +static unsigned long long int end_addr[MAX_RANGES_SUPPORTED]; > + > +struct stats { > + char name[16]; > + unsigned long total; > + unsigned long count; > + unsigned long bytes; > +}; > + > +static struct stats read_stats = { > + .name = "read", .total = 0, .count = 0, .bytes = 0}; > +static struct stats pread_stats = { > + .name = "pread", .total = 0, .count = 0, .bytes = 0}; > +static struct stats write_stats = { > + .name = "write", .total = 0, .count = 0, .bytes = 0}; > +static struct stats pwrite_stats = { > + .name = "pwrite", .total = 0, .count = 0, .bytes = 0}; > +static struct stats seek_stats = { > + .name = "seek", .total = 0, .count = 0, .bytes = 0}; > + > +static void update_stats(struct stats * const ustats, > + unsigned long measurement, unsigned long bytes) > +{ > + ustats->total += measurement; > + ustats->bytes += bytes; > + ustats->count++; > +} > + > +static void print_ustats(const struct stats * const ustats) > +{ > + DEBUG_PRINT_L1("%s\t%7d\t%7.0f\t%7.0f\n", > + ustats->name, ustats->count, > + (float)ustats->total / (float)ustats->count, > + (float)ustats->bytes / (float)ustats->count); > +} > + > +static void print_stats(void) > +{ > + DEBUG_PRINT_L1("\nSyscall\tCall\tAvgTime\tAvgSize\n" > + "\tCount\t(ticks)\t(bytes)\n" > + "-------------------------------\n"); > + > + print_ustats(&read_stats); > + print_ustats(&pread_stats); > + print_ustats(&write_stats); > + print_ustats(&pwrite_stats); > + print_ustats(&seek_stats); > +} > + > +static int build_memory_map(void) > +{ > + char line[256]; > + FILE *fp; > + int i; > + > + range_count = 0; > + > + fp = fopen("/proc/iomem", "r"); > + if (!fp) { > + fprintf(stderr, "/proc/iomem: error %d: %s\n", > + errno, strerror(errno)); > + return -errno; > + } > + > + while (fgets(line, sizeof(line), fp) != 0) { > + if (strstr(line, system_ram_str)) { > + char *dash, *end_ptr; > + > + /* Given a line like this: > + * d0400000-10ffaffff : System RAM > + * replace the "-" with a space > + */ > + dash = strstr(line, "-"); > + dash[0] = 0x20; > + > + start_addr[range_count] = strtoull(line, &end_ptr, 16); > + end_addr[range_count] = strtoull(end_ptr, NULL, 16); > + range_count++; > + } > + } > + > + fclose(fp); > + > + DEBUG_PRINT_L1("RAM Ranges\n"); > + for (i = 0; i < range_count; i++) > + DEBUG_PRINT_L1("\trange %d: 0x%llx\t- 0x%llx\n", > + i, start_addr[i], end_addr[i]); > + > + if (range_count == 0) { > + fprintf(stderr, "No valid address ranges found. Error.\n"); > + return -1; > + } > + > + return 0; > +} > + > +static int read_adi(int fd, unsigned char *buf, int buf_sz) > +{ > + int ret, bytes_read = 0; > + long start, end, elapsed_time = 0; > + > + do { > + RDTICK(start); > + ret = read(fd, buf + bytes_read, buf_sz - bytes_read); > + RDTICK(end); > + if (ret < 0) > + return -errno; > + > + elapsed_time += end - start; > + update_stats(&read_stats, elapsed_time, buf_sz); > + bytes_read += ret; > + > + } while (bytes_read < buf_sz); > + > + DEBUG_PRINT_T("\tread elapsed timed = %ld\n", elapsed_time); > + DEBUG_PRINT_L3("\tRead %d bytes\n", bytes_read); > + > + return bytes_read; > +} > + > +static int pread_adi(int fd, unsigned char *buf, > + int buf_sz, unsigned long offset) > +{ > + int ret, i, bytes_read = 0; > + unsigned long cur_offset; > + long start, end, elapsed_time = 0; > + > + cur_offset = offset; > + do { > + RDTICK(start); > + ret = pread(fd, buf + bytes_read, buf_sz - bytes_read, > + cur_offset); > + RDTICK(end); > + if (ret < 0) > + return -errno; > + > + elapsed_time += end - start; > + update_stats(&pread_stats, elapsed_time, buf_sz); > + bytes_read += ret; > + cur_offset += ret; > + > + } while (bytes_read < buf_sz); > + > + DEBUG_PRINT_T("\tpread elapsed timed = %ld\n", elapsed_time); > + DEBUG_PRINT_L3("\tRead %d bytes starting at offset 0x%lx\n", > + bytes_read, offset); > + for (i = 0; i < bytes_read; i++) > + DEBUG_PRINT_L4("\t\t0x%lx\t%d\n", offset + i, buf[i]); > + > + return bytes_read; > +} > + > +static int write_adi(int fd, const unsigned char * const buf, int buf_sz) > +{ > + int ret, bytes_written = 0; > + long start, end, elapsed_time = 0; > + > + do { > + RDTICK(start); > + ret = write(fd, buf + bytes_written, buf_sz - bytes_written); > + RDTICK(end); > + if (ret < 0) > + return -errno; > + > + elapsed_time += (end - start); > + update_stats(&write_stats, elapsed_time, buf_sz); > + bytes_written += ret; > + } while (bytes_written < buf_sz); > + > + DEBUG_PRINT_T("\twrite elapsed timed = %ld\n", elapsed_time); > + DEBUG_PRINT_L3("\tWrote %d of %d bytes\n", bytes_written, buf_sz); > + > + return bytes_written; > +} > + > +static int pwrite_adi(int fd, const unsigned char * const buf, > + int buf_sz, unsigned long offset) > +{ > + int ret, bytes_written = 0; > + unsigned long cur_offset; > + long start, end, elapsed_time = 0; > + > + cur_offset = offset; > + > + do { > + RDTICK(start); > + ret = pwrite(fd, buf + bytes_written, > + buf_sz - bytes_written, cur_offset); > + RDTICK(end); > + if (ret < 0) { > + fprintf(stderr, "pwrite(): error %d: %s\n", > + errno, strerror(errno)); > + return -errno; > + } > + > + elapsed_time += (end - start); > + update_stats(&pwrite_stats, elapsed_time, buf_sz); > + bytes_written += ret; > + cur_offset += ret; > + > + } while (bytes_written < buf_sz); > + > + DEBUG_PRINT_T("\tpwrite elapsed timed = %ld\n", elapsed_time); > + DEBUG_PRINT_L3("\tWrote %d of %d bytes starting at address 0x%lx\n", > + bytes_written, buf_sz, offset); > + > + return bytes_written; > +} > + > +static off_t seek_adi(int fd, off_t offset, int whence) > +{ > + long start, end; > + off_t ret; > + > + RDTICK(start); > + ret = lseek(fd, offset, whence); > + RDTICK(end); > + DEBUG_PRINT_L2("\tlseek ret = 0x%llx\n", ret); > + if (ret < 0) > + goto out; > + > + DEBUG_PRINT_T("\tlseek elapsed timed = %ld\n", end - start); > + update_stats(&seek_stats, end - start, 0); > + > +out: > + (void)lseek(fd, 0, SEEK_END); > + return ret; > +} > + > +static int test0_prpw_aligned_1byte(int fd) > +{ > + /* somewhat arbitrarily chosen address */ > + unsigned long paddr = > + (end_addr[range_count - 1] - 0x1000) & ~(ADI_BLKSZ - 1); > + unsigned char version[1], expected_version; > + loff_t offset; > + int ret; > + > + version[0] = random_version(); > + expected_version = version[0]; > + > + offset = paddr / ADI_BLKSZ; > + > + ret = pwrite_adi(fd, version, sizeof(version), offset); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + ret = pread_adi(fd, version, sizeof(version), offset); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + if (expected_version != version[0]) { > + DEBUG_PRINT_L2("\tExpected version %d but read version %d\n", > + expected_version, version[0]); > + TEST_STEP_FAILURE(-expected_version); > + } > + > + ret = 0; > +out: > + RETURN_FROM_TEST(ret); > +} > + > +#define TEST1_VERSION_SZ 4096 > +static int test1_prpw_aligned_4096bytes(int fd) > +{ > + /* somewhat arbitrarily chosen address */ > + unsigned long paddr = > + (end_addr[range_count - 1] - 0x6000) & ~(ADI_BLKSZ - 1); > + unsigned char version[TEST1_VERSION_SZ], > + expected_version[TEST1_VERSION_SZ]; > + loff_t offset; > + int ret, i; > + > + for (i = 0; i < TEST1_VERSION_SZ; i++) { > + version[i] = random_version(); > + expected_version[i] = version[i]; > + } > + > + offset = paddr / ADI_BLKSZ; > + > + ret = pwrite_adi(fd, version, sizeof(version), offset); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + ret = pread_adi(fd, version, sizeof(version), offset); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + for (i = 0; i < TEST1_VERSION_SZ; i++) { > + if (expected_version[i] != version[i]) { > + DEBUG_PRINT_L2( > + "\tExpected version %d but read version %d\n", > + expected_version, version[0]); > + TEST_STEP_FAILURE(-expected_version[i]); > + } > + } > + > + ret = 0; > +out: > + RETURN_FROM_TEST(ret); > +} > + > +#define TEST2_VERSION_SZ 10327 > +static int test2_prpw_aligned_10327bytes(int fd) > +{ > + /* somewhat arbitrarily chosen address */ > + unsigned long paddr = > + (start_addr[0] + 0x6000) & ~(ADI_BLKSZ - 1); > + unsigned char version[TEST2_VERSION_SZ], > + expected_version[TEST2_VERSION_SZ]; > + loff_t offset; > + int ret, i; > + > + for (i = 0; i < TEST2_VERSION_SZ; i++) { > + version[i] = random_version(); > + expected_version[i] = version[i]; > + } > + > + offset = paddr / ADI_BLKSZ; > + > + ret = pwrite_adi(fd, version, sizeof(version), offset); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + ret = pread_adi(fd, version, sizeof(version), offset); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + for (i = 0; i < TEST2_VERSION_SZ; i++) { > + if (expected_version[i] != version[i]) { > + DEBUG_PRINT_L2( > + "\tExpected version %d but read version %d\n", > + expected_version, version[0]); > + TEST_STEP_FAILURE(-expected_version[i]); > + } > + } > + > + ret = 0; > +out: > + RETURN_FROM_TEST(ret); > +} > + > +#define TEST3_VERSION_SZ 12541 > +static int test3_prpw_unaligned_12541bytes(int fd) > +{ > + /* somewhat arbitrarily chosen address */ > + unsigned long paddr = > + ((start_addr[0] + 0xC000) & ~(ADI_BLKSZ - 1)) + 17; > + unsigned char version[TEST3_VERSION_SZ], > + expected_version[TEST3_VERSION_SZ]; > + loff_t offset; > + int ret, i; > + > + for (i = 0; i < TEST3_VERSION_SZ; i++) { > + version[i] = random_version(); > + expected_version[i] = version[i]; > + } > + > + offset = paddr / ADI_BLKSZ; > + > + ret = pwrite_adi(fd, version, sizeof(version), offset); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + ret = pread_adi(fd, version, sizeof(version), offset); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + for (i = 0; i < TEST3_VERSION_SZ; i++) { > + if (expected_version[i] != version[i]) { > + DEBUG_PRINT_L2( > + "\tExpected version %d but read version %d\n", > + expected_version, version[0]); > + TEST_STEP_FAILURE(-expected_version[i]); > + } > + } > + > + ret = 0; > +out: > + RETURN_FROM_TEST(ret); > +} > + > +static int test4_lseek(int fd) > +{ > +#define OFFSET_ADD (0x100) > +#define OFFSET_SUBTRACT (0xFFFFFFF000000000) > + > + off_t offset_out, offset_in; > + int ret; > + > + > + offset_in = 0x123456789abcdef0; > + offset_out = seek_adi(fd, offset_in, SEEK_SET); > + if (offset_out != offset_in) { > + ret = -1; > + TEST_STEP_FAILURE(ret); > + } > + > + /* seek to the current offset. this should return EINVAL */ > + offset_out = seek_adi(fd, offset_in, SEEK_SET); > + if (offset_out < 0 && errno == EINVAL) > + DEBUG_PRINT_L2( > + "\tSEEK_SET failed as designed. Not an error\n"); > + else { > + ret = -2; > + TEST_STEP_FAILURE(ret); > + } > + > + offset_out = seek_adi(fd, 0, SEEK_CUR); > + if (offset_out != offset_in) { > + ret = -3; > + TEST_STEP_FAILURE(ret); > + } > + > + offset_out = seek_adi(fd, OFFSET_ADD, SEEK_CUR); > + if (offset_out != (offset_in + OFFSET_ADD)) { > + ret = -4; > + TEST_STEP_FAILURE(ret); > + } > + > + offset_out = seek_adi(fd, OFFSET_SUBTRACT, SEEK_CUR); > + if (offset_out != (offset_in + OFFSET_ADD + OFFSET_SUBTRACT)) { > + ret = -5; > + TEST_STEP_FAILURE(ret); > + } > + > + ret = 0; > +out: > + RETURN_FROM_TEST(ret); > +} > + > +static int test5_rw_aligned_1byte(int fd) > +{ > + /* somewhat arbitrarily chosen address */ > + unsigned long paddr = > + (end_addr[range_count - 1] - 0xF000) & ~(ADI_BLKSZ - 1); > + unsigned char version, expected_version; > + loff_t offset; > + off_t oret; > + int ret; > + > + offset = paddr / ADI_BLKSZ; > + version = expected_version = random_version(); > + > + oret = seek_adi(fd, offset, SEEK_SET); > + if (oret != offset) { > + ret = -1; > + TEST_STEP_FAILURE(ret); > + } > + > + ret = write_adi(fd, &version, sizeof(version)); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + oret = seek_adi(fd, offset, SEEK_SET); > + if (oret != offset) { > + ret = -1; > + TEST_STEP_FAILURE(ret); > + } > + > + ret = read_adi(fd, &version, sizeof(version)); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + if (expected_version != version) { > + DEBUG_PRINT_L2("\tExpected version %d but read version %d\n", > + expected_version, version); > + TEST_STEP_FAILURE(-expected_version); > + } > + > + ret = 0; > +out: > + RETURN_FROM_TEST(ret); > +} > + > +#define TEST6_VERSION_SZ 9434 > +static int test6_rw_aligned_9434bytes(int fd) > +{ > + /* somewhat arbitrarily chosen address */ > + unsigned long paddr = > + (end_addr[range_count - 1] - 0x5F000) & ~(ADI_BLKSZ - 1); > + unsigned char version[TEST6_VERSION_SZ], > + expected_version[TEST6_VERSION_SZ]; > + loff_t offset; > + off_t oret; > + int ret, i; > + > + offset = paddr / ADI_BLKSZ; > + for (i = 0; i < TEST6_VERSION_SZ; i++) > + version[i] = expected_version[i] = random_version(); > + > + oret = seek_adi(fd, offset, SEEK_SET); > + if (oret != offset) { > + ret = -1; > + TEST_STEP_FAILURE(ret); > + } > + > + ret = write_adi(fd, version, sizeof(version)); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + memset(version, 0, TEST6_VERSION_SZ); > + > + oret = seek_adi(fd, offset, SEEK_SET); > + if (oret != offset) { > + ret = -1; > + TEST_STEP_FAILURE(ret); > + } > + > + ret = read_adi(fd, version, sizeof(version)); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + for (i = 0; i < TEST6_VERSION_SZ; i++) { > + if (expected_version[i] != version[i]) { > + DEBUG_PRINT_L2( > + "\tExpected version %d but read version %d\n", > + expected_version[i], version[i]); > + TEST_STEP_FAILURE(-expected_version[i]); > + } > + } > + > + ret = 0; > +out: > + RETURN_FROM_TEST(ret); > +} > + > +#define TEST7_VERSION_SZ 14963 > +static int test7_rw_aligned_14963bytes(int fd) > +{ > + /* somewhat arbitrarily chosen address */ > + unsigned long paddr = > + ((start_addr[range_count - 1] + 0xF000) & ~(ADI_BLKSZ - 1)) + 39; > + unsigned char version[TEST7_VERSION_SZ], > + expected_version[TEST7_VERSION_SZ]; > + loff_t offset; > + off_t oret; > + int ret, i; > + > + offset = paddr / ADI_BLKSZ; > + for (i = 0; i < TEST7_VERSION_SZ; i++) { > + version[i] = random_version(); > + expected_version[i] = version[i]; > + } > + > + oret = seek_adi(fd, offset, SEEK_SET); > + if (oret != offset) { > + ret = -1; > + TEST_STEP_FAILURE(ret); > + } > + > + ret = write_adi(fd, version, sizeof(version)); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + memset(version, 0, TEST7_VERSION_SZ); > + > + oret = seek_adi(fd, offset, SEEK_SET); > + if (oret != offset) { > + ret = -1; > + TEST_STEP_FAILURE(ret); > + } > + > + ret = read_adi(fd, version, sizeof(version)); > + if (ret != sizeof(version)) > + TEST_STEP_FAILURE(ret); > + > + for (i = 0; i < TEST7_VERSION_SZ; i++) { > + if (expected_version[i] != version[i]) { > + DEBUG_PRINT_L2( > + "\tExpected version %d but read version %d\n", > + expected_version[i], version[i]); > + TEST_STEP_FAILURE(-expected_version[i]); > + } > + > + paddr += ADI_BLKSZ; > + } > + > + ret = 0; > +out: > + RETURN_FROM_TEST(ret); > +} > + > +static int (*tests[])(int fd) = { > + test0_prpw_aligned_1byte, > + test1_prpw_aligned_4096bytes, > + test2_prpw_aligned_10327bytes, > + test3_prpw_unaligned_12541bytes, > + test4_lseek, > + test5_rw_aligned_1byte, > + test6_rw_aligned_9434bytes, > + test7_rw_aligned_14963bytes, > +}; > +#define TEST_COUNT ARRAY_SIZE(tests) > + > +int main(int argc, char *argv[]) > +{ > + int fd, ret, test; > + > + ret = build_memory_map(); > + if (ret < 0) > + return ret; > + > + fd = open("/dev/adi", O_RDWR); > + if (fd < 0) { > + fprintf(stderr, "open: error %d: %s\n", > + errno, strerror(errno)); > + return -errno; > + } > + > + for (test = 0; test < TEST_COUNT; test++) { > + DEBUG_PRINT_L1("Running test #%d\n", test); > + > + ret = (*tests[test])(fd); > + if (ret != 0) > + ksft_test_result_fail("Test #%d failed: error %d\n", > + test, ret); > + else > + ksft_test_result_pass("Test #%d passed\n", test); > + } > + > + print_stats(); > + close(fd); > + > + if (ksft_get_fail_cnt() > 0) > + ksft_exit_fail(); > + else > + ksft_exit_pass(); > + > + /* it's impossible to get here, but the compiler throws a warning > + * about control reaching the end of non-void function. bah. > + */ > + return 0; > +} > diff --git a/tools/testing/selftests/sparc64/drivers/drivers_test.sh b/tools/testing/selftests/sparc64/drivers/drivers_test.sh > new file mode 100755 > index 000000000000..6d08273b7532 > --- /dev/null > +++ b/tools/testing/selftests/sparc64/drivers/drivers_test.sh > @@ -0,0 +1,30 @@ > +#!/bin/sh > +# SPDX-License-Identifier: GPL-2.0 > + > +SRC_TREE=../../../../ > + > +test_run() > +{ > + if [ -f ${SRC_TREE}/drivers/char/adi.ko ]; then > + insmod ${SRC_TREE}/drivers/char/adi.ko 2> /dev/null > + if [ $? -ne 0 ]; then > + rc=1 > + fi > + else > + # Use modprobe dry run to check for missing adi module > + if ! /sbin/modprobe -q -n adi; then > + echo "adi: [SKIP]" > + elif /sbin/modprobe -q adi; then > + echo "adi: ok" > + else > + echo "adi: [FAIL]" > + rc=1 > + fi > + fi > + ./adi-test > + rmmod adi 2> /dev/null > +} > + > +rc=0 > +test_run > +exit $rc > diff --git a/tools/testing/selftests/sparc64/run.sh b/tools/testing/selftests/sparc64/run.sh > new file mode 100755 > index 000000000000..38ad61f9328e > --- /dev/null > +++ b/tools/testing/selftests/sparc64/run.sh > @@ -0,0 +1,3 @@ > +#!/bin/sh > + > +(cd drivers; ./drivers_test.sh)