From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id CFD953857829 for ; Wed, 29 Sep 2021 10:04:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CFD953857829 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-Uho1rG-eMY23hZ6l98G4BA-1; Wed, 29 Sep 2021 06:04:01 -0400 X-MC-Unique: Uho1rG-eMY23hZ6l98G4BA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 72C1F824FA9 for ; Wed, 29 Sep 2021 10:04:00 +0000 (UTC) Received: from sparse.redhat.com (unknown [10.35.207.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9056604CC; Wed, 29 Sep 2021 10:03:49 +0000 (UTC) From: Nir Soffer To: systemtap@sourceware.org Cc: fche@redhat.com, Nir Soffer Subject: [PATCH] Simple test for traceaio Date: Wed, 29 Sep 2021 13:03:48 +0300 Message-Id: <20210929100348.1090036-1-nsoffer@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: systemtap@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Systemtap mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Sep 2021 10:04:04 -0000 Add simple test program calling io_submit() with several iocbs, testing handling or PWRITE, PREAD, PWRITEV, and PREADV. The test can be run manually by compiling the program, running it with "stap -c", and inspecting the generated trace. With more work, this can be used in "make installcheck", and verified using expected output file. Signed-off-by: Nir Soffer --- testsuite/systemtap.examples/io/traceaio.c | 94 ++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 testsuite/systemtap.examples/io/traceaio.c diff --git a/testsuite/systemtap.examples/io/traceaio.c b/testsuite/systemtap.examples/io/traceaio.c new file mode 100644 index 000000000..54168af10 --- /dev/null +++ b/testsuite/systemtap.examples/io/traceaio.c @@ -0,0 +1,94 @@ +// Test program for traceaio.stp example. +// Copyright (C) 2001 Red Hat Inc. +// +// This file is part of systemtap, and is free software. You can +// redistribute it and/or modify it under the terms of the GNU General +// Public License (GPL); either version 2, or (at your option) any +// later version. +// +// Example usage: +// +// $ gcc -D_GNU_SOURCE -o traceaio traceaio.c -laio +// +// $ sudo stap traceaio.stp -c "./traceaio /var/tmp/traceaio.data" +// Tracing started +// [ 0 traceaio(756217):] io_submit(140589416931328, 4, 0x7ffc6d6bb8a0) +// iocb[ 0]=0x7ffc6d6bb8c0, fd=3, opcode=1, offset=0, nbytes=4096, buf=0x1764000 +// iocb[ 1]=0x7ffc6d6bb900, fd=3, opcode=0, offset=4096, nbytes=4096, buf=0x1765000 +// iocb[ 2]=0x7ffc6d6bb940, fd=3, opcode=8, offset=8192, nbytes=1, buf=0x7ffc6d6bb880 +// iovec[ 0]=0x7ffc6d6bb880, base=0x1766000, len=4096 +// iocb[ 3]=0x7ffc6d6bb980, fd=3, opcode=7, offset=12288, nbytes=1, buf=0x7ffc6d6bb890 +// iovec[ 0]=0x7ffc6d6bb890, base=0x1767000, len=4096 +// Tracing stopped +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define IO_SIZE 4096 + +int main(int argc, char *argv[]) +{ + int fd; + void *buffer; + io_context_t ioctx = {0}; + struct iocb iocbs[4]; + struct iocb *iocbp[] = {&iocbs[0], &iocbs[1], &iocbs[2], &iocbs[3]}; + struct iovec iovs[2]; + int err; + + if (argc != 2) { + fprintf(stderr, "Usage: traceaio-test FILENAME\n"); + exit(1); + } + + fd = open(argv[1], O_RDWR | O_CREAT | O_DIRECT, 0644); + assert(fd != -1); + + err = fallocate(fd, 0, 0, 4 * IO_SIZE); + assert(err == 0); + + err = posix_memalign(&buffer, IO_SIZE, 4 * IO_SIZE); + assert(err == 0); + + memset(buffer, 0, 4 * IO_SIZE); + + err = io_setup(128, &ioctx); + assert(err == 0); + + /* PWRITE */ + + io_prep_pwrite(&iocbs[0], fd, buffer + 0 * IO_SIZE, IO_SIZE, 0 * IO_SIZE); + + /* PREAD */ + + io_prep_pread(&iocbs[1], fd, buffer + 1 * IO_SIZE, IO_SIZE, 1 * IO_SIZE); + + /* PWRITEV */ + + iovs[0].iov_base = buffer + 2 * IO_SIZE; + iovs[0].iov_len = IO_SIZE; + io_prep_pwritev(&iocbs[2], fd, &iovs[0], 1, 2 * IO_SIZE); + + /* PREADV */ + + iovs[1].iov_base = buffer + 3 * IO_SIZE; + iovs[1].iov_len = IO_SIZE; + io_prep_preadv(&iocbs[3], fd, &iovs[1], 1, 3 * IO_SIZE); + + io_submit(ioctx, 4, iocbp); + + io_getevents(ioctx, 4, 4, NULL, NULL); + io_destroy(ioctx); + free(buffer); + close(fd); + + return 0; +} -- 2.31.1