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

goblint / GobPie / 9678350809

26 Jun 2024 10:54AM UTC coverage: 58.518%. First build
9678350809

Pull #72

github

web-flow
Merge 986be0326 into e8d777526
Pull Request #72: Add functional tests

123 of 233 branches covered (52.79%)

Branch coverage included in aggregate %.

128 of 160 new or added lines in 20 files covered. (80.0%)

406 of 671 relevant lines covered (60.51%)

2.74 hits per line

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

0.0
/src/main/java/Main.java
1
import HTTPserver.GobPieHTTPServer;
2
import abstractdebugging.AbstractDebuggingServerLauncher;
3
import abstractdebugging.ResultsService;
4
import analysis.GoblintAnalysis;
5
import api.GoblintService;
6
import api.GoblintServiceLauncher;
7
import api.messages.params.Params;
8
import goblintserver.GoblintConfWatcher;
9
import goblintserver.GoblintServer;
10
import gobpie.GobPieConfReader;
11
import gobpie.GobPieConfiguration;
12
import gobpie.GobPieException;
13
import magpiebridge.GoblintLanguageExtensionHandler;
14
import magpiebridge.GoblintMagpieServer;
15
import magpiebridge.GoblintServerConfiguration;
16
import magpiebridge.ShowCFGCommand;
17
import magpiebridge.core.MagpieServer;
18
import magpiebridge.core.ServerAnalysis;
19
import org.apache.logging.log4j.LogManager;
20
import org.apache.logging.log4j.Logger;
21
import org.eclipse.lsp4j.MessageParams;
22
import org.eclipse.lsp4j.MessageType;
23
import org.eclipse.lsp4j.jsonrpc.messages.Either;
24
import util.FileWatcher;
25

26
import java.io.File;
27
import java.nio.file.Path;
28

29
public class Main {
×
30

31
    private static final String gobPieConfFileName = "gobpie.json";
32

33
    private static final Logger log = LogManager.getLogger(Main.class);
×
34

35
    public static void main(String... args) {
36

37
        GoblintMagpieServer magpieServer = createMagpieServer();
×
38

39
        try {
40
            // Read GobPie configuration file
41
            GobPieConfReader gobPieConfReader = new GobPieConfReader(magpieServer, gobPieConfFileName);
×
42
            GobPieConfiguration gobpieConfiguration = gobPieConfReader.readGobPieConfiguration();
×
43

44
            // Start GoblintServer
45
            GoblintServer goblintServer = startGoblintServer(magpieServer, gobpieConfiguration);
×
46

47
            // Connect GoblintService and read configuration
48
            GoblintService goblintService = connectGoblintService(magpieServer, gobpieConfiguration, goblintServer);
×
49

50
            // Create file watcher for Goblint configuration
NEW
51
            GoblintConfWatcher goblintConfWatcher = getGoblintConfWatcher(magpieServer, goblintService, gobpieConfiguration);
×
52

53
            // Add analysis
NEW
54
            addAnalysis(magpieServer, gobpieConfiguration, goblintServer, goblintService, goblintConfWatcher);
×
55

56
            // Launch magpieServer
57
            magpieServer.configurationDone();
×
58
            log.info("MagpieBridge server launched.");
×
59

NEW
60
            if (args.length > 0 && gobpieConfiguration.abstractDebugging()) {
×
61
                // Launch abstract debugging server
62
                String socketAddress = args[0];
×
63
                launchAbstractDebuggingServer(socketAddress, goblintService);
×
64
                log.info("Abstract debugging server launched on: " + socketAddress);
×
65
            } else {
×
66
                log.info("Abstract debugging server disabled.");
×
67
            }
68
        } catch (GobPieException e) {
×
69
            String message = e.getMessage();
×
70
            String terminalMessage;
71
            if (e.getCause() == null) terminalMessage = message;
×
72
            else terminalMessage = message + " Cause: " + e.getCause().getMessage();
×
73
            forwardErrorMessageToClient(magpieServer, message, terminalMessage);
×
74
        }
×
75

76
    }
×
77

78

79
    /**
80
     * Method for creating and launching MagpieBridge server.
81
     */
82

83
    private static GoblintMagpieServer createMagpieServer() {
84
        // set up configuration for MagpieServer
85
        GoblintServerConfiguration serverConfig = new GoblintServerConfiguration();
×
86
        serverConfig.setUseMagpieHTTPServer(false);
×
87
        //TODO: Track any relevant changes in https://github.com/MagpieBridge/MagpieBridge/issues/88 and update this accordingly.
88
        serverConfig.setLanguageExtensionHandler(new GoblintLanguageExtensionHandler(serverConfig.getLanguageExtensionHandler()));
×
89
        GoblintMagpieServer magpieServer = new GoblintMagpieServer(serverConfig);
×
90
        // launch MagpieServer
91
        // note that the server will not accept messages until configurationDone is called
92
        magpieServer.launchOnStdio();
×
93

94
        return magpieServer;
×
95
    }
96

97

98
    /**
99
     * Starts Goblint server.
100
     *
101
     * @throws GobPieException if running the server start command fails
102
     */
103
    public static GoblintServer startGoblintServer(MagpieServer magpieServer, GobPieConfiguration gobpieConfiguration) {
104
        GoblintServer goblintServer = new GoblintServer(magpieServer, gobpieConfiguration);
×
105
        if (log.isDebugEnabled()) {
×
106
            log.debug("Goblint version info:\n" + goblintServer.checkGoblintVersion());
×
107
        }
108
        goblintServer.startGoblintServer();
×
109

110
        return goblintServer;
×
111
    }
112

113

114
    /**
115
     * Connects the Goblint service to the Goblint server and reads the Goblint configuration file.
116
     *
117
     * @throws GobPieException if connecting fails
118
     */
119
    private static GoblintService connectGoblintService(MagpieServer magpieServer, GobPieConfiguration gobpieConfiguration, GoblintServer goblintServer) {
120
        GoblintServiceLauncher launcher = new GoblintServiceLauncher();
×
121
        GoblintService goblintService = launcher.connect(goblintServer.getGoblintSocket());
×
122

123
        // Read Goblint configurations
NEW
124
        goblintService.read_config(new Params(new File(gobpieConfiguration.goblintConf()).getAbsolutePath()))
×
125
                .exceptionally(ex -> {
×
126
                    String msg = "Goblint was unable to successfully read the configuration: " + ex.getMessage();
×
127
                    magpieServer.forwardMessageToClient(new MessageParams(MessageType.Warning, msg));
×
128
                    log.error(msg);
×
129
                    return null;
×
130
                })
131
                .join();
×
132

133
        return goblintService;
×
134
    }
135

136
    private static GoblintConfWatcher getGoblintConfWatcher(GoblintMagpieServer magpieServer, GoblintService goblintService, GobPieConfiguration gobpieConfiguration) {
NEW
137
        FileWatcher fileWatcher = new FileWatcher(Path.of(gobpieConfiguration.goblintConf()));
×
NEW
138
        return new GoblintConfWatcher(magpieServer, goblintService, gobpieConfiguration, fileWatcher);
×
139
    }
140

141

142
    /**
143
     * Method for creating and adding Goblint analysis to MagpieBridge server.
144
     * <p>
145
     * Creates the GoblintAnalysis classes.
146
     */
147
    private static void addAnalysis(MagpieServer magpieServer, GobPieConfiguration gobpieConfiguration,
148
                                    GoblintServer goblintServer, GoblintService goblintService, GoblintConfWatcher goblintConfWatcher) {
149
        // define language
150
        String language = "c";
×
151

152
        // add analysis to the MagpieServer
NEW
153
        ServerAnalysis serverAnalysis = new GoblintAnalysis(magpieServer, goblintServer, goblintService, gobpieConfiguration, goblintConfWatcher);
×
154
        magpieServer.addAnalysis(Either.forLeft(serverAnalysis), language);
×
155

156
        // add HTTP server for showing CFGs, only if the option is specified in the configuration
157
        if (gobpieConfiguration.showCfg()) {
×
158
            String httpServerAddress = new GobPieHTTPServer(goblintService).start();
×
159
            magpieServer.addHttpServer(httpServerAddress);
×
160
            magpieServer.addCommand("showcfg", new ShowCFGCommand(httpServerAddress));
×
161
        }
162
    }
×
163

164

165
    /**
166
     * Launch abstract debugging server
167
     *
168
     * @throws GobPieException if creating domain socket for server fails
169
     */
170
    private static void launchAbstractDebuggingServer(String socketAddress, GoblintService goblintService) {
171
        ResultsService resultsService = new ResultsService(goblintService);
×
172
        AbstractDebuggingServerLauncher launcher = new AbstractDebuggingServerLauncher(resultsService);
×
173
        launcher.launchOnDomainSocket(socketAddress);
×
174
    }
×
175

176

177
    /**
178
     * Method for forwarding Error messages to MagpieServer.
179
     *
180
     * @param popUpMessage    The message shown on the pop-up message.
181
     * @param terminalMessage The message shown in the terminal.
182
     */
183

184
    private static void forwardErrorMessageToClient(MagpieServer magpieServer, String popUpMessage, String terminalMessage) {
185
        magpieServer.forwardMessageToClient(
×
186
                new MessageParams(MessageType.Error, "Unable to start GobPie extension: " + popUpMessage + " Check the output terminal of GobPie extension for more information.")
187
        );
188
        log.error(terminalMessage);
×
189
    }
×
190

191
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc