-
Notifications
You must be signed in to change notification settings - Fork 245
Benchmark cache #955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Benchmark cache #955
Changes from 50 commits
323b113
2f5cd16
d5885e6
174e791
57483af
6f53747
75cedf4
a5cf430
0c3f561
0c2509b
e06fb1f
f01d790
3a2d0db
588e1ea
6049f50
468a50b
bd7043e
a1e8b7b
df1f34c
99d9aec
31991fd
19c9f4c
8f64838
9b23f5b
d173c1c
4194533
17c8956
cf390fd
579c8f9
164bc95
dec578c
a99be7d
a835fd0
8be58e5
91330df
929350b
973d64d
741a901
a4ec3fc
85ade75
d15498c
ecff047
502dbe1
a1b04d6
2d13640
5b769de
7b31337
864693e
580a08d
3849695
cdcecc3
4798414
5cca11a
5d30ad2
18dbd90
dd03d7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| <?php | ||
|
|
||
| use DBA\Agent; | ||
| use DBA\Benchmark; | ||
| use DBA\Factory; | ||
|
|
||
| class BenchmarkTest extends HashtopolisTest { | ||
| protected $minVersion = "0.13.0"; | ||
| protected $maxVersion = "master"; | ||
| protected $runType = HashtopolisTest::RUN_FAST; | ||
|
|
||
| private $agent = 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(){ | ||
|
|
||
| $benchmark = BenchmarkUtils::saveBenchmarkInCache("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), "676:1.78", 1000, "speed", 1); | ||
|
|
||
| if(!isset($benchmark)) { | ||
| $this->testFailed("BenchmarkTest:testAddToCache", "Cannot add benchmark to cache"); | ||
| } else { | ||
| $this->testSuccess("BenchmarkTest:testAddToCache"); | ||
| } | ||
| } | ||
|
|
||
| private function testGetFromCache(){ | ||
| $benchmark = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?l?l?l?l -d 1 --force", $this->agent->getHardwareGroupId(), 1000, 1, 1); | ||
|
|
||
| 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, 1); | ||
| $benchmark3 = BenchmarkUtils::getBenchmarkByValue("#HL# -d 1 --attack-mode 3 ?l?l?l?l --force", $this->agent->getHardwareGroupId(),1000, 1, 1); | ||
| $benchmark4 = BenchmarkUtils::getBenchmarkByValue("#HL# --force -a3 ?l?l?l?l -d 1", $this->agent->getHardwareGroupId(), 1000, 1, 1); | ||
|
|
||
| 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(1000, "#HL# -a 3 ?l?l?l?l -d 1 --force", 1, "1", 0); | ||
| 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, 1, time() - 10, 1); //ttl in the past to test invalid ttl | ||
| Factory::getBenchmarkFactory()->save($benchmark); | ||
| $found = BenchmarkUtils::getBenchmarkByValue("#HL# -a 3 ?u?u?u", 1, 200, 1, 1); | ||
| 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()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <?php | ||
| use DBA\QueryFilter; | ||
| use DBA\Factory; | ||
| use DBA\OrderFilter; | ||
| use DBA\CrackerBinary; | ||
|
|
||
| require_once(dirname(__FILE__) . "/inc/load.php"); | ||
|
|
||
| if (!Login::getInstance()->isLoggedin()) { | ||
| header("Location: index.php?err=4" . time() . "&fw=" . urlencode($_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'])); | ||
| die(); | ||
| } | ||
|
|
||
| Template::loadInstance("benchmarks/index"); | ||
|
|
||
| AccessControl::getInstance()->checkPermission(DViewControl::AGENTS_VIEW_PERM); | ||
|
|
||
| if (isset($_POST['action']) && CSRF::check($_POST['csrf'])) { | ||
| $benchmarkHandler = new BenchmarkHandler(); | ||
| $benchmarkHandler->handle($_POST['action']); | ||
| if (UI::getNumMessages() == 0) { | ||
| Util::refresh(); | ||
| } | ||
| } | ||
|
|
||
| if (isset($_GET['id'])) { | ||
| //go to detail page | ||
| // Template::loadInstance("benchmark/detail"); | ||
|
||
| $agent = Factory::getAgentFactory()->get($_GET['id']); | ||
| if (!$agent) { | ||
| UI::printError("ERROR", "Agent not found!"); | ||
| } else { | ||
| $qF = new QueryFilter("agentId", $agent->getId(), "="); | ||
|
||
| $benchmarks = Factory::getBenchmarkFactory()->filter([Factory::FILTER => [$qF]]); | ||
| } | ||
| } else { | ||
| $benchmarks = Factory::getBenchmarkFactory()->filter([]); | ||
| } | ||
|
|
||
| $oF = new OrderFilter(CrackerBinary::CRACKER_BINARY_ID, "DESC"); | ||
| $versions = Factory::getCrackerBinaryFactory()->filter([Factory::ORDER => $oF]); | ||
| usort($versions, ["Util", "versionComparisonBinary"]); | ||
|
|
||
| foreach ($benchmarks as $benchmark) { | ||
| //format the devices pretty | ||
| $devices = HardwareGroupUtils::getDevicesFromBenchmark($benchmark); | ||
|
|
||
| $tmp_devices_tuple = array_count_values(explode("\n", $devices)); | ||
| $devices_tuple = array(); | ||
| foreach ($tmp_devices_tuple as $key => $value) { | ||
| $devices_tuple[] = str_replace("*", "  ", sprintf("%'*2d× ", $value) . $key); | ||
| } | ||
| $benchmark->setHardwareGroupId(implode("\n", $devices_tuple)); | ||
|
|
||
| //get the correct cracker binary for the benchmarks | ||
| foreach ($versions as $version) { | ||
| if ($benchmark->getCrackerBinaryId() == $version->getId()) { | ||
|
|
||
| $benchmark->setCrackerBinaryId($version->getBinaryName() . " " . $version->getVersion()); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| UI::add('benchmarks', $benchmarks); | ||
| UI::add('numBenchmarks', sizeof($benchmarks)); | ||
|
|
||
| echo Template::getInstance()->render(UI::getObjects()); | ||
Uh oh!
There was an error while loading. Please reload this page.