aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc/tests/libsamsung-ipc-test.py
blob: 54350132d794a2a4b3b1e03f382a9eb3afaebe43 (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
#!/usr/bin/env python3
#
#  This file is part of libsamsung-ipc.
#
#  Copyright (C) 2020 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
#
#  libsamsung-ipc is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 2 of the License, or
#  (at your option) any later version.
#
#  libsamsung-ipc is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with libsamsung-ipc.  If not, see <http://www.gnu.org/licenses/>.

import os
import re
import sys
import sh

class libsamsung_ipc_test(object):
    def __init__(self):
        srcdir = os.environ.get('srcdir', None)

        command_path = ''
        if srcdir:
            command_path = '.' + os.sep + 'libsamsung-ipc-test'
        # Enable to run tests without automake
        else:
            command_path = os.path.dirname(sys.argv[0]) \
                + os.sep \
                + 'libsamsung-ipc-test'

        if 'VALGRIND' in os.environ:
            self.run = sh.Command(os.environ['VALGRIND'])
            self.run = self.run.bake('-v',
                                     '--log-file=valgrind.%p.log',
                                     '--leak-check=full',
                                     command_path)
        else:
            self.run = sh.Command(command_path)

    def run_all_tests(self):
        output = str(self.run('list-tests')).split(os.linesep)
        # Remove the last line break from the output
        output.remove('')

        # Also Remove the first line from the output: We have an output like
        # that:
        # Available tests:
        #  [list of tests]
        output.pop(0)

        for test_name in output:
            self.run('test', test_name.replace(' ', ''))

def main():
    tests = libsamsung_ipc_test()
    tests.run_all_tests()

if __name__ == '__main__':
    main()