aboutsummaryrefslogtreecommitdiff
path: root/test/test_build.py
blob: 96da14e3d6774c61b361e260bce91f3b92f2531d (plain)
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
import os
import signal

from test_general import SalisTest

SIM_NAME = "test-build.sim"

class TestBuild(SalisTest):
    def cmds_new(self, anc, arch):
        return (
            f"./salis.py new -a{anc} -b -f -g{compiler} -H{self.tempdir.name} -n{SIM_NAME} {optimized} -s{seed} -u{ui} -v{arch}"
            for compiler in ["clang", "gcc"]
            for optimized in ["", "-o"]
            for seed in [-1, 0, 1234]
            for ui in ["curses", "daemon"]
        )

    def cmds_new_null(self):
        return self.cmds_new("0123", "null")

    def cmds_new_v1(self):
        return self.cmds_new("55a", "v1")

    def cmds_load(self):
        return (
            f"./salis.py load -b -g{compiler} -H{self.tempdir.name} -n{SIM_NAME} {optimized} -u{ui}"
            for compiler in ["clang", "gcc"]
            for optimized in ["", "-o"]
            for ui in ["curses", "daemon"]
        )

    def cmds_server(self):
        return (
            f"./salis.py server -b -g{compiler} -H{self.tempdir.name} -n{SIM_NAME} {optimized}"
            for compiler in ["clang", "gcc"]
            for optimized in ["", "-o"]
        )

    def cmds_client(self):
        return (
            f"./salis.py client -b -g{c_compiler} {optimized} -x{cxx_compiler}"
            for c_compiler in ["clang", "gcc"]
            for cxx_compiler in ["clang", "gcc"]
            for optimized in ["", "-o"]
        )

    def files_on_build(self):
        return [
            os.path.join(self.tempdir.name, SIM_NAME, "opts.json"),
        ]

    def test_null_new(self):
        for cmd in self.cmds_new_null():
            SalisTest.run_subprocess(cmd)
            self.assert_file_list_exists(self.files_on_build())

    def test_v1_new(self):
        for cmd in self.cmds_new_v1():
            SalisTest.run_subprocess(cmd)
            self.assert_file_list_exists(self.files_on_build())

    def test_null_load(self):
        SalisTest.run_subprocess(next(self.cmds_new_null()))
        self.assert_file_list_exists(self.files_on_build())

        for cmd in self.cmds_load():
            SalisTest.run_subprocess(cmd)
            self.assert_file_list_exists(self.files_on_build())

    def test_v1_load(self):
        SalisTest.run_subprocess(next(self.cmds_new_v1()))
        self.assert_file_list_exists(self.files_on_build())

        for cmd in self.cmds_load():
            SalisTest.run_subprocess(cmd)
            self.assert_file_list_exists(self.files_on_build())

    def test_server(self):
        SalisTest.run_subprocess(next(self.cmds_new_null()))
        self.assert_file_list_exists(self.files_on_build())

        for cmd in self.cmds_server():
            SalisTest.run_subprocess(cmd)
            self.assert_file_list_exists(self.files_on_build())

    @SalisTest.run_ui_test(anc="0123", anc_path="anc", name="def.sim", ui="null", ui_path="test/ui", vm_arch="null")
    def test_client(self):
        with SalisTest.run_pipe(f"./salis.py server -H{self.tempdir.name}") as server_proc:
            for line in server_proc.stdout:
                if "Listening..." in line:
                    break

            for cmd in self.cmds_client():
                SalisTest.run_subprocess(cmd)

            server_proc.send_signal(signal.SIGINT)