Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature:Autograding] Automated output and input generation #3882

Merged
merged 92 commits into from Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from 71 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
2297070
output files are now in test_output
weastel May 24, 2019
7b59f0d
Merge branch 'master' of https://github.com/Submitty/Submitty into au…
weastel May 24, 2019
3e20f93
solution are included in tmp_work
weastel May 24, 2019
a70e466
Merge branch 'master' into automated_input_and_output
weastel May 29, 2019
5010751
diff.json is now made
weastel May 30, 2019
1ee749c
Merge branch 'master' into automated_input_and_output
weastel May 30, 2019
cb8b1d9
change expected_file for imageDiff_doit
weastel May 30, 2019
0049858
Fix integration tests to add test_output folder in tmp_work
weastel Jun 1, 2019
3dbbacd
Fix json_diff when single parameter is passed
weastel Jun 1, 2019
891b5c2
Fix integration tests for minimal_code_editing
weastel Jun 1, 2019
f0519a5
Merge branch 'master' into automated_input_and_output
weastel Jun 1, 2019
0c15391
Merge branch 'master' into automated_input_and_output
weastel Jun 2, 2019
dafde2f
Fix all tests
weastel Jun 3, 2019
8d5ab77
Merge branch 'master' into automated_input_and_output
weastel Jun 4, 2019
e4a9785
Merge branch 'master' into automated_input_and_output
weastel Jun 5, 2019
6cb94c9
Merge branch 'master' into automated_input_and_output
weastel Jun 5, 2019
85c4b38
Merge branch 'master' into automated_input_and_output
weastel Jun 7, 2019
ad37dbc
Change solution directory to instructor_solution directory
weastel Jun 7, 2019
3e34df2
genrating ouput folder in generated_output
weastel Jun 8, 2019
e162ac5
Merge branch 'master' of https://github.com/Submitty/Submitty into au…
weastel Jun 8, 2019
e6c550e
Add new example for automated output as cpp_hidden_tests
weastel Jun 8, 2019
3e86881
updating functions for instructor uses
weastel Jun 8, 2019
fdc88b0
Merge branch 'master' into automated_output_generator
weastel Jun 12, 2019
2b0d0c2
View generated output in details
weastel Jun 13, 2019
b89622d
Merge branch 'master' into automated_output_generator
weastel Jun 13, 2019
90e4de4
Automated output example for python in more autograding example
weastel Jun 13, 2019
80ce45f
Merge branch 'master' into automated_output_generator
weastel Jun 13, 2019
a89a778
Change generated_output to random_output
weastel Jun 13, 2019
fac1381
View expected file for random output
weastel Jun 14, 2019
532136c
Merge branch 'master' into automated_output_generator
weastel Jun 14, 2019
7e96303
Add input generation into solution_runner.cpp
weastel Jun 15, 2019
7e297ab
Merge branch 'master' of https://github.com/Submitty/Submitty into au…
weastel Jun 18, 2019
a6d5cbc
Add more autograding example for random input
weastel Jun 18, 2019
67d12f2
add autograding example for random input and output
weastel Jun 19, 2019
6e6ca3a
Merge branch 'master' into automated_input_generator
weastel Jun 19, 2019
8ab5249
Merge branch 'master' into automated_input_generator
weastel Jun 21, 2019
3feac4f
Copy only txt files from random_input to runner and output generator
weastel Jun 21, 2019
9516fdd
set examples for only automated_output and input
weastel Jun 21, 2019
27d7af0
Merge branch 'master' into automated_input_generator
weastel Jun 25, 2019
b1def9b
refactoring code
weastel Jun 25, 2019
cc86fda
function to Grant_all_permission
weastel Jun 25, 2019
f1327f0
removing random_input files before archiving
weastel Jun 25, 2019
7a3576c
Merge branch 'master' into automated_input_generator
weastel Jun 25, 2019
133d4de
change function name for getPathForInstructor
weastel Jun 25, 2019
764c8f8
Merge branch 'master' into automated_input_generator
weastel Jun 25, 2019
0efe461
Printing in log file when only it has output.input commands
weastel Jun 25, 2019
b08c021
Merge branch 'master' into automated_input_generator
weastel Jun 26, 2019
9607923
Merge branch 'master' into automated_input_generator
bmcutler Jul 2, 2019
de901c2
Merge branch 'master' of github.com:Submitty/Submitty into automated_…
bmcutler Jul 4, 2019
0f35cde
updated random input/output test case
bmcutler Jul 4, 2019
7e8cd22
add spy program for testing security of instructor solution & generat…
bmcutler Jul 4, 2019
b27a873
modify sample courses
bmcutler Jul 4, 2019
5c23e93
Change input generation command to input_generation_command
weastel Jul 4, 2019
ec2b778
modify python random input example
bmcutler Jul 4, 2019
a7cfbf6
Merge branch 'automated_input_generator' of github.com:Submitty/Submi…
bmcutler Jul 4, 2019
7318980
new config format
bmcutler Jul 4, 2019
5bb8c5f
Add spy.py for testing security for python files
weastel Jul 5, 2019
f7a7c69
Merge branch 'master' into automated_input_generator
weastel Jul 8, 2019
08d8d13
Add remove_read_permissions
weastel Jul 10, 2019
993d8ca
Merge branch 'master' into automated_input_generator
weastel Jul 12, 2019
f8772fc
Merge branch 'master' into automated_input_generator
bmcutler Jul 15, 2019
57e66da
Merge branch 'automated_input_generator' of https://github.com/Submit…
emaicus Jul 16, 2019
375fce4
Remove remove_read_permissions from roots
weastel Jul 17, 2019
6b0fddd
Merge branch 'automated_input_generator' of https://github.com/Submit…
weastel Jul 17, 2019
9ef8a77
Merge branch 'master' into automated_input_generator
bmcutler Jul 22, 2019
0adb22d
Merge branch 'automated_input_generator' of https://github.com/Submit…
emaicus Jul 23, 2019
a01d23f
Add remove_permission_for_others_and_groups
weastel Jul 23, 2019
4bb3e5e
Merge branch 'master' of https://github.com/Submitty/Submitty into au…
weastel Jul 23, 2019
0244252
Merge branch 'automated_input_generator' of https://github.com/Submit…
weastel Jul 23, 2019
343f420
fix permissions issue
emaicus Jul 23, 2019
30eac44
Fix
emaicus Jul 23, 2019
462016b
remove main_solution runner
weastel Jul 26, 2019
15d04c0
remove additional lines of code
weastel Jul 27, 2019
9b2a2ff
remove additional lines of code
weastel Jul 27, 2019
068e62d
Merge branch 'master' into automated_input_generator
weastel Jul 27, 2019
de6ad20
Merge branch 'master' into automated_input_generator
bmcutler Jul 29, 2019
35ee6f3
add header function and change comments
weastel Jul 30, 2019
1021580
update comments
weastel Jul 30, 2019
0ac6399
Merge branch 'master' into automated_input_generator
weastel Jul 31, 2019
3dd2867
Remove header and add executeSetOfCommands
weastel Jul 31, 2019
a016f78
Merge branch 'automated_input_generator' of https://github.com/Submit…
weastel Jul 31, 2019
8a1329c
Move output generation out of the validator
emaicus Jul 31, 2019
cc20733
Fixed merge conflicts
emaicus Jul 31, 2019
ef0dcc8
Merge branch 'master' of https://github.com/Submitty/Submitty into au…
emaicus Jul 31, 2019
6d9ba20
Merge branch 'master' into automated_input_generator
bmcutler Aug 2, 2019
ea46b7e
update
weastel Aug 2, 2019
53eb35b
update and add comments
weastel Aug 2, 2019
31dd3ba
Remove 'autograding' entry for work_to_random_output
emaicus Aug 2, 2019
c17d690
Remove work_to_random_output
emaicus Aug 2, 2019
4f14cd0
Merge branch 'master' of https://github.com/Submitty/Submitty into au…
emaicus Aug 2, 2019
aa18c5e
Fixes
emaicus Aug 2, 2019
199ad1c
Merge branch 'master' of https://github.com/Submitty/Submitty into au…
emaicus Aug 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 43 additions & 1 deletion .setup/data/courses/development.yml
Expand Up @@ -169,7 +169,28 @@ gradeables:
g_grade_released_date: +1010 days
eg_regrade_request_date: +1015 days
eg_max_random_submissions: 0


