summaryrefslogtreecommitdiff
path: root/test/test_build.py
blob: e13669a2ad51dc6de18d4a562c4c8dd232a16410 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# file    : test/test_build.py
# project : Salis-VM
# author  : Paul Oliver <contact@pauloliver.dev>

# index:
# [section] command lists
# [section] tests null
# [section] tests v1
# [section] tests server & client

import signal

from test_general import SalisTest

class TestBuild(SalisTest):
    SIM_NAME = "test-build.sim"

    # --------------------------------------------------------------------------
    # [section] command lists
    # --------------------------------------------------------------------------
    def commands_new(self, anc, arch):
        return [
            f"./salis.py new -a{anc} -b -f -g{compiler} -H{self.tempdir.name} -n{self.SIM_NAME} {log_trace} {optimized} -s{seed} -u{ui} -v{arch}"
            for compiler in ["clang", "gcc", "tcc"]
            for log_trace in ["", "-l"]
            for optimized in ["", "-o"]
            for seed in [-1, 0, 1234]
            for ui in ["curses", "daemon"]
        ]

    def commands_load(self):
        return [
            f"./salis.py load -b -g{compiler} -H{self.tempdir.name} -n{self.SIM_NAME} {log_trace} {optimized} -u{ui}"
            for compiler in ["clang", "gcc", "tcc"]
            for log_trace in ["", "-l"]
            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{self.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} -G{cpp_compiler} {optimized}"
            for c_compiler, cpp_compiler in [("clang", "clang++"), ("gcc", "g++")]
            for optimized in ["", "-o"]
        ]

    # --------------------------------------------------------------------------
    # [section] tests null
    # --------------------------------------------------------------------------
    def test_null_new(self):
        for command in self.commands_new("0123", "null"):
            self.run_subprocess(command)
            self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"])

    def test_null_load(self):
        self.run_subprocess(self.commands_new("0123", "null")[0])
        self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"])

        for command in self.commands_load():
            self.run_subprocess(command)
            self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"])

    # --------------------------------------------------------------------------
    # [section] tests v1
    # --------------------------------------------------------------------------
    def test_v1_new(self):
        for command in self.commands_new("55a", "v1"):
            self.run_subprocess(command)
            self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"])

    def test_v1_load(self):
        self.run_subprocess(self.commands_new("55a", "v1")[0])
        self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"])

        for command in self.commands_load():
            self.run_subprocess(command)
            self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"])

    # --------------------------------------------------------------------------
    # [section] tests server & client
    # --------------------------------------------------------------------------
    def client_test(self):
        with self.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():
                self.run_subprocess(cmd)

            server_proc.send_signal(signal.SIGINT)

    def test_server(self):
        self.run_subprocess(self.commands_new("0123", "null")[0])
        self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"])

        for cmd in self.cmds_server():
            self.run_subprocess(cmd)
            self.assert_files_exist([f"{self.tempdir.name}/{self.SIM_NAME}/opts.json"])

    def test_client_null(self):
        self.run_ui_test("0123", "anc", "null", "test/ui", "null")
        self.client_test()

    def test_client_v1(self):
        self.run_ui_test("55a", "anc", "null", "test/ui", "v1")
        self.client_test()