Skip to content
Snippets Groups Projects
Commit 80504351 authored by ben.franksen's avatar ben.franksen
Browse files

test: convert more of the test programs to use test framework

parent 670b4009
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,10 @@ SNCFLAGS_DEFAULT += +m -i
SNCFLAGS_vxWorks += -nil-
# Sequence programs and/or object files to create
TESTPROD += declarations
TESTPROD += local
TESTPROD += pvPutAsync
TESTPROD += pvSync
TESTPROD += sncDelay
TESTPROD += sncEntry
TESTPROD += sncEntryOpte
......@@ -18,23 +22,23 @@ TESTPROD += sncEntryVar
TESTPROD += sncExitOptx
TESTPROD += sncOptt
TESTPROD += sncOpttVar
TESTPROD += assign
TESTPROD += change
TESTPROD += declarations
TESTPROD += local
TESTPROD += stop
TESTPROD += subscript
TESTPROD += syncq
TESTPROD += pvSync
TESTPROD += pvPutAsync
TESTPROD += array
TESTPROD += stop
TESTPROD += userfunc
TESTPROD += race
REGRESSION_TESTS_WITH_DB += bittypes
REGRESSION_TESTS_WITH_DB += eftest
REGRESSION_TESTS_WITH_DB += norace
REGRESSION_TESTS_WITH_DB += pvGet
REGRESSION_TESTS_WITH_DB += bittypes
# uncomment this test to see race
# fail (safe mode off)
REGRESSION_TESTS_WITH_DB += race
REGRESSION_TESTS_WITHOUT_DB += array
REGRESSION_TESTS_WITHOUT_DB += assign
REGRESSION_TESTS_WITHOUT_DB += change
REGRESSION_TESTS_WITHOUT_DB += safeMonitor
REGRESSION_TESTS += $(REGRESSION_TESTS_WITHOUT_DB)
......@@ -72,3 +76,5 @@ include $(TOP)/configure/RULES
%.t: %$(EXE)
@$(RM) $@
@$(PERL) ../makeTestfile.pl $@ $* $<
norace.o race.o: ../raceCommon.st
program array
%%#include <stdlib.h>
%%#include "epicsUnitTest.h"
entry {
testPlan(20);
}
ss array {
state init {
......@@ -17,23 +22,23 @@ ss array {
&a4a5s[3]
};
assign a4a5s to {};
entry {
when () {
int i, j;
for (i = 0; i < 4; i++) {
printf("\n");
for (j = 0; j < 5; j++) {
printf(" %s=", a4a5s[i][j]);
printf("%s", (*a4ps[i])[j]);
testOk(a4a5s[i][j] == (*a4ps[i])[j],
"a4a5s[%d][%d]=%s==%s=(*a4ps[%d])[%d])",
i, j, a4a5s[i][j], (*a4ps[i])[j], i, j);
}
}
printf("\n");
for (i = 0; i < 4; i++) {
printf(" %p", a4ps[i]);
testDiag("a4ps[%d]=%p", i, a4ps[i]);
}
printf("\n");
}
when (delay(1)) {
exit(0);
} state init
} exit
}
}
exit {
testDone();
exit(0);
}
program assign_test
%%#include <stdlib.h>
%%#include "epicsUnitTest.h"
int x = 0;
assign x;
foreign pvStatERROR;
#define NTESTS 3
entry {
testPlan(NTESTS);
}
ss w {
int n = 1;
state w {
when (delay(1)) {
when(n > NTESTS) {
} exit
when (delay(0.01)) {
int status;
x = !x;
pvPut(x);
status = pvPut(x);
testOk1(status==pvStatERROR);
n++;
} state w
}
}
......@@ -22,3 +39,8 @@ ss r {
} state yes
}
}
exit {
testDone();
exit(0);
}
/* Test state change statement */
program changetest
%%#include <errlog.h>
%%#include <time.h>
%%#include <stdlib.h>
%%#include "epicsUnitTest.h"
#define MAX_TEST 50
entry {
/* uncomment to get repeatability */
testPlan(MAX_TEST);
/* uncomment for repeatability */
/* srandom(12345); */
}
ss main {
int x = 0;
int n = 1;
state zero {
#if 0
/* uncomment to test rejection of state change in entry block */
......@@ -18,9 +23,13 @@ ss main {
state zero;
}
#endif
when (delay(1)) {
x = time(0) %10 - 5;
errlogPrintf("state=zero, new random x=%d\n", x);
when (n > MAX_TEST) {
} exit
when (delay(0.01)) {
testOk(x == 0, "state=zero, x=%d", x);
x = random() % 10 - 5;
testDiag("new random x=%d", x);
n++;
if (x > 0) {
state pos;
} else if (x < 0) {
......@@ -35,17 +44,28 @@ ss main {
#endif
}
state pos {
when (delay(1)) {
errlogPrintf("state=pos, x=%d\n", x);
if (x == 0) state zero;
when (n > MAX_TEST) {
} exit
when (delay(0.01)) {
testOk(x > 0, "state=pos, x=%d", x);
n++;
x--;
if (x == 0) state zero;
} state pos
}
state neg {
when (delay(1)) {
errlogPrintf("state=neg, x=%d\n", x);
if (x == 0) state zero;
when (n > MAX_TEST) {
} exit
when (delay(0.01)) {
testOk(x < 0, "state=neg, x=%d", x);
n++;
x++;
if (x == 0) state zero;
} state neg
}
}
exit {
testDone();
exit(0);
}
record(stringout,"a") {
field(VAL,"aaaaaaaaaaaaaaaaaaaa")
field(OUT,"x CA")
}
record(stringout,"b") {
field(VAL,"bbbbbbbbbbbbbbbbbbbb")
field(OUT,"x CA")
}
record(stringout,"c") {
field(VAL,"cccccccccccccccccccc")
field(OUT,"x CA")
}
record(stringout,"x") {
}
record(seq,"s") {
field(PINI,"YES")
field(DLY1,"0.05")
field(LNK1,"a.PROC")
field(DLY2,"0.05")
field(LNK2,"b.PROC")
field(DLY3,"0.05")
field(LNK3,"c.PROC")
field(FLNK,"s.PROC CA")
}
program norace
option +s;
#include "raceCommon.st"
program race
/* un-comment the following to demonstrate safe mode */
/* option +s; */
%%#include <stdio.h>
%%#include <assert.h>
%%#include <sched.h>
string x;
assign x to "x";
monitor x;
string y;
assign y to "";
evflag efx;
sync x to efx;
foreign MAX_STRING_SIZE;
ss race1 {
state init {
when () {
x[0] = 0;
} state wait
}
state wait {
string z;
assign z to "";
when (delay(0.001)) {
int j;
for (j=0; j <1000; j++) {
int i;
for (i=0; i<MAX_STRING_SIZE; i++) {
/* sched_yield(); */
if (!x[i]) break;
if (x[i] != x[0]) {
/* this should never be executed */
printf("%c/%c\n",x[0],x[i]);
printf("%s\n",x);
break;
}
}
}
} state wait
when ( (x[0] && x[1] && x[0] != x[1])
|| (y[0] && y[1] && y[0] != y[1])
|| (z[0] && z[1] && z[0] != z[1]) ) {
/* this should never be executed */
printf("%c/%c\n",x[0],x[1]);
} state wait
}
}
ss race2 {
state init {
when () {
x[0] = 0;
} state wait
}
state wait {
when (delay(0.001)) {
int j;
for (j=0; j <1000; j++) {
int i;
for (i=0; i<MAX_STRING_SIZE; i++) {
/* sched_yield(); */
if (!x[i]) break;
if (x[i] != x[0]) {
/* this should never be executed */
printf("%c/%c\n",x[0],x[i]);
printf("%s\n",x);
break;
}
}
}
} state wait
when (delay(0.002)) {
int j;
for (j=0; j <1000; j++) {
int i;
for (i=0; i<MAX_STRING_SIZE; i++) {
/* sched_yield(); */
if (!x[i]) break;
if (x[i] != x[0]) {
/* this should never be executed */
printf("%c/%c\n",x[0],x[i]);
printf("%s\n",x);
break;
}
}
}
} state wait
when (x[0] && x[1] && x[0] != x[1]) {
/* this should never be executed */
printf("%c/%c\n",x[0],x[1]);
} state wait
}
}
ss race3 {
state init {
when () {
x[0] = 0;
} state wait
}
state wait {
string z;
assign z to "";
when (delay(0.001)) {
int j;
for (j=0; j <1000; j++) {
int i;
for (i=0; i<MAX_STRING_SIZE; i++) {
/* sched_yield(); */
if (!x[i]) break;
if (x[i] != x[0]) {
/* this should never be executed */
printf("%c/%c\n",x[0],x[i]);
printf("%s\n",x);
break;
}
}
}
} state wait
when (x[0] && x[1] && x[0] != x[1]) {
/* this should never be executed */
printf("%c/%c\n",x[0],x[1]);
} state wait
}
}
#include "raceCommon.st"
%%#include <stdlib.h>
%%#include "epicsUnitTest.h"
%%#include <stdio.h>
%%#include <assert.h>
%%#include <sched.h>
string x;
assign x to "x";
monitor x;
string y;
assign y to "";
evflag efx;
sync x to efx;
foreign MAX_STRING_SIZE;
entry {
testPlan(0);
testDiag("This test will run for 30 seconds...");
}
ss race1 {
state init {
when () {
x[0] = 0;
} state wait
}
state wait {
string z;
assign z to "";
when (delay(0.001)) {
int j;
for (j=0; j <1000; j++) {
int i;
for (i=0; i<MAX_STRING_SIZE; i++) {
/* sched_yield(); */
if (!x[i]) break;
if (x[i] != x[0]) {
/* this should never be executed */
testFail("x[0]=%c!=%c=x[%d]",x[0],x[i],i);
break;
}
}
}
} state wait
when ( (x[0] && x[1] && x[0] != x[1])
|| (y[0] && y[1] && y[0] != y[1])
|| (z[0] && z[1] && z[0] != z[1]) ) {
/* this should never be executed */
testFail("%c/%c",x[0],x[1]);
} state wait
}
}
ss race2 {
state init {
when () {
x[0] = 0;
} state wait
}
state wait {
when (delay(0.001)) {
int j;
for (j=0; j <1000; j++) {
int i;
for (i=0; i<MAX_STRING_SIZE; i++) {
/* sched_yield(); */
if (!x[i]) break;
if (x[i] != x[0]) {
/* this should never be executed */
testFail("x[0]=%c!=%c=x[%d]",x[0],x[i],i);
break;
}
}
}
} state wait
when (delay(0.002)) {
int j;
for (j=0; j <1000; j++) {
int i;
for (i=0; i<MAX_STRING_SIZE; i++) {
/* sched_yield(); */
if (!x[i]) break;
if (x[i] != x[0]) {
/* this should never be executed */
testFail("x[0]=%c!=%c=x[%d]",x[0],x[i],i);
break;
}
}
}
} state wait
when (x[0] && x[1] && x[0] != x[1]) {
/* this should never be executed */
testFail("x[0]=%c!=%c=x[1]",x[0],x[1]);
} state wait
}
}
ss race3 {
state init {
when () {
x[0] = 0;
} state wait
}
state wait {
string z;
assign z to "";
when (delay(0.001)) {
int j;
for (j=0; j <1000; j++) {
int i;
for (i=0; i<MAX_STRING_SIZE; i++) {
/* sched_yield(); */
if (!x[i]) break;
if (x[i] != x[0]) {
/* this should never be executed */
testFail("x[0]=%c!=%c=x[%d]",x[0],x[i],i);
break;
}
}
}
} state wait
when (x[0] && x[1] && x[0] != x[1]) {
/* this should never be executed */
testFail("x[0]=%c!=%c=x[1]",x[0],x[1]);
} state wait
}
}
ss stop {
state idle {
when (delay(30)) {
} exit
}
}
exit {
testDone();
exit(0);
}
program safeMonitor
%%#include "stdlib.h"
%%#include <stdlib.h>
%%#include "epicsUnitTest.h"
%%#include "epicsThread.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment