File: mlscolor-test

package info (click to toggle)
android-platform-external-libselinux 8.1.0%2Br23-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 33,252 kB
  • sloc: ansic: 142,533; python: 23,929; makefile: 1,760; yacc: 1,367; sh: 1,108; lex: 448; xml: 176
file content (43 lines) | stat: -rw-r--r-- 1,107 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python -E
import sys
import re
from selinux import *
verbose = 0
errors = 0

if len(sys.argv) > 1 and sys.argv[1] == "-v":
    verbose = 1

for arg in sys.argv[1:]:
    f = open(arg, 'r')
    for line in f:
        if line.startswith('#'):
            continue
        if not line.strip():
            continue
        line = line.rstrip('\n')
#       print line
        context, expected = line.split("=")
        rc, raw = selinux_trans_to_raw_context(context)
        if rc < 0:
            print "Unable to get raw context of '%s'" % (context)
            errors += 1
            continue
        rc, colors = selinux_raw_context_to_color(raw)
        if rc < 0:
            print "Unable to get colors for '%s'" % (context)
            errors += 1
            continue
        colors = colors.rstrip()
        if colors != expected:
            print "For '%s' got\n\t'%s' expected\n\t'%s'" % (context, colors, expected)
            errors += 1
            continue
    f.close()

s = "s"
if errors == 1:
    s = ""
print "mlscolor-test done with %d error%s" % (errors, s)

sys.exit(errors)