libsemanage: Read-only FS [2/2]
PATCH 1/1 libsemanage: Read-only FS [2/2]
This patch compliments the libsemanage: Read-only FS patch by adding CUnit tests. The tests in semanage_access_check should not be run as root (they use DAC permissions to simulate a read-only fs).
libsemanage/tests/libsemanage-tests.c +107 -0
@@ -0,0 +1,107 @@ +/* Authors: Christopher Ashworth <[email protected]> +* Caleb Case <[email protected]> +* Chad Sellers <[email protected]> +* +* Copyright (C) 2006 Tresys Technology, LLC +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "test_semanage_store.h" + +#include <CUnit/Basic.h> +#include <CUnit/Console.h> +#include <CUnit/TestDB.h> + +#include <stdio.h> +#include <getopt.h> +#include <stdlib.h> + +#define DECLARE_SUITE (name) \ + suite = CU_add_suite(#name, name##_test_init, name##_test_cleanup); \ + if (NULL == suite) { \ + CU_cleanup_registry(); \ + return CU_get_error(); } \ + if (name##_add_tests(suite)) { \ + CU_cleanup_registry(); \ + return CU_get_error(); } + +static void usage (char *progname) +{ +printf ("usage: %s [options]\n" , progname); +printf ("options:\n" ); +printf ("\t-v, --verbose\t\t\tverbose output\n" ); +printf ("\t-i, --interactive\t\tinteractive console\n" ); +} + +static int do_tests (int interactive,int verbose) +{ +CU_pSuite suite =NULL ; + +/* Initialize the CUnit test registry. */ +if (CUE_SUCCESS !=CU_initialize_registry ()) +return CU_get_error (); + +DECLARE_SUITE (semanage_store); + +if (verbose) +CU_basic_set_mode (CU_BRM_VERBOSE ); +else +CU_basic_set_mode (CU_BRM_NORMAL ); + +if (interactive) +CU_console_run_tests (); +else +CU_basic_run_tests (); +CU_cleanup_registry (); +return CU_get_error (); + +} + +/* The main function for setting up and running the libsemanage unit tests. +* Returns a CUE_SUCCESS on success, or a CUnit error code on failure. +*/ +int main (int argc,char **argv) +{ +int i, verbose =1 , interactive =0 ; + +struct option opts[] = { + {"verbose" ,0 ,NULL ,'v' }, + {"interactive" ,0 ,NULL ,'i' }, + {NULL ,0 ,NULL ,0 } + }; + +while ((i =getopt_long (argc, argv,"vi" , opts,NULL )) !=-1 ) { +switch (i) { +case 'v' : + verbose =1 ; +break ; +case 'i' : + interactive =1 ; +break ; +case 'h' : +default : { +usage (argv[0 ]); +exit (1 ); + } + } + } + +if (do_tests (interactive, verbose)) +return -1 ; + +return 0 ; +} +
libsemanage/tests/Makefile +32 -0
@@ -0,0 +1,32 @@ +# Add your test source files here: +SOURCES = $(wildcard *.c) + +# Point this variable to the libsemanage source directory you want to test: +TESTSRC=../src + +# Add the required external object files here: +LIBSEMANAGE = ../src/libsemanage.a + +########################################################################### + +EXECUTABLE = libsemanage-tests +CC = gcc +CFLAGS = -c -g -o0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter +INCLUDE = -I$(TESTSRC) -I$(TESTSRC)/../include/semanage +LDFLAGS = -lcunit -lsemanage +OBJECTS = $(SOURCES:.c=.o) + +all: $(EXECUTABLE) + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(OBJECTS) $(LIBSEMANAGE) $(LDFLAGS) -o $@ + +%.o: %.c + $(CC) $(CFLAGS) $(INCLUDE) $*.c -o $*.o + +clean: + rm -rf $(OBJECTS) $(EXECUTABLE) + +test: all + ./$(EXECUTABLE) +
libsemanage/tests/README +64 -0
64 lines not on this page · raw message
libsemanage/tests/test_semanage_store.c +280 -0
280 lines not on this page · raw message
libsemanage/tests/test_semanage_store.h +32 -0
@@ -0,0 +1,32 @@ +/* Authors: Christopher Ashworth <[email protected]> +* +* Copyright (C) 2006 Tresys Technology, LLC +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef __TEST_SEMANAGE_STORE_H__ +#define __TEST_SEMANAGE_STORE_H__ + +#include <CUnit/Basic.h> + +int semanage_store_test_init (void ); +int semanage_store_test_cleanup (void ); +int semanage_store_add_tests (CU_pSuite suite); + +void test_semanage_store_access_check (void ); +void test_semanage_get_lock (void ); + +#endif
libsemanage/tests/utilities.c +36 -0
@@ -0,0 +1,36 @@ +/* Authors: Christopher Ashworth <[email protected]> +* +* Copyright (C) 2006 Tresys Technology, LLC +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* The purpose of this file is to provide some functions commonly needed +* by our unit tests. +*/ + +#include "utilities.h" + +/* Silence any error output caused by our tests +* by using this dummy function to catch messages. +*/ +void test_msg_handler ( +void * varg, +semanage_handle_t * handle, +const char * fmt, + ...) +{ +} +
libsemanage/tests/utilities.h +22 -0
@@ -0,0 +1,22 @@ +/* Authors: Christopher Ashworth <[email protected]> +* +* Copyright (C) 2006 Tresys Technology, LLC +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This library 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 +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "handle.h" + +void test_msg_handler (void * varg,semanage_handle_t * handle,const char * fmt, ...);
--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.
Quoted 1 line · Caleb Case
This patch compliments the libsemanage: Read-only FS patch by adding CUnit tests. The tests in
semanage_access_checkshould not be run as root (they use DAC permissions to simulate a read-only fs).
Thanks, both patches merged.
Signature · 8 lines
Stephen Smalley National Security Agency -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.