More tests added

This commit is contained in:
lcbcFoo 2018-04-15 19:32:46 -03:00
parent c4fd14d49c
commit 4b3160f9a2
11 changed files with 633 additions and 29 deletions

View file

@ -1,5 +1,5 @@
bload wcet_benchmark/insertsort.out
ep 0x40001000
run
dump -binary 0x44000000 1 ../../riscv/res.bin
quit

View file

@ -31,7 +31,7 @@ char* console_buffer;
// Internal
static char* heap;
static char* out_mem;
char* out_mem;
static LEON23_APBUART_Regs_Map *uart_regs;
/* Sends output via UART, adapted from BCC source code */

131
riscv/wcet_benchmark/bs.c Normal file
View file

@ -0,0 +1,131 @@
/*************************************************************************/
/* */
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
/* ===================================================== */
/* Collected and Modified by S.-S. Lim */
/* sslim@archi.snu.ac.kr */
/* Real-Time Research Group */
/* Seoul National University */
/* */
/* */
/* < Features > - restrictions for our experimental environment */
/* */
/* 1. Completely structured. */
/* - There are no unconditional jumps. */
/* - There are no exit from loop bodies. */
/* (There are no 'break' or 'return' in loop bodies) */
/* 2. No 'switch' statements. */
/* 3. No 'do..while' statements. */
/* 4. Expressions are restricted. */
/* - There are no multiple expressions joined by 'or', */
/* 'and' operations. */
/* 5. No library calls. */
/* - All the functions needed are implemented in the */
/* source file. */
/* */
/* */
/*************************************************************************/
/* */
/* FILE: bs.c */
/* SOURCE : Public Domain Code */
/* */
/* DESCRIPTION : */
/* */
/* Binary search for the array of 15 integer elements. */
/* */
/* REMARK : */
/* */
/* EXECUTION TIME : */
/* */
/* */
/*************************************************************************/
#ifdef TEST
#include "../mini_printf.h"
#include "../posix_c.h"
#else
#include <stdio.h>
#endif
struct DATA {
int key;
int value;
} ;
#ifdef DEBUG
int cnt1;
#endif
int binary_search(struct DATA data[],int x);
void main()
{
struct DATA data[30] = {
{1, 100},
{5,200},
{6, 300},
{7, 700},
{8, 900},
{9, 250},
{10, 400},
{11, 600},
{12, 800},
{13, 1500},
{14, 1200},
{15, 110},
{16, 140},
{17, 133},
{18, 10},
{19, 1040},
{20,2040},
{21, 350},
{22, 7410},
{23, 90043},
{24, 25340},
{25, 4310},
{26, 60970},
{27, 8780},
{28, 6500},
{29, 210},
{30, 1761},
{31, 14123},
{32, 15433},
{33, 164} };
int res = binary_search(data, 29);
#ifdef TEST
if(res == 210){
int ok = 1;
memcpy(out_mem, &ok, sizeof(int));
return;
}
int ok = 0;
memcpy(out_mem, &ok, sizeof(int));
#endif
}
int binary_search(struct DATA data[], int x)
{
int fvalue, mid, up, low ;
low = 0;
up = 29;
fvalue = -1 /* all data are positive */ ;
while (low <= up) {
mid = (low + up) >> 1;
if ( data[mid].key == x ) { /* found */
up = low - 1;
fvalue = data[mid].value;
}
else /* not found */
if ( data[mid].key > x ) {
up = mid - 1;
}
else {
low = mid + 1;
}
}
return fvalue;
}

View file

@ -54,13 +54,19 @@ int vector[];
}
}
}
int sorted = 1;
for(int j = 0; j < NUMELEMS -1 ; j++)
if(vector[j] > vector[j + 1]){
printf("%d\n", 0);
#ifdef TEST
for(int i = 0; i < NUMELEMS -1 ; i++){
if(vector[i] > vector[i + 1]){
j = 0;
memcpy(out_mem, &j, sizeof(int));
return;
}
printf("%d\n", 1);
}
j = 1;
memcpy(out_mem, &j, sizeof(int));
#endif
}

View file

@ -72,9 +72,17 @@ int main()
a = 30;
a = fib(a);
if(a == 832040)
printf("%d\n", 1);
else
printf("%d\n", 0);
return a;
#ifdef TEST
if(a == 832040){
int i = 1;
memcpy(out_mem, &i, sizeof(int));
return 0;
}
int i = 0;
memcpy(out_mem, &i, sizeof(int));
#endif
return 0;
}

View file

