Β©οΈAdvanced C Autograding
Discover the advanced autograding options for C assignments
In this guide, we explore the advanced grading options available for C assignments. For more information about setting up a C assignment from scratch, see:
Β©οΈCreate your first C assignmentCheck Unit Tests
Check is an industry-standard unit testing framework for C. It is particularly useful for grading assignments that require students to write functions and classes. Unit testing with check offers several advantages over conventional IO testing including the ability to use assertions, parametrize test cases, and provide better feedback for students. Consider the example submission below:
#ifndef BUBBLESORT_H
#define BUBBLESORT_H
void bubbleSort(int arr[], int n);
#endif // BUBBLESORT_H#include "bubble_sort.h"
void bubble_sort(int arr[], int n) {
int i, j, temp;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
// Swap arr[j] and arr[j+1]
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}In this example, students have been tasked with creating the bubble_sort() function. We can create robust test cases to check this submission using assertions from the check unit testing framework.
"cg junitxml" command
We could simply compile and run the test cases to show students a simple pass or fail depending on the exit code of the tests. However, we wouldn't be able to award partial marks for each test case unless we parsed the results of the unit tests. To accomplish that, we can use the cg junitxml command. This command allows us to parse the number of test cases passed and the feedback from failed test cases from any unit test report written in the JUnit XML format.
Running the command cg junitxml --help shows the following information:
The cg junitxml command works well in combination with the Custom Test block by displaying the results of the parsed JUnit XML report beautifully, making it easy to read and interpret, as shown in the image below.

Unfortunately, the check framework doesn't have a method for automatically outputting JUnit XML. Instead we can use the srunner_set_xml() command to generate an XML report (in check's own format) and use the following script to convert that into the JUnit XML format.
Instructions

In the AutoTest settings, navigate to the Setup tab.
Add an Install GCC block to your setup configuration.
Add a Script block to your setup configuration and install check with the following command.
In the AutoTest settings, navigate to the Tests tab.
Add an Upload Files block. Upload
bubble_sort.h,unit_test.c, andjunit_xml.py.Add a Script block. Move all the uploaded files to the student's directory and compile
bubble_sort.cwith the following commands.Add a Connect Rubric block and a Custom Test block. Nest the Custom Test block within the Connect Rubric block. Run the unit tests and parse the results with the following commands.
Build and publish your snapshot.
Clang-tidy
Clang-tidy is an industry-standard static analysis tool for C, C++, and Objective-C that allows you to diagnose and fix code style violations, interface misuse, and bugs. It is a useful tool for enforcing code styling best practices for beginner programmers.
"cg comments" command
Simply running clang-tidy would allow us to produce the default command line output. However, this wouldn't be particularly useful for students as they would have to spend time interpreting the output and would have to switch back and forth between the AutoTest output and their code. Instead, we can use the cg comments command to parse the output of clang-tidy and write the comments directly onto our students' code. The cg comments command will highlight each target line according to the severity of the comment and can be read by hovering over the line number with the mouse cursor. The comments are also placed on students' code in the editor, making it a powerful combination.


Instructions

In the AutoTest settings, navigate to the Setup tab.
Add a Script block. Install clang-tidy using the following command.
In the AutoTest settings, navigate to the Tests tab.
Add a Connect Rubric block and a Custom Test block. Nest the Custom Test block in the Connect Rubric block. Run clang-tidy and parse the output using the following commands.
Build and Publish your snapshot.
Last updated