utils module#

class utils.BuildResult[source]#

Bases: object

exception utils.Panic[source]#

Bases: Exception

class utils.TestResult[source]#

Bases: object

utils.did_xv6_crash(stdout_lines: List[str], test_result: TestResult)[source]#

Will check output to see if xv6 crashed. We look for cpu0: panic, and or unexpected traps.

If a crash is detected, the test_result will be set with and True will be returned,

Parameters
  • stdout_lines

  • test_result

Returns

utils.exec_as_student(cmd, timeout=60) Tuple[str, int][source]#

Run a command as the student. Any and all times that student code is run, it should be done through this function. Any other way would be incredibly insecure.

Parameters
  • cmd – Command to run

  • timeout – Timeout for command

Returns

bytes output, int return code

utils.fix_permissions()[source]#

Fix the file permissions of the student repo

  • DEPRECATED *

Returns

utils.hide_test()[source]#
utils.points_test(points: int)[source]#
utils.register_build(func)[source]#
utils.register_test(test_name)[source]#
utils.search_lines(stdout_lines: List[str], expected_lines: List[str], case_sensitive: bool = True) Tuple[bool, List[str]][source]#

Search lines for expected lines. This will return true if all expected lines are in the student standard out lines in order. There can be interruptions in the student standard out. This function has the advantage of allowing students to still print out debugging lines while their output is still accurately checked for the expected result. The diff is not available for this.

>>> search_lines(['a', 'b', 'c'], ['a', 'b', 'c']) -> (True, [])
>>> search_lines(['a', 'debugging', 'b', 'c'], ['a', 'b', 'c']) -> (True, [])
>>> search_lines(['a', 'b'],      ['a', 'b', 'c']) -> (False, [])
  • Optionally specify if the equality comparison should be case sensitive *

Parameters
  • stdout_lines

  • expected_lines

  • case_sensitive

Returns

utils.test_lines(stdout_lines: List[str], expected_lines: List[str], case_sensitive: bool = True, context_length: int = 1000) Tuple[bool, List[str]][source]#

Test lines for exact equality. Whitespace will be stripped off each line automatically.

  • Optionally specify if the equality comparison should be case sensitive *

>>> test_lines(['a', 'b', 'c'], ['a', 'b', 'c']) -> (True, [])
>>> test_lines(['a', 'debugging', 'b', 'c'], ['a', 'b', 'c'])
# -> (False, ['--- ', '+++ ', '@@ -1,3 +1,4 @@', ' a', '+debugging', ' b', ' c'])
>>> test_lines(['a', 'b'],      ['a', 'b', 'c'])
# -> (False, ['--- ', '+++ ', '@@ -1,3 +1,2 @@', ' a', ' b', '-c'])
Parameters
  • stdout_lines – students standard out lines as a list of strings

  • expected_lines – expected lines as a list of strings

  • case_sensitive – optional boolean to indicate if comparison should be case sensitive

  • context_length – the length of the context of the generated diff (the smaller the faster)

Returns

True and an empty list if exact match was found, False with the unified diff otherwise

utils.trim(stdout: str) List[str][source]#

This mess of a function is where we parse out the pieces we want from the xv6 output.

A parsed list of string lines is returned.

Parameters

stdout

Returns

utils.verify_expected(stdout_lines: List[str], expected_lines: List[str], test_result: TestResult, case_sensitive: bool = True, search: bool = False)[source]#

Check to lists of strings for quality. Will strip off whitespace from each line before checking for equality. The stdout_lines should be from the student code. The expected_lines should then be whichever lines are expected for this test.

  • The fields on the test_result object will be set automatically based on if the

expected output was found. *

Parameters
  • stdout_lines – students lines as a list of strings

  • expected_lines – expected lines as a list of strings

  • test_result – TestResult object for this test

  • case_sensitive – boolean to indicate if the comparison should be case sensitive

  • search – boolean to indicate if the stdout should be searched instead of directly compared for equality

Returns

utils.xv6_run(cmd: str, test_result: TestResult, timeout=5) List[str][source]#

Start xv6 and run command specified. The test_result.output will be appended with a message saying what command is being run.

We return a list of the lines parsed

Parameters
  • cmd

  • test_result

  • timeout

Returns