@ -76,11 +76,18 @@ int main()
i++;
}
for(int i = 0; i < 10; i++)
#ifdef TEST
for(int i = 0; i < 11 - 1; i++){
if(a[i] > a[i + 1]){
printf("%d\n", 0);
j = 0;
memcpy(out_mem, &j, sizeof(int));
return 0;
}
printf("%d\n", 1);
}
j = 1;
memcpy(out_mem, &j, sizeof(int));
#endif
return 0;
}

View file

@ -139,13 +139,19 @@ void Multiply(matrix A, matrix B, matrix Res)
}
// Check result
#ifdef TEST
for(int i = 0; i < UPPERLIMIT; i++){
for(int j = 0; j < UPPERLIMIT; j++){
if(Res[i][j] != correct[i][j]){
printf("%d ", correct[i][j]);
int ok = 0;
memcpy(out_mem, &ok, sizeof(int));
return;
}
}
}
printf("%d\n", 1);
int ok = 1;
memcpy(out_mem, &ok, sizeof(int));
#endif
}

257
riscv/wcet_benchmark/ndes.c Normal file
View file

@ -0,0 +1,257 @@
/* MDH WCET BENCHMARK SUITE. */
/* 2012/10/03, Jan Gustafsson <jan.gustafsson@mdh.se>
* Changes:
* - init of "is" fixed (added a lot of brackets)
* - warning: array subscript is of type 'char': fixed in three places
*/
/* #include <math.h> -- no include files in Uppsala tests, plz */
#ifdef TEST
#include "../mini_printf.h"
#include "../posix_c.h"
#else
#include <stdio.h>
#endif
/* All output disabled for wcsim */
/* A read from this address will result in an known value of 1 */
/* #define KNOWN_VALUE (int)(*((char *)0x80200001)) Changed JG/Ebbe */
#define KNOWN_VALUE 1
/* A read from this address will result in an unknown value */
//#define UNKNOWN_VALUE (int)(*((char *)0x80200003))
#define WORSTCASE 1
typedef struct IMMENSE { unsigned long l, r; } immense;
typedef struct GREAT { unsigned long l, c, r; } great;
unsigned long bit[33];
static immense icd;
static char ipc1[57]={0,57,49,41,33,25,17,9,1,58,50,
42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,
52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,
30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4};
static char ipc2[49]={0,14,17,11,24,1,5,3,28,15,6,21,
10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,
37,47,55,30,40,51,45,33,48,44,49,39,56,34,
53,46,42,50,36,29,32};
void des(immense inp, immense key, int * newkey, int isw, immense * out);
unsigned long getbit(immense source, int bitno, int nbits);
void ks(/*immense key, */int n, great * kn);
void cyfun(unsigned long ir, great k, unsigned long * iout);
void des(immense inp, immense key, int * newkey, int isw, immense * out) {
static char ip[65] =
{0,58,50,42,34,26,18,10,2,60,52,44,36,
28,20,12,4,62,54,46,38,30,22,14,6,64,56,48,40,
32,24,16,8,57,49,41,33,25,17,9,1,59,51,43,35,
27,19,11,3,61,53,45,37,29,21,13,5,63,55,47,39,
31,23,15,7};
static char ipm[65]=
{0,40,8,48,16,56,24,64,32,39,7,47,15,
55,23,63,31,38,6,46,14,54,22,62,30,37,5,45,13,
53,21,61,29,36,4,44,12,52,20,60,28,35,3,43,11,
51,19,59,27,34,2,42,10,50,18,58,26,33,1,41,9,
49,17,57,25};
static great kns[17];
#ifdef WORSTCASE
static int initflag=1;
#else
static int initflag=0;
#endif
int ii,i,j,k;
unsigned long ic,shifter,getbit();
immense itmp;
great pg;
if (initflag) {
initflag=0;
bit[1]=shifter=1L;
for(j=2;j<=32;j++) bit[j] = (shifter <<= 1);
}
if (*newkey) {
*newkey=0;
icd.r=icd.l=0L;
for (j=28,k=56;j>=1;j--,k--) {
icd.r = (icd.r <<= 1) | getbit(key,ipc1[j],32);
icd.l = (icd.l <<= 1) | getbit(key,ipc1[k],32);
}
for(i=1;i<=16;i++) {pg = kns[i]; ks(/* key,*/ i, &pg); kns[i] = pg;}
}
itmp.r=itmp.l=0L;
for (j=32,k=64;j>=1;j--,k--) {
itmp.r = (itmp.r <<= 1) | getbit(inp,ip[j],32);
itmp.l = (itmp.l <<= 1) | getbit(inp,ip[k],32);
}
for (i=1;i<=16;i++) {
ii = (isw == 1 ? 17-i : i);
cyfun(itmp.l, kns[ii], &ic);
ic ^= itmp.r;
itmp.r=itmp.l;
itmp.l=ic;
}
ic=itmp.r;
itmp.r=itmp.l;
itmp.l=ic;
(*out).r=(*out).l=0L;
for (j=32,k=64; j >= 1; j--, k--) {
(*out).r = ((*out).r <<= 1) | getbit(itmp,ipm[j],32);
(*out).l = ((*out).l <<= 1) | getbit(itmp,ipm[k],32);
}
}
unsigned long getbit(immense source, int bitno, int nbits) {
if (bitno <= nbits)
return bit[bitno] & source.r ? 1L : 0L;
else
return bit[bitno-nbits] & source.l ? 1L : 0L;
}
void ks(/*immense key, */int n, great * kn) {
int i,j,k,l;
if (n == 1 || n == 2 || n == 9 || n == 16) {
icd.r = (icd.r | ((icd.r & 1L) << 28)) >> 1;
icd.l = (icd.l | ((icd.l & 1L) << 28)) >> 1;
}
else
for (i=1;i<=2;i++) {
icd.r = (icd.r | ((icd.r & 1L) << 28)) >> 1;
icd.l = (icd.l | ((icd.l & 1L) << 28)) >> 1;
}
(*kn).r=(*kn).c=(*kn).l=0;
for (j=16,k=32,l=48; j>=1; j--,k--,l--) {
(*kn).r=((*kn).r <<= 1) | (unsigned short)
getbit(icd,ipc2[j],28);
(*kn).c=((*kn).c <<= 1) | (unsigned short)
getbit(icd,ipc2[k],28);
(*kn).l=((*kn).l <<= 1) | (unsigned short)
getbit(icd,ipc2[l],28);
}
}
void cyfun(unsigned long ir, great k, unsigned long * iout) {
static int iet[49]={0,32,1,2,3,4,5,4,5,6,7,8,9,8,9,
10,11,12,13,12,13,14,15,16,17,16,17,18,19,
20,21,20,21,22,23,24,25,24,25,26,27,28,29,
28,29,30,31,32,1};
static int ipp[33]={0,16,7,20,21,29,12,28,17,1,15,
23,26,5,18,31,10,2,8,24,14,32,27,3,9,19,13,
30,6,22,11,4,25};
static char is[16][4][9]={
{{0,14,15,10,7,2,12,4,13},{0,0,3,13,13,14,10,13,1},
{0,4,0,13,10,4,9,1,7},{0,15,13,1,3,11,4,6, 2}},
{{0,4,1,0,13,12,1,11,2},{0,15,13,7,8,11,15,0,15},
{0,1,14,6,6,2,14,4,11},{0,12,8,10,15,8,3,11,1}},
{{0,13,8,9,14,4,10,2,8},{0,7,4,0,11,2,4,11,13},
{0,14,7,4,9,1,15,11,4},{0,8,10,13,0,12,2,13,14}},
{{0,1,14,14,3,1,15,14,4},{0,4,7,9,5,12,2,7,8},
{0,8,11,9,0,11,5,13,1},{0,2,1,0,6,7,12,8,7}},
{{0,2,6,6,0,7,9,15,6},{0,14,15,3,6,4,7,4,10},
{0,13,10,8,12,10,2,12,9},{0,4,3,6,10,1,9,1,4}},
{{0,15,11,3,6,10,2,0,15},{0,2,2,4,15,7,12,9,3},
{0,6,4,15,11,13,8,3,12},{0,9,15,9,1,14,5,4,10}},
{{0,11,3,15,9,11,6,8,11},{0,13,8,6,0,13,9,1,7},
{0,2,13,3,7,7,12,7,14},{0,1,4,8,13,2,15,10,8}},
{{0,8,4,5,10,6,8,13,1},{0,1,14,10,3,1,5,10,4},
{0,11,1,0,13,8,3,14,2},{0,7,2,7,8,13,10,7,13}},
{{0,3,9,1,1,8,0,3,10},{0,10,12,2,4,5,6,14,12},
{0,15,5,11,15,15,7,10,0},{0,5,11,4,9,6,11,9,15}},
{{0,10,7,13,2,5,13,12,9},{0,6,0,8,7,0,1,3,5},
{0,12,8,1,1,9,0,15,6},{0,11,6,15,4,15,14,5,12}},
{{0,6,2,12,8,3,3,9,3},{0,12,1,5,2,15,13,5,6},
{0,9,12,2,3,12,4,6,10},{0,3,7,14,5,0,1,0,9}},
{{0,12,13,7,5,15,4,7,14},{0,11,10,14,12,10,14,12,11},
{0,7,6,12,14,5,10,8,13},{0,14,12,3,11,9,7,15,0}},
{{0,5,12,11,11,13,14,5,5},{0,9,6,12,1,3,0,2,0},
{0,3,9,5,5,6,1,0,15},{0,10,0,11,12,10,6,14,3}},
{{0,9,0,4,12,0,7,10,0},{0,5,9,11,10,9,11,15,14},
{0,10,3,10,2,3,13,5,3},{0,0,5,5,7,4,0,2,5}},
{{0,0,5,2,4,14,5,6,12},{0,3,11,15,14,8,3,8,9},
{0,5,2,14,8,0,11,9,5},{0,6,14,2,2,5,8,3,6}},
{{0,7,10,8,15,9,11,1,7},{0,8,5,1,9,6,8,6,2},
{0,0,15,7,4,14,6,2,8},{0,13,9,12,14,3,13,12,11}}};
static char ibin[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
great ie;
unsigned long itmp,ietmp1,ietmp2;
char iec[9];
int jj,irow,icol,iss,j,l,m;
unsigned long *p;
p = bit;
ie.r=ie.c=ie.l=0;
for (j=16,l=32,m=48;j>=1;j--,l--,m--) {
ie.r = (ie.r <<=1) | (p[iet[j]] & ir ? 1 : 0);
ie.c = (ie.c <<=1) | (p[iet[l]] & ir ? 1 : 0);
ie.l = (ie.l <<=1) | (p[iet[m]] & ir ? 1 : 0);
}
ie.r ^= k.r;
ie.c ^= k.c;
ie.l ^= k.l;
ietmp1=((unsigned long) ie.c << 16)+(unsigned long) ie.r;
ietmp2=((unsigned long) ie.l << 8)+((unsigned long) ie.c >> 8);
for (j=1,m=5;j<=4;j++,m++) {
iec[j]=ietmp1 & 0x3fL;
iec[m]=ietmp2 & 0x3fL;
ietmp1 >>= 6;
ietmp2 >>= 6;
}
itmp=0L;
for (jj=8;jj>=1;jj--) {
j =iec[jj];
irow=((j & 0x1) << 1)+((j & 0x20) >> 5);
icol=((j & 0x2) << 2)+(j & 0x4)
+((j & 0x8) >> 2)+((j & 0x10) >> 4);
iss=is[icol][irow][jj];
itmp = (itmp <<= 4) | ibin[iss];
}
*iout=0L;
p = bit;
for (j=32;j>=1;j--)
*iout = (*iout <<= 1) | (p[ipp[j]] & itmp ? 1 : 0);
}
#ifdef WORSTCASE
int value = 1;
#else
int value = 0;
#endif
int main(void)
{
immense inp, key, out;
int newkey, isw;
inp.l = KNOWN_VALUE * 35;
inp.r = KNOWN_VALUE * 26;
key.l = KNOWN_VALUE * 2;
key.r = KNOWN_VALUE * 16;
newkey = value;
isw = value;
des(inp, key, &newkey, isw, &out);
#ifdef TEST
int ok;
if(out.l == 2489587893 && out.r == 1806503748){
ok = 1;
memcpy(out_mem, &ok, sizeof(int));
return 0;
}
ok = 0;
memcpy(out_mem, &ok, sizeof(int));
#endif
return 0;
}

View file

@ -48,10 +48,15 @@ int main () {
uint x = 154023;
uint y = 513239;
swap (&x, &y);
int i;
if(prime(x) && !prime(y))
printf("%d\n", 1);
else
printf("%d\n", 0);
#ifdef TEST
if(prime(x) && !prime(y)){
i = 1;
memcpy(out_mem, &i, sizeof(int));
return 0;
}
i = 0;
memcpy(out_mem, &i, sizeof(int));
#endif
}

View file

@ -47,12 +47,18 @@ int main()
sort(arr, 0, 60-1);
for(int i = 0; i < 60-1; i++){
if(arr[i] > arr[i + 1]){
printf("%d\n", 0);
return 0;
}
}
printf("%d\n", 1);
#ifdef TEST
for(int i = 0; i < 60-1; i++){
if(arr[i] > arr[i + 1]){
int j = 0;
memcpy(out_mem, &j, sizeof(int));
return 0;
}
}
int j = 1;
memcpy(out_mem, &j, sizeof(int));
#endif
return 0;
}

