diff options
author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/c/selfCheck.c | |
parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/c/selfCheck.c')
-rw-r--r-- | SD-VBS/common/c/selfCheck.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/SD-VBS/common/c/selfCheck.c b/SD-VBS/common/c/selfCheck.c new file mode 100644 index 0000000..e79a6a4 --- /dev/null +++ b/SD-VBS/common/c/selfCheck.c | |||
@@ -0,0 +1,65 @@ | |||
1 | /******************************** | ||
2 | Author: Sravanthi Kota Venkata | ||
3 | ********************************/ | ||
4 | |||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <math.h> | ||
8 | #include "sdvbs_common.h" | ||
9 | |||
10 | int selfCheck(I2D* in1, char* path, int tol) | ||
11 | { | ||
12 | int r1, c1, ret=1; | ||
13 | FILE* fd; | ||
14 | int count=0, *buffer, i, j; | ||
15 | char file[100]; | ||
16 | int* data = in1->data; | ||
17 | |||
18 | r1 = in1->height; | ||
19 | c1 = in1->width; | ||
20 | |||
21 | buffer = (int*)malloc(sizeof(int)*r1*c1); | ||
22 | |||
23 | sprintf(file, "%s", path); | ||
24 | fd = fopen(file, "r"); | ||
25 | if(fd == NULL) | ||
26 | { | ||
27 | printf("Error: Expected file not opened \n"); | ||
28 | return -1; | ||
29 | } | ||
30 | |||
31 | while(!feof(fd)) | ||
32 | { | ||
33 | fscanf(fd, "%d", &buffer[count]); | ||
34 | count++; | ||
35 | } | ||
36 | count--; | ||
37 | |||
38 | if(count < (r1*c1)) | ||
39 | { | ||
40 | printf("Checking error: dimensions mismatch. Expected = %d, Observed = %d \n", count, (r1*c1)); | ||
41 | return -1; | ||
42 | } | ||
43 | |||
44 | for(i=0; i<r1*c1; i++) | ||
45 | { | ||
46 | if((abs(data[i])-abs(buffer[i]))>tol || (abs(buffer[i])-abs(data[i]))>tol) | ||
47 | { | ||
48 | printf("Checking error: Values mismtach at %d element\n", i); | ||
49 | printf("Expected value = %d, observed = %d\n", buffer[i], data[i] ); | ||
50 | return -1; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | fclose(fd); | ||
55 | free(buffer); | ||
56 | printf("Verification\t\t- Successful\n"); | ||
57 | return ret; | ||
58 | } | ||
59 | |||
60 | |||
61 | |||
62 | |||
63 | |||
64 | |||
65 | |||