package org.freertr.user;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.freertr.addr.addrIP;
import org.freertr.cfg.cfgAll;
import org.freertr.enc.enc7bit;
import org.freertr.pipe.pipeProgress;
import org.freertr.serv.servHttp;
import org.freertr.tab.tabGen;
import org.freertr.tab.tabIntMatcher;
import org.freertr.util.bits;
import org.freertr.util.cmds;
import org.freertr.util.logger;
import org.freertr.util.syncInt;
import org.freertr.util.verCore;
import org.freertr.util.version;
/**
* process image tester
*
* @author matecsaba
*/
public class userTester {
/**
* create instance
*/
protected userTester() {
}
/**
* port base
*/
protected final static int portBase = 34000;
/**
* slot increment
*/
protected final static int portSlot = 100;
/**
* changelog separator
*/
protected final static String chgLogSep = "---------------------------------- ";
/**
* style to use
*/
protected final static String htmlStyle = "";
/**
* temporary path
*/
protected String temp = "../binTmp/";
/**
* commands to use
*/
protected cmds cmd;
/**
* reader to use
*/
protected pipeProgress rdr;
/**
* config path
*/
protected String path = "../cfg/";
/**
* discarded tests
*/
protected String discard = "^$";
/**
* test url
*/
protected String url = path;
/**
* slot number
*/
protected int slot = 0;
/**
* worker count
*/
protected int parallel = 0;
/**
* worker delay
*/
protected int paragap = 300;
/**
* persistent file
*/
protected String persistF = null;
/**
* persistent port
*/
protected int persistP = 0;
/**
* persistent config
*/
protected List persistD = null;
/**
* persistent process
*/
protected userTesterPrc persistC = null;
/**
* remote image file
*/
protected String remoteF = null;
/**
* remote image config
*/
protected List remoteD = null;
/**
* remote image address
*/
protected addrIP remoteA = null;
/**
* remote image local
*/
protected addrIP remoteL = null;
/**
* remote image port
*/
protected int remoteP = 0;
/**
* remote image syncer
*/
protected String remoteS = null;
/**
* list of other images
*/
protected final List others = new ArrayList();
/**
* other image 0th parameter
*/
protected String other0;
/**
* list of captures
*/
protected final List capture = new ArrayList();
/**
* write summary
*/
protected boolean summary = false;
/**
* config archive
*/
protected String cfgarch = "./";
/**
* open a window
*/
protected boolean window = false;
/**
* wait after tests
*/
protected boolean wait = false;
/**
* dont exit
*/
protected boolean unexit = false;
/**
* save config
*/
protected boolean config = false;
/**
* generate md files
*/
protected boolean mdfile = false;
/**
* randomize test order
*/
protected boolean randord = false;
/**
* chattyness matcher
*/
protected tabIntMatcher chatty;
/**
* release number
*/
protected String releaseN = "unknown";
/**
* release version
*/
protected String releaseV = "unknown";
/**
* maximum retries
*/
protected int maxTry = 1;
/**
* reapply counter
*/
protected int reapply = 0;
/**
* restart counter
*/
protected int restart = 0;
/**
* delay in ms
*/
protected int predelay = 0;
/**
* delay in ms
*/
protected int postdelay = 0;
/**
* oob base port
*/
protected int oobase = 20001;
/**
* java natives
*/
protected String jvn = "java";
/**
* java parameters
*/
protected String jvp = " XmxZZZm -jar " + version.getFileName();
/**
* beginning to use
*/
protected String beg = "-";
/**
* separator to use
*/
protected final static String sep = " ---------- ";
/**
* needed tests
*/
protected final tabGen needed = new tabGen();
/**
* finished tests
*/
protected final tabGen finished = new tabGen();
/**
* startup time
*/
protected long started;
/**
* failed tests
*/
protected syncInt errored = new syncInt(0);
/**
* retries seen
*/
protected syncInt retries = new syncInt(0);
/**
* tracebacks seend
*/
protected syncInt traces = new syncInt(0);
/**
* list of workers
*/
protected userTesterOne[] workers;
/**
* convert result to string
*
* @param s string
* @return converted string
*/
protected final static String result2string(String s) {
if (s.equals("success")) {
return "ok";
} else {
return "not ok";
}
}
/**
* do the copier work
*
* @param c command to do
* @param m true to move, false to copy
*/
protected final static void doMover(cmds c, boolean m) {
String s = c.word();
String t = c.word();
c.error("moving results " + s + " to " + t);
doMover(c, s, t, ".csv", m);
doMover(c, s, t, ".ftr", m);
doMover(c, s, t, ".html", m);
}
/**
* do the copier work
*
* @param c command to do
* @param s source
* @param t target
* @param e extension
* @param m true to move, false to copy
* @return true on error, false on success
*/
protected final static boolean doMover(cmds c, String s, String t, String e, boolean m) {
s += e;
t += e;
boolean b;
if (m) {
b = userFlash.rename(s, t, true, true);
} else {
b = userFlash.copy(s, t, true);
}
c.error("moved " + s + " to " + t + " error=" + b);
return b;
}
/**
* get one tester
*
* @param slt slot to use
* @return tester created
*/
protected userTesterOne getTester(int slt) {
return new userTesterOne(this, slt);
}
/**
* convert features to list
*
* @param ftr features
* @param mod modifier
* @return converted list
*/
protected final static List features2list(tabGen ftr, int mod) {
List res = new ArrayList();
for (int i = 0; i < ftr.size(); i++) {
String a = ftr.get(i).getter(mod);
if (a == null) {
continue;
}
res.add(a);
}
return res;
}
/**
* add html style
*
* @param l text to update
*/
protected final static void addHtmlStyle(List l) {
l.add(htmlStyle);
}
/**
* do the summary work
*
* @param c command to do
*/
protected void doSummary(cmds c) {
cmd = c;
String target = "rtrp4sum-";
beg = target;
path = "./";
List nams = new ArrayList();
List fils = new ArrayList();
List> lins = new ArrayList>();
for (;;) {
String s = cmd.word();
if (s.length() < 1) {
break;
}
if (s.equals("path")) {
path = cmd.word();
continue;
}
if (s.equals("target")) {
target = cmd.word();
continue;
}
if (s.equals("begin")) {
beg = cmd.word();
continue;
}
if (s.equals("addone")) {
s = cmd.word();
nams.add(s);
s = cmd.word();
fils.add(s);
continue;
}
}
for (int i = 0; i < fils.size(); i++) {
String s = fils.get(i);
s = path + s + ".csv";
cmd.error("reading " + s + " as " + nams.get(i));
List cur = bits.txt2buf(s);
if (cur == null) {
cmd.error("error reading");
return;
}
cur.remove(0);
cur.remove(0);
cur.remove(0);
cur.remove(0);
lins.add(cur);
}
if (lins.size() < 2) {
cmd.error("not enough summary found");
return;
}
int o = lins.get(0).size();
cmd.error("doing " + o + " features");
for (int i = 1; i < lins.size(); i++) {
if (lins.get(i).size() != o) {
cmd.error("mismatching size in " + nams.get(i));
return;
}
}
releaseN = version.headLine;
List url = new ArrayList();
List fil = new ArrayList();
List> res = new ArrayList>();
List tst = new ArrayList();
for (;;) {
if (lins.get(0).size() < 1) {
break;
}
c = new cmds("lin", lins.get(0).remove(0));
List cur = new ArrayList();
url.add(c.word(";"));
fil.add(c.word(";"));
cur.add(result2string(c.word(";")));
tst.add(c.getRemaining());
for (int i = 1; i < lins.size(); i++) {
c = new cmds("lin", lins.get(i).remove(0));
c.word(";");
c.word(";");
cur.add(result2string(c.word(";")));
}
res.add(cur);
}
String a = "url;file";
for (int i = 0; i < lins.size(); i++) {
a += ";" + nams.get(i);
}
a += ";test";
List txt = new ArrayList();
txt.add(a);
a = "-;-;";
for (int i = 0; i < lins.size(); i++) {
a += "-;";
}
a += releaseN;
txt.add(a);
for (o = 0; o < fil.size(); o++) {
a = url.get(o) + ";" + fil.get(o);
List cur = res.get(o);
for (int i = 0; i < lins.size(); i++) {
a += ";" + cur.get(i);
}
a += ";" + tst.get(o);
txt.add(a);
}
bits.buf2txt(true, txt, target + ".csv");
txt = new ArrayList();
txt.add(servHttp.htmlHead);
addHtmlStyle(txt);
txt.add("dataplanes");
txt.add("release: " + releaseN + "
");
txt.add("
");
a = "file | ";
for (int i = 0; i < lins.size(); i++) {
a += "" + nams.get(i) + " | ";
}
a += "test |
";
txt.add(a);
for (o = 0; o < fil.size(); o++) {
a = "" + fil.get(o) + " | ";
List cur = res.get(o);
for (int i = 0; i < lins.size(); i++) {
String s = cur.get(i);
String b;
if (s.length() <= 2) {
b = "good";
} else {
b = "bad";
}
a += "" + s + " | ";
}
a += "" + tst.get(o) + " |
";
txt.add(a);
}
txt.add("