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_cancel invoked via libaio with one of the data structures points 13f08c3bdfSopenharmony_ci * to invalid data and expects it to return -EFAULT. 14f08c3bdfSopenharmony_ci */ 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include "config.h" 17f08c3bdfSopenharmony_ci#include "tst_test.h" 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci#ifdef HAVE_LIBAIO 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci#include <libaio.h> 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic void run(void) 24f08c3bdfSopenharmony_ci{ 25f08c3bdfSopenharmony_ci io_context_t ctx; 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci memset(&ctx, 0, sizeof(ctx)); 28f08c3bdfSopenharmony_ci TEST(io_cancel(ctx, NULL, NULL)); 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_ci if (TST_RET == 0) { 31f08c3bdfSopenharmony_ci tst_res(TFAIL, "io_cancel() succeeded unexpectedly"); 32f08c3bdfSopenharmony_ci return; 33f08c3bdfSopenharmony_ci } 34f08c3bdfSopenharmony_ci 35f08c3bdfSopenharmony_ci if (TST_RET == -EFAULT) { 36f08c3bdfSopenharmony_ci tst_res(TPASS, "io_cancel() failed with EFAULT"); 37f08c3bdfSopenharmony_ci return; 38f08c3bdfSopenharmony_ci } 39f08c3bdfSopenharmony_ci 40f08c3bdfSopenharmony_ci tst_res(TFAIL, "io_cancel() failed unexpectedly %s (%ld) expected EFAULT", 41f08c3bdfSopenharmony_ci tst_strerrno(-TST_RET), -TST_RET); 42f08c3bdfSopenharmony_ci} 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_cistatic struct tst_test test = { 45f08c3bdfSopenharmony_ci .needs_kconfigs = (const char *[]) { 46f08c3bdfSopenharmony_ci "CONFIG_AIO=y", 47f08c3bdfSopenharmony_ci NULL 48f08c3bdfSopenharmony_ci }, 49f08c3bdfSopenharmony_ci .test_all = run, 50f08c3bdfSopenharmony_ci}; 51f08c3bdfSopenharmony_ci 52f08c3bdfSopenharmony_ci#else 53f08c3bdfSopenharmony_ciTST_TEST_TCONF("test requires libaio and it's development packages"); 54f08c3bdfSopenharmony_ci#endif 55