- gradeable_config: cpp_random_input_output
components:
- gc_lower_clamp: 0
gc_default: 5
gc_max_value: 5
gc_upper_clamp: 5
gc_title: Question 1
marks:
- gcm_note: Full Credit
gcm_points : 0
- gcm_note: Question 1 Mark 1
gcm_points : -5
g_ta_view_start_date: -2 days
eg_submission_open_date: -1 days
eg_submission_due_date: +1000 days
g_grade_start_date: +1005 days
g_grade_due_date: +1010 days
g_grade_released_date: +1010 days
eg_regrade_request_date: +1015 days
eg_max_random_submissions: 0

- gradeable_config: early_submission_incentive
components:
- gc_lower_clamp: 0
Expand Down Expand Up @@ -443,6 +464,27 @@ gradeables:
eg_regrade_request_date: +1015 days
eg_max_random_submissions: 0

- gradeable_config: python_random_input_output
components:
- gc_lower_clamp: 0
gc_default: 5
gc_max_value: 5
gc_upper_clamp: 5
gc_title: Question 1
marks:
- gcm_note: Full Credit
gcm_points : 0
- gcm_note: Question 1 Mark 1
gcm_points : -5
g_ta_view_start_date: -2 days
eg_submission_open_date: -1 days
eg_submission_due_date: +1000 days
g_grade_start_date: +1005 days
g_grade_due_date: +1010 days
g_grade_released_date: +1010 days
eg_regrade_request_date: +1015 days
eg_max_random_submissions: 0

