mirror of
https://github.com/ipxe/ipxe
synced 2026-10-07 15:05:42 +03:00
[test] Add schema and count validators in Project Wycheproof tests
The schema and test counts are currently validated only at the point of attempting to generate source code. Promote these checks to become standard validators. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -267,6 +267,24 @@ class TestFile:
|
||||
schema = scalar_field(str)
|
||||
testGroups = list_field(TestGroup)
|
||||
|
||||
@schema.validator
|
||||
def validate_schema(self, attr, value):
|
||||
"""Validate schema"""
|
||||
if value != self.SCHEMA:
|
||||
raise ValueError(
|
||||
"%s: found schema %s (expected %s)" %
|
||||
(self.SRCFILE, value, self.SCHEMA)
|
||||
)
|
||||
|
||||
@numberOfTests.validator
|
||||
def validate_number_of_tests(self, attr, value):
|
||||
"""Validate number of tests"""
|
||||
if value != len(self.tests):
|
||||
raise ValueError(
|
||||
"%s: found %d tests (expected %d)" %
|
||||
(self.SRCFILE, len(self.tests), value)
|
||||
)
|
||||
|
||||
@property
|
||||
def basename(self):
|
||||
"""Base name for test cases"""
|
||||
@@ -279,20 +297,10 @@ class TestFile:
|
||||
|
||||
def source(self):
|
||||
"""Generate source code"""
|
||||
if self.schema != self.SCHEMA:
|
||||
raise ValueError(
|
||||
"%s: found schema %s (expected %s)" %
|
||||
(self.SRCFILE, self.schema, self.SCHEMA)
|
||||
)
|
||||
generator = Path(__file__).name
|
||||
execname = "wycheproof_%s_exec" % self.basename
|
||||
tests = self.tests
|
||||
label = tests[0].test_label
|
||||
if len(tests) != self.numberOfTests:
|
||||
raise ValueError(
|
||||
"%s: found %d tests (expected %d)" %
|
||||
(self.SRCFILE, len(tests), self.numberOfTests)
|
||||
)
|
||||
definitions = "\n".join(x.definition() for x in tests)
|
||||
invocations = "".join(x.invocation() for x in tests if not x.skip)
|
||||
code = (
|
||||
|
||||
Reference in New Issue
Block a user