Merge "Migrate tests/ to Python 3"
This commit is contained in:
commit
df4f088f9e
8 changed files with 92 additions and 42 deletions
|
@ -24,18 +24,6 @@ cc_library_host_shared {
|
|||
},
|
||||
}
|
||||
|
||||
python_defaults {
|
||||
name: "py2_only",
|
||||
version: {
|
||||
py2: {
|
||||
enabled: true,
|
||||
},
|
||||
py3: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
python_binary_host {
|
||||
name: "treble_sepolicy_tests",
|
||||
srcs: [
|
||||
|
@ -45,7 +33,6 @@ python_binary_host {
|
|||
"treble_sepolicy_tests.py",
|
||||
],
|
||||
required: ["libsepolwrap"],
|
||||
defaults: ["py2_only"],
|
||||
}
|
||||
|
||||
python_binary_host {
|
||||
|
@ -56,7 +43,6 @@ python_binary_host {
|
|||
"sepolicy_tests.py",
|
||||
],
|
||||
required: ["libsepolwrap"],
|
||||
defaults: ["py2_only"],
|
||||
}
|
||||
|
||||
python_binary_host {
|
||||
|
@ -67,7 +53,6 @@ python_binary_host {
|
|||
"searchpolicy.py",
|
||||
],
|
||||
required: ["libsepolwrap"],
|
||||
defaults: ["py2_only"],
|
||||
}
|
||||
|
||||
python_binary_host {
|
||||
|
@ -76,7 +61,6 @@ python_binary_host {
|
|||
"combine_maps.py",
|
||||
"mini_parser.py",
|
||||
],
|
||||
defaults: ["py2_only"],
|
||||
}
|
||||
|
||||
python_binary_host {
|
||||
|
@ -84,7 +68,6 @@ python_binary_host {
|
|||
srcs: [
|
||||
"fc_sort.py",
|
||||
],
|
||||
defaults: ["py2_only"],
|
||||
}
|
||||
|
||||
python_test_host {
|
||||
|
@ -93,7 +76,6 @@ python_test_host {
|
|||
"fc_sort.py",
|
||||
"fc_sort_test.py",
|
||||
],
|
||||
defaults: ["py2_only"],
|
||||
test_options: {
|
||||
unit_test: true,
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python2
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2021 - The Android Open Source Project
|
||||
# Copyright 2021 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Copyright 2021 - The Android Open Source Project
|
||||
# Copyright 2021 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
# Copyright 2021 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from os.path import basename
|
||||
import re
|
||||
import sys
|
||||
|
@ -6,8 +20,6 @@ import sys
|
|||
# files and retrieve type and attribute information until proper support is
|
||||
# built into libsepol
|
||||
|
||||
# get the text in the next matching parens
|
||||
|
||||
class MiniCilParser:
|
||||
def __init__(self, policyFile):
|
||||
self.types = set() # types declared in mapping
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
# Copyright 2021 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from ctypes import *
|
||||
import re
|
||||
import os
|
||||
|
@ -129,7 +143,7 @@ class Policy:
|
|||
# all types associated with an attribute if IsAttr=True
|
||||
def QueryTypeAttribute(self, Type, IsAttr):
|
||||
TypeIterP = self.__libsepolwrap.init_type_iter(self.__policydbP,
|
||||
create_string_buffer(Type), IsAttr)
|
||||
create_string_buffer(Type.encode("ascii")), IsAttr)
|
||||
if (TypeIterP == None):
|
||||
sys.exit("Failed to initialize type iterator")
|
||||
buf = create_string_buffer(self.__BUFSIZE)
|
||||
|
@ -138,7 +152,7 @@ class Policy:
|
|||
ret = self.__libsepolwrap.get_type(buf, self.__BUFSIZE,
|
||||
self.__policydbP, TypeIterP)
|
||||
if ret == 0:
|
||||
TypeAttr.add(buf.value)
|
||||
TypeAttr.add(buf.value.decode("ascii"))
|
||||
continue
|
||||
if ret == 1:
|
||||
break;
|
||||
|
@ -237,7 +251,7 @@ class Policy:
|
|||
ret = self.__libsepolwrap.get_type(buf, self.__BUFSIZE,
|
||||
self.__policydbP, TypeIterP)
|
||||
if ret == 0:
|
||||
AllTypes.add(buf.value)
|
||||
AllTypes.add(buf.value.decode("ascii"))
|
||||
continue
|
||||
if ret == 1:
|
||||
break;
|
||||
|
@ -302,7 +316,7 @@ class Policy:
|
|||
ret = self.__libsepolwrap.get_allow_rule(buf, self.__BUFSIZE,
|
||||
policydbP, avtabIterP)
|
||||
if ret == 0:
|
||||
Rule = TERule(buf.value)
|
||||
Rule = TERule(buf.value.decode("ascii"))
|
||||
Rules.add(Rule)
|
||||
continue
|
||||
if ret == 1:
|
||||
|
@ -399,10 +413,10 @@ class Policy:
|
|||
ret = self.__libsepolwrap.get_genfs(buf, self.__BUFSIZE,
|
||||
self.__policydbP, GenfsIterP)
|
||||
if ret == 0:
|
||||
self.__GenfsDictAdd(self.__GenfsDict, buf.value)
|
||||
self.__GenfsDictAdd(self.__GenfsDict, buf.value.decode("ascii"))
|
||||
continue
|
||||
if ret == 1:
|
||||
self.__GenfsDictAdd(self.__GenfsDict, buf.value)
|
||||
self.__GenfsDictAdd(self.__GenfsDict, buf.value.decode("ascii"))
|
||||
break;
|
||||
# We should never get here.
|
||||
sys.exit("Failed to get genfs entries")
|
||||
|
@ -434,7 +448,7 @@ class Policy:
|
|||
|
||||
# load policy
|
||||
def __InitPolicy(self, PolicyPath):
|
||||
cPolicyPath = create_string_buffer(PolicyPath)
|
||||
cPolicyPath = create_string_buffer(PolicyPath.encode("ascii"))
|
||||
self.__policydbP = self.__libsepolwrap.load_policy(cPolicyPath)
|
||||
if (self.__policydbP is None):
|
||||
sys.exit("Failed to load policy")
|
||||
|
|
|
@ -1,4 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright 2021 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
import policy
|
||||
|
@ -70,4 +84,4 @@ for r in TERules:
|
|||
" ".join(r.perms) + ";")
|
||||
|
||||
for r in sorted(rules):
|
||||
print r
|
||||
print(r)
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
# Copyright 2021 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from optparse import OptionParser
|
||||
from optparse import Option, OptionValueError
|
||||
import os
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
# Copyright 2021 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from optparse import OptionParser
|
||||
from optparse import Option, OptionValueError
|
||||
import os
|
||||
|
@ -36,17 +50,17 @@ class scontext:
|
|||
def PrintScontexts():
|
||||
for d in sorted(alldomains.keys()):
|
||||
sctx = alldomains[d]
|
||||
print d
|
||||
print "\tcoredomain="+str(sctx.coredomain)
|
||||
print "\tappdomain="+str(sctx.appdomain)
|
||||
print "\tfromSystem="+str(sctx.fromSystem)
|
||||
print "\tfromVendor="+str(sctx.fromVendor)
|
||||
print "\tattributes="+str(sctx.attributes)
|
||||
print "\tentrypoints="+str(sctx.entrypoints)
|
||||
print "\tentrypointpaths="
|
||||
print(d)
|
||||
print("\tcoredomain="+str(sctx.coredomain))
|
||||
print("\tappdomain="+str(sctx.appdomain))
|
||||
print("\tfromSystem="+str(sctx.fromSystem))
|
||||
print("\tfromVendor="+str(sctx.fromVendor))
|
||||
print("\tattributes="+str(sctx.attributes))
|
||||
print("\tentrypoints="+str(sctx.entrypoints))
|
||||
print("\tentrypointpaths=")
|
||||
if sctx.entrypointpaths is not None:
|
||||
for path in sctx.entrypointpaths:
|
||||
print "\t\t"+str(path)
|
||||
print("\t\t"+str(path))
|
||||
|
||||
alldomains = {}
|
||||
coredomains = set()
|
||||
|
@ -367,7 +381,7 @@ if __name__ == '__main__':
|
|||
|
||||
# Mapping files and public platform policy are only necessary for the
|
||||
# TrebleCompatMapping test.
|
||||
if options.tests is None or options.tests is "TrebleCompatMapping":
|
||||
if options.tests is None or options.tests == "TrebleCompatMapping":
|
||||
if not options.basepolicy:
|
||||
sys.exit("Must specify the current platform-only policy file\n"
|
||||
+ parser.usage)
|
||||
|
|
Loading…
Reference in a new issue