- gradeable_config: test_notes_upload
components:
- gc_lower_clamp: 0
Expand Down
165 changes: 140 additions & 25 deletions autograder/autograder/grade_item.py
Expand Up @@ -122,15 +122,13 @@ def zip_my_directory(path,zipfilename):
zipf.write(os.path.join(root,my_file),os.path.join(relpath,my_file))
zipf.close()


def unzip_this_file(zipfilename,path):
if not os.path.exists(zipfilename):
raise RuntimeError("ERROR: zip file does not exist '", zipfilename, "'")
zip_ref = zipfile.ZipFile(zipfilename,'r')
zip_ref.extractall(path)
zip_ref.close()


def allow_only_one_part(path, log_path=os.devnull):
"""
Given a path to a directory, iterate through the directory and detect folders that start with
Expand Down Expand Up @@ -190,6 +188,14 @@ def remove_test_input_files(overall_log,test_input_path,testcase_folder):
print ("removing (likely) stale test_input file: ", my_file, file=f)
os.remove(my_file)

def add_all_permissions(folder):
add_permissions_recursive(folder,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)

def remove_read_permissions(top_dir):
os.chmod(top_dir,os.stat(top_dir).st_mode & ~stat.S_IRGRP & ~stat.S_IWGRP & ~stat.S_IXGRP & ~stat.S_IROTH & ~stat.S_IWOTH & ~stat.S_IXOTH)

def grade_from_zip(my_autograding_zip_file,my_submission_zip_file,which_untrusted):

Expand Down Expand Up @@ -370,10 +376,7 @@ def grade_from_zip(my_autograding_zip_file,my_submission_zip_file,which_untruste
add_permissions(os.path.join(testcase_folder,"my_compile.out"), stat.S_IXUSR | stat.S_IXGRP |stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
#untrusted_grant_rwx_access(which_untrusted, tmp_compilation)
untrusted_grant_rwx_access(which_untrusted, testcase_folder)
add_permissions_recursive(testcase_folder,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
add_all_permissions(testcase_folder)

if USE_DOCKER:
try:
Expand Down Expand Up @@ -431,22 +434,17 @@ def grade_from_zip(my_autograding_zip_file,my_submission_zip_file,which_untruste
else:
print (which_machine,which_untrusted,"COMPILATION FAILURE")
grade_items_logging.log_message(job_id,is_batch_job,which_untrusted,item_name,message="COMPILATION FAILURE")
add_permissions_recursive(tmp_compilation,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)


add_all_permissions(tmp_compilation)

# return to the main tmp directory
os.chdir(tmp)


# --------------------------------------------------------------------
# make the runner directory

# --------------------------------------------------------------------
# RUN INPUT GENERATION
with open(os.path.join(tmp_logs,"overall.txt"),'a') as f:
print ("====================================\nRUNNER STARTS", file=f)
print ("====================================\nINPUT GENERATION STARTS", file=f)

tmp_work = os.path.join(tmp,"TMP_WORK")
tmp_work_test_input = os.path.join(tmp_work, "test_input")
tmp_work_test_output = os.path.join(tmp_work, "test_output")
Expand All @@ -466,6 +464,60 @@ def grade_from_zip(my_autograding_zip_file,my_submission_zip_file,which_untruste

os.chdir(tmp_work)

#random_input_tmp_work = os.path.join(tmp_work,"random_input")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these newly added, commented out lines

#os.mkdir(random_input_tmp_work)

with open(os.path.join(tmp_logs,"input_generator_log.txt"), 'w') as logfile:
for testcase_num in range(1, len(my_testcases)+1):
random_input_testcase_folder = os.path.join(tmp_work,"random_input", "test{:02}".format(testcase_num))
bmcutler marked this conversation as resolved.
Show resolved Hide resolved

os.makedirs(random_input_testcase_folder)
os.chdir(random_input_testcase_folder)

# copy any instructor provided solution code files to testcase folder
copy_contents_into(job_id,instructor_solution_path,random_input_testcase_folder,tmp_logs)

# copy compile.out to the current directory
shutil.copy (os.path.join(bin_path,"solution_runner.out"),os.path.join(random_input_testcase_folder,"my_solution_runner.out"))
add_permissions(os.path.join(random_input_testcase_folder,"my_solution_runner.out"), stat.S_IXUSR | stat.S_IXGRP |stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
untrusted_grant_rwx_access(which_untrusted, random_input_testcase_folder)
add_all_permissions(random_input_testcase_folder)

inout_generator_success = subprocess.call([os.path.join(SUBMITTY_INSTALL_DIR, "sbin", "untrusted_execute"),
which_untrusted,
os.path.join(random_input_testcase_folder,"my_solution_runner.out"),
queue_obj["gradeable"],
queue_obj["who"],
str(queue_obj["version"]),
submission_string,
"input",
'--testcase', str(testcase_num)],
stdout=logfile,
cwd=random_input_testcase_folder)
# remove the compilation program
untrusted_grant_rwx_access(which_untrusted, random_input_testcase_folder)
os.remove(os.path.join(random_input_testcase_folder,"my_solution_runner.out"))

if inout_generator_success == 0:
print (which_machine,which_untrusted,"INPUT GENERATOR OK")
else:
print (which_machine,which_untrusted,"INPUT GENERATOR FAILURE")
grade_items_logging.log_message(job_id,is_batch_job,which_untrusted,item_name,message="INPUT GENERATOR FAILURE")

# return to the main tmp directory
os.chdir(tmp_work)
subprocess.call(['ls', '-lR', '.'], stdout=open(tmp_logs + "/overall.txt", 'a'))

# --------------------------------------------------------------------

# --------------------------------------------------------------------
# make the runner directory

with open(os.path.join(tmp_logs,"overall.txt"),'a') as f:
print ("====================================\nRUNNER STARTS", file=f)

os.chdir(tmp_work)

# move all executable files from the compilation directory to the main tmp directory
# Note: Must preserve the directory structure of compiled files (esp for Java)

Expand Down Expand Up @@ -531,14 +583,58 @@ def grade_from_zip(my_autograding_zip_file,my_submission_zip_file,which_untruste
print (which_machine,which_untrusted, "RUNNER FAILURE")
grade_items_logging.log_message(job_id, is_batch_job, which_untrusted, item_name, message="RUNNER FAILURE")

add_permissions_recursive(tmp_work,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
add_permissions_recursive(tmp_compilation,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
# RUN SOLUTION RUNNER
with open(os.path.join(tmp_logs,"overall.txt"),'a') as f:
print ("====================================\nRUNNER SOLUTION STARTS", file=f)
tmp_work_random_output = os.path.join(tmp_work,"random_output")
os.mkdir(tmp_work_random_output)

with open(os.path.join(tmp_logs,"output_generator_log.txt"), 'w') as logfile:
for testcase_num in range(1, len(my_testcases)+1):
testcase_folder = os.path.join(tmp_work_random_output, "test{:02}".format(testcase_num))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, let's add an "if no need to run output generation continue" here

random_input_testcase_folder = os.path.join(tmp_work, "random_input", "test{:02}".format(testcase_num))
os.makedirs(testcase_folder)
os.chdir(testcase_folder)

# copy any instructor provided solution code files to testcase folder
copy_contents_into(job_id,instructor_solution_path,testcase_folder,tmp_logs)

# copy test input into testcase folder
copy_contents_into(job_id,test_input_path,testcase_folder,tmp_logs)
pattern_copy("random_input_to_runner",["*.txt"],random_input_testcase_folder,testcase_folder,tmp_logs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the random input is not a .txt file?
(I know I said we didn't need to worry about this for version 1.0, so maybe we can ignore this, but let's add a comment at least)
This is preventing us from pull generator.py & solution.py into the test case -- but it's sloppy.


# copy compile.out to the current directory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't accurate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed compile.out to run.out

shutil.copy (os.path.join(bin_path,"solution_runner.out"),os.path.join(testcase_folder,"my_solution_runner.out"))
add_permissions(os.path.join(testcase_folder,"my_solution_runner.out"), stat.S_IXUSR | stat.S_IXGRP |stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH)
untrusted_grant_rwx_access(which_untrusted, testcase_folder)
add_all_permissions(testcase_folder)

output_generator_success = subprocess.call([os.path.join(SUBMITTY_INSTALL_DIR, "sbin", "untrusted_execute"),
which_untrusted,
os.path.join(testcase_folder,"my_solution_runner.out"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution won't work for networked gradeables. I'll handle this in the upcoming refactor.

queue_obj["gradeable"],
queue_obj["who"],
str(queue_obj["version"]),
submission_string,
"output",
'--testcase', str(testcase_num)],
stdout=logfile,
cwd=testcase_folder)
# remove the compilation program
untrusted_grant_rwx_access(which_untrusted, testcase_folder)
os.remove(os.path.join(testcase_folder,"my_solution_runner.out"))

if output_generator_success == 0:
print (which_machine,which_untrusted,"OUTPUT GENERATION OK")
else:
print (which_machine,which_untrusted,"OUTPUT GENERATION FAILURE")
grade_items_logging.log_message(job_id,is_batch_job,which_untrusted,item_name,message="OUTPUT GENERATION FAILURE")
add_all_permissions(tmp_work)
add_all_permissions(tmp_compilation)

# return to the main tmp directory
os.chdir(tmp_work)
subprocess.call(['ls', '-lR', '.'], stdout=open(tmp_logs + "/overall.txt", 'a'))

# --------------------------------------------------------------------
# RUN VALIDATOR
Expand Down Expand Up @@ -646,14 +742,33 @@ def grade_from_zip(my_autograding_zip_file,my_submission_zip_file,which_untruste
# remove the test_input directory, so we don't archive it!
shutil.rmtree(os.path.join(tmp_work,"test_input"))

# remove the test_output directory, so we don't archive it!
shutil.rmtree(os.path.join(tmp_work,"test_output"))

# loop over the test case directories, and remove any files that are also in the test_input folder
for testcase_num in range(1, len(my_testcases)+1):
testcase_folder = os.path.join(tmp_work, "test{:02}".format(testcase_num))
random_input_testcase_folder = os.path.join(tmp_work,"random_input","test{:02}".format(testcase_num))
remove_test_input_files(os.path.join(tmp_logs,"overall.txt"),test_input_path,testcase_folder)
remove_test_input_files(os.path.join(tmp_logs,"overall.txt"),random_input_testcase_folder,testcase_folder)

# loop over the random output test case directories, and remove any files that are also in the test_input folder
for testcase_num in range(1, len(my_testcases)+1):
testcase_folder = os.path.join(tmp_work,"random_output", "test{:02}".format(testcase_num))
random_input_testcase_folder = os.path.join(tmp_work,"random_input","test{:02}".format(testcase_num))
remove_test_input_files(os.path.join(tmp_logs,"overall.txt"),test_input_path,testcase_folder)
remove_test_input_files(os.path.join(tmp_logs,"overall.txt"),random_input_testcase_folder,testcase_folder)

patterns_work_to_details = complete_config_obj["autograding"]["work_to_details"]
pattern_copy("work_to_details",patterns_work_to_details,tmp_work,os.path.join(tmp_results,"details"),tmp_logs)

try:
patterns_work_to_random_output = complete_config_obj["autograding"]["work_to_random_output"]
pattern_copy("work_to_random_output", patterns_work_to_random_output, tmp_results, tmp_logs)
except:
with open(os.path.join(tmp_logs,"overall.txt"),'a') as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message isn't actually logged. Call print with file=f, or, better, use f.write, but don't forget a newline!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why hasn't this been resolved?

print ("Sorry this is not working")

if ("work_to_public" in complete_config_obj["autograding"] and
len(complete_config_obj["autograding"]["work_to_public"]) > 0):
# create the directory
Expand Down
10 changes: 7 additions & 3 deletions autograder/autograder/grade_item_main_runner.py
Expand Up @@ -83,7 +83,7 @@ def executeTestcases(complete_config_obj, tmp_logs, tmp_work, queue_obj, submiss
for name, info in container_info.items():
mounted_directory = info['mounted_directory']
#Copies the code needed to run into mounted_directory
setup_folder_for_grading(mounted_directory, tmp_work, job_id, tmp_logs,testcases[testcase_num-1])
setup_folder_for_grading(mounted_directory, tmp_work, job_id, tmp_logs,testcases[testcase_num-1],testcase_num)


# Start the docker containers.
Expand Down Expand Up @@ -168,8 +168,9 @@ def executeTestcases(complete_config_obj, tmp_logs, tmp_work, queue_obj, submiss
else:
try:
# Move the files necessary for grading (runner, inputs, etc.) into the testcase folder.
setup_folder_for_grading(testcase_folder, tmp_work, job_id, tmp_logs,testcases[testcase_num-1])
setup_folder_for_grading(testcase_folder, tmp_work, job_id, tmp_logs,testcases[testcase_num-1],testcase_num)
my_testcase_runner = os.path.join(testcase_folder, 'my_runner.out')
grade_item.remove_read_permissions(os.path.join(tmp_work,"random_input"))

display_sys_variable = os.environ.get('DISPLAY', None)
display_line = [] if display_sys_variable is None else ['--display', str(display_sys_variable)]
Expand All @@ -184,6 +185,7 @@ def executeTestcases(complete_config_obj, tmp_logs, tmp_work, queue_obj, submiss
'--testcase', str(testcase_num)]
+ display_line,
stdout=logfile)
grade_item.add_all_permissions(os.path.join(tmp_work,"random_input"))
except Exception as e:
grade_items_logging.log_message(job_id, message="ERROR thrown by main runner. See traces entry for more details.")
print ("ERROR caught runner.out exception={0}".format(str(e.args[0])).encode("utf-8"),file=logfile)
Expand Down Expand Up @@ -294,12 +296,13 @@ def pre_command_copy_file(tmp_work, source_testcase, source_directory, destinati



def setup_folder_for_grading(target_folder, tmp_work, job_id, tmp_logs, testcase):
def setup_folder_for_grading(target_folder, tmp_work, job_id, tmp_logs, testcase, testcase_num):
#The paths to the important folders.
tmp_work_test_input = os.path.join(tmp_work, "test_input")
tmp_work_submission = os.path.join(tmp_work, "submitted_files")
tmp_work_compiled = os.path.join(tmp_work, "compiled_files")
tmp_work_checkout = os.path.join(tmp_work, "checkout")
tmp_work_random_input = os.path.join(tmp_work, "random_input", "test{:02}".format(testcase_num))
my_runner = os.path.join(tmp_work,"my_runner.out")

#######################################################################################
Expand Down Expand Up @@ -332,6 +335,7 @@ def setup_folder_for_grading(target_folder, tmp_work, job_id, tmp_logs, testcase
grade_item.copy_contents_into(job_id,tmp_work_compiled ,target_folder,tmp_logs)
grade_item.copy_contents_into(job_id,tmp_work_checkout ,target_folder,tmp_logs)
grade_item.copy_contents_into(job_id,tmp_work_test_input,target_folder,tmp_logs)
grade_item.pattern_copy("random_input_to_runner",["*.txt"],tmp_work_random_input,target_folder,tmp_logs)
#copy the compiled runner to the test directory
shutil.copy(my_runner,target_folder)

Expand Down