elfutils/tests/Regression/eu-strip-invalid-section-alignment-while/testprog.c
Martin Cermak 178121d8af Introduce CI gating setup for elfutils
Set up CI gating.  This will introduce new testcase called
fedora-ci.koji-build.tier0.functional and will configure it
as a mandatory CI gating testcase for elfutils fedora builds.

The provided test coverage comes from RHEL. This commit
"upstreams" it and makes it public.

The test cases are executed by running ./runtest.sh.
The main.fmf file keeps the testcase metadata.  Makefiles
and PURPOSE files are legacy and could be dropped.  We keep
them for backward compatibility though.  The plans and .fmf
folders contain configuration files needed for execution of
provided testcases within the Fedora CI infrastructure.
Rest of the provided files are reproducer or helper files.

Provided tests use Flexible Metadata Format, as documented in
https://fmf.readthedocs.io/ .

plans/ci.fmf: Change how from beakerlib to tmt

Removed tests that didn't run unprivileged with
tmt run --all provision --how=local

- tests/Regression/GNU-Property-notes-not-recognized
  Tries to install extra pacakger with yum.

- tests/Regression/bz447416-segfaults
  Tries to do eu-stack -p 1

- tests/Regression/elfutils-default-yama-scope-scriptlet-failed
  Does not have permission to do:
  grep /var/log/anaconda/packaging.log

- tests/Sanity/yama-scope
  su: user ptrace_scope_testuser does not exist or the user entry does not
      contain all the required fields

- tests/testsuite
  yum-builddep -y /tmp/tmp.7gnbiIzrYg/SPECS/elfutils.spec

- tests/Regression/rpmtests
  Tries to download and builddep src.rpm package from koji.

Removed not enabled tests:
- tests/Regression/bz652858-elfutils-prelink-stap-interaction
- tests/Sanity/elfutils-debuginfod

CVE reproducers are now public, so no longer confidential.

Remove unused tests/Sanity/elfutils-debuginfod/typescript
2021-04-19 10:42:42 +02:00

116 lines
3.3 KiB
C

/*
* aio-dio-subblock-eof-read - test AIO read of last block of DIO file
* Copyright (C) 2005 Jeff Moyer
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* Code taken from an example posted to linux-aio at kvack.org
* http://marc.info/?l=linux-aio&m=112263621431161&w=2
* Original Author: Drangon Zhou
* Munged & rewritten by Jeff Moyer.
*
* Description: This source code implements a test to ensure that an AIO
* read of the last block in a file opened with O_DIRECT returns the proper
* amount of data. In the past, there was a bug that resulted in a return
* value of the requested block size, when in fact there was only a fraction
* of that data available. Thus, if the last data block contained 300 bytes
* worth of data, and the user issued a 4k read, we want to ensure that
* the return value is 300, not 4k.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <libaio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
/* Create a file of a size that is not a multiple of block size */
#define FILE_SIZE 300
#define fail(fmt , args...) \
do {\
printf(fmt , ##args);\
exit(1);\
} while (0)
static unsigned char buffer[4096] __attribute((aligned (4096)));
int
main(int argc, char **argv)
{
int ret;
int fd;
const char *filename;
struct iocb myiocb;
struct iocb *cb = &myiocb;
io_context_t ioctx;
struct io_event ie;
if (argc != 2)
fail("only arg should be file name");
filename = argv[1];
fd = open(filename, O_CREAT|O_RDWR|O_DIRECT, 0600);
if (fd < 0)
fail("open returned error %d\n", errno);
ret = ftruncate(fd, FILE_SIZE);
if (ret < 0)
fail("truncate returned error %d\n", errno);
/* <1> use normal disk read, this should be ok */
ret = read(fd, buffer, 4096);
if (ret != FILE_SIZE)
fail("buffered read returned %d, should be 300\n", ret);
/* <2> use AIO disk read, it sees error. */
memset(&myiocb, 0, sizeof(myiocb));
cb->data = 0;
cb->key = 0;
cb->aio_lio_opcode = IO_CMD_PREAD;
cb->aio_reqprio = 0;
cb->aio_fildes = fd;
cb->u.c.buf = buffer;
cb->u.c.nbytes = 4096;
cb->u.c.offset = 0;
ret = io_queue_init(1, &ioctx);
if (ret != 0)
fail("io_queue_init returned error %d\n", ret);
ret = io_submit(ioctx, 1, &cb);
if (ret != 1)
fail("io_submit returned error %d\n", ret);
ret = io_getevents(ioctx, 1, 1, &ie, NULL);
if (ret != 1)
fail("io_getevents returned %d\n", ret);
/*
* If all goes well, we should see 300 bytes read. If things
* are broken, we may very well see a result of 4k.
*/
if (ie.res != FILE_SIZE)
fail("AIO read of last block in file returned %ld bytes, "
"expected %d\n", ie.res, FILE_SIZE);
printf("AIO read of last block in file succeeded.\n");
return 0;
}