File: mlscolor-test

package info (click to toggle)
android-platform-external-libselinux 10.0.0%2Br36-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 34,176 kB
  • sloc: ansic: 147,112; python: 25,790; makefile: 1,930; yacc: 1,389; sh: 1,206; lex: 452; xml: 180
file content (44 lines) | stat: -rw-r--r-- 1,113 bytes parent folder | download | duplicates (6)
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
44
#!/usr/bin/python3 -E
import sys
import selinux


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.selinux_trans_to_raw_context(context)
        if rc < 0:
            print("Unable to get raw context of '%s'" % (context))
            errors += 1
            continue
        rc, colors = selinux.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)