1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. 4f08c3bdfSopenharmony_ci * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/*\ 8f08c3bdfSopenharmony_ci * [Description] 9f08c3bdfSopenharmony_ci * 10f08c3bdfSopenharmony_ci * This is a timer sample test that timer slack is 200us. 11f08c3bdfSopenharmony_ci */ 12f08c3bdfSopenharmony_ci 13f08c3bdfSopenharmony_ci#include <errno.h> 14f08c3bdfSopenharmony_ci#include <sys/prctl.h> 15f08c3bdfSopenharmony_ci#include "lapi/prctl.h" 16f08c3bdfSopenharmony_ci#include "tst_timer_test.h" 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_cistatic int sample_fn(int clk_id, long long usec) 19f08c3bdfSopenharmony_ci{ 20f08c3bdfSopenharmony_ci struct timespec t = tst_timespec_from_us(usec); 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_ci tst_timer_start(clk_id); 23f08c3bdfSopenharmony_ci TEST(nanosleep(&t, NULL)); 24f08c3bdfSopenharmony_ci tst_timer_stop(); 25f08c3bdfSopenharmony_ci tst_timer_sample(); 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci if (TST_RET != 0) { 28f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, 29f08c3bdfSopenharmony_ci "nanosleep() returned %li", TST_RET); 30f08c3bdfSopenharmony_ci return 1; 31f08c3bdfSopenharmony_ci } 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci return 0; 34f08c3bdfSopenharmony_ci} 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_cistatic void setup(void) 37f08c3bdfSopenharmony_ci{ 38f08c3bdfSopenharmony_ci TEST(prctl(PR_SET_TIMERSLACK, 200000)); 39f08c3bdfSopenharmony_ci if (TST_RET != 0) 40f08c3bdfSopenharmony_ci tst_brk(TBROK | TTERRNO, 41f08c3bdfSopenharmony_ci "prctl set timerslack 200us failed"); 42f08c3bdfSopenharmony_ci} 43f08c3bdfSopenharmony_ci 44f08c3bdfSopenharmony_cistatic struct tst_test test = { 45f08c3bdfSopenharmony_ci .setup = setup, 46f08c3bdfSopenharmony_ci .scall = "prctl()", 47f08c3bdfSopenharmony_ci .sample = sample_fn, 48f08c3bdfSopenharmony_ci}; 49