1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) Crackerjack Project., 2007
4f08c3bdfSopenharmony_ci * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
5f08c3bdfSopenharmony_ci * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
6f08c3bdfSopenharmony_ci * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
7f08c3bdfSopenharmony_ci */
8f08c3bdfSopenharmony_ci
9f08c3bdfSopenharmony_ci/*\
10f08c3bdfSopenharmony_ci * [Description]
11f08c3bdfSopenharmony_ci *
12f08c3bdfSopenharmony_ci * Test io_getevents invoked via libaio with invalid ctx and expects it to
13f08c3bdfSopenharmony_ci * return -EINVAL.
14f08c3bdfSopenharmony_ci */
15f08c3bdfSopenharmony_ci
16f08c3bdfSopenharmony_ci#include "config.h"
17f08c3bdfSopenharmony_ci#include "tst_test.h"
18f08c3bdfSopenharmony_ci
19f08c3bdfSopenharmony_ci#ifdef HAVE_LIBAIO
20f08c3bdfSopenharmony_ci#include <libaio.h>
21f08c3bdfSopenharmony_ci
22f08c3bdfSopenharmony_cistatic void run(void)
23f08c3bdfSopenharmony_ci{
24f08c3bdfSopenharmony_ci	io_context_t ctx;
25f08c3bdfSopenharmony_ci
26f08c3bdfSopenharmony_ci	memset(&ctx, 0, sizeof(ctx));
27f08c3bdfSopenharmony_ci	TEST(io_getevents(ctx, 0, 0, NULL, NULL));
28f08c3bdfSopenharmony_ci
29f08c3bdfSopenharmony_ci	if (TST_RET == 0) {
30f08c3bdfSopenharmony_ci		tst_res(TFAIL, "io_getevents() succeeded unexpectedly");
31f08c3bdfSopenharmony_ci		return;
32f08c3bdfSopenharmony_ci	}
33f08c3bdfSopenharmony_ci
34f08c3bdfSopenharmony_ci	if (TST_RET == -EINVAL) {
35f08c3bdfSopenharmony_ci		tst_res(TPASS, "io_getevents() failed with EINVAL");
36f08c3bdfSopenharmony_ci		return;
37f08c3bdfSopenharmony_ci	}
38f08c3bdfSopenharmony_ci
39f08c3bdfSopenharmony_ci	tst_res(TFAIL, "io_getevents() failed unexpectedly %s (%ld) expected EINVAL",
40f08c3bdfSopenharmony_ci		tst_strerrno(-TST_RET), -TST_RET);
41f08c3bdfSopenharmony_ci}
42f08c3bdfSopenharmony_ci
43f08c3bdfSopenharmony_cistatic struct tst_test test = {
44f08c3bdfSopenharmony_ci	.needs_kconfigs = (const char *[]) {
45f08c3bdfSopenharmony_ci		"CONFIG_AIO=y",
46f08c3bdfSopenharmony_ci		NULL
47f08c3bdfSopenharmony_ci	},
48f08c3bdfSopenharmony_ci	.test_all = run,
49f08c3bdfSopenharmony_ci};
50f08c3bdfSopenharmony_ci
51f08c3bdfSopenharmony_ci#else
52f08c3bdfSopenharmony_ciTST_TEST_TCONF("test requires libaio and it's development packages");
53f08c3bdfSopenharmony_ci#endif
54