vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

personality.c (6056B)


      1 // $Id$    --*- c -*--
      2 
      3 // Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
      4 //  
      5 // This program is free software; you can redistribute it and/or modify
      6 // it under the terms of the GNU General Public License as published by
      7 // the Free Software Foundation; version 2 of the License.
      8 //  
      9 // This program is distributed in the hope that it will be useful,
     10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 // GNU General Public License for more details.
     13 //  
     14 // You should have received a copy of the GNU General Public License
     15 // along with this program; if not, write to the Free Software
     16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     17 
     18 
     19 #ifdef HAVE_CONFIG_H
     20 #  include <config.h>
     21 #endif
     22 
     23 #include "lib_internal/coreassert.h"
     24 #include "vserver.h"
     25 
     26 #include <string.h>
     27 #include <unistd.h>
     28 #include <linux/personality.h>
     29 
     30 
     31 #define TEST_T2PF(X,Y,Z) assert(vc_text2personalityflag(X,Y)==Z)
     32 #define TEST_PF2T(Y,X) {					\
     33     uint_least32_t x = (X);					\
     34     char const *rc=vc_lopersonality2text(&x);			\
     35     assert((rc==0 && Y==0) || (rc!=0 && Y!=0));			\
     36     if (rc!=0 && Y!=0) assert(strcmp(rc, Y ? Y : "")==0);	\
     37   }
     38 
     39 #define TEST_LIST(STR,LEN,EXP_RES,EXP_PERS,ERR_POS,ERR_LEN) {		\
     40     struct vc_err_listparser	err;					\
     41     char			buf[] = STR;				\
     42     volatile int		res;					\
     43     uint_least32_t		personality = 0;			\
     44     res = vc_list2personalityflag(buf, LEN, &personality, &err);	\
     45     assert(res==(EXP_RES));						\
     46     assert(personality==(uint_least32_t)(EXP_PERS));			\
     47     assert(err.len==ERR_LEN);						\
     48     if (ERR_POS==-1) assert(err.ptr==0);				\
     49     else             assert(err.ptr==buf+(ERR_POS));			\
     50   }
     51     
     52 
     53 
     54 #define TEST_T2PT(X,Y,Z) assert(vc_str2personalitytype(X,Y)==Z)
     55 
     56 
     57 
     58 int main()
     59 {
     60   TEST_T2PF("mmap_page_zero",      0, MMAP_PAGE_ZERO);
     61   TEST_T2PF("MMAP_PAGE_ZERO",      0, MMAP_PAGE_ZERO);
     62   TEST_T2PF("MmAp_PaGe_ZeRo",      0, MMAP_PAGE_ZERO);
     63   TEST_T2PF("mmap_page_zero",     14, MMAP_PAGE_ZERO);
     64   TEST_T2PF("MMAP_PAGE_ZERO",     14, MMAP_PAGE_ZERO);
     65   TEST_T2PF("MMAP_PAGE_ZEROXXXX", 14, MMAP_PAGE_ZERO);
     66   TEST_T2PF("MMAP_PAGE_ZEROXXXX", 13, 0);
     67   TEST_T2PF("MMAP_PAGE_ZERO",     13, 0);
     68   TEST_T2PF("MMAP_PAGE_ZERXXX",   13, 0);
     69   TEST_T2PF("XXX",                 0, 0);
     70   TEST_T2PF("",                    0, 0);
     71   
     72   TEST_T2PF("ADDR_LIMIT_32BIT",    0, ADDR_LIMIT_32BIT);
     73   TEST_T2PF("SHORT_INODE",         0, SHORT_INODE);
     74   TEST_T2PF("WHOLE_SECONDS",       0, WHOLE_SECONDS);
     75   TEST_T2PF("STICKY_TIMEOUTS",     0, STICKY_TIMEOUTS);
     76   TEST_T2PF("ADDR_LIMIT_3GB",      0, ADDR_LIMIT_3GB);
     77 
     78 
     79     // the  _loc* tests
     80   TEST_PF2T("MMAP_PAGE_ZERO",      MMAP_PAGE_ZERO);
     81   TEST_PF2T("ADDR_LIMIT_32BIT",    ADDR_LIMIT_32BIT);
     82   TEST_PF2T("SHORT_INODE",         SHORT_INODE);
     83   TEST_PF2T("WHOLE_SECONDS",       WHOLE_SECONDS);
     84   TEST_PF2T("STICKY_TIMEOUTS",     STICKY_TIMEOUTS);
     85   TEST_PF2T("ADDR_LIMIT_3GB",      ADDR_LIMIT_3GB);
     86 
     87 
     88 
     89   TEST_LIST("mmap_page_zero",      14,  0, MMAP_PAGE_ZERO, -1, 0);
     90   TEST_LIST("mmap_page_zero,XXX",  14,  0, MMAP_PAGE_ZERO, -1, 0);
     91   TEST_LIST("mmap_page_zero",       0,  0, MMAP_PAGE_ZERO, -1, 0);
     92   TEST_LIST("MmAp_pAgE_ZeRo",       0,  0, MMAP_PAGE_ZERO, -1, 0);
     93   TEST_LIST("mmap_page_zero,XXX",   0, -1, MMAP_PAGE_ZERO, 15, 3);
     94   TEST_LIST("~mmap_page_zero",      0, -1,              0,  0,15);
     95   TEST_LIST("!mmap_page_zero",      0, -1,              0,  0,15);
     96   TEST_LIST("",                     0,  0,              0, -1, 0);
     97   TEST_LIST("0",                    0,  0,              0, -1, 0);
     98   TEST_LIST("00",                   0,  0,              0, -1, 0);
     99   TEST_LIST("1",                    0,  0,              1, -1, 0);
    100   TEST_LIST("1,23,42",              0,  0,        1|23|42, -1, 0);
    101   TEST_LIST("^1",                   0,  0,              2, -1, 0);
    102   TEST_LIST("^4,^2",                0,  0,           0x14, -1, 0);
    103   TEST_LIST("^2,^3",                0,  0,           0x0c, -1, 0);
    104   TEST_LIST("^2,~^3",               0, -1,           0x04,  3, 3);
    105   TEST_LIST("~0",                   0, -1,              0,  0, 2);
    106   TEST_LIST("^",                    0, -1,              0,  1, 0);
    107   TEST_LIST("~",                    0, -1,              0,  0, 1);
    108   TEST_LIST("!",                    0, -1,              0,  0, 1);
    109   TEST_LIST("X",                    0, -1,              0,  0, 1);
    110   TEST_LIST("all",                  0, -1,              0,  0, 3);
    111   TEST_LIST("ALL",                  0, -1,              0,  0, 3);
    112   TEST_LIST("~all",                 0, -1,              0,  0, 4);
    113   TEST_LIST("~ALL",                 0, -1,              0,  0, 4);
    114   TEST_LIST("any",                  0, -1,              0,  0, 3);
    115   TEST_LIST("ANY",                  0, -1,              0,  0, 3);
    116   TEST_LIST("~any",                 0, -1,              0,  0, 4);
    117   TEST_LIST("~ANY",                 0, -1,              0,  0, 4);
    118   TEST_LIST("none",                 0, -1,              0,  0, 4);
    119   TEST_LIST("NONE",                 0, -1,              0,  0, 4);
    120   TEST_LIST("~none",                0, -1,              0,  0, 5);
    121   TEST_LIST("~NONE",                0, -1,              0,  0, 5);
    122   TEST_LIST("mmap_page_zero,all",   0, -1, MMAP_PAGE_ZERO, 15, 3);
    123   TEST_LIST("mmap_page_zero,any",   0, -1, MMAP_PAGE_ZERO, 15, 3);
    124 
    125   TEST_LIST("mmap_page_zero,addr_limit_32bit,short_inode,whole_seconds,"
    126 	    "sticky_timeouts,addr_limit_3gb",
    127 	    0, 0,
    128 	    MMAP_PAGE_ZERO|ADDR_LIMIT_32BIT|SHORT_INODE|WHOLE_SECONDS|
    129 	    STICKY_TIMEOUTS|ADDR_LIMIT_3GB,
    130 	    -1, 0);
    131 
    132   TEST_T2PT("linux",     0, PER_LINUX);
    133   TEST_T2PT("LINUX",     0, PER_LINUX);
    134   TEST_T2PT("LiNuX",     0, PER_LINUX);
    135   TEST_T2PT("LiNuX",     5, PER_LINUX);
    136   TEST_T2PT("LiNuX",     4, VC_BAD_PERSONALITY);
    137   TEST_T2PT("LiNuXAAA",  5, PER_LINUX);
    138   TEST_T2PT("LiNuXAAA",  4, VC_BAD_PERSONALITY);
    139   TEST_T2PT("LiNuAAA",   4, VC_BAD_PERSONALITY);
    140   TEST_T2PT("XXX",       0, VC_BAD_PERSONALITY);
    141   TEST_T2PT("",          0, VC_BAD_PERSONALITY);
    142 
    143   
    144   return 0;
    145 }