From patchwork Sat Feb 2 01:59:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Muckle X-Patchwork-Id: 1035320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="Krsm9XEM"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43ry1T0McWz9sBZ for ; Sat, 2 Feb 2019 13:03:23 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 14C9C3EABF1 for ; Sat, 2 Feb 2019 03:03:20 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 359DA3EABD9 for ; Sat, 2 Feb 2019 03:03:16 +0100 (CET) Received: from mail-vs1-xe49.google.com (mail-vs1-xe49.google.com [IPv6:2607:f8b0:4864:20::e49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 8EE4A6019FB for ; Sat, 2 Feb 2019 03:03:15 +0100 (CET) Received: by mail-vs1-xe49.google.com with SMTP id g5so3637039vsi.2 for ; Fri, 01 Feb 2019 18:03:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=iLoTrd4lsaVkM1bBm2gmC67Uh4yK61M9cWlFkIou9Hc=; b=Krsm9XEMYwtT1nDJAPbiuxNwJFry090QjKpOpeIMPlCwz1x8J7pSATC+G3xqq1b9CI IvfuNluBQG7bgfD4jNXOerr/w4cn9SC0h7TKEWNNJmsMrpt6A30IJ/7Okoiq6/N8/BbR jcMfgntNj03688/nwgk0rHl3r/tYYb74hLV+uy7UD6cPBZqhR/99GGanAc45GGBLaZ0a MlLwA29msbG/HHX3h+icisbqmoT2DCfaUdD6sgyvwrFIHGZtobuuHXgGwX0m3M8tkaAl QfmfiyXh/AbTFiOAAeadj9MiaTe/bApMTAGcKWbVTdA62X+uaGVfUZedEWCHZQxU6+c6 4cCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=iLoTrd4lsaVkM1bBm2gmC67Uh4yK61M9cWlFkIou9Hc=; b=pO9IjZf/9GcCbYaOn9CcjX55icD06neAQR6AG3B2BaP2pBeZBTzJkzq0Kyqr4+6LtL U6jg0ME0erxzlmhXTniic+Zp2qDN0htz5GJ8I9ROaZI+JJ+sbqbA94Sg3M/6cbc7dJ0D WbyFuf4LKgPZqt3EThN5hKeqenYAKkjn3fIFhSV3K95WnMMW1qctkDTx4DKPjJfjToNZ 8aq3Wy5lR9b4p89hZScKd1HF35yOkFYwVEfHz4WKEzW9O/x4sActVLY/HTHeRx+yNEia NKBRC4a782LgP8oi3qbllYIF9pG/x4E/xegvvhp9lCrD7VE5BphqINA5hXdKByFjfX6E fDeQ== X-Gm-Message-State: AHQUAua8gAmGUjApcsLaRn3LH8LEcmgEbPiPEBF2WjxdrdiM1npyW2FC rRRuOABuauRAn8w3zWXcTg3kG2AJXOgLDIz20tsYAmd9py6QepkqCRLK0MgFOLxwHMtIEzrnGVW CN4gUStMBm9mKGmclxD6FbojUfZD6ddFnkyrcK5siDIB6CdbfwP4mGRlZgXM= X-Google-Smtp-Source: AHgI3IZkov2jaX6SEDmrb5nfrIv93JzMqgAU9BXoxKnjxjcKG+TYKpxZgH+BSzL+b/GR3yOs1jSXpFeVjf5H X-Received: by 2002:a1f:91d4:: with SMTP id t203mr18777442vkd.2.1549072994336; Fri, 01 Feb 2019 18:03:14 -0800 (PST) Date: Fri, 1 Feb 2019 17:59:24 -0800 Message-Id: <20190202015923.189057-1-smuckle@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1.611.gfbb209baf1-goog From: Steve Muckle To: ltp@lists.linux.it X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-7.4 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: kernel-team@android.com Subject: [LTP] [PATCH DRAFT] syscalls/stime: convert to new lib, use direct syscall X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Use direct syscall to expand test compatibility to Android. Change-Id: Icdeec19bd3675902266adc1ef7f9173b76016e15 Signed-off-by: Steve Muckle --- I set about cleaning up the stime tests but later realized I don't have a platform that has the stime syscall so I cannot test this patch fully. If someone else has such a platform (looks like 32-bit x86 has it) and wants to take the patch over, feel free :) . testcases/kernel/syscalls/stime/stime01.c | 217 +++++----------------- testcases/kernel/syscalls/stime/stime02.c | 176 ++++-------------- 2 files changed, 80 insertions(+), 313 deletions(-) diff --git a/testcases/kernel/syscalls/stime/stime01.c b/testcases/kernel/syscalls/stime/stime01.c index 378aa52a8..55c8053b0 100644 --- a/testcases/kernel/syscalls/stime/stime01.c +++ b/testcases/kernel/syscalls/stime/stime01.c @@ -1,24 +1,6 @@ +// 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 - */ - -/* - * Test Name: stime01 + * Copyright (c) International Business Machines Corp., 2001 * * Test Description: * Verify that the system call stime() successfully sets the system's idea @@ -27,177 +9,64 @@ * Expected Result: * stime() should succeed to set the system data/time to the specified time. * - * Algorithm: - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * - * Usage: - * stime01 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -f : Turn off functionality Testing. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * * History * 07/2001 John George * -Ported - * - * Restrictions: - * This test should be run by 'super-user' (root) only. - * */ -#include -#include -#include -#include -#include #include -#include -#include -#include #include -#include "test.h" - -#define INCR_TIME 30 /* increment in the system's current time */ +#include "lapi/syscalls.h" +#include "tst_test.h" #define BASH_CLOCK -char *TCID = "stime01"; -int TST_TOTAL = 1; -struct timeval real_time_tv, pres_time_tv; -time_t new_time; - -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ +static struct timeval real_time_tv; -int main(int ac, char **av) +static void run(void) { - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - /* - * ``Break`` the clock. - * - * This is being done inline here so that the offset is - * automatically reset based on the elapsed time, and not a - * fixed time sampled once in setup. - * - * The big assumption here is the clock state isn't super - * fubared if so, the executing party needs to go fix their - * RTC's battery, or they have more pressing issues to attend - * to as far as clock skew is concerned :P. - */ - if (gettimeofday(&real_time_tv, NULL) < 0) { - tst_brkm(TBROK | TERRNO, NULL, - "failed to get current time via gettimeofday(2)"); - } - - /* Get the system's new time */ - new_time = real_time_tv.tv_sec + INCR_TIME; - - tst_count = 0; - - /* - * Invoke stime(2) to set the system's time to the specified - * new_time. - */ - if (stime(&new_time) < 0) { - tst_resm(TFAIL | TERRNO, "stime(%ld) failed", new_time); - } else { - - /* - * Get the system's current time after call - * to stime(). - */ - if (gettimeofday(&pres_time_tv, NULL) < 0) { - tst_brkm(TFAIL | TERRNO, cleanup, - "time() failed to get " - "system's time after stime"); - } - - /* Now do the actual verification */ - switch (pres_time_tv.tv_sec - new_time) { - case 0: - case 1: - tst_resm(TINFO, "pt.tv_sec: %ld", - pres_time_tv.tv_sec); - tst_resm(TPASS, "system time was set " - "to %ld", new_time); - break; - default: - tst_resm(TFAIL, "system time was not " - "set to %ld (time is " - "actually: %ld)", - new_time, pres_time_tv.tv_sec); - } - - if (settimeofday(&real_time_tv, NULL) < 0) { - tst_resm(TBROK | TERRNO, - "failed to restore time to original " - "value; system clock may need to be " - "fixed manually"); - } - + time_t new_time; + struct timeval pres_time_tv; + + if (gettimeofday(&real_time_tv, NULL) < 0) + tst_brk(TBROK | TERRNO, + "failed to get current time via gettimeofday(2)"); + + new_time = real_time_tv.tv_sec + 30; + + /* Invoke stime to set the system's time to the specified new_time. */ + if (tst_syscall(__NR_stime, &new_time) < 0) { + tst_res(TFAIL | TERRNO, "stime(%ld) failed", new_time); + } else { + if (gettimeofday(&pres_time_tv, NULL) < 0) + tst_brk(TFAIL | TERRNO, "time() failed to get " + "system's time after stime"); + + switch (pres_time_tv.tv_sec - new_time) { + case 0: + case 1: + tst_res(TINFO, "pt.tv_sec: %ld", pres_time_tv.tv_sec); + tst_res(TPASS, "system time was set to %ld", new_time); + break; + default: + tst_res(TFAIL, "system time not set to %ld (time " + "actually: %ld)", new_time, + pres_time_tv.tv_sec); } - } - - cleanup(); - tst_exit(); - } -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Get the current time and system's new time to be set in the test. - */ -void setup(void) +static void cleanup(void) { - tst_require_root(); - - TEST_PAUSE; - -} - -/* - * void - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - /* Restore the original system time. */ - if (settimeofday(&real_time_tv, NULL) != 0) { - tst_resm(TBROK | TERRNO, "failed to restore time to original " - "value; system clock may need to be " - "fixed manually"); - } - + if (settimeofday(&real_time_tv, NULL) != 0) + tst_res(TBROK | TERRNO, "failed to restore time to original " + "value; system clock may need to be fixed manually"); } + +static struct tst_test test = { + .test_all = run, + .cleanup = cleanup, + .needs_root = 1, +}; diff --git a/testcases/kernel/syscalls/stime/stime02.c b/testcases/kernel/syscalls/stime/stime02.c index 180e36119..cf86069ba 100644 --- a/testcases/kernel/syscalls/stime/stime02.c +++ b/testcases/kernel/syscalls/stime/stime02.c @@ -1,24 +1,6 @@ +// 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 - */ - -/* - * Test Name: stime02 + * Copyright (c) International Business Machines Corp., 2001 * * Test Description: * Verify that the system call stime() fails to set the system's idea @@ -27,144 +9,60 @@ * Expected Result: * stime() should fail with return value -1 and set errno to EPERM. * - * Algorithm: - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * if errno set == expected errno - * Issue sys call fails with expected return value and errno. - * Otherwise, - * Issue sys call fails with unexpected errno. - * Otherwise, - * Issue sys call returns unexpected value. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * Usage: - * stime02 [-c n] [-e] [-i n] [-I x] [-p x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * * History * 07/2001 John George * -Ported - * - * Restrictions: */ -#include -#include #include #include -#include #include -#include -#include -#include #include -#include "test.h" +#include "lapi/syscalls.h" +#include "tst_test.h" -#define INCR_TIME 10 /* increment in the system's current time */ +static time_t new_time; -char *TCID = "stime02"; -int TST_TOTAL = 1; - -time_t curr_time; /* system's current time in seconds */ -time_t new_time; /* system's new time */ -time_t tloc; /* argument var. for time() */ -char nobody_uid[] = "nobody"; -struct passwd *ltpuser; - -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) +static void run(void) { - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Invoke stime(2) to set the system's time - * to the specified new_time as non-root user. - */ - TEST(stime(&new_time)); - - if (TEST_RETURN == -1) { - if (TEST_ERRNO == EPERM) { - tst_resm(TPASS, "stime(2) fails, Caller not " - "root, errno:%d", TEST_ERRNO); - } else { - tst_resm(TFAIL, "stime(2) fails, Caller not " - "root, errno:%d, expected errno:%d", - TEST_ERRNO, EPERM); - } - } else { - tst_resm(TFAIL, "stime(2) returned %ld, expected -1, " - "errno:%d", TEST_RETURN, EPERM); - } - tst_count++; /* incr TEST_LOOP counter */ - } - - cleanup(); - tst_exit(); - + /* + * Invoke stime to set the system's time to the specified new_time as + * non-root user. + */ + TEST(tst_syscall(__NR_stime, &new_time)); + + if (TST_RET == -1) + if (TST_ERR == EPERM) + tst_res(TPASS | TTERRNO, "stime(2) fails, Caller not " + "root"); + else + tst_res(TFAIL| TTERRNO, "stime(2) fails, Caller not " + "root, expected errno:%d", EPERM); + else + tst_res(TFAIL, "stime(2) returned %ld, expected -1, " + "errno:%d", TST_RET, EPERM); } -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Get the current time and system's new time. - */ -void setup(void) +static void setup(void) { - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); + time_t curr_time; + struct passwd *ltpuser; /* Switch to nobody user for correct error code collection */ - ltpuser = getpwnam(nobody_uid); - if (setuid(ltpuser->pw_uid) == -1) { - tst_resm(TINFO, "setuid failed to " - "to set the effective uid to %d", ltpuser->pw_uid); - perror("setuid"); - } + ltpuser = getpwnam("nobody"); + if (setuid(ltpuser->pw_uid) == -1) + tst_brk(TBROK | TERRNO, "setuid failed to " + "set the effective uid to %d", ltpuser->pw_uid); - TEST_PAUSE; + if ((curr_time = time(NULL)) < 0) + tst_brk(TBROK | TERRNO, "time() failed to get current time"); - /* Get the current time */ - if ((curr_time = time(&tloc)) < 0) { - tst_brkm(TBROK, cleanup, - "time() failed to get current time, errno=%d", errno); - } - - /* Get the system's new time */ - new_time = curr_time + INCR_TIME; + new_time = curr_time + 10; } -/* - * void - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - -} +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, +};