-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathunit_tests.c
46 lines (37 loc) · 1.33 KB
/
unit_tests.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <criterion/criterion.h>
#include <signal.h>
#include <common.h>
#include <time.h>
// Include src headers
#include "student_code.h"
#include "defines.h"
// Define any testing parameters
#define NUMBER_OF_REPEATS 10
// Include unit tests
#include "tests/unittests_functions.c"
#include "tests/unittests_mmu_pagetable.c"
TestSuite(Functions, .disabled=false, .timeout=60.0);
TestSuite(MMU_PageTable, .disabled=false, .timeout=60.0);
// From: https://github.com/codewars/criterion-hooks/blob/main/criterion-hooks.c
// PRE_TEST: occurs after the test initialization, but before the test is run.
ReportHook(PRE_TEST)(struct criterion_test *test) {
log_info("Starting test: %s\n", test->name)
}
// From: https://github.com/codewars/criterion-hooks/blob/main/criterion-hooks.c
// TEST_CRASH: occurs when a test crashes unexpectedly.
ReportHook(TEST_CRASH)(struct criterion_test_stats *stats) {
log_error("Test Crashed. Caught unexpected signal: ");
switch (stats->signal) {
case SIGILL:
log_error("SIGILL (%d). %s\n", stats->signal, "Invalid instruction.");
break;
case SIGFPE:
log_error("SIGFPE (%d). %s\n", stats->signal, "Erroneous arithmetic operation.");
break;
case SIGSEGV:
log_error("SIGSEGV (%d). %s\n", stats->signal, "Invalid memory access.");
break;
default:
log_error("%d\n", stats->signal);
}
}