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/fSelfCheck.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/fSelfCheck.c')
| -rw-r--r-- | SD-VBS/common/c/fSelfCheck.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/SD-VBS/common/c/fSelfCheck.c b/SD-VBS/common/c/fSelfCheck.c new file mode 100644 index 0000000..fe146b5 --- /dev/null +++ b/SD-VBS/common/c/fSelfCheck.c | |||
| @@ -0,0 +1,59 @@ | |||
| 1 | /******************************** | ||
| 2 | Author: Sravanthi Kota Venkata | ||
| 3 | ********************************/ | ||
| 4 | |||
| 5 | #include "sdvbs_common.h" | ||
| 6 | |||
| 7 | int fSelfCheck(F2D* in1, char* path, float tol) | ||
| 8 | { | ||
| 9 | int r1, c1, ret=1; | ||
| 10 | float *buffer; | ||
| 11 | FILE* fd; | ||
| 12 | int count=0, i, j; | ||
| 13 | char file[256]; | ||
| 14 | |||
| 15 | r1 = in1->height; | ||
| 16 | c1 = in1->width; | ||
| 17 | |||
| 18 | buffer = (float*)malloc(sizeof(float)*r1*c1); | ||
| 19 | |||
| 20 | sprintf(file, "%s", path); | ||
| 21 | fd = fopen(file, "r"); | ||
| 22 | |||
| 23 | if(fd == NULL) | ||
| 24 | { | ||
| 25 | printf("Error: Expected file not opened %s\n", file); | ||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | |||
| 29 | while(!feof(fd)) | ||
| 30 | { | ||
| 31 | fscanf(fd, "%f", &buffer[count]); | ||
| 32 | count++; | ||
| 33 | } | ||
| 34 | count--; | ||
| 35 | |||
| 36 | if(count != (r1*c1)) | ||
| 37 | { | ||
| 38 | printf("Checking error: dimensions mismatch. Expected = %d, Observed = %d \n", count, (r1*c1)); | ||
| 39 | return -1; | ||
| 40 | } | ||
| 41 | |||
| 42 | for(i=0; i<r1*c1; i++) | ||
| 43 | { | ||
| 44 | float inVal = asubsref(in1,i); | ||
| 45 | |||
| 46 | if( (inVal-buffer[i])>tol || (buffer[i]-inVal)>tol ) | ||
| 47 | { | ||
| 48 | printf("Mismatch %d: (%f, %f)\n", i, buffer[i], inVal); | ||
| 49 | return -1; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | fclose(fd); | ||
| 54 | printf("Verification\t\t- Successful\n"); | ||
| 55 | free(buffer); | ||
| 56 | return ret; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
