Home | History | Annotate | Download | only in test
      1 #!/usr/bin/env python
      2 
      3 import os
      4 import sys
      5 import time
      6 load_path = '../'
      7 if False:
      8     sys.path.insert(0, load_path)
      9 
     10 import capng
     11 last = capng.CAP_LAST_CAP
     12 
     13 print("Doing basic bit tests...")
     14 capng.capng_clear(capng.CAPNG_SELECT_BOTH)
     15 if capng.capng_have_capabilities(capng.CAPNG_SELECT_BOTH) != capng.CAPNG_NONE:
     16 	print("Failed clearing capabilities\n")
     17 	sys.exit(1)
     18 
     19 capng.capng_fill(capng.CAPNG_SELECT_BOTH)
     20 if capng.capng_have_capabilities(capng.CAPNG_SELECT_BOTH) != capng.CAPNG_FULL:
     21 	print("Failed filling capabilities")
     22 	sys.exit(1)
     23 
     24 text = capng.capng_print_caps_numeric(capng.CAPNG_PRINT_BUFFER, capng.CAPNG_SELECT_CAPS)
     25 len = len(text)
     26 if len < 80 and last > 30:
     27 	last = 30
     28 
     29 print("Doing advanced bit tests for %d capabilities...\n" % (last))
     30 for i in range(last+1):
     31 	capng.capng_clear(capng.CAPNG_SELECT_BOTH)
     32 	rc = capng.capng_update(capng.CAPNG_ADD, capng.CAPNG_EFFECTIVE, i)
     33 	if rc:
     34 		print("Failed update test 1")
     35 		sys.exit(1)
     36 
     37 	rc = capng.capng_have_capability(capng.CAPNG_EFFECTIVE, int(i))
     38 	if rc <= capng.CAPNG_NONE:
     39 		print("Failed have capability test 1")
     40 		capng.capng_print_caps_numeric(capng.CAPNG_PRINT_STDOUT, capng.CAPNG_SELECT_CAPS)
     41 		sys.exit(1)
     42 
     43 	if capng.capng_have_capabilities(capng.CAPNG_SELECT_CAPS) != capng.CAPNG_PARTIAL:
     44 		print("Failed have capabilities test 1")
     45 		sys.exit(1)
     46 	
     47 	capng.capng_fill(capng.CAPNG_SELECT_BOTH)
     48 	rc = capng.capng_update(capng.CAPNG_DROP, capng.CAPNG_EFFECTIVE, i)
     49 	if rc:
     50 		print("Failed update test 3")
     51 		sys.exit(1)
     52 
     53 	if capng.capng_have_capabilities(capng.CAPNG_SELECT_CAPS)!=capng.CAPNG_PARTIAL:
     54 		print("Failed have capabilities test 3")
     55 		capng.capng_print_caps_numeric(capng.CAPNG_PRINT_STDOUT, capng.CAPNG_SELECT_CAPS)
     56 		sys.exit(1)
     57 
     58 	rc = capng.capng_update(capng.CAPNG_ADD, capng.CAPNG_EFFECTIVE, i)
     59 	if rc:
     60 		print("Failed update test 4")
     61 		sys.exit(1)
     62 
     63 	if capng.capng_have_capabilities(capng.CAPNG_SELECT_CAPS) != capng.CAPNG_FULL:
     64 		print("Failed have capabilities test 4")
     65 		capng.capng_print_caps_numeric(capng.CAPNG_PRINT_STDOUT, capng.CAPNG_SELECT_CAPS)
     66 		sys.exit(1)
     67 
     68 sys.exit(0)
     69