From owner-svn-src-all@freebsd.org Thu Jul 26 00:16:42 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 870211057332; Thu, 26 Jul 2018 00:16:42 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3AEBA733BE; Thu, 26 Jul 2018 00:16:42 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 17F202153F; Thu, 26 Jul 2018 00:16:42 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6Q0Gf9c015579; Thu, 26 Jul 2018 00:16:41 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6Q0GfmM015575; Thu, 26 Jul 2018 00:16:41 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201807260016.w6Q0GfmM015575@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Thu, 26 Jul 2018 00:16:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336728 - in head: etc/mtree tests/sys tests/sys/auditpipe X-SVN-Group: head X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: in head: etc/mtree tests/sys tests/sys/auditpipe X-SVN-Commit-Revision: 336728 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jul 2018 00:16:42 -0000 Author: asomers Date: Thu Jul 26 00:16:41 2018 New Revision: 336728 URL: https://svnweb.freebsd.org/changeset/base/336728 Log: Introduce test program for auditpipe(4) Submitted by: aniketp MFC after: 2 weeks Sponsored by: Google, Inc. (GSoC 2018) Differential Revision: https://reviews.freebsd.org/D16395 Added: head/tests/sys/auditpipe/ head/tests/sys/auditpipe/Makefile (contents, props changed) head/tests/sys/auditpipe/auditpipe_test.c (contents, props changed) Modified: head/etc/mtree/BSD.tests.dist head/tests/sys/Makefile Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Wed Jul 25 22:46:36 2018 (r336727) +++ head/etc/mtree/BSD.tests.dist Thu Jul 26 00:16:41 2018 (r336728) @@ -432,6 +432,8 @@ .. audit .. + auditpipe + .. capsicum .. cddl Modified: head/tests/sys/Makefile ============================================================================== --- head/tests/sys/Makefile Wed Jul 25 22:46:36 2018 (r336727) +++ head/tests/sys/Makefile Thu Jul 26 00:16:41 2018 (r336728) @@ -7,6 +7,7 @@ TESTSDIR= ${TESTSBASE}/sys TESTS_SUBDIRS+= acl TESTS_SUBDIRS+= aio TESTS_SUBDIRS+= audit +TESTS_SUBDIRS+= auditpipe TESTS_SUBDIRS+= capsicum TESTS_SUBDIRS+= ${_cddl} TESTS_SUBDIRS+= fifo Added: head/tests/sys/auditpipe/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/auditpipe/Makefile Thu Jul 26 00:16:41 2018 (r336728) @@ -0,0 +1,10 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/sys/auditpipe + +ATF_TESTS_C= auditpipe_test + +TEST_METADATA+= required_user="root" +WARNS?= 6 + +.include Added: head/tests/sys/auditpipe/auditpipe_test.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/auditpipe/auditpipe_test.c Thu Jul 26 00:16:41 2018 (r336728) @@ -0,0 +1,185 @@ +/*- + * Copyright (c) 2018 Aniket Pandey + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include + +#include +#include + +#include +#include +#include +#include + +static int filedesc; +static FILE *fileptr; + +ATF_TC(auditpipe_get_qlen); +ATF_TC_HEAD(auditpipe_get_qlen, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_QLEN works properly"); +} + +ATF_TC_BODY(auditpipe_get_qlen, tc) +{ + int qlen = -1; + ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLEN, &qlen)); + ATF_REQUIRE(qlen != -1); + close(filedesc); +} + + +ATF_TC(auditpipe_get_qlimit); +ATF_TC_HEAD(auditpipe_get_qlimit, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_QLIMIT works properly"); +} + +ATF_TC_BODY(auditpipe_get_qlimit, tc) +{ + int qlimit = -1; + ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT, &qlimit)); + ATF_REQUIRE(qlimit != -1); + close(filedesc); +} + + +ATF_TC_WITH_CLEANUP(auditpipe_set_qlimit); +ATF_TC_HEAD(auditpipe_set_qlimit, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_SET_QLIMIT works properly"); +} + +ATF_TC_BODY(auditpipe_set_qlimit, tc) +{ + int test_qlimit, curr_qlimit, recv_qlimit; + + ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1); + /* Retreive the current QLIMIT value and store it in a file */ + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT, &curr_qlimit)); + ATF_REQUIRE((fileptr = fopen("qlimit_store", "a")) != NULL); + ATF_REQUIRE_EQ(sizeof(curr_qlimit), + fprintf(fileptr, "%d\n", curr_qlimit)); + + /* + * Set QLIMIT different from the current system value to confirm + * proper functioning of AUDITPIPE_SET_QLIMIT ioctl. + */ + test_qlimit = curr_qlimit - 1; + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_SET_QLIMIT, &test_qlimit)); + /* Receive modified value and check whether QLIMIT was set correctly */ + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT, &recv_qlimit)); + ATF_REQUIRE_EQ(test_qlimit, recv_qlimit); + + fclose(fileptr); + close(filedesc); +} + +ATF_TC_CLEANUP(auditpipe_set_qlimit, tc) +{ + if (atf_utils_file_exists("qlimit_store")) { + int fd, curr_qlim; + ATF_REQUIRE((fileptr = fopen("qlimit_store", "r")) != NULL); + ATF_REQUIRE(fscanf(fileptr, "%d", &curr_qlim)); + + ATF_REQUIRE((fd = open("/dev/auditpipe", O_RDONLY)) != -1); + /* Set QLIMIT's value as it was prior to test-case invocation */ + ATF_REQUIRE_EQ(0, ioctl(fd, AUDITPIPE_SET_QLIMIT, &curr_qlim)); + + close(fd); + fclose(fileptr); + } +} + + +ATF_TC(auditpipe_get_qlimit_min); +ATF_TC_HEAD(auditpipe_get_qlimit_min, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_QLIMIT_MIN works properly"); +} + +ATF_TC_BODY(auditpipe_get_qlimit_min, tc) +{ + int qlim_min = -1; + ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT_MIN, &qlim_min)); + ATF_REQUIRE(qlim_min != -1); + close(filedesc); +} + + +ATF_TC(auditpipe_get_qlimit_max); +ATF_TC_HEAD(auditpipe_get_qlimit_max, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_QLIMIT_MAX works properly"); +} + +ATF_TC_BODY(auditpipe_get_qlimit_max, tc) +{ + int qlim_max = -1; + ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT_MAX, &qlim_max)); + ATF_REQUIRE(qlim_max != -1); + close(filedesc); +} + + +ATF_TC(auditpipe_get_maxauditdata); +ATF_TC_HEAD(auditpipe_get_maxauditdata, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_MAXAUDITDATA works properly"); +} + +ATF_TC_BODY(auditpipe_get_maxauditdata, tc) +{ + int audata = -1; + ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_MAXAUDITDATA, &audata)); + ATF_REQUIRE(audata != -1); + close(filedesc); +} + + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, auditpipe_get_qlen); + ATF_TP_ADD_TC(tp, auditpipe_get_qlimit); + ATF_TP_ADD_TC(tp, auditpipe_set_qlimit); + ATF_TP_ADD_TC(tp, auditpipe_get_qlimit_min); + ATF_TP_ADD_TC(tp, auditpipe_get_qlimit_max); + ATF_TP_ADD_TC(tp, auditpipe_get_maxauditdata); + + return (atf_no_error()); +}