summaryrefslogtreecommitdiffstats
path: root/tests/lib/test_grpc.py
blob: 2e292fadc99bbef750e2d75331ba47c5cb616a2e (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
import inspect
import os
import subprocess

import frrtest
import pytest


class TestGRPC(object):
    program = "./test_grpc"

    @pytest.mark.skipif(
        'S["GRPC_TRUE"]=""\n' not in open("../config.status").readlines(),
        reason="GRPC not enabled",
    )
    def test_exits_cleanly(self):
        basedir = os.path.dirname(inspect.getsourcefile(type(self)))
        program = os.path.join(basedir, self.program)
        proc = subprocess.Popen(
            [frrtest.binpath(program)],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
        )
        output, _ = proc.communicate()
        self.exitcode = proc.wait()
        if self.exitcode != 0:
            print("OUTPUT:\n" + output.decode("ascii"))
            raise frrtest.TestExitNonzero(self)