-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathunit_tests.c
53 lines (43 loc) · 1.46 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
47
48
49
50
51
52
53
#include <criterion/criterion.h>
#include <limits.h>
#include <signal.h>
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#include <common.h>
// Include student code
#include "student_code.h"
// Include our unit test files
#include "tests/unittests_functions.c"
#include "tests/unittests_alloc.c"
#include "tests/unittests_free.c"
TestSuite(Functions, .disabled=false, .timeout=60.0);
TestSuite(Alloc, .disabled=false, .timeout=60.0);
TestSuite(Free, .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);
}
}