Automated Testing – Automated Testing Using Virtual Machines

testingvirtualization

I am working on making a system for the automated testing of student assignments. The biggest hurdle I am facing right now is figuring out how to sandbox the testing of the code yet still get and process the results of the test. I need to run it on a VM as there is no guarantee the code will not be malicious.

I would like to have a process similar to the following:

  1. Student submits assignment
  2. VM is created and is given the source code submitted by the student
  3. VM runs the tests on the source code
  4. VM returns results of the test back to the host operating system
  5. Results are processed

Steps 2 and 4 are the ones I am looking for a good solution for. I am not sure what would be a good way automate the passing of files to the VM and the passing of results back from the VM. It seems like this is a problem that might have a solution already and I would rather not reinvent the wheel.

Best Answer

I would probably just use ssh to the VM. First copy the executable into the VM using ssh (scp or sftp), then execute it again using ssh and read it's output, possibly use ssh again to pull output files (scp/sftp again, though it's easiest to stick with standard output whenever sufficient) and shut down the VM.

The VM needs to have networking enabled for this, but you can easily prevent it from reaching outside world by configuring firewall on the host.

The VM should have it's disk image mounted in copy-on-write mode and the writable part discarded after the shutdown, so all tests run with the same initial state. You can optionally check that the copy-on-write file does not contain changes to any files it is not supposed to contain.

Related Topic