16cd6a6acSopenharmony_ci/*
26cd6a6acSopenharmony_ci * Copyright 2011 Tresys Technology, LLC. All rights reserved.
36cd6a6acSopenharmony_ci *
46cd6a6acSopenharmony_ci * Redistribution and use in source and binary forms, with or without
56cd6a6acSopenharmony_ci * modification, are permitted provided that the following conditions are met:
66cd6a6acSopenharmony_ci *
76cd6a6acSopenharmony_ci *    1. Redistributions of source code must retain the above copyright notice,
86cd6a6acSopenharmony_ci *       this list of conditions and the following disclaimer.
96cd6a6acSopenharmony_ci *
106cd6a6acSopenharmony_ci *    2. Redistributions in binary form must reproduce the above copyright notice,
116cd6a6acSopenharmony_ci *       this list of conditions and the following disclaimer in the documentation
126cd6a6acSopenharmony_ci *       and/or other materials provided with the distribution.
136cd6a6acSopenharmony_ci *
146cd6a6acSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY TRESYS TECHNOLOGY, LLC ``AS IS'' AND ANY EXPRESS
156cd6a6acSopenharmony_ci * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
166cd6a6acSopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
176cd6a6acSopenharmony_ci * EVENT SHALL TRESYS TECHNOLOGY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
186cd6a6acSopenharmony_ci * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
196cd6a6acSopenharmony_ci * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
206cd6a6acSopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
216cd6a6acSopenharmony_ci * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
226cd6a6acSopenharmony_ci * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
236cd6a6acSopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
246cd6a6acSopenharmony_ci *
256cd6a6acSopenharmony_ci * The views and conclusions contained in the software and documentation are those
266cd6a6acSopenharmony_ci * of the authors and should not be interpreted as representing official policies,
276cd6a6acSopenharmony_ci * either expressed or implied, of Tresys Technology, LLC.
286cd6a6acSopenharmony_ci */
296cd6a6acSopenharmony_ci
306cd6a6acSopenharmony_ci#include <sepol/policydb/policydb.h>
316cd6a6acSopenharmony_ci
326cd6a6acSopenharmony_ci#include "CuTest.h"
336cd6a6acSopenharmony_ci#include "test_integration.h"
346cd6a6acSopenharmony_ci#include <unistd.h>
356cd6a6acSopenharmony_ci#include <sys/wait.h>
366cd6a6acSopenharmony_ci#include <sys/types.h>
376cd6a6acSopenharmony_ci#include <sys/stat.h>
386cd6a6acSopenharmony_ci#include <fcntl.h>
396cd6a6acSopenharmony_ci
406cd6a6acSopenharmony_civoid test_integration(CuTest *tc) {
416cd6a6acSopenharmony_ci	int status = 0, status1 = 0, status2 = 0;
426cd6a6acSopenharmony_ci
436cd6a6acSopenharmony_ci	status = system("./secilc -M -c 24 test/integration.cil &> /dev/null");
446cd6a6acSopenharmony_ci
456cd6a6acSopenharmony_ci	if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGQUIT))
466cd6a6acSopenharmony_ci		printf("Call to system for secilc failed.\n");
476cd6a6acSopenharmony_ci
486cd6a6acSopenharmony_ci	status1 = system("checkpolicy -M -c 24 -o policy.conf.24 test/policy.conf &> /dev/null");
496cd6a6acSopenharmony_ci
506cd6a6acSopenharmony_ci	if (WIFSIGNALED(status1) && (WTERMSIG(status1) == SIGINT || WTERMSIG(status1) == SIGQUIT))
516cd6a6acSopenharmony_ci		printf("Call to checkpolicy failed.\n");
526cd6a6acSopenharmony_ci
536cd6a6acSopenharmony_ci	status2 = system("sediff -q policy.24 \\; policy.conf.24 &> /dev/null");
546cd6a6acSopenharmony_ci
556cd6a6acSopenharmony_ci	if (WIFSIGNALED(status2) && (WTERMSIG(status2) == SIGINT || WTERMSIG(status2) == SIGQUIT))
566cd6a6acSopenharmony_ci		printf("Call to sediff for secilc failed.\n");
576cd6a6acSopenharmony_ci
586cd6a6acSopenharmony_ci	CuAssertIntEquals(tc, 1, WIFEXITED(status));
596cd6a6acSopenharmony_ci	CuAssertIntEquals(tc, 0, WEXITSTATUS(status));
606cd6a6acSopenharmony_ci	CuAssertIntEquals(tc, 1, WIFEXITED(status1));
616cd6a6acSopenharmony_ci	CuAssertIntEquals(tc, 0, WEXITSTATUS(status1));
626cd6a6acSopenharmony_ci	CuAssertIntEquals(tc, 1, WIFEXITED(status2));
636cd6a6acSopenharmony_ci	CuAssertIntEquals(tc, 0, WEXITSTATUS(status2));
646cd6a6acSopenharmony_ci}
656cd6a6acSopenharmony_ci
666cd6a6acSopenharmony_civoid test_min_policy(CuTest *tc) {
676cd6a6acSopenharmony_ci	int status = 0;
686cd6a6acSopenharmony_ci
696cd6a6acSopenharmony_ci	status = system("./secilc -M -c 24 test/policy.cil &> /dev/null");
706cd6a6acSopenharmony_ci
716cd6a6acSopenharmony_ci	if (WIFSIGNALED(status) && (WTERMSIG(status) == SIGINT || WTERMSIG(status) == SIGQUIT))
726cd6a6acSopenharmony_ci		printf("Call to system for secilc failed.\n");
736cd6a6acSopenharmony_ci
746cd6a6acSopenharmony_ci	CuAssertIntEquals(tc, 1, WIFEXITED(status));
756cd6a6acSopenharmony_ci	CuAssertIntEquals(tc, 0, WEXITSTATUS(status));
766cd6a6acSopenharmony_ci}
77