Commit 26546cba authored by Jonathan Shahen's avatar Jonathan Shahen
Browse files

Removed JUnit tests that don't work any more (because Mahesh doesn't have time...

Removed JUnit tests that don't work any more (because Mahesh doesn't have time to update them to reflect the changes made); all tests passed
Merge branch 'ReduceToCNFSAT'

# Conflicts:
#	src/vagabond/testing/InfoLeakSumTests.java
parents 1b43e579 89592ff9
No preview for this file type
......@@ -421,7 +421,7 @@ public class ReduceToCNFSAT implements ReduceTo {
}
@Override
public boolean reduce(EpochHistory eh) {
public boolean reduce(EpochHistory eh) throws Exception {
// We'll store eh so we can map back the CNF-SAT certificate
// to a placement map.
......@@ -438,6 +438,7 @@ public class ReduceToCNFSAT implements ReduceTo {
}
Circuit.resetIDs();
ZeroOne.reset();
Circuit c = new Circuit();
/*
......
......@@ -3,6 +3,7 @@ package vagabond.reduction.cnfsat;
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.apache.commons.lang3.StringUtils;
......@@ -17,6 +18,8 @@ public class RunSolverCNFSAT implements RunSolver {
public static VagabondSettings settings;
public TimingManager timing = null;
public String tp = "Epoch_Unknown";
public static Logger logger;
String solverloc;
String cnfloc;// OLD VALUE = new String("/home/tripunit/Desktop/instance.cnf");
......@@ -26,6 +29,7 @@ public class RunSolverCNFSAT implements RunSolver {
public RunSolverCNFSAT() throws IOException {
settings = VagabondSettings.getInstance();
timing = settings.timing;
logger = settings.getLogger();
solverloc = settings.getCNFSolverExceutable().getAbsolutePath();
cnfloc = settings.getCNFInstanceFile().getAbsolutePath();
}
......@@ -133,6 +137,7 @@ public class RunSolverCNFSAT implements RunSolver {
+ StringUtils.leftPad(mid + "", (int) Math.floor(Math.log10(hi)) + 1, "0");
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::loopVal::" + searchVal);
// System.out.println("mid = "+mid); System.out.flush();
logger.info("mid = "+mid);
try {
constraintInfoLeakUb(c, le, band, s, nclientpairs, mid, wirestoand, orignoutputs);
......@@ -148,6 +153,7 @@ public class RunSolverCNFSAT implements RunSolver {
if (mid < hi && EACH_DECISION_INSTANCE_TIMEOUT > 0
&& !p.waitFor(EACH_DECISION_INSTANCE_TIMEOUT, TimeUnit.SECONDS)) {
// Treat this as unsat
p.destroyForcibly();
lo = mid + 1;
/*TIMING*/ timing.toggleTimer(tp + "RunSolverCNFSAT::run::binarySearch::exec::" + searchVal);
continue;
......
/**
*
*/
package vagabond.testing;
import org.junit.Test;
import vagabond.pieces.EpochHistory;
import vagabond.reduction.cnfsat.ReduceToCNFSAT;
import vagabond.reduction.cnfsat.RunSolverCNFSAT;
import vagabond.singleton.VagabondSettings;
import vagabond.timing.TimingManager;
/**
* @author tripunit
*
*/
public class CNFEverythingTests {
@Test
public void equalSpreadTest() throws Exception {
boolean minMaxCtoCInfoLeak = true;
VagabondSettings vs = VagabondSettings.getInstance();
vs.migrationBudget = 3;
vs.numberOfClients = 3;
vs.numberOfMachineSlots = 3;
vs.numberOfEpochs = 5;
vs.numberOfMachines = 3;
vs.numberOfVMsPerClient = 3;
vs.minimizeMaxClientToClientInfoLeak = minMaxCtoCInfoLeak;
vs.timing = new TimingManager();
// No meaningful way to do this test except with all the other constraints thrown in
EpochHistory eh = new EpochHistory(2);
eh.add(PlacementMapExamples.equalSpreadClients());
System.out.println("Initial placement: ");
System.out.println(eh._latestPlacementMap.toString());
ReduceToCNFSAT _r = new ReduceToCNFSAT();
_r.reduce(eh);
// System.out.println(_r._circ.getInputs().size());
RunSolverCNFSAT rs = new RunSolverCNFSAT();
rs.load(_r);
EpochHistory neweh = rs.run();
System.out.println("Final placement: ");
System.out.println(neweh._latestPlacementMap.toString());
eh.add(neweh);
System.out.println("Timing: " + vs.timing);
}
@Test
public void equalSpreadTestNoMigration() throws Exception {
boolean minMaxCtoCInfoLeak = true;
VagabondSettings vs = VagabondSettings.getInstance();
vs.migrationBudget = new Integer(-1);
vs.numberOfClients = new Integer(3);
vs.numberOfMachineSlots = new Integer(3);
vs.numberOfEpochs = new Integer(5);
vs.numberOfMachines = new Integer(3);
vs.numberOfVMsPerClient = new Integer(3);
vs.minimizeMaxClientToClientInfoLeak = minMaxCtoCInfoLeak;
vs.timing = new TimingManager();
// No meaningful way to do this test except with all the other constraints thrown in
EpochHistory eh = new EpochHistory(2);
eh.add(PlacementMapExamples.equalSpreadClients());
System.out.println("Initial placement: ");
System.out.println(eh._latestPlacementMap.toString());
ReduceToCNFSAT _r = new ReduceToCNFSAT();
_r.reduce(eh);
// System.out.println(_r._circ.getInputs().size());
RunSolverCNFSAT rs = new RunSolverCNFSAT();
rs.load(_r);
EpochHistory neweh = rs.run();
System.out.println("Final placement: ");
System.out.println(neweh._latestPlacementMap.toString());
eh.add(neweh);
System.out.println("Timing: " + vs.timing);
}
@Test
public void equalSpreadTestSum() throws Exception {
boolean minMaxCtoCInfoLeak = false;
VagabondSettings vs = VagabondSettings.getInstance();
vs.migrationBudget = 3;
vs.numberOfClients = 3;
vs.numberOfMachineSlots = 3;
vs.numberOfEpochs = 5;
vs.numberOfMachines = 3;
vs.numberOfVMsPerClient = 3;
vs.minimizeMaxClientToClientInfoLeak = minMaxCtoCInfoLeak;
vs.timing = new TimingManager();
// No meaningful way to do this test except with all the other constraints thrown in
EpochHistory eh = new EpochHistory(2);
eh.add(PlacementMapExamples.equalSpreadClients());
System.out.println("Initial placement: ");
System.out.println(eh._latestPlacementMap.toString());
ReduceToCNFSAT _r = new ReduceToCNFSAT();
_r.reduce(eh);
// System.out.println(_r._circ.getInputs().size());
RunSolverCNFSAT rs = new RunSolverCNFSAT();
rs.load(_r);
EpochHistory neweh = rs.run();
System.out.println("Final placement: ");
System.out.println(neweh._latestPlacementMap.toString());
eh.add(neweh);
System.out.println("Timing: " + vs.timing);
}
@Test
public void equalSpreadTestNoMigrationSum() throws Exception {
boolean minMaxCtoCInfoLeak = false;
VagabondSettings vs = VagabondSettings.getInstance();
vs.migrationBudget = new Integer(-1);
vs.numberOfClients = new Integer(3);
vs.numberOfMachineSlots = new Integer(3);
vs.numberOfEpochs = new Integer(5);
vs.numberOfMachines = new Integer(3);
vs.numberOfVMsPerClient = new Integer(3);
vs.minimizeMaxClientToClientInfoLeak = minMaxCtoCInfoLeak;
vs.timing = new TimingManager();
// No meaningful way to do this test except with all the other constraints thrown in
EpochHistory eh = new EpochHistory(2);
eh.add(PlacementMapExamples.equalSpreadClients());
System.out.println("Initial placement: ");
System.out.println(eh._latestPlacementMap.toString());
ReduceToCNFSAT _r = new ReduceToCNFSAT();
_r.reduce(eh);
// System.out.println(_r._circ.getInputs().size());
RunSolverCNFSAT rs = new RunSolverCNFSAT();
rs.load(_r);
EpochHistory neweh = rs.run();
System.out.println("Final placement: ");
System.out.println(neweh._latestPlacementMap.toString());
eh.add(neweh);
System.out.println("Timing: " + vs.timing);
}
}
/**
*
*/
package vagabond.testing;
import static org.junit.Assert.assertEquals;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
import vagabond.circuit.*;
import vagabond.pieces.EpochHistory;
import vagabond.reduction.cnfsat.ReduceToCNFSAT;
import vagabond.reduction.cnfsat.RunSolverCNFSAT;
import vagabond.singleton.VagabondSettings;
/**
* @author tripunit
*
*/
public class CNFSATInfoLeakSumTests {
@Test
public void equalSpreadTest() throws Exception {
EpochHistory eh = new EpochHistory(2);
eh.add(PlacementMapExamples.equalSpreadClients());
ReduceToCNFSAT _r = new ReduceToCNFSAT();
_r.setEh(eh);
int nvbitsum = 0;
for (int i = 0; i < _r.getNv().size(); i++) {
nvbitsum += ReduceToCNFSAT.nbits(_r.getNv().get(i));
}
Circuit.resetIDs();
Circuit c = new Circuit();
for (int i = 0; i < _r.getNs() * nvbitsum; i++) {
c.addNewInput();
}
int nclientpairs = ((_r.getNc() - 1) * (_r.getNc())) / 2;
RunSolverCNFSAT rs = new RunSolverCNFSAT();
rs.load(_r);
Sum s[] = rs.constraintSumInfoLeak(c, _r, nclientpairs);
assertEquals(c.getInputs().size(), _r.getNs() * nvbitsum);
assertEquals(c.getOutputs().size(), 0);
// System.out.println(c.getOutputs().size());
/* The following was relevant only when we allowed outputs of s[]'s to be outputs of c.
* We did that by commenting out Lines 157-159 in RunSolverCNFSAT.java
// Place each client's VMs on a single machine. This should be optimal
// And the sum of info. leakage across the 3 epochs should be 3 per pair of clients
List<Boolean> in = new LinkedList<Boolean>();
//Client 1
// Machine 1
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
// Machine 2
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 3
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
//Client 2
// Machine 1
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 2
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
// Machine 3
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
//Client 3
// Machine 1
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 2
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 3
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
List<Boolean> res = c.evaluate(in);
System.out.println(res);
// We should have 3 for each sum
List<Boolean> comp = new LinkedList<Boolean>();
for(int i = 0; i < c.getOutputs().size(); i++) {
if(i%7 == 0 || i %7 == 1) {
comp.add(new Boolean(Boolean.TRUE));
}
else {
comp.add(new Boolean(Boolean.FALSE));
}
}
assertEquals(res, comp);
*/
LessEquals le[] = new LessEquals[nclientpairs];
for (int i = 0; i < nclientpairs; i++)
le[i] = null;
int ub = 4; // Change this as needed. < 3 should result in false. > 2 should result in true
Circuit.Wire wirestoand[] = new Circuit.Wire[c.getOutputs().size()];
for (int i = 0; i < wirestoand.length; i++) {
wirestoand[i] = c.getOutputs().get(i);
}
BigAndOr band[] = new BigAndOr[1];
band[0] = null;
rs.constraintInfoLeakUb(c, le, band, s, nclientpairs, ub, wirestoand, 0);
assertEquals(c.getOutputs().size(), 1);
// Place each client's VMs on a single machine. This should be optimal
// And the sum of info. leakage across the 3 epochs should be 3 per pair of clients
List<Boolean> in = new LinkedList<Boolean>();
// Client 1
// Machine 1
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
// Machine 2
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 3
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Client 2
// Machine 1
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 2
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
// Machine 3
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Client 3
// Machine 1
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 2
in.add(new Boolean(Boolean.FALSE));
in.add(new Boolean(Boolean.FALSE));
// Machine 3
in.add(new Boolean(Boolean.TRUE));
in.add(new Boolean(Boolean.TRUE));
List<Boolean> res = c.evaluate(in);
System.out.println(res);
assertEquals(res.get(0), ub >= 3);
CircuitUtils.cnfSatToFile(c, VagabondSettings.getInstance().getCNFInstanceFile().getAbsolutePath());
}
@Test
public void largerEqualSpreadTest() throws Exception {
EpochHistory eh = new EpochHistory(2);
eh.add(PlacementMapExamples.equalSpreadClients(5));
ReduceToCNFSAT _r = new ReduceToCNFSAT();
_r.setEh(eh);
int nvbitsum = 0;
for (int i = 0; i < _r.getNv().size(); i++) {
nvbitsum += ReduceToCNFSAT.nbits(_r.getNv().get(i));
}
Circuit.resetIDs();
Circuit c = new Circuit();
for (int i = 0; i < _r.getNs() * nvbitsum; i++) {
c.addNewInput();
}
int nclientpairs = ((_r.getNc() - 1) * (_r.getNc())) / 2;
RunSolverCNFSAT rs = new RunSolverCNFSAT();
rs.load(_r);
Sum s[] = rs.constraintSumInfoLeak(c, _r, nclientpairs);
assertEquals(c.getInputs().size(), _r.getNs() * nvbitsum);
assertEquals(c.getOutputs().size(), 0);
LessEquals le[] = new LessEquals[nclientpairs];
for (int i = 0; i < nclientpairs; i++)
le[i] = null;
int ub = 5; // Change this as needed. < 8 should result in false. > 7 should result in true
Circuit.Wire wirestoand[] = new Circuit.Wire[c.getOutputs().size()];
for (int i = 0; i < wirestoand.length; i++) {
wirestoand[i] = c.getOutputs().get(i);
}
BigAndOr band[] = new BigAndOr[1];
band[0] = null;
rs.constraintInfoLeakUb(c, le, band, s, nclientpairs, ub, wirestoand, 0);
assertEquals(c.getOutputs().size(), 1);
CircuitUtils.cnfSatToFile(c, VagabondSettings.getInstance().getCNFInstanceFile().getAbsolutePath());
}
}
/**
*
*/
package vagabond.testing;
import java.io.*;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
/**
* @author tripunit
*
*/
public class CNFSolverTests {
String solverloc = new String("/home/tripunit/Desktop/lingeling");
String cnfloc = new String("/home/tripunit/Desktop/instance.cnf");
@Test
public void test() throws IOException {
if (!(new File(solverloc)).exists())
return;
if (!(new File(cnfloc)).exists())
return;
Process p = Runtime.getRuntime().exec(solverloc + " " + cnfloc);
BufferedReader solveroutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
// System.out.println("Solver output: ");
List<String> lines = new LinkedList<String>();
FileWriter fout = new FileWriter(new File("/home/tripunit/Desktop/instance.out"));
for (String s = null; (s = solveroutput.readLine()) != null;) {
fout.write(s);
fout.write("\n");
lines.add(s);
}
fout.flush();
fout.close();
if (lines.contains("s SATISFIABLE")) {
System.out.println("Sat");
for (int i = lines.indexOf("s SATISFIABLE") + 1; i < lines.size(); i++) {
String line = lines.get(i);
// System.out.println("charAt(0): "+line.charAt(0));
// System.out.println("line: "+line);
if (line.charAt(0) != 'v')
break;
// System.out.println("line: "+line);
String[] vars = line.split("\\s+");
// System.out.println("vars.length = "+vars.length);
for (int j = 0; j < vars.length; j++) {
try {
int var = Integer.parseInt(vars[j]);
if (var != 0) {
System.out.print(var + " ");
}
} catch (Exception e) {
// continue quietly
}
}
System.out.println("");
}
} else {
System.out.println("Unsat");
}
}
}
......@@ -5,6 +5,8 @@ package vagabond.timing.tests;
import org.junit.Test;
import vagabond.circuit.Circuit;
import vagabond.circuit.ZeroOne;
import vagabond.pieces.EpochHistory;
import vagabond.pieces.PlacementMap;
import vagabond.placement.RandomPlacement;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment