-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathmain.c
More file actions
74 lines (61 loc) · 1.83 KB
/
main.c
File metadata and controls
74 lines (61 loc) · 1.83 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libtock-sync/peripherals/crc.h>
#include <libtock-sync/peripherals/rng.h>
#include <libtock-sync/services/alarm.h>
struct test_case {
libtock_crc_alg_t alg;
uint32_t output;
char* input;
};
#define CASE(alg, output, input) char input_##alg##_##output [] = input;
#include "test_cases.h"
#undef CASE
static struct test_case test_cases[] = {
#define CASE(alg, output, input) \
{ alg, output, input_##alg##_##output },
#include "test_cases.h"
#undef CASE
};
int n_test_cases = sizeof(test_cases) / sizeof(struct test_case);
uint32_t procid;
int main(void) {
int r;
printf("[CRC Test] This app tests the CRC syscall interface\n");
// Get a random number to distinguish this app instance
int num_bytes;
r = libtocksync_rng_get_random_bytes((uint8_t*) &procid, 4, 4, &num_bytes);
if (r != RETURNCODE_SUCCESS || num_bytes != 4) {
printf("RNG failure\n");
exit(1);
}
if (!libtocksync_crc_exists()) {
printf("CRC driver does not exist\n");
exit(1);
}
while (1) {
for (int test_index = 0; test_index < n_test_cases; test_index++) {
struct test_case* t = &test_cases[test_index];
uint32_t result;
if ((r = libtocksync_crc_compute((uint8_t*) t->input, strlen(t->input), t->alg, &result)) != RETURNCODE_SUCCESS) {
printf("CRC compute failed: %s\n", tock_strrcode(r));
exit(1);
}
printf("[%8lx] Case %2d: ", procid, test_index);
if (r == RETURNCODE_SUCCESS) {
printf("result=%08lx ", result);
if (result == t->output) {
printf("(OK)");
} else {
printf("(Expected %08lx)", t->output);
}
} else {
printf("failed with status %d\n", r);
}
printf("\n");
}
printf("\n");
libtocksync_alarm_delay_ms(1000);
}
}