From patchwork Sat Apr 6 21:49:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 10888251 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9B81C1708 for ; Sat, 6 Apr 2019 21:49:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27C381FFBD for ; Sat, 6 Apr 2019 21:49:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1608A287A5; Sat, 6 Apr 2019 21:49:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12BAB2874F for ; Sat, 6 Apr 2019 21:49:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726229AbfDFVte (ORCPT ); Sat, 6 Apr 2019 17:49:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:44348 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726027AbfDFVte (ORCPT ); Sat, 6 Apr 2019 17:49:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9C1ECAD82; Sat, 6 Apr 2019 21:49:33 +0000 (UTC) From: Petr Vorel To: linux-kselftest@vger.kernel.org Cc: Petr Vorel , Mimi Zohar , shuah , Cyril Hrubis Subject: [RFC PATCH 1/2] selftests: Start shell API Date: Sat, 6 Apr 2019 23:49:14 +0200 Message-Id: <20190406214915.16914-2-pvorel@suse.cz> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190406214915.16914-1-pvorel@suse.cz> References: <20190406214915.16914-1-pvorel@suse.cz> MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP kselftest.sh is a beginning of shell API. ATM it's a stub (target could be as rich as LTP API), containing only: * exit codes * filling TEST variable * logging functions * requiring root function * add script directory into PATH Inspired by kexec functions (with some cleanup) and LTP. Signed-off-by: Petr Vorel --- tools/testing/selftests/kselftest.sh | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tools/testing/selftests/kselftest.sh diff --git a/tools/testing/selftests/kselftest.sh b/tools/testing/selftests/kselftest.sh new file mode 100644 index 000000000000..519ec2707dd8 --- /dev/null +++ b/tools/testing/selftests/kselftest.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2019 Petr Vorel + +PATH="$(dirname $0):$PATH" + +KSFT_PASS=0 +KSFT_FAIL=1 +KSFT_XFAIL=2 +KSFT_XPASS=3 +KSFT_SKIP=4 + +TEST=$(basename $0) + +ksft_info() +{ + echo "[INFO] $TEST: $1" +} + +ksft_pass() +{ + echo "[PASS] $TEST: $1" + exit $KSFT_PASS +} + +ksft_fail() +{ + echo "[FAIL] $TEST: $1" + exit $KSFT_FAIL +} + +ksft_xfail() +{ + echo "[FAIL] $TEST: $1" + exit $KSFT_XFAIL +} + +ksft_xpass() +{ + echo "[PASS] $TEST: $1" + exit $KSFT_XPASS +} + +ksft_skip() +{ + echo "[SKIP] $TEST: $1" + exit $KSFT_SKIP +} + +ksft_require_root() +{ + [ $(id -ru) -eq 0 ] || ksft_skip "requires root privileges" +}