-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathBenchmarkTest.class.php
More file actions
120 lines (99 loc) · 6.02 KB
/
BenchmarkTest.class.php
File metadata and controls
120 lines (99 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
use DBA\Agent;
use DBA\Benchmark;
use DBA\CrackerBinary;
use DBA\Factory;
class BenchmarkTest extends HashtopolisTest {
protected $minVersion = "0.13.0";
protected $maxVersion = "master";
protected $runType = HashtopolisTest::RUN_FAST;
private $agent = null;
private $crackerBinary = null;
public function init($version) {
HashtopolisTestFramework::log(HashtopolisTestFramework::LOG_INFO, "Initializing " . $this->getTestName() . "...");
parent::init($version);
}
public function run() {
HashtopolisTestFramework::log(HashtopolisTestFramework::LOG_INFO, "Running " . $this->getTestName() . "...");
$this->createAgentWithHardwareGroup();
$this->testAddToCache();
$this->testGetFromCache();
$this->testDeleteCache();
$this->testTtl();
HashtopolisTestFramework::log(HashtopolisTestFramework::LOG_INFO, $this->getTestName() . " completed");
}
public function getTestName() {
return "Benchmark Test";
}
private function createAgentWithHardwareGroup() {
$agent = new Agent(100, "testAgent", "ebfc57ec-2d6f-4a60-932d-60f127dbb2a8",0, null, "", 0, 1, 0, "TeStToKeN0", "sendProgress",
1683904809, "127.0.0.1", 1, 0, "s3-python-0.7.1");
$agentSameHardware = new Agent(101, "testAgent2", "ebfc57ec-2d6f-4a60-932d-60f127dbb2a9",0, null, "", 0, 1, 0, "TeStToKeN1", "sendProgress",
1683904809, "127.0.0.2", 1, 0, "s3-python-0.7.1");
$agentDifferentHardware = new Agent(102, "testAgent3", "ebfc57ec-2d6f-4a60-932d-60f127dbb2b8",0, null, "", 0, 1, 0, "TeStToKeN2", "sendProgress",
1683904809, "127.0.0.3", 1, 0, "s3-python-0.7.1");
Factory::getAgentFactory()->save($agent);
Factory::getAgentFactory()->save($agentSameHardware);
Factory::getAgentFactory()->save($agentDifferentHardware);
$agent = HardwareGroupUtils::updateHardwareOfAgent("11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz", $agent);
$agentSameHardware = HardwareGroupUtils::updateHardwareOfAgent("11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz", $agentSameHardware);
$agentDifferentHardware = HardwareGroupUtils::updateHardwareOfAgent("10th Gen Intel(R) Core(TM) i6-1165G7 @ 2.80GHz", $agentDifferentHardware);
if ($agent->getHardwareGroupId() != $agentSameHardware->getHardwareGroupId()) {
$this->testFailed("BenchmarkTest:createAgentWithHardwareGroup", "Agents with the same hardware are not added to the same hardwareGroup!
Agent1 hardwaregroup id: " . $agent->getHardwareGroupId() . "Agent2 hardwareGroupId: " . $agentSameHardware->getHardwareGroupId());
}
if ($agent->getHardwareGroupId() == $agentDifferentHardware->getHardwareGroupId()) {
$this->testFailed("BenchmarkTest:createAgentWithHardwareGroup", "Agents with different hardware are added to the same hardwareGroup!
Agent1 hardwaregroup id: " . $agent->getHardwareGroupId() . "Agent2 hardwareGroupId: " . $agentDifferentHardware->getHardwareGroupId());
}
$this->agent = $agent; //save agent for future tests
$this->testSuccess("BenchmarkTest:createAgentWithHardwareGroup");
}
private function testAddToCache(){
$crackerBinary = new CrackerBinary(3036, 1, "6.2.6", "https://hashcat.net/files/hashcat-6.2.6.7z", "hashcat");
Factory::getCrackerBinaryFactory()->save($crackerBinary);
$benchmark = BenchmarkUtils::saveBenchmarkInCache("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), "676:1.78", 1000, "speed", $crackerBinary->getId());
if(!isset($benchmark)) {
$this->testFailed("BenchmarkTest:testAddToCache", "Cannot add benchmark to cache");
} else {
$this->testSuccess("BenchmarkTest:testAddToCache");
}
$this->crackerBinary = $crackerBinary; //save crackerbinary for future tests
}
private function testGetFromCache(){
$benchmark = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), 1000, 1, $this->crackerBinary->getId());
if(!isset($benchmark)) {
$this->testFailed("BenchmarkTest:testGetFromCache", "Cannot get benchmark from cache in normal situation");
} else {
$this->testSuccess("BenchmarkTest:testGetFromCache");
}
$benchmark2 = BenchmarkUtils::getBenchmarkByValue("#HL# -a3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(),1000, 1, $this->crackerBinary->getId());
$benchmark3 = BenchmarkUtils::getBenchmarkByValue("#HL# -d 1 --attack-mode 3 ?l?l?l?l --force", $this->agent->getHardwareGroupId(),1000, 1, $this->crackerBinary->getId());
$benchmark4 = BenchmarkUtils::getBenchmarkByValue("#HL# --force -a3 ?l?l?l?l -d 1", $this->agent->getHardwareGroupId(), 1000, 1, $this->crackerBinary->getId());
if(!isset($benchmark2) || !isset($benchmark3) || !isset($benchmark4)) {
$this->testFailed("BenchmarkTest:testGetFromCache", "Cannot get benchmark from cache with parsing commandline in different formats");
} else {
$this->testSuccess("BenchmarkTest:testGetFromCache");
}
}
private function testDeleteCache() {
BenchmarkUtils::deleteCache();
$benchmark = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), 1000, "1", $this->crackerBinary->getId());
if(isset($benchmark)) {
$this->testFailed("BenchmarkTest:testDeleteCache", "There is still a value in the cache!");
} else {
$this->testSuccess("BenchmarkTest:testDeleteCache");
}
}
private function testTtl() {
$benchmark = new Benchmark(3, "speed", "1234:88","#HL# -a 3 ?u?u?u", 200, $this->agent->getHardwareGroupId(), time() - 10, $this->crackerBinary->getId()); //ttl in the past to test invalid ttl
Factory::getBenchmarkFactory()->save($benchmark);
$found = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?u?u?u", $this->agent->getHardwareGroupId(), 200, 1, $this->crackerBinary->getId());
if($found != null) {
$this->testFailed("BenchmarkTest:testTtl", "benchmark with ttl in the past should not be valid!");
} else {
$this->testSuccess("BenchmarkTest:testTtl");
}
}
}
HashtopolisTestFramework::register(new BenchmarkTest());