test_0.c revision 228761
112967Sgavin.maltby@oracle.com/*- 212967Sgavin.maltby@oracle.com * Copyright (c) 2003-2007 Tim Kientzle 312967Sgavin.maltby@oracle.com * All rights reserved. 412967Sgavin.maltby@oracle.com * 512967Sgavin.maltby@oracle.com * Redistribution and use in source and binary forms, with or without 612967Sgavin.maltby@oracle.com * modification, are permitted provided that the following conditions 712967Sgavin.maltby@oracle.com * are met: 812967Sgavin.maltby@oracle.com * 1. Redistributions of source code must retain the above copyright 912967Sgavin.maltby@oracle.com * notice, this list of conditions and the following disclaimer. 1012967Sgavin.maltby@oracle.com * 2. Redistributions in binary form must reproduce the above copyright 1112967Sgavin.maltby@oracle.com * notice, this list of conditions and the following disclaimer in the 1212967Sgavin.maltby@oracle.com * documentation and/or other materials provided with the distribution. 1312967Sgavin.maltby@oracle.com * 1412967Sgavin.maltby@oracle.com * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 1512967Sgavin.maltby@oracle.com * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1612967Sgavin.maltby@oracle.com * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1712967Sgavin.maltby@oracle.com * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 1812967Sgavin.maltby@oracle.com * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1912967Sgavin.maltby@oracle.com * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2012967Sgavin.maltby@oracle.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2112967Sgavin.maltby@oracle.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2212967Sgavin.maltby@oracle.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2312967Sgavin.maltby@oracle.com * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2412967Sgavin.maltby@oracle.com */ 2512967Sgavin.maltby@oracle.com#include "test.h" 2612967Sgavin.maltby@oracle.com__FBSDID("$FreeBSD: src/usr.bin/tar/test/test_0.c,v 1.2 2008/05/26 17:10:10 kientzle Exp $"); 2712967Sgavin.maltby@oracle.com 2812967Sgavin.maltby@oracle.com/* 2912967Sgavin.maltby@oracle.com * This first test does basic sanity checks on the environment. For 3012967Sgavin.maltby@oracle.com * most of these, we just exit on failure. 3112967Sgavin.maltby@oracle.com */ 3212967Sgavin.maltby@oracle.com#if !defined(_WIN32) || defined(__CYGWIN__) 3312967Sgavin.maltby@oracle.com#define DEV_NULL "/dev/null" 3412967Sgavin.maltby@oracle.com#else 3512967Sgavin.maltby@oracle.com#define DEV_NULL "NUL" 3612967Sgavin.maltby@oracle.com#endif 3712967Sgavin.maltby@oracle.com 3812967Sgavin.maltby@oracle.comDEFINE_TEST(test_0) 3912967Sgavin.maltby@oracle.com{ 4012967Sgavin.maltby@oracle.com struct stat st; 4112967Sgavin.maltby@oracle.com 42 failure("File %s does not exist?!", testprog); 43 if (!assertEqualInt(0, stat(testprogfile, &st))) 44 exit(1); 45 46 failure("%s is not executable?!", testprog); 47 if (!assert((st.st_mode & 0111) != 0)) 48 exit(1); 49 50 /* 51 * Try to succesfully run the program; this requires that 52 * we know some option that will succeed. 53 */ 54 if (0 == systemf("%s --version >" DEV_NULL, testprog)) { 55 /* This worked. */ 56 } else if (0 == systemf("%s -W version >" DEV_NULL, testprog)) { 57 /* This worked. */ 58 } else { 59 failure("Unable to successfully run any of the following:\n" 60 " * %s --version\n" 61 " * %s -W version\n", 62 testprog, testprog); 63 assert(0); 64 } 65 66 /* TODO: Ensure that our reference files are available. */ 67} 68