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) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com> 7f08c3bdfSopenharmony_ci */ 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ci/*\ 10f08c3bdfSopenharmony_ci * [Description] 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * Test io_destroy invoked via libaio with invalid ctx and expects it to 13f08c3bdfSopenharmony_ci * return -EINVAL. 14f08c3bdfSopenharmony_ci */ 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_ci#include <errno.h> 17f08c3bdfSopenharmony_ci#include <string.h> 18f08c3bdfSopenharmony_ci#include "config.h" 19f08c3bdfSopenharmony_ci#include "tst_test.h" 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci#ifdef HAVE_LIBAIO 22f08c3bdfSopenharmony_ci#include <libaio.h> 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_cistatic void verify_io_destroy(void) 25f08c3bdfSopenharmony_ci{ 26f08c3bdfSopenharmony_ci io_context_t ctx; 27f08c3bdfSopenharmony_ci 28f08c3bdfSopenharmony_ci memset(&ctx, 0xff, sizeof(ctx)); 29f08c3bdfSopenharmony_ci TEST(io_destroy(ctx)); 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci if (TST_RET == 0) { 32f08c3bdfSopenharmony_ci tst_res(TFAIL, "io_destroy() succeeded unexpectedly"); 33f08c3bdfSopenharmony_ci return; 34f08c3bdfSopenharmony_ci } 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci if (TST_RET == -ENOSYS) { 37f08c3bdfSopenharmony_ci tst_res(TCONF, "io_destroy() not supported"); 38f08c3bdfSopenharmony_ci return; 39f08c3bdfSopenharmony_ci } 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci if (TST_RET == -EINVAL) { 42f08c3bdfSopenharmony_ci tst_res(TPASS, "io_destroy() failed as expected, returned -EINVAL"); 43f08c3bdfSopenharmony_ci return; 44f08c3bdfSopenharmony_ci } 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci tst_res(TFAIL, "io_destroy() failed unexpectedly, returned -%s expected -EINVAL", 47f08c3bdfSopenharmony_ci tst_strerrno(-TST_RET)); 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cistatic struct tst_test test = { 51f08c3bdfSopenharmony_ci .test_all = verify_io_destroy, 52f08c3bdfSopenharmony_ci}; 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ci#else 55f08c3bdfSopenharmony_ci TST_TEST_TCONF("test requires libaio and it's development packages"); 56f08c3bdfSopenharmony_ci#endif 57