[LTP] [PATCH 1/2] gettimeofday01: Convert to new API
Yang Xu
xuyang2018.jy@fujitsu.com
Mon Dec 18 07:21:28 CET 2023
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
.../syscalls/gettimeofday/gettimeofday01.c | 103 ++----------------
1 file changed, 12 insertions(+), 91 deletions(-)
diff --git a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
index f9acb9665..84e98fd9a 100644
--- a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
+++ b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
@@ -1,107 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
*
* Copyright (c) International Business Machines Corp., 2001
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Linux Test Project, 2001-2023
*/
-/*
- * NAME
- * gettimeofday01.c
- *
+/*\
* DESCRIPTION
- * Testcase to check that gettimeofday(2) sets errno to EFAULT.
- *
- * ALGORITHM
- * Call gettimeofday() with an invalid buffer, and expect EFAULT to be
- * set in errno.
*
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
+ * Test for EFAULT error.
*
- * RESTRICTIONS
- * NONE
+ * - gettimeofday fail with EFAULT when one of tv or tz pointed outside the accessible
+ * address space
*/
-#include <sys/time.h>
-#include <errno.h>
-#include "test.h"
-#include <unistd.h>
+#include "tst_test.h"
#include "lapi/syscalls.h"
-char *TCID = "gettimeofday01";
-int TST_TOTAL = 1;
-
-#if !defined UCLINUX
-
-void cleanup(void);
-void setup(void);
-
-int main(int ac, char **av)
-{
- int lc;
- int ret;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
- TEST(tst_syscall(__NR_gettimeofday, (void *)-1, (void *)-1));
-
- /* gettimeofday returns an int, so we need to turn the long
- * TEST_RETURN into an int to test with */
- ret = TEST_RETURN;
- if (ret != -1) {
- tst_resm(TFAIL,
- "call succeeded unexpectedly (got back %i, wanted -1)",
- ret);
- continue;
- }
-
- if (TEST_ERRNO == EFAULT)
- tst_resm(TPASS,
- "gettimeofday(2) set the errno EFAULT correctly");
- else
- tst_resm(TFAIL,
- "gettimeofday(2) didn't set errno to EFAULT, errno=%i (%s)",
- errno, strerror(errno));
- }
-
- cleanup();
- tst_exit();
-}
-
-void setup(void)
-{
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-}
-
-void cleanup(void)
+static void verify_gettimeofday(void)
{
+ TST_EXP_FAIL(tst_syscall(__NR_gettimeofday, (void *)-1, (void *)-1), EFAULT);
}
-#else
-int main(void)
-{
- tst_brkm(TCONF, "gettimeofday EFAULT check disabled on uClinux");
-}
-#endif
+static struct tst_test test = {
+ .test_all = verify_gettimeofday,
+};
--
2.39.3
More information about the ltp
mailing list