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
|
# file : test/test_general.py
# project : Salis-VM
# author : Paul Oliver <contact@pauloliver.dev>
# index:
# [section] setup/teardown
# [section] file lists
# [section] assertions
# [section] subprocess
import os
import subprocess
import unittest
from tempfile import TemporaryDirectory
class SalisTest(unittest.TestCase):
# --------------------------------------------------------------------------
# [section] setup/teardown
# --------------------------------------------------------------------------
def setUp(self):
self.tempdir = TemporaryDirectory(prefix="salis_test_")
def tearDown(self):
self.tempdir.cleanup()
# --------------------------------------------------------------------------
# [section] file lists
# --------------------------------------------------------------------------
def files_on_new(self, name):
return [
f"{self.tempdir.name}/{name}/evas/evas-{0:016x}",
f"{self.tempdir.name}/{name}/opts.json",
f"{self.tempdir.name}/{name}/{name}",
f"{self.tempdir.name}/{name}/{name}-{0:016x}",
f"{self.tempdir.name}/{name}/{name}.sqlite3",
]
# --------------------------------------------------------------------------
# [section] assertions
# --------------------------------------------------------------------------
def assert_files_exist(self, files):
for file in files:
assert os.path.isfile(file), f"{file} does not exist"
# --------------------------------------------------------------------------
# [section] subprocess
# --------------------------------------------------------------------------
def run_subprocess(self, command):
subprocess.run(command.split(), check=True, stdout=subprocess.DEVNULL)
def run_pipe(self, command):
return subprocess.Popen(command.split(), stdout=subprocess.PIPE, text=True)
def run_ui_test(self, anc, anc_path, ui, ui_path, vm_arch, clones=1, cores=1, mvec_pow=20, name="def.sim", seed=0, data_push_pow=28, sync_pow=20, auto_save_pow=36, **kwargs):
command = f"./salis.py new -a{anc} -A{anc_path} -C{clones} -c{cores} -d{data_push_pow} -f -H{self.tempdir.name} -m{mvec_pow} -n{name} -s{seed} -u{ui} -U{ui_path} -v{vm_arch} -y{sync_pow} -z{auto_save_pow}"
self.run_subprocess(command)
self.assert_files_exist(self.files_on_new(name))
|