1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org> 4f08c3bdfSopenharmony_ci * 5f08c3bdfSopenharmony_ci * Description: 6f08c3bdfSopenharmony_ci * Basic io_pgetevents() test to receive 1 event successfully. 7f08c3bdfSopenharmony_ci */ 8f08c3bdfSopenharmony_ci#include "time64_variants.h" 9f08c3bdfSopenharmony_ci#include "tst_test.h" 10f08c3bdfSopenharmony_ci#include "tst_timer.h" 11f08c3bdfSopenharmony_ci#include "lapi/io_pgetevents.h" 12f08c3bdfSopenharmony_ci 13f08c3bdfSopenharmony_ci#ifdef HAVE_LIBAIO 14f08c3bdfSopenharmony_cistatic int fd; 15f08c3bdfSopenharmony_ci 16f08c3bdfSopenharmony_cistatic struct time64_variants variants[] = { 17f08c3bdfSopenharmony_ci#if (__NR_io_pgetevents != __LTP__NR_INVALID_SYSCALL) 18f08c3bdfSopenharmony_ci { .io_pgetevents = sys_io_pgetevents, .ts_type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"}, 19f08c3bdfSopenharmony_ci#endif 20f08c3bdfSopenharmony_ci 21f08c3bdfSopenharmony_ci#if (__NR_io_pgetevents_time64 != __LTP__NR_INVALID_SYSCALL) 22f08c3bdfSopenharmony_ci { .io_pgetevents = sys_io_pgetevents_time64, .ts_type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"}, 23f08c3bdfSopenharmony_ci#endif 24f08c3bdfSopenharmony_ci}; 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_cistatic void setup(void) 27f08c3bdfSopenharmony_ci{ 28f08c3bdfSopenharmony_ci tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc); 29f08c3bdfSopenharmony_ci} 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_cistatic void run(void) 32f08c3bdfSopenharmony_ci{ 33f08c3bdfSopenharmony_ci struct time64_variants *tv = &variants[tst_variant]; 34f08c3bdfSopenharmony_ci struct io_event events[1]; 35f08c3bdfSopenharmony_ci struct iocb cb, *cbs[1]; 36f08c3bdfSopenharmony_ci io_context_t ctx = 0; 37f08c3bdfSopenharmony_ci struct tst_ts to = tst_ts_from_ns(tv->ts_type, 10000); 38f08c3bdfSopenharmony_ci sigset_t sigmask; 39f08c3bdfSopenharmony_ci char data[4096]; 40f08c3bdfSopenharmony_ci int ret; 41f08c3bdfSopenharmony_ci 42f08c3bdfSopenharmony_ci cbs[0] = &cb; 43f08c3bdfSopenharmony_ci sigemptyset(&sigmask); 44f08c3bdfSopenharmony_ci 45f08c3bdfSopenharmony_ci fd = SAFE_OPEN("io_pgetevents_file", O_RDWR | O_CREAT, 0644); 46f08c3bdfSopenharmony_ci io_prep_pwrite(&cb, fd, data, 4096, 0); 47f08c3bdfSopenharmony_ci 48f08c3bdfSopenharmony_ci TEST(io_setup(1, &ctx)); 49f08c3bdfSopenharmony_ci if (TST_RET == -ENOSYS) 50f08c3bdfSopenharmony_ci tst_brk(TCONF | TRERRNO, "io_setup(): AIO not supported by kernel"); 51f08c3bdfSopenharmony_ci if (TST_RET < 0) 52f08c3bdfSopenharmony_ci tst_brk(TBROK | TRERRNO, "io_setup() failed"); 53f08c3bdfSopenharmony_ci 54f08c3bdfSopenharmony_ci ret = io_submit(ctx, 1, cbs); 55f08c3bdfSopenharmony_ci if (ret != 1) 56f08c3bdfSopenharmony_ci tst_brk(TBROK | TERRNO, "io_submit() failed"); 57f08c3bdfSopenharmony_ci 58f08c3bdfSopenharmony_ci /* get the reply */ 59f08c3bdfSopenharmony_ci ret = tv->io_pgetevents(ctx, 1, 1, events, tst_ts_get(&to), &sigmask); 60f08c3bdfSopenharmony_ci 61f08c3bdfSopenharmony_ci if (ret == 1) 62f08c3bdfSopenharmony_ci tst_res(TPASS, "io_pgetevents() works as expected"); 63f08c3bdfSopenharmony_ci else 64f08c3bdfSopenharmony_ci tst_res(TFAIL | TERRNO, "io_pgetevents() failed"); 65f08c3bdfSopenharmony_ci 66f08c3bdfSopenharmony_ci if (io_destroy(ctx) < 0) 67f08c3bdfSopenharmony_ci tst_brk(TBROK | TERRNO, "io_destroy() failed"); 68f08c3bdfSopenharmony_ci 69f08c3bdfSopenharmony_ci SAFE_CLOSE(fd); 70f08c3bdfSopenharmony_ci} 71f08c3bdfSopenharmony_ci 72f08c3bdfSopenharmony_cistatic struct tst_test test = { 73f08c3bdfSopenharmony_ci .min_kver = "4.18", 74f08c3bdfSopenharmony_ci .test_all = run, 75f08c3bdfSopenharmony_ci .test_variants = ARRAY_SIZE(variants), 76f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 77f08c3bdfSopenharmony_ci .setup = setup, 78f08c3bdfSopenharmony_ci}; 79f08c3bdfSopenharmony_ci 80f08c3bdfSopenharmony_ci#else 81f08c3bdfSopenharmony_ciTST_TEST_TCONF("test requires libaio and it's development packages"); 82f08c3bdfSopenharmony_ci#endif 83