forked from linux-test-project/ltp
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor timerfd_create01 using new LTP API
Signed-off-by: Andrea Cervesato <[email protected]> Reviewed-by: Li Wang <[email protected]>
- Loading branch information
1 parent
d7ba08b
commit 08eadc6
Showing
1 changed file
with
22 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,40 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (c) 2014 Fujitsu Ltd. | ||
* Author: Zeng Linggang <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as | ||
* published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it would be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* Zeng Linggang <[email protected]> | ||
* Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]> | ||
*/ | ||
/* | ||
* DESCRIPTION | ||
* Verify that, | ||
* 1. The clockid argument is neither CLOCK_MONOTONIC nor CLOCK_REALTIME, | ||
* EINVAL would return. | ||
* 2. flags is invalid, EINVAL would return. | ||
/*\ | ||
* [Description] | ||
* | ||
* This test verifies that: | ||
* - clockid argument is neither CLOCK_MONOTONIC nor CLOCK_REALTIME, | ||
* EINVAL would return. | ||
* - flags is invalid, EINVAL would return. | ||
*/ | ||
|
||
#define _GNU_SOURCE | ||
|
||
#include <errno.h> | ||
|
||
#include "test.h" | ||
#include "lapi/timerfd.h" | ||
|
||
char *TCID = "timerfd_create01"; | ||
#include "tst_test.h" | ||
#include "tst_safe_timerfd.h" | ||
|
||
static struct test_case_t { | ||
int clockid; | ||
int flags; | ||
int exp_errno; | ||
} test_cases[] = { | ||
{-1, 0, EINVAL}, | ||
{0, -1, EINVAL}, | ||
} tcases[] = { | ||
{ -1, 0, EINVAL }, | ||
{ 0, -1, EINVAL }, | ||
}; | ||
|
||
int TST_TOTAL = ARRAY_SIZE(test_cases); | ||
static void setup(void); | ||
static void timerfd_create_verify(const struct test_case_t *); | ||
static void cleanup(void); | ||
|
||
int main(int argc, char *argv[]) | ||
static void run(unsigned int i) | ||
{ | ||
int lc; | ||
int i; | ||
|
||
tst_parse_opts(argc, argv, NULL, NULL); | ||
struct test_case_t *test = &tcases[i]; | ||
|
||
setup(); | ||
|
||
for (lc = 0; TEST_LOOPING(lc); lc++) { | ||
tst_count = 0; | ||
for (i = 0; i < TST_TOTAL; i++) | ||
timerfd_create_verify(&test_cases[i]); | ||
} | ||
|
||
cleanup(); | ||
tst_exit(); | ||
TST_EXP_FAIL(timerfd_create(test->clockid, test->flags), test->exp_errno); | ||
} | ||
|
||
static void setup(void) | ||
{ | ||
tst_sig(NOFORK, DEF_HANDLER, cleanup); | ||
|
||
TEST_PAUSE; | ||
} | ||
|
||
static void timerfd_create_verify(const struct test_case_t *test) | ||
{ | ||
TEST(timerfd_create(test->clockid, test->flags)); | ||
|
||
if (TEST_RETURN != -1) { | ||
tst_resm(TFAIL, "timerfd_create() succeeded unexpectedly"); | ||
return; | ||
} | ||
|
||
if (TEST_ERRNO == test->exp_errno) { | ||
tst_resm(TPASS | TTERRNO, | ||
"timerfd_create() failed as expected"); | ||
} else { | ||
tst_resm(TFAIL | TTERRNO, | ||
"timerfd_create() failed unexpectedly; expected: " | ||
"%d - %s", test->exp_errno, strerror(test->exp_errno)); | ||
} | ||
} | ||
|
||
static void cleanup(void) | ||
{ | ||
} | ||
static struct tst_test test = { | ||
.test = run, | ||
.tcnt = ARRAY_SIZE(tcases), | ||
}; |