• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wirenboard / wb-mqtt-gpio / 93

31 Jul 2026 10:43AM UTC coverage: 44.281% (+4.5%) from 39.772%
93

push

github

web-flow
Use exported vars instead of MAKEFLAGS for coverage options (#82)

493 of 1086 branches covered (45.4%)

875 of 1976 relevant lines covered (44.28%)

3.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.4
/src/gpio_chip.cpp
1
#include "gpio_chip.h"
2
#include "exceptions.h"
3
#include "gpio_counter.h"
4
#include "gpio_line.h"
5
#include "log.h"
6
#include "utils.h"
7

8
#include <wblib/utils.h>
9

10
#include <cassert>
11
#include <fcntl.h>
12
#include <sys/ioctl.h>
13
#include <unistd.h>
14

15
#define LOG(logger) ::logger.Log() << "[gpio chip] "
16

17
using namespace std;
18

19
TGpioChip::TGpioChip(const string& path): Fd(-1), Path(path), Valid(false)
4✔
20
{
21
    Fd = open(Path.c_str(), O_RDWR | O_CLOEXEC);
4✔
22
    if (Fd < 0) {
4✔
23
        Name = Path;
4✔
24
        Label = "disconnected";
4✔
25
        LineCount = 0;
4✔
26
        LOG(Error) << "Unable to open device path '" << Path << "'"
8✔
27
                   << ". Will treat all lines on it as disconnected";
4✔
28
        return;
4✔
29
    }
30

31
    LOG(Debug) << "Open chip at " << Path;
×
32

33
    WB_SCOPE_THROW_EXIT(close(Fd);)
×
34

35
    gpiochip_info info{};
×
36
    int retVal = ioctl(Fd, GPIO_GET_CHIPINFO_IOCTL, &info);
×
37
    if (retVal < 0) {
×
38
        wb_throw(TGpioDriverException, "unable to get GPIO chip info from '" + Path + "'");
×
39
    }
40

41
    Valid = true;
×
42
    LineCount = info.lines;
×
43

44
    Name = info.name;
×
45
    Label = info.label;
×
46

47
    if (Label.empty()) {
×
48
        Label = "unknown";
×
49
    }
50
}
×
51

52
TGpioChip::TGpioChip(): Fd(-1), Path("/dev/null"), Valid(false)
×
53
{
54
    LineCount = 0;
×
55
    Name = "Dummy gpiochip";
×
56
    Label = "unknown";
×
57
}
×
58

59
TGpioChip::~TGpioChip()
4✔
60
{
61
    if (Fd > -1) {
4✔
62
        close(Fd);
×
63
        LOG(Debug) << "Close chip at " << Path;
×
64
    }
65
}
4✔
66

67
vector<PGpioLine> TGpioChip::LoadLines(const TLinesConfig& linesConfigs)
×
68
{
69
    vector<PGpioLine> lines;
×
70

71
    lines.reserve(linesConfigs.size());
×
72

73
    for (const auto& lineConfig: linesConfigs) {
×
74
        auto line = make_shared<TGpioLine>(shared_from_this(), lineConfig);
×
75
        lines.push_back(line);
×
76
    }
×
77

78
    return lines;
×
79
}
×
80

81
void TGpioChip::ThrowErrIfNotValid() const
×
82
{
83
    if (!Valid)
×
84
        wb_throw(TGpioDriverException, "Gpiochip at " + Path + " seems to be not valid");
×
85
}
×
86

87
const string& TGpioChip::GetName() const
×
88
{
89
    return Name;
×
90
}
91

92
const string& TGpioChip::GetLabel() const
×
93
{
94
    return Label;
×
95
}
96

97
const string& TGpioChip::GetPath() const
1✔
98
{
99
    return Path;
1✔
100
}
101

102
uint32_t TGpioChip::GetLineCount() const
×
103
{
104
    ThrowErrIfNotValid();
×
105
    return LineCount;
×
106
}
107

108
uint32_t TGpioChip::GetNumber() const
×
109
{
110
    return Utils::GpioPathToChipNumber(Path);
×
111
}
112

113
string TGpioChip::Describe() const
×
114
{
115
    return "GPIO chip @ '" + Path + "' Name: '" + Name + "' Label: '" + Label + "'";
×
116
}
117

118
int TGpioChip::GetFd() const
×
119
{
120
    ThrowErrIfNotValid();
×
121
    return Fd;
×
122
}
123

124
bool TGpioChip::IsValid() const
6✔
125
{
126
    return Valid;
6✔
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc