Adds a validation test for trait names

Standard trait names should follow the regex "^[A-Z][A-Z0-9]*$". One of the
traits (HW_CPU_X86_AES-NI) erroneously contained a hyphen, so we correct that
and add a test to ensure no future traits wander from the standard trait name
regex.

Luckily, nothing yet is consuming os-traits and so the AES-NI slipup is yet to
have any impact.

Change-Id: I0603bcb4a1038289d2a3b6ce18aa823c7fac0829
This commit is contained in:
Jay Pipes 2017-05-04 19:11:32 -04:00
parent 8503afd938
commit b169eb4a8e
2 changed files with 11 additions and 1 deletions

View File

@ -46,7 +46,7 @@ TRAITS = [
'BMI2',
'TBM',
# ref: https://en.wikipedia.org/wiki/AES_instruction_set
'AES-NI',
'AESNI',
# ref: https://en.wikipedia.org/wiki/Intel_SHA_extensions
'SHA',
# ref: https://en.wikipedia.org/wiki/Intel_MPX

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import re
import os_traits as ot
from os_traits.hw.cpu import x86
from os_traits.hw.nic import offload
@ -53,3 +55,11 @@ class TestSymbols(base.TestCase):
def test_is_custom(self):
self.assertTrue(ot.is_custom('CUSTOM_FOO'))
self.assertFalse(ot.is_custom('HW_CPU_X86_SSE42'))
def test_trait_names_match_regex(self):
traits = ot.get_traits()
valid_name = re.compile("^[A-Z][A-Z0-9_]*$")
for t in traits:
match = valid_name.match(t)
if not match:
self.fail("Trait %s does not validate name regex." % t)