178
riscv/wcet_benchmark/ud.c Normal file
View file

@ -0,0 +1,178 @@
/* MDH WCET BENCHMARK SUITE. File version $Id: ud.c,v 1.4 2005/11/11 10:32:53 ael01 Exp $ */
/*************************************************************************/
/* */
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
/* ===================================================== */
/* Collected and Modified by S.-S. Lim */
/* sslim@archi.snu.ac.kr */
/* Real-Time Research Group */
/* Seoul National University */
/* */
/* */
/* < Features > - restrictions for our experimental environment */
/* */
/* 1. Completely structured. */
/* - There are no unconditional jumps. */
/* - There are no exit from loop bodies. */
/* (There are no 'break' or 'return' in loop bodies) */
/* 2. No 'switch' statements. */
/* 3. No 'do..while' statements. */
/* 4. Expressions are restricted. */
/* - There are no multiple expressions joined by 'or', */
/* 'and' operations. */
/* 5. No library calls. */
/* - All the functions needed are implemented in the */
/* source file. */
/* */
/* */
/*************************************************************************/
/* */
/* FILE: ludcmp.c */
/* SOURCE : Turbo C Programming for Engineering */
/* */
/* DESCRIPTION : */
/* */
/* Simultaneous linear equations by LU decomposition. */
/* The arrays a[][] and b[] are input and the array x[] is output */
/* row vector. */
/* The variable n is the number of equations. */
/* The input arrays are initialized in function main. */
/* */
/* */
/* REMARK : */
/* */
/* EXECUTION TIME : */
/* */
/* */
/*************************************************************************/
/*************************************************************************
* This file:
*
* - Name changed to "ud.c"
* - Modified for use with Uppsala/Paderborn tool
* : doubles changed to int
* : some tests removed
* - Program is much more linear, all loops will run to end
* - Purpose: test the effect of conditional flows
*
*************************************************************************/
/*
** Benchmark Suite for Real-Time Applications, by Sung-Soo Lim
**
** III-4. ludcmp.c : Simultaneous Linear Equations by LU Decomposition
** (from the book C Programming for EEs by Hyun Soon Ahn)
*/
#ifdef TEST
#include "../mini_printf.h"
#include "../posix_c.h"
#else
#include <stdio.h>
#endif
long int a[50][50], b[50], x[50];
int ludcmp(int nmax, int n);
/* static double fabs(double n) */
/* { */
/* double f; */
/* if (n >= 0) f = n; */
/* else f = -n; */
/* return f; */
/* } */
int main()
{
int i, j, nmax = 50, n = 3, chkerr;
long int /* eps, */ w;
/* eps = 1.0e-6; */
/* Init loop */
for(i = 0; i <= n; i++)
{
w = 0.0; /* data to fill in cells */
for(j = 0; j <= n; j++)
{
a[i][j] = (i + 1) + (j + 1);
if(i == j) /* only once per loop pass */
a[i][j] *= 2.0;
w += a[i][j];
}
b[i] = w;
}
/* chkerr = ludcmp(nmax, n, eps); */
chkerr = ludcmp(nmax,n);
#ifdef TEST
for(int i = 0; i <= n; i++){
if(x[i] != 1){
j = 0;
memcpy(out_mem, &j, sizeof(int));
return 0;
}
}
j = 1;
memcpy(out_mem, &j, sizeof(int));
#endif
return 0;
}
int ludcmp(int nmax, int n)
{
int i, j, k;
long w, y[100];
/* if(n > 99 || eps <= 0.0) return(999); */
for(i = 0; i < n; i++)
{
/* if(fabs(a[i][i]) <= eps) return(1); */
for(j = i+1; j <= n; j++) /* triangular loop vs. i */
{
w = a[j][i];
if(i != 0) /* sub-loop is conditional, done
all iterations except first of the
OUTER loop */
for(k = 0; k < i; k++)
w -= a[j][k] * a[k][i];
a[j][i] = w / a[i][i];
}
for(j = i+1; j <= n; j++) /* triangular loop vs. i */
{
w = a[i+1][j];
for(k = 0; k <= i; k++) /* triangular loop vs. i */
w -= a[i+1][k] * a[k][j];
a[i+1][j] = w;
}
}
y[0] = b[0];
for(i = 1; i <= n; i++) /* iterates n times */
{
w = b[i];
for(j = 0; j < i; j++) /* triangular sub loop */
w -= a[i][j] * y[j];
y[i] = w;
}
x[n] = y[n] / a[n][n];
for(i = n-1; i >= 0; i--) /* iterates n times */
{
w = y[i];
for(j = i+1; j <= n; j++) /* triangular sub loop */
w -= a[i][j] * x[j];
x[i] = w / a[i][i] ;
}
return(0);
}