1111
1212logger = logging .getLogger (__name__ )
1313
14-
1514def iset ():
1615 '''Function to check and set defaults for all "implemented" fields which are dependent on
1716 the xlen.'''
@@ -210,23 +209,7 @@ def imp_normalise(foo):
210209 break
211210 return foo
212211
213-
214- def errPrint (foo , space = ' ' ):
215- '''
216- Function to petty print the error from cerberus.
217- '''
218- error = ''
219- for key in foo .keys ():
220- error += space + str (key ) + ":"
221- if isinstance (foo [key ][0 ], dict ):
222- error += "\n " + errPrint (foo [key ][0 ], space + space )
223- else :
224- error += str (foo [key ][0 ])
225- error += "\n "
226- return error .rstrip ()
227-
228-
229- def check_specs (isa_spec , platform_spec , work_dir ):
212+ def check_specs (isa_spec , platform_spec , work_dir ,logging = False ):
230213 '''
231214 Function to perform ensure that the isa and platform specifications confirm
232215 to their schemas. The :py:mod:`Cerberus` module is used to validate that the
@@ -235,20 +218,25 @@ def check_specs(isa_spec, platform_spec, work_dir):
235218 :param isa_spec: The path to the DUT isa specification yaml file.
236219
237220 :param platform_spec: The path to the DUT platform specification yaml file.
221+
222+ :param logging: A boolean to indicate whether log is to be printed.
223+
224+ :type logging: bool
238225
239226 :type isa_spec: str
240227
241228 :type platform_spec: str
242229
243230 :raise ValidationError: It is raised when the specifications violate the
244- schema rules.
231+ schema rules. It also contains the specific errors in each of the fields.
245232
246- :return: A tuple with the first entry being the path to normalized isa file
247- and the second being path to the platform spec file.
233+ :return: A tuple with the first entry being the absolute path to normalized isa file
234+ and the second being the absolute path to the platform spec file.
248235 '''
249236 global inp_yaml
250237
251- logger .info ('Input-ISA file' )
238+ if logging :
239+ logger .info ('Input-ISA file' )
252240
253241 foo = isa_spec
254242 schema = constants .isa_schema
@@ -257,11 +245,13 @@ def check_specs(isa_spec, platform_spec, work_dir):
257245 and constraints
258246 """
259247 # Load input YAML file
260- logger .info ('Loading input file: ' + str (foo ))
248+ if logging :
249+ logger .info ('Loading input file: ' + str (foo ))
261250 inp_yaml = utils .load_yaml (foo )
262251
263252 # instantiate validator
264- logger .info ('Load Schema ' + str (schema ))
253+ if logging :
254+ logger .info ('Load Schema ' + str (schema ))
265255 schema_yaml = utils .load_yaml (schema )
266256
267257 #Extract xlen
@@ -274,28 +264,30 @@ def check_specs(isa_spec, platform_spec, work_dir):
274264 normalized = validator .normalized (inp_yaml , schema_yaml )
275265
276266 # Perform Validation
277- logger .info ('Initiating Validation' )
267+ if logging :
268+ logger .info ('Initiating Validation' )
278269 valid = validator .validate (inp_yaml )
279270
280271 # Print out errors
281272 if valid :
282- logger .info ('No Syntax errors in Input ISA Yaml. :)' )
273+ if logging :
274+ logger .info ('No Syntax errors in Input ISA Yaml. :)' )
283275 else :
284276 error_list = validator .errors
285- logger .error ("Error in " + foo + "\n " + errPrint (error_list ))
286- raise ValidationError (
287- "Error in ISA Yaml. Refer to logs for more details." )
277+ raise ValidationError ("Error in " + foo + "." ,error_list )
288278
289279 file_name = os .path .split (foo )
290280 file_name_split = file_name [1 ].split ('.' )
291281 output_filename = os .path .join (
292282 work_dir , file_name_split [0 ] + '_checked.' + file_name_split [1 ])
293283 ifile = output_filename
294284 outfile = open (output_filename , 'w' )
295- logger .info ('Dumping out Normalized Checked YAML: ' + output_filename )
285+ if logging :
286+ logger .info ('Dumping out Normalized Checked YAML: ' + output_filename )
296287 yaml .dump (imp_normalise (normalized ), outfile )
297288
298- logger .info ('Input-Platform file' )
289+ if logging :
290+ logger .info ('Input-Platform file' )
299291
300292 foo = platform_spec
301293 schema = constants .platform_schema
@@ -304,13 +296,15 @@ def check_specs(isa_spec, platform_spec, work_dir):
304296 and constraints
305297 """
306298 # Load input YAML file
307- logger .info ('Loading input file: ' + str (foo ))
299+ if logging :
300+ logger .info ('Loading input file: ' + str (foo ))
308301 inp_yaml = utils .load_yaml (foo )
309302 if inp_yaml is None :
310303 inp_yaml = {'mtime' : {'implemented' : False }}
311304
312305 # instantiate validator
313- logger .info ('Load Schema ' + str (schema ))
306+ if logging :
307+ logger .info ('Load Schema ' + str (schema ))
314308 schema_yaml = utils .load_yaml (schema )
315309
316310 validator = schemaValidator (schema_yaml , xlen = xlen )
@@ -319,24 +313,25 @@ def check_specs(isa_spec, platform_spec, work_dir):
319313 normalized = validator .normalized (inp_yaml , schema_yaml )
320314
321315 # Perform Validation
322- logger .info ('Initiating Validation' )
316+ if logging :
317+ logger .info ('Initiating Validation' )
323318 valid = validator .validate (inp_yaml )
324319
325320 # Print out errors
326321 if valid :
327- logger .info ('No Syntax errors in Input Platform Yaml. :)' )
322+ if logging :
323+ logger .info ('No Syntax errors in Input Platform Yaml. :)' )
328324 else :
329325 error_list = validator .errors
330- logger .error ("Error in " + foo + "\n " + errPrint (error_list ))
331- raise ValidationError ("Error in Platform\
332- Yaml. Refer to logs for more details." )
326+ raise ValidationError ("Error in " + foo + "." ,error_list )
333327
334328 file_name = os .path .split (foo )
335329 file_name_split = file_name [1 ].split ('.' )
336330 output_filename = os .path .join (
337331 work_dir , file_name_split [0 ] + '_checked.' + file_name_split [1 ])
338332 pfile = output_filename
339333 outfile = open (output_filename , 'w' )
340- logger .info ('Dumping out Normalized Checked YAML: ' + output_filename )
334+ if logging :
335+ logger .info ('Dumping out Normalized Checked YAML: ' + output_filename )
341336 yaml .dump (imp_normalise (normalized ), outfile )
342337 return (ifile , pfile )
0 commit comments