AsmGrader 0.0.0
Loading...
Searching...
No Matches
asmgrader::TestContext Class Reference

User-facing API for use within an assignment test case for: Interacting with or querying data for the student's assembled binary Test result collection (requirements, pass/fail cases) Performing any other esoteric test-related action. More...

#include <test_context.hpp>

Public Member Functions

 TestContext (TestBase &test, Program program, std::function< void(const RequirementResult &)> on_requirement=common::noop) noexcept
 
bool require (bool condition, std::string msg, RequirementResult::DebugInfo debug_info=RequirementResult::DebugInfo{})
 
bool require (bool condition, RequirementResult::DebugInfo debug_info=RequirementResult::DebugInfo{})
 
TestResult finalize ()
 Obtain the final test results Run after the test is complete. Note: has no ill effects if run before test is complete.
 
std::string_view get_name () const
 Test name getter.
 
void restart_program ()
 Restarts the entire program.
 
Result< SyscallRecordexec_syscall (u64 sys_nr, std::array< std::uint64_t, 6 > args)
 
std::string get_stdout ()
 Get any new stdout from the program since the last call to this function.
 
std::string get_full_stdout ()
 Get all stdout from since the beginning of the test invokation.
 
std::size_t flush_stdin ()
 Flushes any reamaining unread data in the stdin buffer Returns: number of bytes flushed, or error kind if failure occured.
 
const std::vector< SyscallRecord > & get_syscall_records () const
 Obtain a list of the syscalls that have been executed so far.
 
RegistersState get_registers () const
 Get the current register state of the program.
 
void send_stdin (const std::string &input)
 Get any new stdout from the program since the last call to this function.
 
template<typename T >
AsmSymbol< T > find_symbol (std::string_view name)
 Find a named symbol in the associated program.
 
template<std::size_t NumBytes>
AsmBuffer< NumBytes > create_buffer ()
 Create a buffer of NumBytes
 
template<typename Func >
AsmFunction< Func > find_function (std::string name)
 Find a named function in the associated program.
 
RunResult run ()
 Run the program normally from _start
 

Detailed Description

User-facing API for use within an assignment test case for: Interacting with or querying data for the student's assembled binary Test result collection (requirements, pass/fail cases) Performing any other esoteric test-related action.

Constructor & Destructor Documentation

◆ TestContext()

asmgrader::TestContext::TestContext ( TestBase & test,
Program program,
std::function< void(const RequirementResult &)> on_requirement = common::noop )
explicitnoexcept

Member Function Documentation

◆ create_buffer()

template<std::size_t NumBytes>
AsmBuffer< NumBytes > asmgrader::TestContext::create_buffer ( )

Create a buffer of NumBytes

◆ exec_syscall()

Result< SyscallRecord > asmgrader::TestContext::exec_syscall ( u64 sys_nr,
std::array< std::uint64_t, 6 > args )

◆ finalize()

TestResult asmgrader::TestContext::finalize ( )

Obtain the final test results Run after the test is complete. Note: has no ill effects if run before test is complete.

◆ find_function()

template<typename Func >
AsmFunction< Func > asmgrader::TestContext::find_function ( std::string name)

Find a named function in the associated program.

◆ find_symbol()

template<typename T >
AsmSymbol< T > asmgrader::TestContext::find_symbol ( std::string_view name)

Find a named symbol in the associated program.

Template Parameters
Ttype of data that the symbol refers to

◆ flush_stdin()

std::size_t asmgrader::TestContext::flush_stdin ( )

Flushes any reamaining unread data in the stdin buffer Returns: number of bytes flushed, or error kind if failure occured.

◆ get_full_stdout()

std::string asmgrader::TestContext::get_full_stdout ( )

Get all stdout from since the beginning of the test invokation.

◆ get_name()

std::string_view asmgrader::TestContext::get_name ( ) const

Test name getter.

◆ get_registers()

RegistersState asmgrader::TestContext::get_registers ( ) const

Get the current register state of the program.

◆ get_stdout()

std::string asmgrader::TestContext::get_stdout ( )

Get any new stdout from the program since the last call to this function.

◆ get_syscall_records()

const std::vector< SyscallRecord > & asmgrader::TestContext::get_syscall_records ( ) const

Obtain a list of the syscalls that have been executed so far.

◆ require() [1/2]

bool asmgrader::TestContext::require ( bool condition,
RequirementResult::DebugInfo debug_info = RequirementResult::DebugInfo{} )

◆ require() [2/2]

bool asmgrader::TestContext::require ( bool condition,
std::string msg,
RequirementResult::DebugInfo debug_info = RequirementResult::DebugInfo{} )

◆ restart_program()

void asmgrader::TestContext::restart_program ( )

Restarts the entire program.

Note: if the asm executable has changed, this will launch with the NEW executable Important: this has the almost certain effect of invalidating all buffers or other addressable references to said program, as the address space WILL change

◆ run()

RunResult asmgrader::TestContext::run ( )

Run the program normally from _start

◆ send_stdin()

void asmgrader::TestContext::send_stdin ( const std::string & input)

Get any new stdout from the program since the last call to this function.


The documentation for this class was generated from the following files: