From patchwork Sat Apr 6 21:49:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 10888253 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 CE7A118E8 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 A05811FFBD for ; Sat, 6 Apr 2019 21:49:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93A5228455; 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 E60DD284F9 for ; Sat, 6 Apr 2019 21:49:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726184AbfDFVte (ORCPT ); Sat, 6 Apr 2019 17:49:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:44336 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726027AbfDFVtd (ORCPT ); Sat, 6 Apr 2019 17:49:33 -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 BE206ACE6; Sat, 6 Apr 2019 21:49:32 +0000 (UTC) From: Petr Vorel To: linux-kselftest@vger.kernel.org Cc: Petr Vorel , Mimi Zohar , shuah , Cyril Hrubis Subject: [RFC PATCH 0/2] Kselftest shell (or even C) API Date: Sat, 6 Apr 2019 23:49:13 +0200 Message-Id: <20190406214915.16914-1-pvorel@suse.cz> X-Mailer: git-send-email 2.20.1 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 Hi, this is a draft trying to define some API in order to remove some redundancy from kselftest shell scripts. Existing kselftest.h already defines some sort of API for C, there is none for shell. It's just a small example how things could be. Draft, not meant to be really merged. But instead of defining shell library (with more useful helpers), I'd rather adopt LTP shell [1] and C [2] API to kselftest. LTP API [1] is more like a framework, easy to use with a lot of helpers making tests 1) small, concentrating on the problem itself 2) have unique output. API is well documented [3] [4], it's creator Cyril Hrubis made it after years experience of handling (at the time) quite bad quality LTP code. Rewriting LTP tests to use this API improved tests a lot (less buggy, easier to read). Some examples of advantages of LTP API: * SAFE_*() macros for C, which handles errors inside a library * unified messages, unified test status, unified way to exit testing due missing functionality, at the end of testing there is summary of passed, failed and skipped tests * many prepared functionality for both C and shell * handling threads, parent-child synchronization * setup and cleanup functions * "flags" for defining requirements or certain functionality (need root, temporary directory, ...) * and many other kselftest and LTP has a bit different goals and approach. Probably not all of LTP API is needed atm, but I guess it's at least worth of thinking to adopt it. There are of course other options: reinvent a wheel or left kselftest code in a state it is now (code quality varies, some of the code is really messy, buggy, not even compile). [1] https://github.com/linux-test-project/ltp/blob/master/testcases/lib/tst_test.sh [2] https://github.com/linux-test-project/ltp/tree/master/lib [3] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#22-writing-a-test-in-c [4] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#23-writing-a-testcase-in-shell Petr Vorel (2): selftests: Start shell API selftest/kexec: Use kselftest shell API .../selftests/kexec/kexec_common_lib.sh | 74 +++++-------------- .../selftests/kexec/test_kexec_file_load.sh | 53 ++++++------- .../selftests/kexec/test_kexec_load.sh | 20 ++--- tools/testing/selftests/kselftest.sh | 53 +++++++++++++ 4 files changed, 105 insertions(+), 95 deletions(-) mode change 100755 => 100644 tools/testing/selftests/kexec/kexec_common_lib.sh create mode 100644 tools/testing/selftests/kselftest.sh