diff --git a/grader-process-check b/grader-process-check new file mode 100755 --- /dev/null +++ b/grader-process-check @@ -0,0 +1,6 @@ +#!/bin/bash +count=`ps aux | grep "cafe_grader" | grep "grader grading queue" | wc -l` +if [ $count -lt 1 ]; then + cd /home/dae/cafe_grader/judge + /home/dae/.rvm/wrappers/ruby-2.3.0/ruby /home/dae/cafe_grader/judge/scripts/grader grading queue > /home/dae/grading.log & +fi diff --git a/import_problem b/import_problem --- a/import_problem +++ b/import_problem @@ -132,29 +132,35 @@ testrun_info.each do |testrun| tr_num += 1 puts "testrun: #{tr_num}" - + testrun.each do |testcase_info| testcase_num, testcase_fname = testcase_info - + puts "copy #{testcase_fname} to #{testcase_num}" - + create_dir_if_not_exists("#{problem_dir}/test_cases/#{testcase_num}") copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num) - + num_testcases += 1 end end - + + #also include any .txt files + Dir.glob("#{testcase_dir}/*.txt") do |file| + puts "copy data file #{file}" + FileUtils.cp(file,"#{problem_dir}") + end + # generating all_tests.cfg puts "generating testcase config file" - + template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read all_test_cfg = ERB.new(template) - + cfg_file = File.open("#{problem_dir}/test_cases/all_tests.cfg","w") cfg_file.puts all_test_cfg.result binding cfg_file.close - + # copy check script if res = /^wrapper:(.*)$/.match(check_script) # wrapper script @@ -162,13 +168,13 @@ script_name = File.basename(check_script_fname) check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read check_wrapper = ERB.new(check_wrapper_template) - + check_file = File.open("#{problem_dir}/script/check","w") check_file.puts check_wrapper.result binding check_file.close - + File.chmod(0755,"#{problem_dir}/script/check") - + FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/#{script_name}") else if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") @@ -178,24 +184,24 @@ end FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/check", :preserve => true) end - + # generating test_request directory puts "generating test_request template" FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/script") FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/test_cases/1") - + template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read test_request_all_test_cfg = ERB.new(template) - + cfg_file = File.open("#{ev_dir}/test_request/#{problem}/test_cases/all_tests.cfg","w") cfg_file.puts test_request_all_test_cfg.result cfg_file.close - + FileUtils.cp("#{SCRIPT_DIR}/templates/check_empty", "#{ev_dir}/test_request/#{problem}/script/check") FileUtils.cp("#{SCRIPT_DIR}/templates/answer-1.txt", "#{ev_dir}/test_request/#{problem}/test_cases/1") - + puts "done" end diff --git a/installer/install.sh b/installer/install.sh --- a/installer/install.sh +++ b/installer/install.sh @@ -15,7 +15,7 @@ sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev \ ncurses-dev automake libtool bison subversion \ pkg-config curl nodejs unzip pyflakes ruby default-jdk \ - libmysqld-dev mercurial python-setuptools python-dev + libmysqld-dev mercurial python-setuptools python-dev python3-numpy echo "Installing RVM" curl -k -L https://get.rvm.io | bash -s stable diff --git a/load_testcase b/load_testcase new file mode 100755 --- /dev/null +++ b/load_testcase @@ -0,0 +1,85 @@ +#!/usr/bin/env ruby + +def config + Grader::Configuration.get_instance +end + +def display_manual + puts < false, + } + + options[:dry_run] = (ARGV.delete('--dry') != nil) + options[:all] = (ARGV.delete('--all') != nil) + + return options +end + +def process_problem(prob,dry_run = false) + prob.testcases.destroy_all + testcases_root = File.expand_path(GRADER_ROOT+"/../ev/#{prob.name}/test_cases/") + num = 1 + puts "Processing problem #{prob.name}" + loop do + file_root = testcases_root + "/#{num}/" + puts " checking file #{file_root}" + break unless File.exists? file_root + input = File.read(file_root + "/input-#{num}.txt") + answer = File.read(file_root + "/answer-#{num}.txt") + puts " got test case ##{num} of size #{input.size} and #{answer.size}" + + #THIS IS JUST A PLACE HOLDER + group = num #this is wrong!!! fix it!! + score = 10 + #BEWARE + + prob.testcases.create(input: input,sol: answer, num: num, score:score,group: group) unless dry_run + num += 1 + end +end + +######################################### +# main program +######################################### + +options = process_options_and_stop_file + +# load grader environment +GRADER_ENV = 'grading' +require File.join(File.dirname(__FILE__),'config/environment') + +# boot rails, to be able to use the active record +RAILS_ENV = config.rails_env +require RAILS_ROOT + '/config/environment' + +if options[:all] + Problem.all.each { |prob| process_problem(prob,options[:dry_run]) } +else + ARGV.each do |name| + prob = Problem.find_by(name: name) + process_problem(prob,options[:dry_run]) if prob + puts "Cannot find the problem #{name}" unless prob + end +end + diff --git a/rename_problem b/rename_problem --- a/rename_problem +++ b/rename_problem @@ -8,7 +8,7 @@ def rename_problem(old_problem_name, new_problem_name) - if valid_problem_name(new_problem_name) + unless valid_problem_name(new_problem_name) puts "Bad new problem name: #{new_problem_name}" return end @@ -60,7 +60,7 @@ if name.length==0: return false else - return !(/^[a-zA-Z0-9_\-]+$/ === name) + return (/^[a-zA-Z0-9_\-]+$/ === name) end end diff --git a/std-script/box64-new.c b/std-script/box64-new.c --- a/std-script/box64-new.c +++ b/std-script/box64-new.c @@ -603,6 +603,18 @@ /* 311 */ [ __NR_process_vm_writev ] = "process_vm_writev", /* 312 */ [ __NR_kcmp ] = "kcmp", /* 313 */ [ __NR_finit_module ] = "finit_module", +/* 314 */ [ __NR_sched_setattr ] = "sched_setattr", +/* 315 */ [ __NR_sched_getattr ] = "sched_getattr", +/* 316 */ [ __NR_renameat2 ] = "renameat2", +/* 317 */ [ __NR_seccomp ] = "seccomp", +/* 318 */ [ __NR_getrandom ] = "getrandom", +/* 319 */ [ __NR_memfd_create ] = "memfd_create", +/* 320 */ [ __NR_kexec_file_load ] = "kexec_file_load", +/* 321 */ [ __NR_bpf ] = "bpf", +/* 322 */ [ __NR_execveat ] = "execveat", +/* 323 */ [ __NR_userfaultfd ] = "userfaultfd", +/* 324 */ [ __NR_membarrier ] = "membarrier", +/* 325 */ [ __NR_mlock2 ] = "mlock2", }; #define NUM_SYSCALLS ARRAY_SIZE(syscall_names) #define NUM_ACTIONS (NUM_SYSCALLS+64) diff --git a/std-script/compile b/std-script/compile --- a/std-script/compile +++ b/std-script/compile @@ -31,6 +31,7 @@ PYTHON_INTERPRETER = "/usr/bin/python3" PYTHON_CHECKER = "/usr/bin/pyflakes" PHP_INTERPRETER = "/usr/bin/php" +HASKELL_COMPILER = "/usr/bin/ghc" C_OPTIONS = "-O2 -s -static -std=c99 -DCONTEST -lm -Wall" CPLUSPLUS_OPTIONS = "-O2 -s -std=c++11 -static -DCONTEST -lm -Wall" @@ -38,6 +39,7 @@ JAVA_OPTIONS = "" PYTHON_OPTIONS = "" PHP_OPTIONS = "-l" +HASKELL_OPTIONS = "" # Check for the correct number of arguments. Otherwise, print usage. if ARGV.length == 0 or ARGV.length > 4 @@ -145,20 +147,22 @@ end when "python" - command = "#{PYTHON_CHECKER} #{params[:source_file]}" - if system(command, out: params[:message_file]) + #command = "#{PYTHON_CHECKER} #{params[:source_file]}" + #if system(command, out: params[:message_file]) #compile to python bytecode command = "#{PYTHON_INTERPRETER} -c \"import py_compile; py_compile.compile('#{params[:source_file]}','#{params[:source_file]}c');\"" puts "compile: #{command}" - system(command) - puts "pwd: " + Dir.pwd - Dir.new('.').each {|file| puts file} - File.open(params[:output_file],"w") do |out_file| - out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" + system(command, err: params[:message_file]) + if FileTest.exists?("#{params[:source_file]}c") + puts "pwd: " + Dir.pwd + Dir.new('.').each {|file| puts file} + File.open(params[:output_file],"w") do |out_file| + out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" + end + File.chmod(0755, params[:output_file]) + FileUtils.cp("#{params[:source_file]}c",params[:output_file]) end - File.chmod(0755, params[:output_file]) - FileUtils.cp("#{params[:source_file]}c",params[:output_file]) - end + #end when "php" command = "#{PHP_INTERPRETER} #{PHP_OPTIONS} #{params[:source_file]}" @@ -172,6 +176,10 @@ File.chmod(0755, params[:output_file]) end +when "haskell" + command = "#{HASKELL_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{HASKELL_OPTIONS}" + system(command, err: params[:message_file]) + else talk("ERROR: Invalid language specified!") open(params[:message_file],"w") do |f| diff --git a/std-script/judge b/std-script/judge --- a/std-script/judge +++ b/std-script/judge @@ -53,7 +53,7 @@ end language = ARGV[0] -if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" && language != "python" && language != "php" +if language != "c" && language != "c++" && language != "pas" && language != "java" && language != "ruby" && language != "python" && language != "php" && language != "haskell" log "You specified a language that is not supported: #{language}." exit(127) end @@ -140,6 +140,12 @@ if language == "python" then Dir["#{test_result_dir}/*.pyc"].each { |file| FileUtils.cp(file,sandbox_dir)} end } + #additionally copy any extra .txt file + data_files = Dir[problem_home + '/*.txt'] + data_files.each do |file| + FileUtils.cp(file,sandbox_dir) + end + begin execute("#{problem_home}/script/run #{language} #{test_num} ", "Error occured during execution of the run script") rescue diff --git a/std-script/run b/std-script/run --- a/std-script/run +++ b/std-script/run @@ -92,8 +92,9 @@ JAVA_OPTION = "-s set_robust_list -s futex -s clone -s getppid -s clone -s wait4 -p /usr/bin/ -p ./" RUBY_OPTION = "-p /usr/lib64/ -p /usr/local/lib64/ -p /usr/local/lib/ -p /lib64/ -p /dev/urandom -p #{sandbox_dir}/#{program_name} -p #{sandbox_dir}/ -s set_robust_list -s sched_getaffinity -s clock_gettime -s sigaltstack -s pipe2 -s clone -s futex -s openat -s pipe" -PYTHON_OPTION = "-p /usr/lib64/ -p /usr/local/lib64/ -p /usr/local/lib/ -p /usr/bin/ -p /lib64/ -p /dev/urandom -p /usr/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p #{sandbox_dir}/#{source_name} -p /proc/mounts -s statfs -s set_robust_list -s openat -s recvmsg -s connect -s socket -s sendto -s futex -s sigaltstack -E PYTHONNOUSERSITE=yes" +PYTHON_OPTION = "-p /usr/lib64/ -p /usr/local/lib64/ -p /usr/local/lib/ -p /usr/bin/ -p /lib64/ -p /dev/urandom -p /usr/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p #{sandbox_dir}/#{source_name} -p /proc/sys/crypto/fips_enabled -p /proc/self/status -p /proc/mounts -p /var/lib/dpkg/status -s statfs -s set_robust_list -s openat -s sysinfo -s recvmsg -s connect -s socket -s sendto -s futex -s sigaltstack -s getrandom -E PYTHONNOUSERSITE=yes" PHP_OPTION = "-p /usr/lib64/ -p/lib64/ -p /usr/bin/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p /usr/share/ -s setfsuid -s setfsgid -s openat -s set_robust_list -s futex -s clone -s socket -s connect" +HASKELL_OPTION = "-s set_robust_list -s clock_gettime -s sysinfo -s timer_create -s timer_settime -s futex -s timer_delete" case language when "java" @@ -109,6 +110,8 @@ run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit*=2} -m #{mem_limit} #{RUBY_OPTION} -i #{input_file_name} -o output.txt /usr/bin/ruby #{program_name} " when "python" run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit*=2} -m #{[128 * 1024,mem_limit].max} #{PYTHON_OPTION} -i #{input_file_name} -o output.txt /usr/bin/python3 #{program_name} " + when "haskell" + run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit} -m #{[512 * 1024,mem_limit].max} #{HASKELL_OPTION} -i #{input_file_name} -o output.txt #{program_name} " when "php" run_command = "#{problem_home}/script/box -a 2 -f -T -t #{time_limit*=2} -m #{[128 * 1024,mem_limit].max} #{PHP_OPTION} -i #{input_file_name} -o output.txt /usr/bin/php -A -d -A memory_limit=#{mem_limit}k -A #{program_name} " else # for c++, pascal, we do the normal checking