Skip to content

Instantly share code, notes, and snippets.

@jakemco
Last active December 17, 2015 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakemco/5674529 to your computer and use it in GitHub Desktop.
Save jakemco/5674529 to your computer and use it in GitHub Desktop.
Test runner for CSE131 Phase II

CSE 131 - Phase II - Test Runner

Given two equivalent source files, one .cpp or .c, the other .rc, the test runner will compile the reduced c locally, and then copy both tests over to ieng9 to run and diff them.

Prerequisites

  • You must have Ruby and RubyGems

  • You must have rubygem 'differ'

    gem install differ
    

How To Use

  1. Start by copying down the test_runner.rb file to your project folder.

  2. Modify the constants at the top of the file to point to your RC directory and your test directory. My file structure looks like this:

    test_runner.rb
    src/
     |- RC
     |- rc.s (after compiling)
    tests/
     |- foobar.cpp
     |- foobar.rc
    

So my constants are ./src/ and ./tests/ for PATH_TO_RC and PATH_TO_TESTS respectively.

  1. Set the REMOTE_HOST constant to yourusername@ieng9.ucsd.edu
  2. Run by passing the testname to the file, eg ruby test_runner.rb foobar
  3. Type in your ieng9 password four times when prompted (twice for scp, twice for ssh)

Note: If you wish to avoid typing in your password, you can add your local public key to your remote authorized_keys file.

  1. ???
  2. Profit (in the form of diff results)

Tests

Example tests are included in this gist. They should be equivalent files. test_runner.rb will first look for a .cpp file, and then if one is not present, a .c file.

#!/usr/bin/env ruby
require 'differ'
require 'fileutils'
# Path to where the RC executable is, relative to this file
PATH_TO_RC = %(./src/)
# Path to where the tests are kept, relative to this file
PATH_TO_TESTS = %(./tests/)
# Your username @ remote host eg "ricko@ieng9.ucsd.edu"
REMOTE_HOST = %(jmaskiew@ieng9.ucsd.edu)
#================================
def print_usage(msg = "")
puts msg
puts "Usage:"
puts "\truby #{__FILE__} testname"
puts "\nBe sure to modify the constants at the top of the rb file"
exit(1)
end
FileUtils.cd File.dirname(__FILE__)
# Get the testname argument
@testname = ARGV[0]
print_usage if @testname.nil?
# Get the location of the tests
test_path = File.join(PATH_TO_TESTS,@testname)
# Get the rc test and ensure its existence
rc_file = test_path + ".rc"
unless File.exists?(rc_file)
print_usage("No .rc file")
end
# First look for a .cpp file, then a .c file
cpp_file = test_path + ".cpp"
unless File.exists?(cpp_file)
cpp_file = test_path + ".c"
end
unless File.exists?(cpp_file)
print_usage("No .c or .cpp file")
end
# Copy the rc file to the tmp directory
FileUtils.cp(rc_file,File.join(PATH_TO_RC,"_test.rc"))
rc_exec = File.join(PATH_TO_RC,"RC")
unless File.exists?(rc_exec)
print_usage("RC executable not found")
end
# Execute the compiler
FileUtils.chdir PATH_TO_RC do
`./RC _test.rc`
end
# Copy dat shit over
`scp #{File.join(PATH_TO_RC,"rc.s")} "#{REMOTE_HOST}:~"`
`scp #{cpp_file} "#{REMOTE_HOST}:~"`
@rc_out = `ssh #{REMOTE_HOST} 'g++ input.c output.s rc.s;./a.out 2>&1'`
@cpp_out = `ssh #{REMOTE_HOST} 'g++ #{File.basename(cpp_file)};./a.out 2>&1'`
@diff = Differ.diff_by_line(@rc_out, @cpp_out)
puts @diff.format_as(:color)
#include <iostream>
using namespace std;
int main() {
cout << "Hello World" << endl;
return 0;
}
function : int main() {
cout << "Hello World" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment